aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/block.go
diff options
context:
space:
mode:
authorDan Laine <[email protected]>2020-08-31 15:13:04 -0400
committerDan Laine <[email protected]>2020-08-31 15:13:04 -0400
commit3f815d083c8e3ba29267c9a2a36ea124a456e6b6 (patch)
tree3aaaa675e568cb99681fde98733b899d35c20d4f /plugin/evm/block.go
parent5f9c76b5f4eb5bb08b8d3e3125b223f3737631d3 (diff)
Change Parent() to retutn parent's ID rather than the block. Add method parentBlock() to get parent block. Add SaveBlock no-op method to meet new ChainVM interfacev0.2.14
Diffstat (limited to 'plugin/evm/block.go')
-rw-r--r--plugin/evm/block.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/plugin/evm/block.go b/plugin/evm/block.go
index 5c30fe1..a0a903b 100644
--- a/plugin/evm/block.go
+++ b/plugin/evm/block.go
@@ -12,8 +12,6 @@ import (
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/choices"
- "github.com/ava-labs/gecko/snow/consensus/snowman"
- "github.com/ava-labs/gecko/vms/components/missing"
)
// Block implements the snowman.Block interface
@@ -62,14 +60,19 @@ func (b *Block) Status() choices.Status {
}
// Parent implements the snowman.Block interface
-func (b *Block) Parent() snowman.Block {
+func (b *Block) Parent() ids.ID {
+ return ids.NewID(b.ethBlock.ParentHash())
+}
+
+// ParentBlock returns [b]'s parent
+func (b *Block) parentBlock() (*Block, error) {
parentID := ids.NewID(b.ethBlock.ParentHash())
if block := b.vm.getBlock(parentID); block != nil {
b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, block.Status())
- return block
+ return block, nil
}
b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, choices.Unknown)
- return &missing.Block{BlkID: parentID}
+ return nil, fmt.Errorf("couldn't find block %s", parentID)
}
// Verify implements the snowman.Block interface
@@ -92,19 +95,25 @@ func (b *Block) Verify() error {
if b.ethBlock.Hash() == vm.genesisHash {
return nil
}
- p := b.Parent()
+ p, err := b.parentBlock()
+ if err != nil {
+ return fmt.Errorf("couldn't get %s, parent of %s", b.Parent(), p.ID())
+ }
path := []*Block{}
inputs := new(ids.Set)
for {
- if p.Status() == choices.Accepted || p.(*Block).ethBlock.Hash() == vm.genesisHash {
+ if p.Status() == choices.Accepted || p.ethBlock.Hash() == vm.genesisHash {
break
}
if ret, hit := vm.blockAtomicInputCache.Get(p.ID()); hit {
inputs = ret.(*ids.Set)
break
}
- path = append(path, p.(*Block))
- p = p.Parent().(*Block)
+ path = append(path, p)
+ p, err = p.parentBlock()
+ if err != nil {
+ return fmt.Errorf("couldn't get %s, parent of %s", p.Parent(), p.ID())
+ }
}
for i := len(path) - 1; i >= 0; i-- {
inputsCopy := new(ids.Set)