Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot in latest storer fix #5381

Merged
merged 12 commits into from
Aug 18, 2023
2 changes: 2 additions & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ type SnapshotStatisticsHandler interface {
NewSnapshotStarted()
WaitForSnapshotsToFinish()
AddTrieStats(handler TrieStatisticsHandler, trieType TrieType)
GetSnapshotDuration() int64
GetSnapshotNumNodes() uint64
IsInterfaceNil() bool
}

Expand Down
2 changes: 1 addition & 1 deletion epochStart/bootstrap/disabled/disabledAccountsAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (a *accountsAdapter) CancelPrune(_ []byte, _ state.TriePruningIdentifier) {
}

// SnapshotState -
func (a *accountsAdapter) SnapshotState(_ []byte) {
func (a *accountsAdapter) SnapshotState(_ []byte, _ uint32) {
}

// SetStateCheckpoint -
Expand Down
6 changes: 2 additions & 4 deletions integrationTests/state/stateTrie/stateTrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2331,11 +2331,9 @@ func Test_SnapshotStateRemovesLastSnapshotStartedAfterSnapshotFinished(t *testin
_ = adb.SetSyncer(&mock.AccountsDBSyncerStub{})
rootHash, err := addDataTriesForAccountsStartingWithIndex(0, 1, 1, adb)
assert.Nil(t, err)
err = tsm.PutInEpoch([]byte(common.ActiveDBKey), []byte(common.ActiveDBVal), 0)
assert.Nil(t, err)

adb.SnapshotState(rootHash)
for tsm.IsPruningBlocked() {
adb.SnapshotState(rootHash, 1)
for adb.IsSnapshotInProgress() {
time.Sleep(10 * time.Millisecond)
}

Expand Down
11 changes: 9 additions & 2 deletions integrationTests/state/stateTrieSync/stateTrieSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ func addValuesToDataTrie(t *testing.T, adb state.AccountsAdapter, acc state.User
return acc.GetRootHash()
}

type snapshotWatcher interface {
IsSnapshotInProgress() bool
}

func TestSyncMissingSnapshotNodes(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
Expand Down Expand Up @@ -490,8 +494,11 @@ func testSyncMissingSnapshotNodes(t *testing.T, version int) {

tsm := nRequester.TrieStorageManagers[dataRetriever.UserAccountsUnit.String()]
_ = tsm.PutInEpoch([]byte(common.ActiveDBKey), []byte(common.ActiveDBVal), 0)
nRequester.AccntState.SnapshotState(rootHash)
for tsm.IsPruningBlocked() {
nRequester.AccntState.SnapshotState(rootHash, nRequester.EpochNotifier.CurrentEpoch())
sw, ok := nRequester.AccntState.(snapshotWatcher)
assert.True(t, ok)

for sw.IsSnapshotInProgress() {
time.Sleep(time.Millisecond * 100)
}
_ = nRequester.AccntState.RecreateTrie(rootHash)
Expand Down
4 changes: 2 additions & 2 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,8 @@ func (mp *metaProcessor) updateState(lastMetaBlock data.MetaHeaderHandler, lastM
"rootHash", lastMetaBlock.GetRootHash(),
"prevRootHash", prevMetaBlock.GetRootHash(),
"validatorStatsRootHash", lastMetaBlock.GetValidatorStatsRootHash())
mp.accountsDB[state.UserAccountsState].SnapshotState(lastMetaBlock.GetRootHash())
mp.accountsDB[state.PeerAccountsState].SnapshotState(lastMetaBlock.GetValidatorStatsRootHash())
mp.accountsDB[state.UserAccountsState].SnapshotState(lastMetaBlock.GetRootHash(), lastMetaBlock.GetEpoch())
mp.accountsDB[state.PeerAccountsState].SnapshotState(lastMetaBlock.GetValidatorStatsRootHash(), lastMetaBlock.GetEpoch())
go func() {
metaBlock, ok := lastMetaBlock.(*block.MetaBlock)
if !ok {
Expand Down
5 changes: 3 additions & 2 deletions process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,9 @@ func (sp *shardProcessor) snapShotEpochStartFromMeta(header data.ShardHeaderHand
log.Debug("using scheduled root hash for snapshotting", "schRootHash", schRootHash)
rootHash = schRootHash
}
log.Debug("shard trie snapshot from epoch start shard data", "rootHash", rootHash)
accounts.SnapshotState(rootHash)
epoch := header.GetEpoch()
log.Debug("shard trie snapshot from epoch start shard data", "rootHash", rootHash, "epoch", epoch)
accounts.SnapshotState(rootHash, epoch)
sp.markSnapshotDoneInPeerAccounts()
saveEpochStartEconomicsMetrics(sp.appStatusHandler, metaHdr)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion process/transactionEvaluator/simulationAccountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (r *simulationAccountsDB) CancelPrune(_ []byte, _ state.TriePruningIdentifi
}

// SnapshotState won't do anything as write operations are disabled on this component
func (r *simulationAccountsDB) SnapshotState(_ []byte) {
func (r *simulationAccountsDB) SnapshotState(_ []byte, _ uint32) {
}

// SetStateCheckpoint won't do anything as write operations are disabled on this component
Expand Down
4 changes: 2 additions & 2 deletions process/transactionEvaluator/simulationAccountsDB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestReadOnlyAccountsDB_WriteOperationsShouldNotCalled(t *testing.T) {
CancelPruneCalled: func(_ []byte, _ state.TriePruningIdentifier) {
t.Errorf(failErrMsg)
},
SnapshotStateCalled: func(_ []byte) {
SnapshotStateCalled: func(_ []byte, _ uint32) {
t.Errorf(failErrMsg)
},
SetStateCheckpointCalled: func(_ []byte) {
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestReadOnlyAccountsDB_WriteOperationsShouldNotCalled(t *testing.T) {

simAccountsDB.CancelPrune(nil, state.NewRoot)

simAccountsDB.SnapshotState(nil)
simAccountsDB.SnapshotState(nil, 0)

simAccountsDB.SetStateCheckpoint(nil)

Expand Down