Skip to content
Open
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
16 changes: 16 additions & 0 deletions services/api/blocksim_ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 16 additions & 0 deletions services/api/blocksim_ratelimiter_test.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 12 in services/api/blocksim_ratelimiter_test.go

View workflow job for this annotation

GitHub Actions / Lint

context.Background() could be replaced by t.Context() in TestNoopBlockSim (usetesting)
require.NoError(t, err1)
require.NoError(t, err2)
require.Nil(t, resp)
}
11 changes: 10 additions & 1 deletion services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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{}),
Expand Down
Loading