diff options
author | StephenButtolph <[email protected]> | 2020-08-12 22:50:17 -0400 |
---|---|---|
committer | StephenButtolph <[email protected]> | 2020-08-12 22:50:17 -0400 |
commit | 4945ae1427399d9a0f6b3561306f50f360011613 (patch) | |
tree | 77ed83421aa04bc3e423067cfd063f047c586068 /plugin/evm/vm.go | |
parent | 4beccc4f5ddb8a7f7366d036156ec06d7378fa6d (diff) |
read blocks with cachingv0.2.8-rc.3
Diffstat (limited to 'plugin/evm/vm.go')
-rw-r--r-- | plugin/evm/vm.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c22d9d1..6c96870 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -422,10 +422,6 @@ func (vm *VM) updateStatus(blockID ids.ID, status choices.Status) { vm.blockStatusCache.Put(blockID, status) } -func (vm *VM) getCachedBlock(blockID ids.ID) *types.Block { - return vm.chain.GetBlockByHash(blockID.Key()) -} - func (vm *VM) tryBlockGen() error { vm.bdlock.Lock() defer vm.bdlock.Unlock() @@ -474,10 +470,11 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { if statusIntf, ok := vm.blockStatusCache.Get(blockID); ok { status = statusIntf.(choices.Status) } else { - blk := vm.chain.GetBlockByHash(blockID.Key()) - if blk == nil { + wrappedBlk := vm.getBlock(blockID) + if wrappedBlk == nil { return choices.Unknown } + blk := wrappedBlk.ethBlock acceptedBlk := vm.lastAccepted.ethBlock // TODO: There must be a better way of doing this. @@ -488,7 +485,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { highBlock, lowBlock = lowBlock, highBlock } for highBlock.Number().Cmp(lowBlock.Number()) > 0 { - highBlock = vm.chain.GetBlockByHash(highBlock.ParentHash()) + highBlock = vm.getBlock(ids.NewID(highBlock.ParentHash())).ethBlock } if highBlock.Hash() == lowBlock.Hash() { // on the same branch @@ -508,7 +505,7 @@ func (vm *VM) getBlock(id ids.ID) *Block { if blockIntf, ok := vm.blockCache.Get(id); ok { return blockIntf.(*Block) } - ethBlock := vm.getCachedBlock(id) + ethBlock := vm.chain.GetBlockByHash(id.Key()) if ethBlock == nil { return nil } |