mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-03-13 09:18:34 +00:00
Merge pull request #3837 from nspcc-dev/fix-native-init
This commit is contained in:
commit
24a6d842b5
3 changed files with 8 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -677,7 +679,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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue