Skip to content

Commit

Permalink
fix bidSubsidiseBlock call sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 12, 2024
1 parent 59e08d3 commit 1f2bae7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
50 changes: 48 additions & 2 deletions proxy/receiver_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
archiveServerRequests chan *RequestData

proxies []*OrderflowProxyTestSetup

flashbotsSigner *signature.Signer
)

func ServeHTTPRequestToChan(channel chan *RequestData) *httptest.Server {
Expand Down Expand Up @@ -116,6 +118,12 @@ func StartTestOrderflowProxy(name string) (*OrderflowProxyTestSetup, error) {
}

func TestMain(m *testing.M) {
signer, err := signature.NewRandomSigner()
if err != nil {
panic(err)
}
flashbotsSigner = signer

archiveServerRequests = make(chan *RequestData)
builderHub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
Expand Down Expand Up @@ -180,8 +188,9 @@ func createProxy(localBuilder, name string) *ReceiverProxy {
log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
proxy, err := NewReceiverProxy(ReceiverProxyConfig{
ReceiverProxyConstantConfig: ReceiverProxyConstantConfig{
Log: log,
Name: name,
Log: log,
Name: name,
FlashbotsSignerAddress: flashbotsSigner.Address(),
},
CertValidDuration: time.Hour * 24,
CertHosts: []string{"localhost", "127.0.0.1"},
Expand Down Expand Up @@ -475,3 +484,40 @@ func TestProxyShareBundleReplacementUUIDAndCancellation(t *testing.T) {
builderRequest = expectRequest(t, proxies[0].localBuilderRequests)
require.Equal(t, expectedRequest, builderRequest.body)
}

func TestProxyBidSubsidiseBlockCall(t *testing.T) {
defer func() {
proxiesFlushQueue()
for {
select {
case <-time.After(time.Millisecond * 100):
expectNoRequest(t, archiveServerRequests)
return
case <-archiveServerRequests:
}
}
}()

client, err := RPCClientWithCertAndSigner(proxies[0].publicServerEndpoint, proxies[0].proxy.PublicCertPEM, flashbotsSigner, 1)
require.NoError(t, err)

expectedRequest := `{"method":"bid_subsidiseBlock","params":[1000],"id":0,"jsonrpc":"2.0"}`

// we add all proxies to the list of peers
builderHubPeers = nil
for _, proxy := range proxies {
err = proxy.proxy.RegisterSecrets(context.Background())
require.NoError(t, err)
}
proxiesUpdatePeers(t)

args := rpctypes.BidSubsisideBlockArgs(1000)
resp, err := client.Call(context.Background(), BidSubsidiseBlockMethod, &args)
require.NoError(t, err)
require.Nil(t, resp.Error)

builderRequest := expectRequest(t, proxies[0].localBuilderRequests)
require.Equal(t, expectedRequest, builderRequest.body)
expectNoRequest(t, proxies[1].localBuilderRequests)
expectNoRequest(t, proxies[2].localBuilderRequests)
}
2 changes: 2 additions & 0 deletions proxy/sender_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func (prx *SenderProxy) BidSubsidiseBlock(ctx context.Context, bidSubsidiseBlock

func (prx *SenderProxy) HandleParsedRequest(ctx context.Context, parsedRequest ParsedRequest) error {
parsedRequest.receivedAt = apiNow()
// we set it explicitly to note that we need to proxy all calls to all peers
parsedRequest.publicEndpoint = false
prx.Log.Debug("Received request", slog.String("method", parsedRequest.method))

select {
Expand Down
3 changes: 2 additions & 1 deletion proxy/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func (sq *ShareQueue) proxyRequests(peer *shareQueuePeer, worker int) {
method = EthSendRawTransactionMethod
data = req.ethSendRawTransaction
} else if req.bidSubsidiseBlock != nil {
continue
method = BidSubsidiseBlockMethod
data = req.bidSubsidiseBlock
} else {
logger.Error("Unknown request type", slog.String("method", req.method))
shareQueueInternalErrors.Inc()
Expand Down

0 comments on commit 1f2bae7

Please sign in to comment.