core: move natives cache initialisation to a separate method

This commit is contained in:
Anna Shaleva 2022-04-13 14:08:44 +03:00
parent 93fde3b4e6
commit e63d6aeff7

View file

@ -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() {