Skip to content

Commit

Permalink
chore: remove old rate limit from processor
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Letang <[email protected]>
  • Loading branch information
jeremyletang committed May 16, 2024
1 parent 13b93fb commit 3a758d9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 259 deletions.
42 changes: 5 additions & 37 deletions core/processor/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"code.vegaprotocol.io/vega/core/idgeneration"
"code.vegaprotocol.io/vega/core/netparams"
"code.vegaprotocol.io/vega/core/pow"
"code.vegaprotocol.io/vega/core/processor/ratelimit"
"code.vegaprotocol.io/vega/core/snapshot"
"code.vegaprotocol.io/vega/core/teams"
"code.vegaprotocol.io/vega/core/txn"
Expand Down Expand Up @@ -211,7 +210,6 @@ type App struct {
log *logging.Logger
cancelFn func()
stopBlockchain func() error
rates *ratelimit.Rates

// service injection
assets Assets
Expand Down Expand Up @@ -306,15 +304,11 @@ func NewApp(log *logging.Logger,
app := &App{
abci: abci.New(codec),

log: log,
vegaPaths: vegaPaths,
cfg: config,
cancelFn: cancelFn,
stopBlockchain: stopBlockchain,
rates: ratelimit.New(
config.Ratelimit.Requests,
config.Ratelimit.PerNBlocks,
),
log: log,
vegaPaths: vegaPaths,
cfg: config,
cancelFn: cancelFn,
stopBlockchain: stopBlockchain,
assets: assets,
banking: banking,
broker: broker,
Expand Down Expand Up @@ -1048,7 +1042,6 @@ func (app *App) OnBeginBlock(blockHeight uint64, blockHash string, blockTime tim
app.blockCtx = ctx
now := blockTime
app.time.SetTimeNow(ctx, now)
app.rates.NextBlock()
app.currentTimestamp = app.time.GetTimeNow()
app.previousTimestamp = app.time.GetTimeLastBatch()
app.log.Debug("ABCI service BEGIN completed",
Expand Down Expand Up @@ -1330,10 +1323,6 @@ func (app *App) OnCheckTx(ctx context.Context, _ *tmtypes.RequestCheckTx, tx abc
return ctx, &resp
}

// Check ratelimits
// FIXME(): temporary disable all rate limiting
_, isval := app.limitPubkey(tx.PubKeyHex())

gasWanted, err := app.gastimator.CalcGasWantedForTx(tx)
if err != nil { // this error means the transaction couldn't be parsed
app.log.Error("error getting gas estimate", logging.Error(err))
Expand All @@ -1347,30 +1336,9 @@ func (app *App) OnCheckTx(ctx context.Context, _ *tmtypes.RequestCheckTx, tx abc
app.log.Debug("transaction passed checkTx", logging.String("tid", tx.GetPoWTID()), logging.String("command", tx.Command().String()))
}

if isval {
return ctx, &resp
}

return ctx, &resp
}

// limitPubkey returns whether a request should be rate limited or not.
func (app *App) limitPubkey(pk string) (limit bool, isValidator bool) {
// Do not rate limit validators nodes.
if app.top.IsValidatorVegaPubKey(pk) {
return false, true
}

key := ratelimit.Key(pk).String()
if !app.rates.Allow(key) {
app.log.Debug("Rate limit exceeded", logging.String("key", key))
return true, false
}

app.log.Debug("RateLimit allowance", logging.String("key", key), logging.Int("count", app.rates.Count(key)))
return false, false
}

func (app *App) canSubmitTx(tx abci.Tx) (err error) {
defer func() {
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions core/processor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package processor

import (
"code.vegaprotocol.io/vega/core/processor/ratelimit"
"code.vegaprotocol.io/vega/libs/config/encoding"
"code.vegaprotocol.io/vega/logging"
)
Expand All @@ -37,7 +36,6 @@ type Config struct {
LogOrderSubmitDebug encoding.Bool `long:"log-order-submit-debug"`
LogOrderAmendDebug encoding.Bool `long:"log-order-amend-debug"`
LogOrderCancelDebug encoding.Bool `long:"log-order-cancel-debug"`
Ratelimit ratelimit.Config `group:"Ratelimit" namespace:"ratelimit"`
KeepCheckpointsMax uint `long:"keep-checkpoints-max"`
SnapshotDebug Snapshot `group:"SnapshotDebug" namespace:"snapshotdebug"`
}
Expand All @@ -48,7 +46,6 @@ func NewDefaultConfig() Config {
return Config{
Level: encoding.LogLevel{Level: logging.InfoLevel},
LogOrderSubmitDebug: true,
Ratelimit: ratelimit.NewDefaultConfig(),
KeepCheckpointsMax: 20,
SnapshotDebug: Snapshot{
DevEnabled: false,
Expand Down
32 changes: 0 additions & 32 deletions core/processor/ratelimit/config.go

This file was deleted.

89 changes: 0 additions & 89 deletions core/processor/ratelimit/ratelimit.go

This file was deleted.

98 changes: 0 additions & 98 deletions core/processor/ratelimit/ratelimit_test.go

This file was deleted.

0 comments on commit 3a758d9

Please sign in to comment.