From 2fd51cf6b1913233c02d39b05276e1ccc39b17ff Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 4 Jun 2024 18:38:28 +0300 Subject: [PATCH 1/4] native: fix error message on native cache initialization Signed-off-by: Anna Shaleva --- pkg/core/native/management.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 54640a866..52c2a7420 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -677,7 +677,7 @@ func (m *Management) OnPersist(ic *interop.Context) error { // The rest of activating hardforks also require initialization. for _, hf := range currentActiveHFs { if err := native.Initialize(ic, &hf, hfSpecificMD); err != nil { - return fmt.Errorf("initializing %s native contract at HF %d: %w", md.Name, activeIn, err) + return fmt.Errorf("initializing %s native contract at HF %s: %w", md.Name, hf, err) } } From 4a510637be112d374cbbcb9160890411b59208d0 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 4 Jun 2024 18:41:56 +0300 Subject: [PATCH 2/4] interop: improve error message on native cache initialization error Signed-off-by: Anna Shaleva --- pkg/core/interop/context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index ddfeb11e9..c72adbeff 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -256,10 +256,10 @@ func (c *ContractMD) HFSpecificContractMD(hf *config.Hardfork) *HFSpecificContra } md, ok := c.mdCache[key] if !ok { - panic(fmt.Errorf("native contract descriptor cache is not initialized: contract %s, hardfork %s", c.Hash.StringLE(), key)) + panic(fmt.Errorf("native contract descriptor cache is not initialized: contract %s, hardfork %s", c.Name, key)) } if md == nil { - panic(fmt.Errorf("native contract descriptor cache is nil: contract %s, hardfork %s", c.Hash.StringLE(), key)) + panic(fmt.Errorf("native contract descriptor cache is nil: contract %s, hardfork %s", c.Name, key)) } return md } From 210059fff8645e3a22ff4d4e37fa08255df29625 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 4 Jun 2024 18:43:44 +0300 Subject: [PATCH 3/4] native: fix native deploy process It doesn't work for contracts enabled starting from non-nil hardfork: ``` --- FAIL: TestStateroot_GetLatestStateHeight (0.00s) logger.go:146: 2024-06-04T17:08:35.263+0300 INFO initial gas supply is not set or wrong, setting default value {"InitialGASSupply": "52000000"} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO mempool size is not set or wrong, setting default value {"MemPoolSize": 50000} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO P2PNotaryRequestPayloadPool size is not set or wrong, setting default value {"P2PNotaryRequestPayloadPoolSize": 1000} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO MaxBlockSize is not set or wrong, setting default value {"MaxBlockSize": 262144} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO MaxBlockSystemFee is not set or wrong, setting default value {"MaxBlockSystemFee": 900000000000} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO MaxTransactionsPerBlock is not set or wrong, using default value {"MaxTransactionsPerBlock": 512} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO MaxValidUntilBlockIncrement is not set or wrong, using default value {"MaxValidUntilBlockIncrement": 86400} logger.go:146: 2024-06-04T17:08:35.263+0300 INFO Hardforks are not set, using default value logger.go:146: 2024-06-04T17:08:35.266+0300 INFO no storage version found! creating genesis block chain.go:227: Error Trace: /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/neotest/chain/chain.go:227 /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/neotest/chain/chain.go:217 /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/services/stateroot/service_test.go:319 Error: Received unexpected error: onPersist failed: VM has failed: at instruction 0 (SYSCALL): native contract descriptor cache is not initialized: contract c1e14f19c3e60d0b9244d06dd7ba9b113135ec3b, hardfork Default Test: TestStateroot_GetLatestStateHeight FAIL coverage: 28.6% of statements ``` It happens because ActiveIn hardfork wasn't taken into account during `latestHF` computation. This commit also removes the reusage of `activeIn` variable in deploy procedure, it's misleading and not necessary startign from #3444. Signed-off-by: Anna Shaleva --- pkg/core/native/management.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 52c2a7420..0bd36c138 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -619,8 +619,6 @@ func (m *Management) OnPersist(ic *interop.Context) error { for _, hf := range config.Hardforks { if _, ok := activeHFs[hf]; ok && ic.IsHardforkActivation(hf) { isUpdate = true - activation := hf // avoid loop variable pointer exporting. - activeIn = &activation // reuse ActiveIn variable for the initialization hardfork. // Break immediately since native Initialize should be called starting from the first hardfork in a raw // (if there are multiple hardforks with the same enabling height). break @@ -635,6 +633,10 @@ func (m *Management) OnPersist(ic *interop.Context) error { currentActiveHFs = append(currentActiveHFs, hf) } } + // activeIn is not included into the activeHFs list. + if activeIn != nil && activeIn.Cmp(latestHF) > 0 { + latestHF = *activeIn + } if !(isDeploy || isUpdate) { continue } From ee56f736064fd2697dffda122790c3b2cff78740 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 4 Jun 2024 20:48:12 +0300 Subject: [PATCH 4/4] core: fix bug in (bc *Blockchain).isHardforkEnabled This code was never invoked since we had no native contract enabled starting from some hardfork, Notary is the first one. And luckily, we have plenty of tests that fail due to this bug. Signed-off-by: Anna Shaleva --- pkg/core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index b5271b4b4..c9d1a26d5 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1123,7 +1123,7 @@ func (bc *Blockchain) isHardforkEnabled(hf *config.Hardfork, blockHeight uint32) hfs := bc.config.Hardforks if hf != nil { start, ok := hfs[hf.String()] - if !ok || start < blockHeight { + if !ok || start > blockHeight { return false } }