From 82993dab2b21df6c5ded1a651f7f949de91d1fb5 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 9 Apr 2024 13:31:00 +0300 Subject: [PATCH] core: extend error message for contract state check It will give us a clue on what's wrong with contract states if something unexpected happen. Signed-off-by: Anna Shaleva --- pkg/core/blockchain.go | 7 +++++-- pkg/core/blockchain_neotest_test.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 41179cf43..72039a61c 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -12,6 +12,7 @@ import ( "sync/atomic" "time" + json "github.com/nspcc-dev/go-ordered-json" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config/limits" "github.com/nspcc-dev/neo-go/pkg/core/block" @@ -535,8 +536,10 @@ func (bc *Blockchain) init() error { return fmt.Errorf("failed to check native %s state against autogenerated one: %w", md.Name, err) } if !bytes.Equal(storedCSBytes, autogenCSBytes) { - return fmt.Errorf("native %s: version mismatch (stored contract state differs from autogenerated one), "+ - "try to resynchronize the node from the genesis", md.Name) + storedJ, _ := json.Marshal(storedCS) + autogenJ, _ := json.Marshal(autogenCS) + return fmt.Errorf("native %s: version mismatch for the latest hardfork %s (stored contract state differs from autogenerated one), "+ + "try to resynchronize the node from the genesis: %s vs %s", md.Name, current, string(storedJ), string(autogenJ)) } } diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index 32d5ec93f..de7f157f8 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -269,7 +269,7 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) { _, _, _, err = chain.NewMultiWithCustomConfigAndStoreNoCheck(t, customConfig, cache) require.Error(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("native %s: version mismatch (stored contract state differs from autogenerated one)", nativenames.CryptoLib)), err) + require.True(t, strings.Contains(err.Error(), fmt.Sprintf("native %s: version mismatch for the latest hardfork Cockatrice (stored contract state differs from autogenerated one)", nativenames.CryptoLib)), err) }) t.Run("good", func(t *testing.T) {