Add args to newSession

This commit is contained in:
Ferran Borreguero 2024-02-07 09:09:46 +00:00
parent 93ef61bfad
commit 7d72612dbb
6 changed files with 29 additions and 16 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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()
}

View file

@ -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:

View file

@ -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))