aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm
diff options
context:
space:
mode:
authorStephenButtolph <[email protected]>2020-08-12 22:50:17 -0400
committerStephenButtolph <[email protected]>2020-08-12 22:50:17 -0400
commit4945ae1427399d9a0f6b3561306f50f360011613 (patch)
tree77ed83421aa04bc3e423067cfd063f047c586068 /plugin/evm
parent4beccc4f5ddb8a7f7366d036156ec06d7378fa6d (diff)
read blocks with cachingv0.2.8-rc.3
Diffstat (limited to 'plugin/evm')
-rw-r--r--plugin/evm/block.go6
-rw-r--r--plugin/evm/vm.go13
2 files changed, 6 insertions, 13 deletions
diff --git a/plugin/evm/block.go b/plugin/evm/block.go
index eaa78a5..2912d2c 100644
--- a/plugin/evm/block.go
+++ b/plugin/evm/block.go
@@ -50,11 +50,7 @@ func (b *Block) Status() choices.Status {
// Parent implements the snowman.Block interface
func (b *Block) Parent() snowman.Block {
parentID := ids.NewID(b.ethBlock.ParentHash())
- block := &Block{
- id: parentID,
- ethBlock: b.vm.getCachedBlock(parentID),
- vm: b.vm,
- }
+ block := b.vm.getBlock(parentID)
b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", block.ID(), block.Status())
return block
}
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
}