Skip to content

Commit 20fb9b8

Browse files
committed
recon: commit oldBlks' pvData to pvtStore
This CR implements a CommitPvtDataOfOldBlocks() API which takes pvtData for a bunch of blocks and perform the following (i) Update the missingDataEntries, expiryEntries (ii) Store the pvt data This CR also stores an entry named `lastUpdatedOldBlocksList` in the pvtStore which would be used during recovery time to check whether the stateDB is in sync with the pvtStore. FAB-11766 #done Change-Id: I0a98e8b80d1919db8534c15a6a4df4703c045f2b Signed-off-by: senthil <cendhu@gmail.com>
1 parent ec19c71 commit 20fb9b8

File tree

6 files changed

+645
-34
lines changed

6 files changed

+645
-34
lines changed

core/ledger/ledger_interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ type MissingPrivateData struct {
234234
IsEligible bool
235235
}
236236

237+
// MissingPrivateDataList encapsulates a list of
238+
// MissingPrivateData
237239
type MissingPrivateDataList struct {
238240
List []*MissingPrivateData
239241
}
@@ -252,6 +254,7 @@ type BlockPvtData struct {
252254
WriteSets map[uint64]*TxPvtData
253255
}
254256

257+
// Add adds a given missing private data in the MissingPrivateDataList
255258
func (missing *MissingPrivateDataList) Add(txId string, txNum uint64, ns, coll string, isEligible bool) {
256259
missing.List = append(missing.List, &MissingPrivateData{txId, txNum, ns, coll, isEligible})
257260
}
@@ -386,6 +389,7 @@ type CollectionConfigInfo struct {
386389
CommittingBlockNum uint64
387390
}
388391

392+
// Add adds a missing data entry to the MissingPvtDataInfo Map
389393
func (missingPvtDataInfo MissingPvtDataInfo) Add(blkNum, txNum uint64, ns, coll string) {
390394
missingBlockPvtDataInfo, ok := missingPvtDataInfo[blkNum]
391395
if !ok {

core/ledger/pvtdatastorage/kv_encoding.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
eligibleMissingDataKeyPrefix = []byte{4}
2727
ineligibleMissingDataKeyPrefix = []byte{5}
2828
collElgKeyPrefix = []byte{6}
29+
lastUpdatedOldBlocksKey = []byte{7}
2930

3031
nilByte = byte(0)
3132
emptyValue = []byte{}

core/ledger/pvtdatastorage/persistent_msgs_helper.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ func (e *ExpiryData) getOrCreateCollections(ns string) *Collections {
1717
Map: make(map[string]*TxNums),
1818
MissingDataMap: make(map[string]bool)}
1919
e.Map[ns] = collections
20+
} else {
21+
// due to protobuf encoding/decoding, the previously
22+
// initialized map could be a nil now due to 0 length.
23+
// Hence, we need to reinitialize the map.
24+
if collections.Map == nil {
25+
collections.Map = make(map[string]*TxNums)
26+
}
27+
if collections.MissingDataMap == nil {
28+
collections.MissingDataMap = make(map[string]bool)
29+
}
2030
}
21-
2231
return collections
2332
}
2433

core/ledger/pvtdatastorage/store.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ type Store interface {
6565
// collection upgrade transaction and the parameter 'nsCollMap' contains the collections for which the peer
6666
// is now eligible to recieve pvt data
6767
ProcessCollsEligibilityEnabled(committingBlk uint64, nsCollMap map[string][]string) error
68+
// CommitPvtDataOfOldBlocks commits the pvtData (i.e., previously missing data) of old blocks.
69+
// The parameter `blocksPvtData` refers a list of old block's pvtdata which are missing in the pvtstore.
70+
// This call stores an additional entry called `lastUpdatedOldBlocksList` which keeps the exact list
71+
// of updated blocks. This list would be used during recovery process. Once the stateDB is updated with
72+
// these pvtData, the `lastUpdatedOldBlocksList` must be removed. During the peer startup,
73+
// if the `lastUpdatedOldBlocksList` exists, stateDB needs to be updated with the appropriate pvtData.
74+
CommitPvtDataOfOldBlocks(blocksPvtData map[uint64][]*ledger.TxPvtData) error
75+
// GetLastUpdatedOldBlocksList returns the value of `lastUpdatedOldBlocksList`
76+
GetLastUpdatedOldBlocksList() ([]uint64, error)
77+
// ResetLastUpdatedOldBlocksList removes the `lastUpdatedOldBlocksList` entry from the store
78+
ResetLastUpdatedOldBlocksList() error
6879
// IsEmpty returns true if the store does not have any block committed yet
6980
IsEmpty() (bool, error)
7081
// LastCommittedBlockHeight returns the height of the last committed block

0 commit comments

Comments
 (0)