Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: tx rate limit #490

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func CheckCometError(err error, tx cmttypes.Tx) *sdk.TxResponse {
TxHash: txHash,
}

case strings.Contains(errStr, "mempool rate limit exceeded"):
return &sdk.TxResponse{
Code: sdkerrors.ErrMempoolRateLimitExceeded.ABCICode(),
Codespace: sdkerrors.ErrMempoolRateLimitExceeded.Codespace(),
TxHash: txHash,
}

default:
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions client/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func CreateContextWithErrorAndMode(err error, mode string) Context {
// Test the correct code is returned when
func TestBroadcastError(t *testing.T) {
errors := map[error]uint32{
mempool.ErrTxInCache: sdkerrors.ErrTxInMempoolCache.ABCICode(),
mempool.ErrTxTooLarge{}: sdkerrors.ErrTxTooLarge.ABCICode(),
mempool.ErrMempoolIsFull{}: sdkerrors.ErrMempoolIsFull.ABCICode(),
mempool.ErrTxInCache: sdkerrors.ErrTxInMempoolCache.ABCICode(),
mempool.ErrTxTooLarge{}: sdkerrors.ErrTxTooLarge.ABCICode(),
mempool.ErrMempoolIsFull{}: sdkerrors.ErrMempoolIsFull.ABCICode(),
mempool.ErrMempoolRateLimitExceeded{}: sdkerrors.ErrMempoolRateLimitExceeded.ABCICode(),
}

modes := []string{
Expand Down
2 changes: 2 additions & 0 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,6 @@ var (
ErrNotSupported = RegisterWithGRPCCode(testCodespace, 37, codes.Unimplemented, "feature not supported")
ErrNotFound = RegisterWithGRPCCode(testCodespace, 38, codes.NotFound, "not found")
ErrIO = Register(testCodespace, 39, "Internal IO error")

ErrMempoolRateLimitExceeded = Register(testCodespace, 10001, "mempool rate limit exceeded")
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ require (
// replace the store module with the b-harvest fork
replace (
cosmossdk.io/store => github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e
github.com/cometbft/cometbft => github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820
github.com/cometbft/cometbft => github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158
)

// Below are the long-lived replace of the Cosmos SDK
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820 h1:HSi5iZWa3bzjmJuVMXHSgHr5rxzpGyuaCTkEici0S+8=
github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820/go.mod h1:a8NBI2IdO283RZdpH0MuXlze3j+lv6PXuzOtTCq4YGE=
github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158 h1:08cYQa2CGagj4QX8toaCuVobI0CxpEwF3WS+S7LNIqU=
github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158/go.mod h1:a8NBI2IdO283RZdpH0MuXlze3j+lv6PXuzOtTCq4YGE=
github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e h1:e5quTVfHOIYOwKiqDZG9euFWjmEtAMu7m9N6PjlXK4Q=
github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
2 changes: 1 addition & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ require (
// replace the store module with the b-harvest fork
replace (
cosmossdk.io/store => github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e
github.com/cometbft/cometbft => github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820
github.com/cometbft/cometbft => github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158
)

// Below are the long-lived replace of the SimApp
Expand Down
4 changes: 2 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.224 h1:09CiaaF35nRmxrzWZ2uRq5v6Ghg/d2RiPjZnSgtt+RQ=
github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820 h1:HSi5iZWa3bzjmJuVMXHSgHr5rxzpGyuaCTkEici0S+8=
github.com/b-harvest/cometbft v0.0.0-20250114065503-2209f5c8c820/go.mod h1:a8NBI2IdO283RZdpH0MuXlze3j+lv6PXuzOtTCq4YGE=
github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158 h1:08cYQa2CGagj4QX8toaCuVobI0CxpEwF3WS+S7LNIqU=
github.com/b-harvest/cometbft v0.0.0-20250117081724-782b0da6a158/go.mod h1:a8NBI2IdO283RZdpH0MuXlze3j+lv6PXuzOtTCq4YGE=
github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e h1:e5quTVfHOIYOwKiqDZG9euFWjmEtAMu7m9N6PjlXK4Q=
github.com/b-harvest/cosmos-sdk/store v0.0.0-20241219054141-7fb019ef389e/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
4 changes: 4 additions & 0 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ var (
// supplied.
ErrInvalidGasLimit = errorsmod.Register(RootCodespace, 41, "invalid gas limit")

// ErrMempoolRateLimitExceeded defines an error when the mempool rate limit is exceeded.
// Starting at 10001 for future errors added in the cosmos-sdk.
ErrMempoolRateLimitExceeded = errorsmod.Register(RootCodespace, 10001, "mempool rate limit exceeded")

// ErrPanic should only be set when we recovering from a panic
ErrPanic = errorsmod.ErrPanic
)
Loading