@@ -13,6 +13,7 @@ import (
1313 "github.com/flashbots/go-utils/signature"
1414 "github.com/google/uuid"
1515 "github.com/hashicorp/golang-lru/v2/expirable"
16+ "golang.org/x/time/rate"
1617)
1718
1819var (
@@ -61,6 +62,8 @@ type ReceiverProxy struct {
6162 replacementNonceRLU * expirable.LRU [replacementNonceKey , int ]
6263
6364 peerUpdaterClose chan struct {}
65+
66+ localAPIRateLimiter * rate.Limiter
6467}
6568
6669type ReceiverProxyConstantConfig struct {
@@ -86,6 +89,7 @@ type ReceiverProxyConfig struct {
8689 MaxRequestBodySizeBytes int64
8790
8891 ConnectionsPerPeer int
92+ MaxLocalRPS int
8993}
9094
9195func NewReceiverProxy (config ReceiverProxyConfig ) (* ReceiverProxy , error ) {
@@ -105,6 +109,11 @@ func NewReceiverProxy(config ReceiverProxyConfig) (*ReceiverProxy, error) {
105109
106110 localBuilder := rpcclient .NewClient (config .LocalBuilderEndpoint )
107111
112+ limit := rate .Limit (config .MaxLocalRPS )
113+ if config .MaxLocalRPS == 0 {
114+ limit = rate .Inf
115+ }
116+ localAPIRateLimiter := rate .NewLimiter (limit , config .MaxLocalRPS )
108117 prx := & ReceiverProxy {
109118 ReceiverProxyConstantConfig : config .ReceiverProxyConstantConfig ,
110119 ConfigHub : NewBuilderConfigHub (config .Log , config .BuilderConfigHubEndpoint ),
@@ -114,6 +123,7 @@ func NewReceiverProxy(config ReceiverProxyConfig) (*ReceiverProxy, error) {
114123 localBuilder : localBuilder ,
115124 requestUniqueKeysRLU : expirable .NewLRU [uuid.UUID , struct {}](requestsRLUSize , nil , requestsRLUTTL ),
116125 replacementNonceRLU : expirable .NewLRU [replacementNonceKey , int ](replacementNonceSize , nil , replacementNonceTTL ),
126+ localAPIRateLimiter : localAPIRateLimiter ,
117127 }
118128 maxRequestBodySizeBytes := DefaultMaxRequestBodySizeBytes
119129 if config .MaxRequestBodySizeBytes != 0 {
0 commit comments