diff options
author | Dan Laine <[email protected]> | 2020-08-31 15:13:04 -0400 |
---|---|---|
committer | Dan Laine <[email protected]> | 2020-08-31 15:13:04 -0400 |
commit | 3f815d083c8e3ba29267c9a2a36ea124a456e6b6 (patch) | |
tree | 3aaaa675e568cb99681fde98733b899d35c20d4f /plugin | |
parent | 5f9c76b5f4eb5bb08b8d3e3125b223f3737631d3 (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')
-rw-r--r-- | plugin/evm/block.go | 27 | ||||
-rw-r--r-- | plugin/evm/vm.go | 6 |
2 files changed, 24 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) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index e1fdc33..b77e480 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -639,6 +639,12 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { return status } +// SaveBlock persists a block to the database. +// Right now this is a no-op and is only here to satisfy the ChainVM interface. +func (vm *VM) SaveBlock(snowman.Block) error { + return nil +} + func (vm *VM) getBlock(id ids.ID) *Block { if blockIntf, ok := vm.blockCache.Get(id); ok { return blockIntf.(*Block) |