diff --git a/glide.lock b/glide.lock index c3b96755..372a8054 100644 --- a/glide.lock +++ b/glide.lock @@ -36,7 +36,7 @@ imports: - name: github.com/edsrzf/mmap-go version: 0bce6a6887123b67a60366d2c9fe2dfb74289d2e - name: github.com/ethereum/go-ethereum - version: d9e23666755ebeb632dc8c3f902650971594e5a7 + version: ebe1f372357c3184e543472eebeea947ee959aa2 repo: https://github.com/CyberMiles/go-ethereum.git subpackages: - accounts diff --git a/glide.yaml b/glide.yaml index 5e102c54..b3f6c088 100644 --- a/glide.yaml +++ b/glide.yaml @@ -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 diff --git a/modules/vm/app/app.go b/modules/vm/app/app.go index a3fefa33..cbc5a673 100644 --- a/modules/vm/app/app.go +++ b/modules/vm/app/app.go @@ -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 @@ -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"} } } @@ -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} } diff --git a/utils/globals.go b/utils/globals.go index a2e745a9..1781481c 100644 --- a/utils/globals.go +++ b/utils/globals.go @@ -2,6 +2,7 @@ package utils import ( "github.com/tendermint/go-wire/data" + "github.com/ethereum/go-ethereum/common" "math/big" ) @@ -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) ) \ No newline at end of file