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,6 +244,7 @@ func (bv *BlockVoting) run(strat BlockMakerStrategy) {
|
||||||
case core.TxPreEvent: // tx entered pool, apply to pending state
|
case core.TxPreEvent: // tx entered pool, apply to pending state
|
||||||
bv.applyTransaction(e.Tx)
|
bv.applyTransaction(e.Tx)
|
||||||
case Vote:
|
case Vote:
|
||||||
|
if bv.synced {
|
||||||
txHash, err := bv.vote(e.Number, e.Hash)
|
txHash, err := bv.vote(e.Number, e.Hash)
|
||||||
if err == nil && e.TxHash != nil {
|
if err == nil && e.TxHash != nil {
|
||||||
e.TxHash <- txHash
|
e.TxHash <- txHash
|
||||||
|
@ -254,6 +255,9 @@ func (bv *BlockVoting) run(strat BlockMakerStrategy) {
|
||||||
glog.Errorf("Unable to vote: %v", err)
|
glog.Errorf("Unable to vote: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
e.Err <- fmt.Errorf("Node not synced")
|
||||||
|
}
|
||||||
case CreateBlock:
|
case CreateBlock:
|
||||||
block, err := bv.createBlock()
|
block, err := bv.createBlock()
|
||||||
if err == nil && e.Hash != nil {
|
if err == nil && e.Hash != nil {
|
||||||
|
@ -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)
|
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)
|
tx, err := bv.voteSession.Vote(height, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
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() {
|
func (pool *TxPool) resetState() {
|
||||||
currentState, _, err := pool.currentState()
|
currentState, _, err := pool.currentState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue