From 7da394fd3fb62ed999f69d29ee9e003c2f350782 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 12 Oct 2021 13:49:47 +0300 Subject: [PATCH] core: check MPT node is not requested twice by StateSync module This check prevents infinite loop if something goes wrong with MPT nodes restore process. --- pkg/core/statesync_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/core/statesync_test.go b/pkg/core/statesync_test.go index 9f7ac6bd4..c701c6700 100644 --- a/pkg/core/statesync_test.go +++ b/pkg/core/statesync_test.go @@ -220,16 +220,24 @@ func TestStateSyncModule_Init(t *testing.T) { require.Equal(t, uint32(stateSyncPoint), module.BlockHeight()) // add the rest of MPT nodes and jump to state + alreadyRequested := make(map[util.Uint256]struct{}) for { unknownHashes := module.GetUnknownMPTNodesBatch(1) // restore nodes one-by-one if len(unknownHashes) == 0 { break } + if _, ok := alreadyRequested[unknownHashes[0]]; ok { + t.Fatal("bug: node was requested twice") + } + alreadyRequested[unknownHashes[0]] = struct{}{} + var callbackCalled bool err := bcSpout.GetStateSyncModule().Traverse(unknownHashes[0], func(node mpt.Node, nodeBytes []byte) bool { require.NoError(t, module.AddMPTNodes([][]byte{slice.Copy(nodeBytes)})) + callbackCalled = true return true // add nodes one-by-one }) require.NoError(t, err) + require.True(t, callbackCalled) } // check that module is inactive and statejump is completed