Skip to content

Commit

Permalink
Remove old transactions from TX pool (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
ridenaio authored Jul 30, 2019
1 parent 6a3414b commit 3003d65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/dna_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (api *DnaApi) GetCoinbaseAddr() common.Address {
type Balance struct {
Stake decimal.Decimal `json:"stake"`
Balance decimal.Decimal `json:"balance"`
Nonce uint32 `json:"nonce"`
}

func (api *DnaApi) GetBalance(address common.Address) Balance {
Expand All @@ -52,6 +53,7 @@ func (api *DnaApi) GetBalance(address common.Address) Balance {
return Balance{
Stake: blockchain.ConvertToFloat(state.State.GetStakeBalance(address)),
Balance: blockchain.ConvertToFloat(state.State.GetBalance(address)),
Nonce: state.State.GetNonce(address),
}
}

Expand Down
7 changes: 1 addition & 6 deletions core/mempool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,11 @@ func (txpool *TxPool) ResetTo(block *types.Block) {
if tx.Epoch > globalEpoch {
continue
}

sender, _ := types.Sender(tx)
if tx.AccountNonce <= txpool.appState.State.GetNonce(sender) && txpool.appState.State.GetEpoch(sender) == globalEpoch {
continue
}

if err := validation.ValidateTx(appState, tx, false); err != nil {
txpool.Remove(tx)
continue
}
sender, _ := types.Sender(tx)
txpool.appState.NonceCache.SetNonce(sender, tx.Epoch, tx.AccountNonce)
}
}
Expand Down

0 comments on commit 3003d65

Please sign in to comment.