mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Expose Bid as function
This commit is contained in:
parent
1652002fad
commit
2cd097dffb
7 changed files with 53 additions and 33 deletions
|
|
@ -117,7 +117,7 @@ func (b *Builder) BuildBlock() (*types.Block, error) {
|
|||
return block, nil
|
||||
}
|
||||
|
||||
func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||
func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*suavextypes.SubmitBlockRequest, error) {
|
||||
work := b.env
|
||||
|
||||
if b.block == nil {
|
||||
|
|
@ -157,7 +157,7 @@ func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*SubmitBlockRequest, erro
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bidRequest := SubmitBlockRequest{
|
||||
bidRequest := suavextypes.SubmitBlockRequest{
|
||||
Root: phase0.Root(root),
|
||||
SubmitBlockRequest: denebBuilder.SubmitBlockRequest{
|
||||
Message: &blockBidMsg,
|
||||
|
|
@ -169,13 +169,6 @@ func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*SubmitBlockRequest, erro
|
|||
return &bidRequest, nil
|
||||
}
|
||||
|
||||
// SubmitBlockRequest is an extension of the builder.SubmitBlockRequest with the root
|
||||
// of the bid that needs to be signed
|
||||
type SubmitBlockRequest struct {
|
||||
denebBuilder.SubmitBlockRequest
|
||||
Root phase0.Root
|
||||
}
|
||||
|
||||
func receiptToSimResult(receipt *types.Receipt) *suavextypes.SimulateTransactionResult {
|
||||
result := &suavextypes.SimulateTransactionResult{
|
||||
Success: true,
|
||||
|
|
|
|||
|
|
@ -104,6 +104,26 @@ func TestBuilder_ContractWithLogs(t *testing.T) {
|
|||
require.Equal(t, simResult.Logs[0].Topics[0], suaveExample1Artifact.Abi.Events["SomeEvent"].ID)
|
||||
}
|
||||
|
||||
func TestBuilder_Bid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
config, _ := newMockBuilderConfig(t)
|
||||
|
||||
builder, err := NewBuilder(config, &BuilderArgs{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = builder.Bid([48]byte{})
|
||||
require.Error(t, err, "cannot create bid without block")
|
||||
|
||||
_, err = builder.BuildBlock()
|
||||
require.NoError(t, err)
|
||||
|
||||
req, err := builder.Bid([48]byte{})
|
||||
require.NoError(t, err)
|
||||
|
||||
fmt.Println("-- req --", req)
|
||||
}
|
||||
|
||||
func newMockBuilderConfig(t *testing.T) (*BuilderConfig, *testWorkerBackend) {
|
||||
var (
|
||||
db = rawdb.NewMemoryDatabase()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"context"
|
||||
"math/big"
|
||||
|
||||
denebBuilder "github.com/attestantio/go-builder-client/api/deneb"
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
|
@ -65,9 +67,16 @@ type simulateLogMarshaling struct {
|
|||
Data hexutil.Bytes
|
||||
}
|
||||
|
||||
// SubmitBlockRequest is an extension of the builder.SubmitBlockRequest with the root
|
||||
// of the bid that needs to be signed
|
||||
type SubmitBlockRequest struct {
|
||||
denebBuilder.SubmitBlockRequest
|
||||
Root phase0.Root
|
||||
}
|
||||
|
||||
type API interface {
|
||||
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
||||
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||
BuildBlock(ctx context.Context, sessionId string) error
|
||||
Bid(ctx context.Context, sessioId string, blsPubKey string) error
|
||||
Bid(ctx context.Context, sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
|
@ -45,6 +46,8 @@ func (a *APIClient) BuildBlock(ctx context.Context, sessionId string) error {
|
|||
return a.rpc.CallContext(ctx, nil, "suavex_buildBlock", sessionId)
|
||||
}
|
||||
|
||||
func (a *APIClient) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
||||
return a.rpc.CallContext(ctx, nil, "suavex_bid", sessioId, blsPubKey)
|
||||
func (a *APIClient) Bid(ctx context.Context, sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||
var req *SubmitBlockRequest
|
||||
err := a.rpc.CallContext(ctx, &req, "suavex_bid", sessioId, blsPubKey)
|
||||
return req, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ type SessionManager interface {
|
|||
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
||||
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||
BuildBlock(sessionId string) error
|
||||
Bid(sessionId string, blsPubKey string) error
|
||||
Bid(sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
||||
}
|
||||
|
||||
func NewServer(s SessionManager) *Server {
|
||||
|
|
@ -39,8 +40,8 @@ func (s *Server) BuildBlock(ctx context.Context, sessionId string) error {
|
|||
return s.sessionMngr.BuildBlock(sessionId)
|
||||
}
|
||||
|
||||
func (s *Server) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
||||
return nil
|
||||
func (s *Server) Bid(ctx context.Context, sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||
return s.sessionMngr.Bid(sessionId, blsPubKey)
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
|
@ -46,6 +47,6 @@ func (nullSessionManager) BuildBlock(sessionId string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (nullSessionManager) Bid(sessioId string, blsPubKey string) error {
|
||||
return nil
|
||||
func (nullSessionManager) Bid(sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/txpool"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
|
|
@ -19,21 +19,6 @@ import (
|
|||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// blockchain is the minimum interface to the blockchain
|
||||
// required to build a block
|
||||
type blockchain interface {
|
||||
core.ChainContext
|
||||
|
||||
// Header returns the current tip of the chain
|
||||
CurrentHeader() *types.Header
|
||||
|
||||
// StateAt returns the state at the given root
|
||||
StateAt(root common.Hash) (*state.StateDB, error)
|
||||
|
||||
// Config returns the chain config
|
||||
Config() *params.ChainConfig
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
GasCeil uint64
|
||||
SessionIdleTimeout time.Duration
|
||||
|
|
@ -174,6 +159,14 @@ func (s *SessionManager) BuildBlock(sessionId string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *SessionManager) Bid(sessionId string, blsPubKey phase0.BLSPubKey) (*api.SubmitBlockRequest, error) {
|
||||
builder, err := s.getSession(sessionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return builder.Bid(blsPubKey)
|
||||
}
|
||||
|
||||
// CalcBaseFee calculates the basefee of the header.
|
||||
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
||||
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
|
||||
|
|
|
|||
Loading…
Reference in a new issue