diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 2c36e6fd2..02d930896 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -433,14 +433,9 @@ func (bc *Blockchain) init() error { return fmt.Errorf("can't init MPT at height %d: %w", bHeight, err) } - err = bc.contracts.NEO.InitializeCache(bc, bc.dao) + err = bc.initializeNativeCache(bc.dao) if err != nil { - return fmt.Errorf("can't init cache for NEO native contract: %w", err) - } - - err = bc.contracts.Management.InitializeCache(bc.dao) - if err != nil { - return fmt.Errorf("can't init cache for Management native contract: %w", err) + return fmt.Errorf("can't init natives cache: %w", err) } // Check autogenerated native contracts' manifests and NEFs against the stored ones. @@ -575,15 +570,10 @@ func (bc *Blockchain) jumpToStateInternal(p uint32, stage stateJumpStage) error Root: block.PrevStateRoot, }) - err = bc.contracts.NEO.InitializeCache(bc, bc.dao) + err = bc.initializeNativeCache(bc.dao) if err != nil { - return fmt.Errorf("can't init cache for NEO native contract: %w", err) + return fmt.Errorf("failed to initialize natives cache: %w", err) } - err = bc.contracts.Management.InitializeCache(bc.dao) - if err != nil { - return fmt.Errorf("can't init cache for Management native contract: %w", err) - } - bc.contracts.Designate.InitializeCache() if err := bc.updateExtensibleWhitelist(p); err != nil { return fmt.Errorf("failed to update extensible whitelist: %w", err) @@ -595,6 +585,19 @@ func (bc *Blockchain) jumpToStateInternal(p uint32, stage stateJumpStage) error return nil } +func (bc *Blockchain) initializeNativeCache(d *dao.Simple) error { + err := bc.contracts.NEO.InitializeCache(bc, d) + if err != nil { + return fmt.Errorf("can't init cache for NEO native contract: %w", err) + } + err = bc.contracts.Management.InitializeCache(d) + if err != nil { + return fmt.Errorf("can't init cache for Management native contract: %w", err) + } + bc.contracts.Designate.InitializeCache() + return nil +} + // Run runs chain loop, it needs to be run as goroutine and executing it is // critical for correct Blockchain operation. func (bc *Blockchain) Run() {