aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-10-21 16:07:47 -0400
committerDeterminant <[email protected]>2019-10-21 16:07:47 -0400
commit7212dbd90f4cb8fe907617f804c8940db1ce657e (patch)
treea80485085a7c30e2bb06cc64081a1effcffd2204
parent79b1169a9ff0b54ddf3b520a70a79c78ba5c988d (diff)
fix the pool reset bug
-rw-r--r--core/blockchain.go28
-rw-r--r--examples/counter/main.go13
-rw-r--r--examples/payments/main.go5
-rw-r--r--miner/worker.go2
4 files changed, 22 insertions, 26 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 174d403..046e1d4 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1369,20 +1369,24 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
reorg = !currentPreserve && (blockPreserve || mrand.Float64() < 0.5)
}
}
- if !bc.manualCanonical && reorg {
- // Reorganise the chain if the parent is not the head block
- if block.ParentHash() != currentBlock.Hash() {
- if err := bc.reorg(currentBlock, block); err != nil {
- return NonStatTy, err
- }
- }
- // Write the positional metadata for transaction/receipt lookups and preimages
- rawdb.WriteTxLookupEntries(batch, block)
- rawdb.WritePreimages(batch, state.Preimages())
-
+ if bc.manualCanonical {
status = CanonStatTy
} else {
- status = SideStatTy
+ if reorg {
+ // Reorganise the chain if the parent is not the head block
+ if block.ParentHash() != currentBlock.Hash() {
+ if err := bc.reorg(currentBlock, block); err != nil {
+ return NonStatTy, err
+ }
+ }
+ // Write the positional metadata for transaction/receipt lookups and preimages
+ rawdb.WriteTxLookupEntries(batch, block)
+ rawdb.WritePreimages(batch, state.Preimages())
+
+ status = CanonStatTy
+ } else {
+ status = SideStatTy
+ }
}
if err := batch.Write(); err != nil {
return NonStatTy, err
diff --git a/examples/counter/main.go b/examples/counter/main.go
index 5ec83fc..e802a33 100644
--- a/examples/counter/main.go
+++ b/examples/counter/main.go
@@ -141,14 +141,11 @@ func main() {
header.Extra = append(header.Extra, hid...)
})
chain.SetOnSealFinish(func(block *types.Block) error {
- go func() {
- // generate 15 blocks
- blockCount++
- if postGen(block) {
- return
- }
- chain.GenBlock()
- }()
+ blockCount++
+ if postGen(block) {
+ return nil
+ }
+ chain.GenBlock()
return nil
})
diff --git a/examples/payments/main.go b/examples/payments/main.go
index 5a56028..1eab70b 100644
--- a/examples/payments/main.go
+++ b/examples/payments/main.go
@@ -84,9 +84,7 @@ func main() {
})
newBlockChan := make(chan *types.Block)
chain.SetOnSealFinish(func(block *types.Block) error {
- go func() {
- newBlockChan <- block
- }()
+ newBlockChan <- block
return nil
})
@@ -96,7 +94,6 @@ func main() {
tx := types.NewTransaction(nonce, bob.Address, value, uint64(gasLimit), gasPrice, nil)
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), genKey.PrivateKey)
checkError(err)
- _ = signedTx
chain.AddRemoteTxs([]*types.Transaction{signedTx})
nonce++
chain.GenBlock()
diff --git a/miner/worker.go b/miner/worker.go
index fd8d754..19234ee 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -979,7 +979,6 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
if !noempty && !w.manualMining {
// Create an empty block based on temporary copied state for sealing in advance without waiting block
// execution finished.
- log.Trace("commit n1")
w.commit(uncles, nil, false, tstart)
}
@@ -1014,7 +1013,6 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
return
}
}
- log.Trace("commit n2")
w.commit(uncles, w.fullTaskHook, true, tstart)
}