aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/vm.go
diff options
context:
space:
mode:
authorAaron Buchwald <[email protected]>2020-12-14 14:58:15 -0500
committerAaron Buchwald <[email protected]>2020-12-14 14:58:15 -0500
commit3af0238046fe8d2f12dae0155087503f92375e34 (patch)
tree4e40aeb6d25b7a30dc0bab8ac4a35186a75be481 /plugin/evm/vm.go
parentddb43b6d824b5de77e4df9e9f551aa067be9b40e (diff)
Add unit test for building conflicting blocks
Diffstat (limited to 'plugin/evm/vm.go')
-rw-r--r--plugin/evm/vm.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 58ab600..5d379b7 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -156,9 +156,9 @@ type VM struct {
acceptedDB database.Database
+ txPoolStabilizedLock sync.Mutex
txPoolStabilizedHead common.Hash
txPoolStabilizedOk chan struct{}
- txPoolStabilizedLock sync.Mutex
txPoolStabilizedShutdownChan chan struct{}
metalock sync.Mutex
@@ -401,7 +401,10 @@ func (vm *VM) Bootstrapping() error { return vm.fx.Bootstrapping() }
// Bootstrapped notifies this VM that the consensus engine has finished
// bootstrapping
-func (vm *VM) Bootstrapped() error { return vm.fx.Bootstrapped() }
+func (vm *VM) Bootstrapped() error {
+ vm.ctx.Bootstrapped()
+ return vm.fx.Bootstrapped()
+}
// Shutdown implements the snowman.ChainVM interface
func (vm *VM) Shutdown() error {
@@ -421,10 +424,10 @@ func (vm *VM) Shutdown() error {
func (vm *VM) BuildBlock() (snowman.Block, error) {
vm.chain.GenBlock()
block := <-vm.newBlockChan
- if block == nil {
- return nil, errCreateBlock
- }
+
// reset the min block time timer
+ // after finishing attempt to build
+ // a block.
vm.bdlock.Lock()
vm.bdTimerState = bdTimerStateMin
vm.bdGenWaitFlag = false
@@ -432,7 +435,11 @@ func (vm *VM) BuildBlock() (snowman.Block, error) {
vm.blockDelayTimer.SetTimeoutIn(minBlockTime)
vm.bdlock.Unlock()
- log.Debug(fmt.Sprintf("built block %s", block.ID()))
+ if block == nil {
+ return nil, errCreateBlock
+ }
+
+ log.Debug(fmt.Sprintf("Built block %s", block.ID()))
// make sure Tx Pool is updated
<-vm.txPoolStabilizedOk
return block, nil
@@ -739,7 +746,13 @@ func (vm *VM) awaitTxPoolStabilized() {
defer vm.shutdownWg.Done()
for {
select {
- case e := <-vm.newMinedBlockSub.Chan():
+ case e, ok := <-vm.newMinedBlockSub.Chan():
+ if !ok {
+ return
+ }
+ if e == nil {
+ continue
+ }
switch h := e.Data.(type) {
case core.NewMinedBlockEvent:
vm.txPoolStabilizedLock.Lock()