diff --git a/suave/builder/api/api.go b/suave/builder/api/api.go index f144e65f18..773d7086af 100644 --- a/suave/builder/api/api.go +++ b/suave/builder/api/api.go @@ -16,8 +16,21 @@ type Bundle struct { RefundPercent *int `json:"percent,omitempty"` } +type BuildBlockArgs struct { + Slot uint64 + ProposerPubkey []byte + Parent common.Hash + Timestamp uint64 + FeeRecipient common.Address + GasLimit uint64 + Random common.Hash + Withdrawals []*types.Withdrawal + Extra []byte + FillPending bool +} + type API interface { - NewSession(ctx context.Context) (string, error) + NewSession(ctx context.Context, args *BuildBlockArgs) (string, error) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) AddBundle(ctx context.Context, sessionId string, bundle Bundle) error } diff --git a/suave/builder/api/api_client.go b/suave/builder/api/api_client.go index e7ca8246b4..62631df8b4 100644 --- a/suave/builder/api/api_client.go +++ b/suave/builder/api/api_client.go @@ -29,9 +29,9 @@ func NewClientFromRPC(rpc rpcClient) *APIClient { return &APIClient{rpc: rpc} } -func (a *APIClient) NewSession(ctx context.Context) (string, error) { +func (a *APIClient) NewSession(ctx context.Context, args *BuildBlockArgs) (string, error) { var id string - err := a.rpc.CallContext(ctx, &id, "suavex_newSession") + err := a.rpc.CallContext(ctx, &id, "suavex_newSession", args) return id, err } diff --git a/suave/builder/api/api_server.go b/suave/builder/api/api_server.go index e78f435e14..eb598270d9 100644 --- a/suave/builder/api/api_server.go +++ b/suave/builder/api/api_server.go @@ -8,7 +8,7 @@ import ( // SessionManager is the backend that manages the session state of the builder API. type SessionManager interface { - NewSession(context.Context) (string, error) + NewSession(context.Context, *BuildBlockArgs) (string, error) AddTransaction(sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) AddBundle(sessionId string, bundle Bundle) error } @@ -24,8 +24,8 @@ type Server struct { sessionMngr SessionManager } -func (s *Server) NewSession(ctx context.Context) (string, error) { - return s.sessionMngr.NewSession(ctx) +func (s *Server) NewSession(ctx context.Context, args *BuildBlockArgs) (string, error) { + return s.sessionMngr.NewSession(ctx, args) } func (s *Server) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) { @@ -39,7 +39,7 @@ func (s *Server) AddBundle(ctx context.Context, sessionId string, bundle Bundle) type MockServer struct { } -func (s *MockServer) NewSession(ctx context.Context) (string, error) { +func (s *MockServer) NewSession(ctx context.Context, args *BuildBlockArgs) (string, error) { return "", nil } diff --git a/suave/builder/api/api_test.go b/suave/builder/api/api_test.go index 30a9dabb39..356ff0d083 100644 --- a/suave/builder/api/api_test.go +++ b/suave/builder/api/api_test.go @@ -19,7 +19,7 @@ func TestAPI(t *testing.T) { c := NewClientFromRPC(rpc.DialInProc(srv)) - res0, err := c.NewSession(context.Background()) + res0, err := c.NewSession(context.Background(), nil) require.NoError(t, err) require.Equal(t, res0, "1") @@ -30,7 +30,7 @@ func TestAPI(t *testing.T) { type nullSessionManager struct{} -func (nullSessionManager) NewSession(ctx context.Context) (string, error) { +func (nullSessionManager) NewSession(ctx context.Context, args *BuildBlockArgs) (string, error) { return "1", ctx.Err() } diff --git a/suave/builder/session_manager.go b/suave/builder/session_manager.go index 2a2ddda062..194bd9067d 100644 --- a/suave/builder/session_manager.go +++ b/suave/builder/session_manager.go @@ -74,7 +74,7 @@ func NewSessionManager(blockchain blockchain, config *Config) *SessionManager { } // NewSession creates a new builder session and returns the session id -func (s *SessionManager) NewSession(ctx context.Context) (string, error) { +func (s *SessionManager) NewSession(ctx context.Context, args *api.BuildBlockArgs) (string, error) { // Wait for session to become available select { case <-s.sem: diff --git a/suave/builder/session_manager_test.go b/suave/builder/session_manager_test.go index a7a37aa14e..994c5e082f 100644 --- a/suave/builder/session_manager_test.go +++ b/suave/builder/session_manager_test.go @@ -22,7 +22,7 @@ func TestSessionManager_SessionTimeout(t *testing.T) { SessionIdleTimeout: 500 * time.Millisecond, }) - id, err := mngr.NewSession(context.TODO()) + id, err := mngr.NewSession(context.TODO(), nil) require.NoError(t, err) time.Sleep(1 * time.Second) @@ -42,7 +42,7 @@ func TestSessionManager_MaxConcurrentSessions(t *testing.T) { }) t.Run("SessionAvailable", func(t *testing.T) { - sess, err := mngr.NewSession(context.TODO()) + sess, err := mngr.NewSession(context.TODO(), nil) require.NoError(t, err) require.NotZero(t, sess) }) @@ -53,7 +53,7 @@ func TestSessionManager_MaxConcurrentSessions(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - sess, err := mngr.NewSession(ctx) + sess, err := mngr.NewSession(ctx, nil) require.Zero(t, sess) require.ErrorIs(t, err, context.Canceled) }) @@ -62,7 +62,7 @@ func TestSessionManager_MaxConcurrentSessions(t *testing.T) { time.Sleep(d) // Wait for the session to expire. // We should be able to open a session again. - sess, err := mngr.NewSession(context.TODO()) + sess, err := mngr.NewSession(context.TODO(), nil) require.NoError(t, err) require.NotZero(t, sess) }) @@ -73,7 +73,7 @@ func TestSessionManager_SessionRefresh(t *testing.T) { SessionIdleTimeout: 500 * time.Millisecond, }) - id, err := mngr.NewSession(context.TODO()) + id, err := mngr.NewSession(context.TODO(), nil) require.NoError(t, err) // if we query the session under the idle timeout, @@ -98,7 +98,7 @@ func TestSessionManager_StartSession(t *testing.T) { // test that the session starts and it can simulate transactions mngr, bMock := newSessionManager(t, &Config{}) - id, err := mngr.NewSession(context.TODO()) + id, err := mngr.NewSession(context.TODO(), nil) require.NoError(t, err) txn := bMock.state.newTransfer(t, common.Address{}, big.NewInt(1))