Merge pull request #3837 from nspcc-dev/fix-native-init

This commit is contained in:
Roman Khimov 2025-03-12 13:35:37 +03:00 committed by GitHub
commit 24a6d842b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -1123,7 +1123,7 @@ func (bc *Blockchain) isHardforkEnabled(hf *config.Hardfork, blockHeight uint32)
hfs := bc.config.Hardforks hfs := bc.config.Hardforks
if hf != nil { if hf != nil {
start, ok := hfs[hf.String()] start, ok := hfs[hf.String()]
if !ok || start < blockHeight { if !ok || start > blockHeight {
return false return false
} }
} }

View file

@ -256,10 +256,10 @@ func (c *ContractMD) HFSpecificContractMD(hf *config.Hardfork) *HFSpecificContra
} }
md, ok := c.mdCache[key] md, ok := c.mdCache[key]
if !ok { 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 { 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 return md
} }

View file

@ -619,8 +619,6 @@ func (m *Management) OnPersist(ic *interop.Context) error {
for _, hf := range config.Hardforks { for _, hf := range config.Hardforks {
if _, ok := activeHFs[hf]; ok && ic.IsHardforkActivation(hf) { if _, ok := activeHFs[hf]; ok && ic.IsHardforkActivation(hf) {
isUpdate = true 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 // 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). // (if there are multiple hardforks with the same enabling height).
break break
@ -635,6 +633,10 @@ func (m *Management) OnPersist(ic *interop.Context) error {
currentActiveHFs = append(currentActiveHFs, hf) currentActiveHFs = append(currentActiveHFs, hf)
} }
} }
// activeIn is not included into the activeHFs list.
if activeIn != nil && activeIn.Cmp(latestHF) > 0 {
latestHF = *activeIn
}
if !(isDeploy || isUpdate) { if !(isDeploy || isUpdate) {
continue continue
} }
@ -677,7 +679,7 @@ func (m *Management) OnPersist(ic *interop.Context) error {
// The rest of activating hardforks also require initialization. // The rest of activating hardforks also require initialization.
for _, hf := range currentActiveHFs { for _, hf := range currentActiveHFs {
if err := native.Initialize(ic, &hf, hfSpecificMD); err != nil { 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)
} }
} }