mirror of https://github.com/poanetwork/quorum.git
Merge pull request #14 from bas-vk/votenonce
quorum: retrieve nonce from txpool instead of pending state
This commit is contained in:
commit
116bb4544f
|
@ -244,15 +244,19 @@ func (bv *BlockVoting) run(strat BlockMakerStrategy) {
|
|||
case core.TxPreEvent: // tx entered pool, apply to pending state
|
||||
bv.applyTransaction(e.Tx)
|
||||
case Vote:
|
||||
txHash, err := bv.vote(e.Number, e.Hash)
|
||||
if err == nil && e.TxHash != nil {
|
||||
e.TxHash <- txHash
|
||||
} else if err != nil && e.Err != nil {
|
||||
e.Err <- err
|
||||
} else if err != nil {
|
||||
if glog.V(logger.Debug) {
|
||||
glog.Errorf("Unable to vote: %v", err)
|
||||
if bv.synced {
|
||||
txHash, err := bv.vote(e.Number, e.Hash)
|
||||
if err == nil && e.TxHash != nil {
|
||||
e.TxHash <- txHash
|
||||
} else if err != nil && e.Err != nil {
|
||||
e.Err <- err
|
||||
} else if err != nil {
|
||||
if glog.V(logger.Debug) {
|
||||
glog.Errorf("Unable to vote: %v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
e.Err <- fmt.Errorf("Node not synced")
|
||||
}
|
||||
case CreateBlock:
|
||||
block, err := bv.createBlock()
|
||||
|
@ -367,6 +371,10 @@ func (bv *BlockVoting) vote(height *big.Int, hash common.Hash) (common.Hash, err
|
|||
glog.Infof("vote for %s on height %d", hash.Hex(), height)
|
||||
}
|
||||
|
||||
nonce := bv.txpool.Nonce(bv.voteSession.TransactOpts.From)
|
||||
bv.voteSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)
|
||||
defer func() { bv.voteSession.TransactOpts.Nonce = nil }()
|
||||
|
||||
tx, err := bv.voteSession.Vote(height, hash)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
|
|
|
@ -129,6 +129,17 @@ func (pool *TxPool) eventLoop() {
|
|||
}
|
||||
}
|
||||
|
||||
// Nonce returns the nonce for the given addr from the pending state.
|
||||
// Can only be used for local transactions.
|
||||
func (pool *TxPool) Nonce(addr common.Address) uint64 {
|
||||
pool.mu.Lock()
|
||||
defer pool.mu.Unlock()
|
||||
if pool.pendingState == nil {
|
||||
pool.resetState()
|
||||
}
|
||||
return pool.pendingState.GetNonce(addr)
|
||||
}
|
||||
|
||||
func (pool *TxPool) resetState() {
|
||||
currentState, _, err := pool.currentState()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue