@@ -13,7 +13,6 @@ import (
1313 "github.com/onflow/go-ethereum/rlp"
1414 "github.com/onflow/go-ethereum/rpc"
1515 "github.com/rs/zerolog"
16- "github.com/sethvargo/go-limiter"
1716
1817 evmTypes "github.com/onflow/flow-go/fvm/evm/types"
1918
@@ -87,7 +86,7 @@ type BlockChainAPI struct {
8786 transactions storage.TransactionIndexer
8887 receipts storage.ReceiptIndexer
8988 indexingResumedHeight uint64
90- limiter limiter. Store
89+ rateLimiter RateLimiter
9190 collector metrics.Collector
9291}
9392
@@ -98,7 +97,7 @@ func NewBlockChainAPI(
9897 blocks storage.BlockIndexer ,
9998 transactions storage.TransactionIndexer ,
10099 receipts storage.ReceiptIndexer ,
101- ratelimiter limiter. Store ,
100+ rateLimiter RateLimiter ,
102101 collector metrics.Collector ,
103102 indexingResumedHeight uint64 ,
104103) * BlockChainAPI {
@@ -110,14 +109,14 @@ func NewBlockChainAPI(
110109 transactions : transactions ,
111110 receipts : receipts ,
112111 indexingResumedHeight : indexingResumedHeight ,
113- limiter : ratelimiter ,
112+ rateLimiter : rateLimiter ,
114113 collector : collector ,
115114 }
116115}
117116
118117// BlockNumber returns the block number of the chain head.
119118func (b * BlockChainAPI ) BlockNumber (ctx context.Context ) (hexutil.Uint64 , error ) {
120- if err := rateLimit (ctx , b . limiter , b . logger ); err != nil {
119+ if err := b . rateLimiter . Apply (ctx , "BlockNumber" ); err != nil {
121120 return 0 , err
122121 }
123122
@@ -136,7 +135,7 @@ func (b *BlockChainAPI) BlockNumber(ctx context.Context) (hexutil.Uint64, error)
136135// - currentBlock: block number this node is currently importing
137136// - highestBlock: block number of the highest block header this node has received from peers
138137func (b * BlockChainAPI ) Syncing (ctx context.Context ) (interface {}, error ) {
139- if err := rateLimit (ctx , b . limiter , b . logger ); err != nil {
138+ if err := b . rateLimiter . Apply (ctx , "Syncing" ); err != nil {
140139 return nil , err
141140 }
142141
@@ -176,7 +175,7 @@ func (b *BlockChainAPI) SendRawTransaction(
176175 Str ("input" , input .String ()).
177176 Logger ()
178177
179- if err := rateLimit (ctx , b . limiter , l ); err != nil {
178+ if err := b . rateLimiter . Apply (ctx , "SendRawTransaction" ); err != nil {
180179 return common.Hash {}, err
181180 }
182181
@@ -201,7 +200,7 @@ func (b *BlockChainAPI) GetBalance(
201200 Str ("address" , address .String ()).
202201 Logger ()
203202
204- if err := rateLimit (ctx , b . limiter , l ); err != nil {
203+ if err := b . rateLimiter . Apply (ctx , "GetBalance" ); err != nil {
205204 return nil , err
206205 }
207206
@@ -228,7 +227,7 @@ func (b *BlockChainAPI) GetTransactionByHash(
228227 Str ("hash" , hash .String ()).
229228 Logger ()
230229
231- if err := rateLimit (ctx , b . limiter , l ); err != nil {
230+ if err := b . rateLimiter . Apply (ctx , "GetTransactionByHash" ); err != nil {
232231 return nil , err
233232 }
234233
@@ -257,7 +256,7 @@ func (b *BlockChainAPI) GetTransactionByBlockHashAndIndex(
257256 Str ("index" , index .String ()).
258257 Logger ()
259258
260- if err := rateLimit (ctx , b . limiter , l ); err != nil {
259+ if err := b . rateLimiter . Apply (ctx , "GetTransactionByBlockHashAndIndex" ); err != nil {
261260 return nil , err
262261 }
263262
@@ -292,7 +291,7 @@ func (b *BlockChainAPI) GetTransactionByBlockNumberAndIndex(
292291 Str ("index" , index .String ()).
293292 Logger ()
294293
295- if err := rateLimit (ctx , b . limiter , l ); err != nil {
294+ if err := b . rateLimiter . Apply (ctx , "GetTransactionByBlockNumberAndIndex" ); err != nil {
296295 return nil , err
297296 }
298297
@@ -332,7 +331,7 @@ func (b *BlockChainAPI) GetTransactionReceipt(
332331 Str ("hash" , hash .String ()).
333332 Logger ()
334333
335- if err := rateLimit (ctx , b . limiter , l ); err != nil {
334+ if err := b . rateLimiter . Apply (ctx , "GetTransactionReceipt" ); err != nil {
336335 return nil , err
337336 }
338337
@@ -366,7 +365,7 @@ func (b *BlockChainAPI) GetBlockByHash(
366365 Str ("hash" , hash .String ()).
367366 Logger ()
368367
369- if err := rateLimit (ctx , b . limiter , l ); err != nil {
368+ if err := b . rateLimiter . Apply (ctx , "GetBlockByHash" ); err != nil {
370369 return nil , err
371370 }
372371
@@ -400,7 +399,7 @@ func (b *BlockChainAPI) GetBlockByNumber(
400399 Str ("blockNumber" , blockNumber .String ()).
401400 Logger ()
402401
403- if err := rateLimit (ctx , b . limiter , l ); err != nil {
402+ if err := b . rateLimiter . Apply (ctx , "GetBlockByNumber" ); err != nil {
404403 return nil , err
405404 }
406405
@@ -437,7 +436,7 @@ func (b *BlockChainAPI) GetBlockReceipts(
437436 Str ("hash" , blockNumberOrHash .String ()).
438437 Logger ()
439438
440- if err := rateLimit (ctx , b . limiter , l ); err != nil {
439+ if err := b . rateLimiter . Apply (ctx , "GetBlockReceipts" ); err != nil {
441440 return nil , err
442441 }
443442
@@ -483,7 +482,7 @@ func (b *BlockChainAPI) GetBlockTransactionCountByHash(
483482 Str ("hash" , blockHash .String ()).
484483 Logger ()
485484
486- if err := rateLimit (ctx , b . limiter , l ); err != nil {
485+ if err := b . rateLimiter . Apply (ctx , "GetBlockTransactionCountByHash" ); err != nil {
487486 return nil , err
488487 }
489488
@@ -507,7 +506,7 @@ func (b *BlockChainAPI) GetBlockTransactionCountByNumber(
507506 Str ("number" , blockNumber .String ()).
508507 Logger ()
509508
510- if err := rateLimit (ctx , b . limiter , l ); err != nil {
509+ if err := b . rateLimiter . Apply (ctx , "GetBlockTransactionCountByNumber" ); err != nil {
511510 return nil , err
512511 }
513512
@@ -544,7 +543,7 @@ func (b *BlockChainAPI) Call(
544543 Str ("args" , fmt .Sprintf ("%v" , args )).
545544 Logger ()
546545
547- if err := rateLimit (ctx , b . limiter , l ); err != nil {
546+ if err := b . rateLimiter . Apply (ctx , "Call" ); err != nil {
548547 return nil , err
549548 }
550549
@@ -592,7 +591,7 @@ func (b *BlockChainAPI) GetLogs(
592591 Str ("criteria" , fmt .Sprintf ("%v" , criteria )).
593592 Logger ()
594593
595- if err := rateLimit (ctx , b . limiter , l ); err != nil {
594+ if err := b . rateLimiter . Apply (ctx , "GetLogs" ); err != nil {
596595 return nil , err
597596 }
598597
@@ -681,7 +680,7 @@ func (b *BlockChainAPI) GetTransactionCount(
681680 Str ("address" , address .String ()).
682681 Logger ()
683682
684- if err := rateLimit (ctx , b . limiter , l ); err != nil {
683+ if err := b . rateLimiter . Apply (ctx , "GetTransactionCount" ); err != nil {
685684 return nil , err
686685 }
687686
@@ -714,7 +713,7 @@ func (b *BlockChainAPI) EstimateGas(
714713 Str ("args" , fmt .Sprintf ("%v" , args )).
715714 Logger ()
716715
717- if err := rateLimit (ctx , b . limiter , l ); err != nil {
716+ if err := b . rateLimiter . Apply (ctx , "EstimateGas" ); err != nil {
718717 return 0 , err
719718 }
720719
@@ -764,7 +763,7 @@ func (b *BlockChainAPI) GetCode(
764763 Str ("address" , address .String ()).
765764 Logger ()
766765
767- if err := rateLimit (ctx , b . limiter , l ); err != nil {
766+ if err := b . rateLimiter . Apply (ctx , "GetCode" ); err != nil {
768767 return nil , err
769768 }
770769
@@ -880,7 +879,7 @@ func (b *BlockChainAPI) GetStorageAt(
880879 Str ("address" , address .String ()).
881880 Logger ()
882881
883- if err := rateLimit (ctx , b . limiter , l ); err != nil {
882+ if err := b . rateLimiter . Apply (ctx , "GetStorageAt" ); err != nil {
884883 return nil , err
885884 }
886885
0 commit comments