From 01aee7a46974915f535f8a22302028196edee209 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Thu, 10 Sep 2020 00:10:51 -0400 Subject: updated gecko dependency --- plugin/evm/block.go | 8 ++++---- plugin/evm/database.go | 2 +- plugin/evm/export_tx.go | 16 ++++++++-------- plugin/evm/factory.go | 2 +- plugin/evm/import_tx.go | 14 +++++++------- plugin/evm/service.go | 10 +++++----- plugin/evm/static_service.go | 2 +- plugin/evm/tx.go | 16 ++++++++-------- plugin/evm/user.go | 6 +++--- plugin/evm/vm.go | 40 ++++++++++++++++++++-------------------- 10 files changed, 58 insertions(+), 58 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 5c30fe1..cdb26bd 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -10,10 +10,10 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/go-ethereum/rlp" - "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" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/snow/choices" + "github.com/ava-labs/avalanche-go/snow/consensus/snowman" + "github.com/ava-labs/avalanche-go/vms/components/missing" ) // Block implements the snowman.Block interface diff --git a/plugin/evm/database.go b/plugin/evm/database.go index de592e1..1300bbb 100644 --- a/plugin/evm/database.go +++ b/plugin/evm/database.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/go-ethereum/ethdb" - "github.com/ava-labs/gecko/database" + "github.com/ava-labs/avalanche-go/database" ) var ( diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 31b4681..77f4efe 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -10,14 +10,14 @@ import ( "github.com/ava-labs/coreth/core/state" "github.com/ava-labs/go-ethereum/log" - "github.com/ava-labs/gecko/chains/atomic" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow" - "github.com/ava-labs/gecko/utils/crypto" - safemath "github.com/ava-labs/gecko/utils/math" - "github.com/ava-labs/gecko/vms/components/avax" - "github.com/ava-labs/gecko/vms/secp256k1fx" + "github.com/ava-labs/avalanche-go/chains/atomic" + "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/snow" + "github.com/ava-labs/avalanche-go/utils/crypto" + safemath "github.com/ava-labs/avalanche-go/utils/math" + "github.com/ava-labs/avalanche-go/vms/components/avax" + "github.com/ava-labs/avalanche-go/vms/secp256k1fx" ) // UnsignedExportTx is an unsigned ExportTx diff --git a/plugin/evm/factory.go b/plugin/evm/factory.go index 6ae62ae..4fe6047 100644 --- a/plugin/evm/factory.go +++ b/plugin/evm/factory.go @@ -4,7 +4,7 @@ package evm import ( - "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/avalanche-go/ids" ) // ID this VM should be referenced by diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index 35ba8cc..e09f145 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -9,13 +9,13 @@ import ( "github.com/ava-labs/coreth/core/state" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow" - "github.com/ava-labs/gecko/utils/crypto" - "github.com/ava-labs/gecko/utils/math" - "github.com/ava-labs/gecko/vms/components/avax" - "github.com/ava-labs/gecko/vms/secp256k1fx" + "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/snow" + "github.com/ava-labs/avalanche-go/utils/crypto" + "github.com/ava-labs/avalanche-go/utils/math" + "github.com/ava-labs/avalanche-go/vms/components/avax" + "github.com/ava-labs/avalanche-go/vms/secp256k1fx" "github.com/ava-labs/go-ethereum/common" ) diff --git a/plugin/evm/service.go b/plugin/evm/service.go index fdbfd91..2979f46 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -15,11 +15,11 @@ import ( "github.com/ava-labs/coreth" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/gecko/api" - "github.com/ava-labs/gecko/utils/constants" - "github.com/ava-labs/gecko/utils/crypto" - "github.com/ava-labs/gecko/utils/formatting" - "github.com/ava-labs/gecko/utils/json" + "github.com/ava-labs/avalanche-go/api" + "github.com/ava-labs/avalanche-go/utils/constants" + "github.com/ava-labs/avalanche-go/utils/crypto" + "github.com/ava-labs/avalanche-go/utils/formatting" + "github.com/ava-labs/avalanche-go/utils/json" "github.com/ava-labs/go-ethereum/common" "github.com/ava-labs/go-ethereum/common/hexutil" ethcrypto "github.com/ava-labs/go-ethereum/crypto" diff --git a/plugin/evm/static_service.go b/plugin/evm/static_service.go index d3870ca..a379c44 100644 --- a/plugin/evm/static_service.go +++ b/plugin/evm/static_service.go @@ -8,7 +8,7 @@ import ( "encoding/json" "github.com/ava-labs/coreth/core" - "github.com/ava-labs/gecko/utils/formatting" + "github.com/ava-labs/avalanche-go/utils/formatting" ) // StaticService defines the static API services exposed by the evm diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go index 789ce56..70386dd 100644 --- a/plugin/evm/tx.go +++ b/plugin/evm/tx.go @@ -9,14 +9,14 @@ import ( "github.com/ava-labs/coreth/core/state" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow" - "github.com/ava-labs/gecko/utils/codec" - "github.com/ava-labs/gecko/utils/crypto" - "github.com/ava-labs/gecko/utils/hashing" - "github.com/ava-labs/gecko/vms/components/verify" - "github.com/ava-labs/gecko/vms/secp256k1fx" + "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/snow" + "github.com/ava-labs/avalanche-go/utils/codec" + "github.com/ava-labs/avalanche-go/utils/crypto" + "github.com/ava-labs/avalanche-go/utils/hashing" + "github.com/ava-labs/avalanche-go/vms/components/verify" + "github.com/ava-labs/avalanche-go/vms/secp256k1fx" "github.com/ava-labs/go-ethereum/common" ) diff --git a/plugin/evm/user.go b/plugin/evm/user.go index fbf2981..65dbe0c 100644 --- a/plugin/evm/user.go +++ b/plugin/evm/user.go @@ -7,9 +7,9 @@ import ( "errors" "fmt" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/utils/crypto" + "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/utils/crypto" "github.com/ava-labs/go-ethereum/common" ) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index b0073da..7b3d380 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -28,26 +28,26 @@ import ( "github.com/ava-labs/go-ethereum/rpc" geckorpc "github.com/gorilla/rpc/v2" - "github.com/ava-labs/gecko/api/admin" - "github.com/ava-labs/gecko/cache" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow" - "github.com/ava-labs/gecko/snow/choices" - "github.com/ava-labs/gecko/snow/consensus/snowman" - "github.com/ava-labs/gecko/utils/codec" - "github.com/ava-labs/gecko/utils/constants" - "github.com/ava-labs/gecko/utils/crypto" - "github.com/ava-labs/gecko/utils/formatting" - geckojson "github.com/ava-labs/gecko/utils/json" - "github.com/ava-labs/gecko/utils/logging" - "github.com/ava-labs/gecko/utils/timer" - "github.com/ava-labs/gecko/utils/units" - "github.com/ava-labs/gecko/utils/wrappers" - "github.com/ava-labs/gecko/vms/components/avax" - "github.com/ava-labs/gecko/vms/secp256k1fx" - - commonEng "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/avalanche-go/api/admin" + "github.com/ava-labs/avalanche-go/cache" + "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/ids" + "github.com/ava-labs/avalanche-go/snow" + "github.com/ava-labs/avalanche-go/snow/choices" + "github.com/ava-labs/avalanche-go/snow/consensus/snowman" + "github.com/ava-labs/avalanche-go/utils/codec" + "github.com/ava-labs/avalanche-go/utils/constants" + "github.com/ava-labs/avalanche-go/utils/crypto" + "github.com/ava-labs/avalanche-go/utils/formatting" + geckojson "github.com/ava-labs/avalanche-go/utils/json" + "github.com/ava-labs/avalanche-go/utils/logging" + "github.com/ava-labs/avalanche-go/utils/timer" + "github.com/ava-labs/avalanche-go/utils/units" + "github.com/ava-labs/avalanche-go/utils/wrappers" + "github.com/ava-labs/avalanche-go/vms/components/avax" + "github.com/ava-labs/avalanche-go/vms/secp256k1fx" + + commonEng "github.com/ava-labs/avalanche-go/snow/engine/common" ) var ( -- cgit v1.2.3-70-g09d2 From e79850702a6610df73a363a32f9c9bfd4fdfc513 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 11 Sep 2020 00:09:28 -0400 Subject: reduce block cache size --- plugin/evm/vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 7b3d380..073ebd0 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -67,7 +67,7 @@ const ( maxBlockTime = 1000 * time.Millisecond batchSize = 250 maxUTXOsToFetch = 1024 - blockCacheSize = 1 << 17 // 131072 + blockCacheSize = 1 << 10 // 1024 ) const ( -- cgit v1.2.3-70-g09d2 From 288833d594c333af551cb656cfab60ed52054eae Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 11 Sep 2020 13:59:47 -0400 Subject: added accepted status caching --- go.sum | 1 + plugin/evm/block.go | 7 +++- plugin/evm/vm.go | 110 ++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 87 insertions(+), 31 deletions(-) (limited to 'plugin/evm') diff --git a/go.sum b/go.sum index 4f935d9..46dea35 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,7 @@ github.com/aristanetworks/goarista v0.0.0-20200812190859-4cb0e71f3c0e/go.mod h1: github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc= github.com/ava-labs/avalanche-go v0.8.0-beta h1:VdSvj5DKIdzdmK0tk8l1jQIc1m3N7KRTHXTW+9I1LfI= github.com/ava-labs/avalanche-go v0.8.0-beta/go.mod h1:quYojL1hu0ue2glUT1ng28kADs9R94zGdEvfW0/HRg8= +github.com/ava-labs/avalanche-go v0.8.0 h1:aAt4roNkkaQx8jgQeKDvTGqSJ2h++rilBAK/xo/uYqo= github.com/ava-labs/coreth v0.2.5/go.mod h1:pGolKipwq5vGIY2IBBcBkMYrqniXMsS5SBn+BBi4+Js= github.com/ava-labs/coreth v0.2.14-rc.1/go.mod h1:Zhb60GFIB7G5AnUCks0Jo4Rezx/EovL8o+z51aBF1A8= github.com/ava-labs/gecko v0.6.1-rc.1/go.mod h1:TT6uA1BETZpVMR0xiFtE8I5Mv4DULlS+lAL3xuYKnpA= diff --git a/plugin/evm/block.go b/plugin/evm/block.go index cdb26bd..97ffc18 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -30,8 +30,11 @@ func (b *Block) ID() ids.ID { return b.id } func (b *Block) Accept() error { vm := b.vm - vm.ctx.Log.Verbo("Block %s is accepted", b.ID()) - vm.updateStatus(b.ID(), choices.Accepted) + vm.ctx.Log.Verbo("Block %s is accepted", b.id) + vm.updateStatus(b.id, choices.Accepted) + if err := vm.acceptedDB.Put(b.ethBlock.Number().Bytes(), b.id.Bytes()); err != nil { + return err + } tx := vm.getAtomicTx(b.ethBlock) if tx == nil { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 073ebd0..0463112 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -23,14 +23,17 @@ import ( "github.com/ava-labs/coreth/params" "github.com/ava-labs/go-ethereum/common" - ethcrypto "github.com/ava-labs/go-ethereum/crypto" "github.com/ava-labs/go-ethereum/rlp" "github.com/ava-labs/go-ethereum/rpc" + + ethcrypto "github.com/ava-labs/go-ethereum/crypto" + geckorpc "github.com/gorilla/rpc/v2" "github.com/ava-labs/avalanche-go/api/admin" "github.com/ava-labs/avalanche-go/cache" "github.com/ava-labs/avalanche-go/database" + "github.com/ava-labs/avalanche-go/database/prefixdb" "github.com/ava-labs/avalanche-go/ids" "github.com/ava-labs/avalanche-go/snow" "github.com/ava-labs/avalanche-go/snow/choices" @@ -39,7 +42,6 @@ import ( "github.com/ava-labs/avalanche-go/utils/constants" "github.com/ava-labs/avalanche-go/utils/crypto" "github.com/ava-labs/avalanche-go/utils/formatting" - geckojson "github.com/ava-labs/avalanche-go/utils/json" "github.com/ava-labs/avalanche-go/utils/logging" "github.com/ava-labs/avalanche-go/utils/timer" "github.com/ava-labs/avalanche-go/utils/units" @@ -48,6 +50,7 @@ import ( "github.com/ava-labs/avalanche-go/vms/secp256k1fx" commonEng "github.com/ava-labs/avalanche-go/snow/engine/common" + geckojson "github.com/ava-labs/avalanche-go/utils/json" ) var ( @@ -60,6 +63,7 @@ var ( const ( lastAcceptedKey = "snowman_lastAccepted" + acceptedPrefix = "snowman_accepted" ) const ( @@ -157,6 +161,8 @@ type VM struct { networkChan chan<- commonEng.Message newTxPoolHeadChan chan core.NewTxPoolHeadEvent + acceptedDB database.Database + txPoolStabilizedHead common.Hash txPoolStabilizedOk chan struct{} txPoolStabilizedLock sync.Mutex @@ -229,6 +235,8 @@ func (vm *VM) Initialize( return err } + vm.acceptedDB = prefixdb.New([]byte(acceptedPrefix), db) + vm.chainID = g.Config.ChainID vm.txFee = txFee @@ -598,40 +606,56 @@ func (vm *VM) tryBlockGen() error { func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { vm.metalock.Lock() defer vm.metalock.Unlock() - status := choices.Processing if statusIntf, ok := vm.blockStatusCache.Get(blockID); ok { - status = statusIntf.(choices.Status) - } else { - wrappedBlk := vm.getBlock(blockID) - if wrappedBlk == nil { - return choices.Unknown + return statusIntf.(choices.Status) + } + + wrappedBlk := vm.getBlock(blockID) + if wrappedBlk == nil { + return choices.Unknown + } + blk := wrappedBlk.ethBlock + + heightKey := blk.Number().Bytes() + acceptedIDBytes, err := vm.acceptedDB.Get(heightKey) + if err == nil { + if acceptedID, err := ids.ToID(acceptedIDBytes); err != nil { + vm.ctx.Log.Error("snowman-eth: acceptedID bytes didn't match expected value: %s", err) + } else { + if acceptedID.Equals(blockID) { + vm.blockStatusCache.Put(blockID, choices.Accepted) + return choices.Accepted + } + vm.blockStatusCache.Put(blockID, choices.Rejected) + return choices.Rejected } - blk := wrappedBlk.ethBlock - acceptedBlk := vm.lastAccepted.ethBlock - - // TODO: There must be a better way of doing this. - // Traverse up the chain from the lower block until the indices match - highBlock := blk - lowBlock := acceptedBlk - if highBlock.Number().Cmp(lowBlock.Number()) < 0 { - highBlock, lowBlock = lowBlock, highBlock + } + + status := vm.getUncachedStatus(blk) + if status == choices.Accepted { + err := vm.acceptedDB.Put(heightKey, blockID.Bytes()) + if err != nil { + vm.ctx.Log.Error("snowman-eth: failed to write back acceptedID bytes: %s", err) } - for highBlock.Number().Cmp(lowBlock.Number()) > 0 { - parentBlock := vm.getBlock(ids.NewID(highBlock.ParentHash())) - if parentBlock == nil { - vm.blockStatusCache.Put(blockID, choices.Processing) - return choices.Processing + + tempBlock := wrappedBlk + for tempBlock.ethBlock != nil { + parentID := ids.NewID(tempBlock.ethBlock.ParentHash()) + tempBlock = vm.getBlock(parentID) + if tempBlock.ethBlock == nil { + break } - highBlock = parentBlock.ethBlock - } - if highBlock.Hash() == lowBlock.Hash() { // on the same branch - if blk.Number().Cmp(acceptedBlk.Number()) <= 0 { - status = choices.Accepted + heightKey := tempBlock.ethBlock.Number().Bytes() + _, err := vm.acceptedDB.Get(heightKey) + if err == nil { + break + } + + if err := vm.acceptedDB.Put(heightKey, parentID.Bytes()); err != nil { + vm.ctx.Log.Error("snowman-eth: failed to write back acceptedID bytes: %s", err) } - } else { // on different branches - status = choices.Rejected } } @@ -639,6 +663,34 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { return status } +func (vm *VM) getUncachedStatus(blk *types.Block) choices.Status { + acceptedBlk := vm.lastAccepted.ethBlock + + // TODO: There must be a better way of doing this. + // Traverse up the chain from the lower block until the indices match + highBlock := blk + lowBlock := acceptedBlk + if highBlock.Number().Cmp(lowBlock.Number()) < 0 { + highBlock, lowBlock = lowBlock, highBlock + } + for highBlock.Number().Cmp(lowBlock.Number()) > 0 { + parentBlock := vm.getBlock(ids.NewID(highBlock.ParentHash())) + if parentBlock == nil { + return choices.Processing + } + highBlock = parentBlock.ethBlock + } + + if highBlock.Hash() != lowBlock.Hash() { // on different branches + return choices.Rejected + } + // on the same branch + if blk.Number().Cmp(acceptedBlk.Number()) <= 0 { + return choices.Accepted + } + return choices.Processing +} + func (vm *VM) getBlock(id ids.ID) *Block { if blockIntf, ok := vm.blockCache.Get(id); ok { return blockIntf.(*Block) -- cgit v1.2.3-70-g09d2 From 496397e31c5082e20e28a1a2e9c2bbacde5e1deb Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 11 Sep 2020 16:42:52 -0400 Subject: fixed nil pointer --- plugin/evm/vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 0463112..a1224d4 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -643,7 +643,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { for tempBlock.ethBlock != nil { parentID := ids.NewID(tempBlock.ethBlock.ParentHash()) tempBlock = vm.getBlock(parentID) - if tempBlock.ethBlock == nil { + if tempBlock == nil || tempBlock.ethBlock == nil { break } -- cgit v1.2.3-70-g09d2