From 1d189fd90c32c2eebc2ef99971222453646fa99a Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 22 Nov 2023 14:12:55 +0300 Subject: [PATCH] Revert "native: ignore decoding errors during cache init" This reverts commit 822722bd2e8ed0b923d704227a06f538db0ab851. Signed-off-by: Anna Shaleva --- pkg/core/blockchain_neotest_test.go | 4 +--- pkg/core/native/management.go | 12 +++++++++--- pkg/core/native/management_test.go | 4 +--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index 877610cd7..32d5ec93f 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -219,7 +219,6 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) { require.Error(t, err) require.True(t, strings.Contains(err.Error(), "can't init MPT at height"), err) }) - /* See #2801 t.Run("failed native Management initialisation", func(t *testing.T) { ps = newPS(t) @@ -234,9 +233,8 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) { _, _, _, err := chain.NewMultiWithCustomConfigAndStoreNoCheck(t, customConfig, cache) require.Error(t, err) - require.True(t, strings.Contains(err.Error(), "can't init cache for Management native contract"), err) + require.True(t, strings.Contains(err.Error(), "can't init natives cache: failed to initialize cache for ContractManagement"), err) }) - */ t.Run("invalid native contract activation", func(t *testing.T) { ps = newPS(t) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index e48609c1c..ed118a22d 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -619,13 +619,19 @@ func (m *Management) InitializeCache(blockHeight uint32, d *dao.Simple) error { nep17: make(map[util.Uint160]struct{}), } - d.Seek(m.ID, storage.SeekRange{Prefix: []byte{PrefixContract}}, func(k, v []byte) bool { + var initErr error + d.Seek(m.ID, storage.SeekRange{Prefix: []byte{PrefixContract}}, func(_, v []byte) bool { var cs = new(state.Contract) - if stackitem.DeserializeConvertible(v, cs) == nil { - updateContractCache(cache, cs) + initErr = stackitem.DeserializeConvertible(v, cs) + if initErr != nil { + return false } + updateContractCache(cache, cs) return true }) + if initErr != nil { + return initErr + } d.SetCache(m.ID, cache) return nil } diff --git a/pkg/core/native/management_test.go b/pkg/core/native/management_test.go index 4184eb593..c8a13b4a5 100644 --- a/pkg/core/native/management_test.go +++ b/pkg/core/native/management_test.go @@ -85,14 +85,12 @@ func TestManagement_Initialize(t *testing.T) { mgmt := newManagement() require.NoError(t, mgmt.InitializeCache(0, d)) }) - /* See #2801 t.Run("invalid contract state", func(t *testing.T) { d := dao.NewSimple(storage.NewMemoryStore(), false) mgmt := newManagement() d.PutStorageItem(mgmt.ID, []byte{PrefixContract}, state.StorageItem{0xFF}) - require.Error(t, mgmt.InitializeCache(d)) + require.Error(t, mgmt.InitializeCache(0, d)) }) - */ } func TestManagement_GetNEP17Contracts(t *testing.T) {