aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/block.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-08-19 11:16:35 -0400
committerDeterminant <[email protected]>2020-08-19 11:16:35 -0400
commit315ad2c63fa4879e5a91c3aa013c93f8f4969362 (patch)
treeec625529150a06865221d30daab3e141b0a1d0e3 /plugin/evm/block.go
parent0844c8c6919f6d98ebe8a9501360ef5bc362dff3 (diff)
finish the block verification impl
Diffstat (limited to 'plugin/evm/block.go')
-rw-r--r--plugin/evm/block.go24
1 files changed, 20 insertions, 4 deletions
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
}