Skip to content

Commit

Permalink
repair nonce check with feeding failed count
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshishuo committed Mar 27, 2018
1 parent 4f1936e commit f4531f8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import:
- package: github.com/gorilla/mux
version: ^1.5.0
- package: github.com/ethereum/go-ethereum
version: f1.6.7
version: test
repo: https://github.com/CyberMiles/go-ethereum.git
- package: gopkg.in/urfave/cli.v1
version: 1.x
Expand Down
26 changes: 20 additions & 6 deletions modules/vm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,24 @@ func (app *EthermintApplication) validateTx(tx *ethTypes.Transaction) abciTypes.
}

// Check if nonce is not strictly increasing
// if not then recheck with feeding failed count
nonce := currentState.GetNonce(from)
if nonce != tx.Nonce() {
return abciTypes.ResponseCheckTx{
Code: errors.CodeTypeBadNonce,
Log: fmt.Sprintf(
"Nonce not strictly increasing. Expected %d Got %d",
nonce, tx.Nonce())}
if c, ok := utils.CheckFailedCount[from]; ok {
if nonce + c != tx.Nonce() {
return abciTypes.ResponseCheckTx{
Code: errors.CodeTypeBadNonce,
Log: fmt.Sprintf(
"Nonce not strictly increasing. Expected %d Got %d",
nonce, tx.Nonce())}
}
} else {
return abciTypes.ResponseCheckTx{
Code: errors.CodeTypeBadNonce,
Log: fmt.Sprintf(
"Nonce not strictly increasing. Expected %d Got %d",
nonce, tx.Nonce())}
}
}

// Transactor should have enough funds to cover the costs
Expand Down Expand Up @@ -346,6 +357,9 @@ func (app *EthermintApplication) validateTx(tx *ethTypes.Transaction) abciTypes.
}
if _, ok := app.checkedTransactions[ft]; ok {
if tx.GasPrice().Cmp( big.NewInt(MinGasPrice) ) < 0 {
// add failed count
// this map will keep growing because the nonce check will use it ongoing
utils.CheckFailedCount[from] = utils.CheckFailedCount[from] + 1
return abciTypes.ResponseCheckTx{Code: errors.CodeLowGasPriceErr, Log: "The gas price is too low for transaction"}
}
}
Expand All @@ -361,7 +375,7 @@ func (app *EthermintApplication) validateTx(tx *ethTypes.Transaction) abciTypes.
if to := tx.To(); to != nil {
currentState.AddBalance(*to, tx.Value())
}
currentState.SetNonce(from, tx.Nonce()+1)
currentState.SetNonce(from, nonce+1)

return abciTypes.ResponseCheckTx{Code: abciTypes.CodeTypeOK}
}
3 changes: 3 additions & 0 deletions utils/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"github.com/tendermint/go-wire/data"
"github.com/ethereum/go-ethereum/common"
"math/big"
)

Expand All @@ -16,4 +17,6 @@ var(
StateChangeQueue []StateChangeObject
ValidatorPubKeys [][]byte

// record count of failed CheckTx of each from account; used to feed in the nonce check
CheckFailedCount map[common.Address]uint64 = make(map[common.Address]uint64)
)

0 comments on commit f4531f8

Please sign in to comment.