From 315ad2c63fa4879e5a91c3aa013c93f8f4969362 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 19 Aug 2020 11:16:35 -0400 Subject: finish the block verification impl --- plugin/evm/block.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'plugin/evm/block.go') diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 9c15834..45a888f 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -61,23 +61,39 @@ func (b *Block) Parent() snowman.Block { // Verify implements the snowman.Block interface func (b *Block) Verify() error { - p := b + vm := b.vm + if b.ethBlock.Hash() == vm.genesisHash { + return nil + } + p := b.Parent() path := []*Block{} + inputs := new(ids.Set) for { if p.Status() == choices.Accepted { break } - path = append(path, p) + if ret, hit := vm.blockAtomicInputCache.Get(p.ID()); hit { + inputs = ret.(*ids.Set) + break + } + path = append(path, p.(*Block)) p = p.Parent().(*Block) } - inputs := new(ids.Set) for i := len(path) - 1; i >= 0; i-- { + inputs_copy := new(ids.Set) p := path[i] - atx := p.vm.getAtomicTx(p.ethBlock) + atx := vm.getAtomicTx(p.ethBlock) inputs.Union(atx.UnsignedTx.(UnsignedAtomicTx).InputUTXOs()) + inputs_copy.Union(*inputs) + vm.blockAtomicInputCache.Put(p.ID(), inputs_copy) } tx := b.vm.getAtomicTx(b.ethBlock) atx := tx.UnsignedTx.(*UnsignedImportTx) + for _, in := range atx.InputUTXOs().List() { + if inputs.Contains(in) { + return errInvalidBlock + } + } if atx.SemanticVerify(b.vm, tx) != nil { return errInvalidBlock } -- cgit v1.2.3