Merge pull request #2802 from nspcc-dev/fix-node-startup-with-broken-contract
Fix node startup with broken contract
This commit is contained in:
commit
5f763a26e7
4 changed files with 8 additions and 10 deletions
|
@ -636,7 +636,7 @@ func initBlockChain(cfg config.Config, log *zap.Logger) (*core.Blockchain, stora
|
||||||
errArgs = append(errArgs, closeErr)
|
errArgs = append(errArgs, closeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil, cli.NewExitError(fmt.Errorf(errText, errArgs), 1)
|
return nil, nil, cli.NewExitError(fmt.Errorf(errText, errArgs...), 1)
|
||||||
}
|
}
|
||||||
return chain, store, nil
|
return chain, store, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,7 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.True(t, strings.Contains(err.Error(), "can't init MPT at height"), 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) {
|
t.Run("failed native Management initialisation", func(t *testing.T) {
|
||||||
ps = newPS(t)
|
ps = newPS(t)
|
||||||
|
|
||||||
|
@ -223,6 +224,7 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) {
|
||||||
require.Error(t, err)
|
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 cache for Management native contract"), err)
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
t.Run("invalid native contract deactivation", func(t *testing.T) {
|
t.Run("invalid native contract deactivation", func(t *testing.T) {
|
||||||
ps = newPS(t)
|
ps = newPS(t)
|
||||||
_, _, _, err := chain.NewMultiWithCustomConfigAndStoreNoCheck(t, func(c *config.ProtocolConfiguration) {
|
_, _, _, err := chain.NewMultiWithCustomConfigAndStoreNoCheck(t, func(c *config.ProtocolConfiguration) {
|
||||||
|
|
|
@ -539,19 +539,13 @@ func (m *Management) InitializeCache(d *dao.Simple) error {
|
||||||
nep17: make(map[util.Uint160]struct{}),
|
nep17: make(map[util.Uint160]struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
var initErr error
|
d.Seek(m.ID, storage.SeekRange{Prefix: []byte{PrefixContract}}, func(k, v []byte) bool {
|
||||||
d.Seek(m.ID, storage.SeekRange{Prefix: []byte{PrefixContract}}, func(_, v []byte) bool {
|
|
||||||
var cs = new(state.Contract)
|
var cs = new(state.Contract)
|
||||||
initErr = stackitem.DeserializeConvertible(v, cs)
|
if stackitem.DeserializeConvertible(v, cs) == nil {
|
||||||
if initErr != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
updateContractCache(cache, cs)
|
updateContractCache(cache, cs)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if initErr != nil {
|
|
||||||
return initErr
|
|
||||||
}
|
|
||||||
d.SetCache(m.ID, cache)
|
d.SetCache(m.ID, cache)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,14 @@ func TestManagement_Initialize(t *testing.T) {
|
||||||
mgmt := newManagement()
|
mgmt := newManagement()
|
||||||
require.NoError(t, mgmt.InitializeCache(d))
|
require.NoError(t, mgmt.InitializeCache(d))
|
||||||
})
|
})
|
||||||
|
/* See #2801
|
||||||
t.Run("invalid contract state", func(t *testing.T) {
|
t.Run("invalid contract state", func(t *testing.T) {
|
||||||
d := dao.NewSimple(storage.NewMemoryStore(), false, false)
|
d := dao.NewSimple(storage.NewMemoryStore(), false, false)
|
||||||
mgmt := newManagement()
|
mgmt := newManagement()
|
||||||
d.PutStorageItem(mgmt.ID, []byte{PrefixContract}, state.StorageItem{0xFF})
|
d.PutStorageItem(mgmt.ID, []byte{PrefixContract}, state.StorageItem{0xFF})
|
||||||
require.Error(t, mgmt.InitializeCache(d))
|
require.Error(t, mgmt.InitializeCache(d))
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManagement_GetNEP17Contracts(t *testing.T) {
|
func TestManagement_GetNEP17Contracts(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue