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
|
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
|
work := b.env
|
||||||
|
|
||||||
if b.block == nil {
|
if b.block == nil {
|
||||||
|
|
@ -157,7 +157,7 @@ func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*SubmitBlockRequest, erro
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bidRequest := SubmitBlockRequest{
|
bidRequest := suavextypes.SubmitBlockRequest{
|
||||||
Root: phase0.Root(root),
|
Root: phase0.Root(root),
|
||||||
SubmitBlockRequest: denebBuilder.SubmitBlockRequest{
|
SubmitBlockRequest: denebBuilder.SubmitBlockRequest{
|
||||||
Message: &blockBidMsg,
|
Message: &blockBidMsg,
|
||||||
|
|
@ -169,13 +169,6 @@ func (b *Builder) Bid(builderPubKey phase0.BLSPubKey) (*SubmitBlockRequest, erro
|
||||||
return &bidRequest, nil
|
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 {
|
func receiptToSimResult(receipt *types.Receipt) *suavextypes.SimulateTransactionResult {
|
||||||
result := &suavextypes.SimulateTransactionResult{
|
result := &suavextypes.SimulateTransactionResult{
|
||||||
Success: true,
|
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)
|
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) {
|
func newMockBuilderConfig(t *testing.T) (*BuilderConfig, *testWorkerBackend) {
|
||||||
var (
|
var (
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"math/big"
|
"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"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -65,9 +67,16 @@ type simulateLogMarshaling struct {
|
||||||
Data hexutil.Bytes
|
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 {
|
type API interface {
|
||||||
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
||||||
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||||
BuildBlock(ctx context.Context, sessionId string) 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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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)
|
return a.rpc.CallContext(ctx, nil, "suavex_buildBlock", sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIClient) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
func (a *APIClient) Bid(ctx context.Context, sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||||
return a.rpc.CallContext(ctx, nil, "suavex_bid", sessioId, blsPubKey)
|
var req *SubmitBlockRequest
|
||||||
|
err := a.rpc.CallContext(ctx, &req, "suavex_bid", sessioId, blsPubKey)
|
||||||
|
return req, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package api
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -13,7 +14,7 @@ type SessionManager interface {
|
||||||
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
||||||
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||||
BuildBlock(sessionId string) error
|
BuildBlock(sessionId string) error
|
||||||
Bid(sessionId string, blsPubKey string) error
|
Bid(sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(s SessionManager) *Server {
|
func NewServer(s SessionManager) *Server {
|
||||||
|
|
@ -39,8 +40,8 @@ func (s *Server) BuildBlock(ctx context.Context, sessionId string) error {
|
||||||
return s.sessionMngr.BuildBlock(sessionId)
|
return s.sessionMngr.BuildBlock(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
func (s *Server) Bid(ctx context.Context, sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||||
return nil
|
return s.sessionMngr.Bid(sessionId, blsPubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove
|
// TODO: Remove
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
@ -46,6 +47,6 @@ func (nullSessionManager) BuildBlock(sessionId string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nullSessionManager) Bid(sessioId string, blsPubKey string) error {
|
func (nullSessionManager) Bid(sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error) {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/attestantio/go-eth2-client/spec/phase0"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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/txpool"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
|
|
@ -19,21 +19,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"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 {
|
type Config struct {
|
||||||
GasCeil uint64
|
GasCeil uint64
|
||||||
SessionIdleTimeout time.Duration
|
SessionIdleTimeout time.Duration
|
||||||
|
|
@ -174,6 +159,14 @@ func (s *SessionManager) BuildBlock(sessionId string) error {
|
||||||
return err
|
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.
|
// CalcBaseFee calculates the basefee of the header.
|
||||||
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
||||||
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
|
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue