aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-08-20 12:09:32 -0400
committerDeterminant <tederminant@gmail.com>2020-08-20 12:09:32 -0400
commit726ad2214ca0a7e4d165838c531aa0d401524600 (patch)
tree1fb7a76d5caf01648525b864e94a3c720ee9a6ee
parentcb5e141d930e0c245804fe87a2caf4962b8f3c5f (diff)
parent0d2a35293b7aa49d143ce215591104aba1c89388 (diff)
Merge tag 'v0.2.8-rc.6' into ecstasy-transferv0.2.12
-rw-r--r--core/blockchain.go4
-rw-r--r--go.mod2
-rw-r--r--plugin/evm/block.go12
-rw-r--r--plugin/evm/vm.go32
4 files changed, 28 insertions, 22 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 64c2451..6e316c7 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -732,6 +732,8 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
// GetBlockByHash retrieves a block from the database by hash, caching it if found.
func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
number := bc.hc.GetBlockNumber(hash)
if number == nil {
return nil
@@ -742,6 +744,8 @@ func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
hash := rawdb.ReadCanonicalHash(bc.db, number)
if hash == (common.Hash{}) {
return nil
diff --git a/go.mod b/go.mod
index 5ef12a7..c972a38 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/ava-labs/coreth
go 1.14
require (
- github.com/ava-labs/gecko v0.5.7
+ github.com/ava-labs/gecko v0.6.1
github.com/ava-labs/go-ethereum v1.9.3
github.com/cespare/cp v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1
diff --git a/plugin/evm/block.go b/plugin/evm/block.go
index 0779e17..375dc6d 100644
--- a/plugin/evm/block.go
+++ b/plugin/evm/block.go
@@ -13,6 +13,7 @@ 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
@@ -63,13 +64,12 @@ func (b *Block) Status() choices.Status {
// Parent implements the snowman.Block interface
func (b *Block) Parent() snowman.Block {
parentID := ids.NewID(b.ethBlock.ParentHash())
- block := &Block{
- id: parentID,
- ethBlock: b.vm.getCachedBlock(parentID),
- vm: b.vm,
+ if block := b.vm.getBlock(parentID); block != nil {
+ b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, block.Status())
+ return block
}
- b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", block.ID(), block.Status())
- return block
+ b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, choices.Unknown)
+ return &missing.Block{BlkID: parentID}
}
// Verify implements the snowman.Block interface
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index f97de09..08d7bcb 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -62,11 +62,11 @@ const (
)
const (
- minBlockTime = 250 * time.Millisecond
- maxBlockTime = 1000 * time.Millisecond
- batchSize = 250
-
+ minBlockTime = 250 * time.Millisecond
+ maxBlockTime = 1000 * time.Millisecond
+ batchSize = 250
maxUTXOsToFetch = 1024
+ blockCacheSize = 1 << 17 // 131072
)
const (
@@ -303,9 +303,9 @@ func (vm *VM) Initialize(
}
return tx.UnsignedTx.(UnsignedAtomicTx).EVMStateTransfer(state)
})
- vm.blockCache = cache.LRU{Size: 2048}
- vm.blockStatusCache = cache.LRU{Size: 1024}
- vm.blockAtomicInputCache = cache.LRU{Size: 4096}
+ vm.blockCache = cache.LRU{Size: blockCacheSize}
+ vm.blockStatusCache = cache.LRU{Size: blockCacheSize}
+ vm.blockAtomicInputCache = cache.LRU{Size: blockCacheSize}
vm.newBlockChan = make(chan *Block)
vm.networkChan = toEngine
vm.blockDelayTimer = timer.NewTimer(func() {
@@ -553,10 +553,6 @@ func (vm *VM) updateStatus(blockID ids.ID, status choices.Status) {
vm.blockStatusCache.Put(blockID, status)
}
-func (vm *VM) getCachedBlock(blockID ids.ID) *types.Block {
- return vm.chain.GetBlockByHash(blockID.Key())
-}
-
func (vm *VM) tryBlockGen() error {
vm.bdlock.Lock()
defer vm.bdlock.Unlock()
@@ -605,10 +601,11 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status {
if statusIntf, ok := vm.blockStatusCache.Get(blockID); ok {
status = statusIntf.(choices.Status)
} else {
- blk := vm.chain.GetBlockByHash(blockID.Key())
- if blk == nil {
+ wrappedBlk := vm.getBlock(blockID)
+ if wrappedBlk == nil {
return choices.Unknown
}
+ blk := wrappedBlk.ethBlock
acceptedBlk := vm.lastAccepted.ethBlock
// TODO: There must be a better way of doing this.
@@ -619,7 +616,12 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status {
highBlock, lowBlock = lowBlock, highBlock
}
for highBlock.Number().Cmp(lowBlock.Number()) > 0 {
- highBlock = vm.chain.GetBlockByHash(highBlock.ParentHash())
+ parentBlock := vm.getBlock(ids.NewID(highBlock.ParentHash()))
+ if parentBlock == nil {
+ vm.blockStatusCache.Put(blockID, choices.Processing)
+ return choices.Processing
+ }
+ highBlock = parentBlock.ethBlock
}
if highBlock.Hash() == lowBlock.Hash() { // on the same branch
@@ -639,7 +641,7 @@ func (vm *VM) getBlock(id ids.ID) *Block {
if blockIntf, ok := vm.blockCache.Get(id); ok {
return blockIntf.(*Block)
}
- ethBlock := vm.getCachedBlock(id)
+ ethBlock := vm.chain.GetBlockByHash(id.Key())
if ethBlock == nil {
return nil
}