diff --git a/services/api/blocksim_ratelimiter.go b/services/api/blocksim_ratelimiter.go index f59d350e..4d0a8153 100644 --- a/services/api/blocksim_ratelimiter.go +++ b/services/api/blocksim_ratelimiter.go @@ -186,3 +186,19 @@ func SendJSONRPCRequest(client *http.Client, req jsonrpc.JSONRPCRequest, url str } return res, nil, nil } + +var _ IBlockSimRateLimiter = (*NoopBlockSim)(nil) + +type NoopBlockSim struct{} + +func newNoopBlockSim() *NoopBlockSim { + return &NoopBlockSim{} +} + +func (n *NoopBlockSim) Send(context context.Context, payload *common.BuilderBlockValidationRequest, isHighPrio, fastTrack bool) (*common.BuilderBlockValidationResponse, error, error) { + return nil, nil, nil +} + +func (n *NoopBlockSim) CurrentCounter() int64 { + return 0 +} diff --git a/services/api/blocksim_ratelimiter_test.go b/services/api/blocksim_ratelimiter_test.go new file mode 100644 index 00000000..898733ac --- /dev/null +++ b/services/api/blocksim_ratelimiter_test.go @@ -0,0 +1,16 @@ +package api + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNoopBlockSim(t *testing.T) { + n := newNoopBlockSim() + resp, err1, err2 := n.Send(context.Background(), nil, false, false) + require.NoError(t, err1) + require.NoError(t, err2) + require.Nil(t, resp) +} diff --git a/services/api/service.go b/services/api/service.go index 5afaf522..90f30199 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -27,6 +27,7 @@ import ( "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/buger/jsonparser" + "github.com/ethereum/go-ethereum/log" "github.com/flashbots/go-boost-utils/bls" "github.com/flashbots/go-boost-utils/ssz" "github.com/flashbots/go-boost-utils/utils" @@ -297,6 +298,14 @@ func NewRelayAPI(opts RelayAPIOpts) (api *RelayAPI, err error) { } } + var blockSim IBlockSimRateLimiter + if opts.BlockSimURL != "" { + blockSim = NewBlockSimulationRateLimiter(opts.BlockSimURL) + } else { + log.Warn("Running without block simulator") + blockSim = newNoopBlockSim() + } + api = &RelayAPI{ opts: opts, log: opts.Log, @@ -311,7 +320,7 @@ func NewRelayAPI(opts RelayAPIOpts) (api *RelayAPI, err error) { payloadAttributes: make(map[string]payloadAttributesHelper), proposerDutiesResponse: &[]byte{}, - blockSimRateLimiter: NewBlockSimulationRateLimiter(opts.BlockSimURL), + blockSimRateLimiter: blockSim, validatorRegC: make(chan builderApiV1.SignedValidatorRegistration, 450_000), validatorUpdateCh: make(chan struct{}),