Skip to content

Commit

Permalink
Merge PR: Pending pool feature (#997)
Browse files Browse the repository at this point in the history
* add pending pool

* update go.mod

* update go.mod

* update ante handler

* update go.mod

* update go.mod

* update go.mod

* update go.mod

Co-authored-by: MengXiangJian <[email protected]>
  • Loading branch information
ilovers and xiangjianmeng authored Sep 7, 2021
1 parent 6513eee commit f60d868
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
70 changes: 43 additions & 27 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (nvd NonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
// all will be rejected except the first, since the first needs to be included in a block
// before the sequence increments
if ctx.IsCheckTx() {
ctx = ctx.WithAccountNonce(seq)
// will be checkTx and RecheckTx mode
if ctx.IsReCheckTx() {
// recheckTx mode
Expand All @@ -268,36 +269,46 @@ func (nvd NonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
)
}
} else {
// checkTx mode
checkTxModeNonce := seq

if !baseapp.IsMempoolEnableRecheck() {
// if is enable recheck, the sequence of checkState will increase after commit(), so we do not need
// to add pending txs len in the mempool.
// but, if disable recheck, we will not increase sequence of checkState (even in force recheck case, we
// will also reset checkState), so we will need to add pending txs len to get the right nonce
gPool := baseapp.GetGlobalMempool()
if gPool != nil {
cnt := gPool.GetUserPendingTxsCnt(common.BytesToAddress(address.Bytes()).String())
checkTxModeNonce = seq + uint64(cnt)
}
}

if baseapp.IsMempoolEnableSort() {
if msgEthTx.Data.AccountNonce < seq || msgEthTx.Data.AccountNonce > checkTxModeNonce {
if baseapp.IsMempoolEnablePendingPool() {
if msgEthTx.Data.AccountNonce < seq {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidSequence,
"invalid nonce; got %d, expected in the range of [%d, %d]",
msgEthTx.Data.AccountNonce, seq, checkTxModeNonce,
"invalid nonce; got %d, expected %d",
msgEthTx.Data.AccountNonce, seq,
)
}
} else {
if msgEthTx.Data.AccountNonce != checkTxModeNonce {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidSequence,
"invalid nonce; got %d, expected %d",
msgEthTx.Data.AccountNonce, checkTxModeNonce,
)
// checkTx mode
checkTxModeNonce := seq

if !baseapp.IsMempoolEnableRecheck() {
// if is enable recheck, the sequence of checkState will increase after commit(), so we do not need
// to add pending txs len in the mempool.
// but, if disable recheck, we will not increase sequence of checkState (even in force recheck case, we
// will also reset checkState), so we will need to add pending txs len to get the right nonce
gPool := baseapp.GetGlobalMempool()
if gPool != nil {
cnt := gPool.GetUserPendingTxsCnt(common.BytesToAddress(address.Bytes()).String())
checkTxModeNonce = seq + uint64(cnt)
}
}

if baseapp.IsMempoolEnableSort() {
if msgEthTx.Data.AccountNonce < seq || msgEthTx.Data.AccountNonce > checkTxModeNonce {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidSequence,
"invalid nonce; got %d, expected in the range of [%d, %d]",
msgEthTx.Data.AccountNonce, seq, checkTxModeNonce,
)
}
} else {
if msgEthTx.Data.AccountNonce != checkTxModeNonce {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidSequence,
"invalid nonce; got %d, expected %d",
msgEthTx.Data.AccountNonce, checkTxModeNonce,
)
}
}
}
}
Expand Down Expand Up @@ -437,8 +448,13 @@ func (issd IncrementSenderSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.
// increment sequence of all signers
for _, addr := range msgEthTx.GetSigners() {
acc := issd.ak.GetAccount(ctx, addr)

if err := acc.SetSequence(acc.GetSequence() + 1); err != nil {
seq := acc.GetSequence()
if !baseapp.IsMempoolEnablePendingPool() {
seq++
} else if msgEthTx.Data.AccountNonce == seq {
seq++
}
if err := acc.SetSequence(seq); err != nil {
panic(err)
}
issd.ak.SetAccount(ctx, acc)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.39.2-exchain15
github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.39.3-0.20210906101954-ea9c2e5521c8
github.com/tendermint/iavl => github.com/okex/iavl v0.14.3-exchain
github.com/tendermint/tendermint => github.com/okex/tendermint v0.33.9-exchain10
github.com/tendermint/tendermint => github.com/okex/tendermint v0.33.9-okexchain6.0.20210906101911-c04d43a1f4ba
github.com/tendermint/tm-db => github.com/okex/tm-db v0.5.2-exchain1
)
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,14 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/okex/cosmos-sdk v0.39.2-exchain15 h1:JO/k3tcK/ozybF0h9lMvhOgAdEnwz2l46Bs0ra37Ois=
github.com/okex/cosmos-sdk v0.39.2-exchain15/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4=
github.com/okex/cosmos-sdk v0.39.3-0.20210831062138-cebb8df97837 h1:dmmLcohm7L9cON+hnHM80jLdkW8I8FEFWYvwJF7CQS4=
github.com/okex/cosmos-sdk v0.39.3-0.20210831062138-cebb8df97837/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4=
github.com/okex/cosmos-sdk v0.39.3-0.20210906101954-ea9c2e5521c8 h1:YZY8B5VDRhDmF3+fiRziVUASPsVFqt6PAq5TcWOaIgk=
github.com/okex/cosmos-sdk v0.39.3-0.20210906101954-ea9c2e5521c8/go.mod h1:IvlniaZoJAtzILHgcmnfaJ5S125TYJWfJvGqY9zSXb4=
github.com/okex/iavl v0.14.3-exchain h1:kwRIwpFD6B8mDDqoaxeUN3Pg2GW0Vr+sA+b86renWcA=
github.com/okex/iavl v0.14.3-exchain/go.mod h1:vHLYxU/zuxBmxxr1v+5Vnd/JzcIsyK17n9P9RDubPVU=
github.com/okex/tendermint v0.33.9-exchain10 h1:tIMxk2RDv4YxLFht878S1BHTXzA84Ouvz5DtkDSCLGk=
github.com/okex/tendermint v0.33.9-exchain10/go.mod h1:EoGTbJUufUueNIigY3zyO6f7GOj29OdpFhuR8sxWdSU=
github.com/okex/tendermint v0.33.9-okexchain6.0.20210906101911-c04d43a1f4ba h1:mFF3Nuh+PrqN/fxBCDVa9BCawMYOu6LyfhPXxAPsfsA=
github.com/okex/tendermint v0.33.9-okexchain6.0.20210906101911-c04d43a1f4ba/go.mod h1:EoGTbJUufUueNIigY3zyO6f7GOj29OdpFhuR8sxWdSU=
github.com/okex/tm-db v0.5.2-exchain1 h1:c8aX7HoNW58GXHEO6e7BR81SwyBfjWJkqGwNUhF3tlc=
github.com/okex/tm-db v0.5.2-exchain1/go.mod h1:VrPTx04QJhQ9d8TFUTc2GpPBvBf/U9vIdBIzkjBk7Lk=
github.com/okex/tm-db v0.5.3-0.20210831062251-0eeb93ab0259 h1:2FF18PzBoCWH901/jwArYQGbmkG104zCztoCVmKch94=
github.com/okex/tm-db v0.5.3-0.20210831062251-0eeb93ab0259/go.mod h1:VrPTx04QJhQ9d8TFUTc2GpPBvBf/U9vIdBIzkjBk7Lk=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down

0 comments on commit f60d868

Please sign in to comment.