p2p_bidder

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package p2p_bidder implements the active p2p bidding flow of ePBS (bid windows, bid submission, competitor tracking, registration state).

Index

Constants

View Source
const (
	RegistrationStateUnknown             int32 = 0 // Not checked yet
	RegistrationStatePending             int32 = 1 // Deposit submitted, waiting for inclusion in beacon state
	RegistrationStateRegistered          int32 = 2 // Builder registered and deposit epoch finalized
	RegistrationStateWaitingGloas        int32 = 3 // Waiting for Gloas fork activation
	RegistrationStatePendingFinalization int32 = 4 // Builder in beacon state but deposit epoch not finalized
	RegistrationStateExiting             int32 = 5 // Exit submitted, withdrawable epoch set but not reached
	RegistrationStateExited              int32 = 6 // Withdrawable epoch passed, builder has exited
	RegistrationStateUnregistered        int32 = 7 // Builder not in beacon state and no deposit in progress
)

Registration state constants for the p2p bidder service.

Variables

This section is empty.

Functions

func RegistrationStateName

func RegistrationStateName(state int32) string

RegistrationStateName returns the string name for a registration state.

Types

type BidCreator

type BidCreator struct {
	// contains filtered or unexported fields
}

BidCreator builds ePBS bids via the shared payload_bidder and gossips them over p2p. It owns the p2p transport and the (caller-computed) bid economics; the bid construction and signing live in payload_bidder.

func NewBidCreator

func NewBidCreator(
	signer *payload_bidder.Signer,
	clClient *beacon.Client,
	chainSvc chain.Service,
	builderIndex uint64,
	log logrus.FieldLogger,
) *BidCreator

NewBidCreator creates a new bid creator.

func (*BidCreator) CreateAndSubmitBid

func (c *BidCreator) CreateAndSubmitBid(
	ctx context.Context,
	payload *payload_builder.Payload,
	bidValue uint64,
) error

CreateAndSubmitBid builds, signs, and gossips a bid for the given payload at the supplied value. The competitive bid value is decided by the scheduler; the ePBS p2p path takes no execution payment.

func (*BidCreator) GetBuilderIndex

func (c *BidCreator) GetBuilderIndex() uint64

GetBuilderIndex returns the current builder index.

func (*BidCreator) SetBuilderIndex

func (c *BidCreator) SetBuilderIndex(index uint64)

SetBuilderIndex updates the builder index.

type BidSubmissionEvent

type BidSubmissionEvent struct {
	Slot      phase0.Slot
	BlockHash [32]byte
	Value     uint64
	BidCount  int
	Success   bool
	Warning   string // Non-fatal warning (e.g. "no proposer preferences")
	Error     string
}

BidSubmissionEvent represents a bid submission attempt (success or failure).

type BidTracker

type BidTracker struct {
	// contains filtered or unexported fields
}

BidTracker tracks bids observed on the p2p network for competition analysis.

func NewBidTracker

func NewBidTracker(ourBuilderIdx uint64, log logrus.FieldLogger) *BidTracker

NewBidTracker creates a new bid tracker.

func (*BidTracker) Cleanup

func (t *BidTracker) Cleanup(olderThan phase0.Slot)

Cleanup removes old slot data.

func (*BidTracker) GetHighestBid

func (t *BidTracker) GetHighestBid(slot phase0.Slot) *TrackedBid

GetHighestBid returns the highest bid for a slot.

func (*BidTracker) GetOurBid

func (t *BidTracker) GetOurBid(slot phase0.Slot) *TrackedBid

GetOurBid returns our bid for a slot.

func (*BidTracker) GetSlotBids

func (t *BidTracker) GetSlotBids(slot phase0.Slot) *SlotBids

GetSlotBids returns all bids for a slot.

func (*BidTracker) SetBuilderIndex

func (t *BidTracker) SetBuilderIndex(index uint64)

SetBuilderIndex updates the builder index.

func (*BidTracker) TrackBid

func (t *BidTracker) TrackBid(bid *ExecutionPayloadBid, isOurs bool)

TrackBid adds a bid to the tracker.

type ExecutionPayloadBid

type ExecutionPayloadBid struct {
	ParentBlockHash  phase0.Hash32
	ParentBlockRoot  phase0.Root
	BlockHash        phase0.Hash32
	FeeRecipient     [20]byte
	GasLimit         uint64
	BuilderIndex     uint64
	Slot             phase0.Slot
	Value            uint64 // Gwei
	ExecutionPayment uint64 // Gwei
}

ExecutionPayloadBid represents a bid for an execution payload.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler handles time-based bid scheduling. It uses a simple loop that checks current time and triggers actions.

func NewScheduler

func NewScheduler(
	cfg *config.EPBSConfig,
	chainSvc chain.Service,
	bidCreator *BidCreator,
	bidTracker *BidTracker,
	payloadCache *payload_builder.PayloadCache,
	service *Service,
	blsSigner *signer.BLSSigner,
	propPrefsStore *memstore.Store[phase0.Slot, *gloasspec.SignedProposerPreferences],
	log logrus.FieldLogger,
) *Scheduler

NewScheduler creates a new scheduler.

func (*Scheduler) Cleanup

func (s *Scheduler) Cleanup(olderThan phase0.Slot)

Cleanup removes old state.

func (*Scheduler) GetBidTracker

func (s *Scheduler) GetBidTracker() *BidTracker

GetBidTracker returns the bid tracker.

func (*Scheduler) OnHeadEvent

func (s *Scheduler) OnHeadEvent(event *beacon.HeadEvent)

OnHeadEvent closes bidding for the slot — once a block is produced, no more bids can make it.

func (*Scheduler) ProcessTick

func (s *Scheduler) ProcessTick(ctx context.Context)

ProcessTick is called frequently to check if any bids are due.

func (*Scheduler) UpdateConfig

func (s *Scheduler) UpdateConfig(cfg *config.EPBSConfig)

UpdateConfig updates the scheduler configuration.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the p2p bidder orchestrator that handles time-scheduled bidding. It submits bids during the slot's bid window, tracks competitor bids from the gossip stream, and maintains the builder's registration state. Once a slot's block is produced (head event), the bidder is done with that slot — reveals, inclusion tracking, and payment accounting live in the shared payload_bidder services.

func NewService

func NewService(
	cfg *config.EPBSConfig,
	clClient *beacon.Client,
	chainSvc chain.Service,
	blsSigner *signer.BLSSigner,
	propPrefsStore *memstore.Store[phase0.Slot, *gloasspec.SignedProposerPreferences],
	log logrus.FieldLogger,
) (*Service, error)

NewService creates a new p2p bidder service. propPrefsStore is the shared per-slot proposer preferences store (owned by payload_bidder.ProposerPreferencesService); it gates bidding — slots without a cached preference are skipped. It may be nil, in which case no bids are submitted.

func (*Service) FireBidSubmission

func (s *Service) FireBidSubmission(event *BidSubmissionEvent)

FireBidSubmission fires a bid submission event.

func (*Service) GetBidTracker

func (s *Service) GetBidTracker() *BidTracker

GetBidTracker returns the bid tracker.

func (*Service) GetBuilderIndex

func (s *Service) GetBuilderIndex() uint64

GetBuilderIndex returns the builder index.

func (*Service) GetBuilderPubkey

func (s *Service) GetBuilderPubkey() phase0.BLSPubKey

GetBuilderPubkey returns the builder public key.

func (*Service) GetRegistrationState

func (s *Service) GetRegistrationState() int32

GetRegistrationState returns the current registration state.

func (*Service) IsActive

func (s *Service) IsActive() bool

IsActive returns whether the builder can actively participate (registered or pending finalization).

func (*Service) IsEnabled

func (s *Service) IsEnabled() bool

IsEnabled returns whether the p2p bidder service is enabled.

func (*Service) IsRegistered

func (s *Service) IsRegistered() bool

IsRegistered returns whether the builder has a valid index and its deposit is finalized.

func (*Service) RefreshRegistrationState

func (s *Service) RefreshRegistrationState()

RefreshRegistrationState re-evaluates the registration state from the chain service. Called periodically to detect state transitions (e.g. finalization, exit).

func (*Service) SetBuilderRegistered

func (s *Service) SetBuilderRegistered(index uint64)

SetBuilderRegistered updates the builder index when the lifecycle manager detects registration. It sets the appropriate state based on finalization status. Called by the lifecycle manager's registration callback.

func (*Service) SetEnabled

func (s *Service) SetEnabled(enabled bool)

SetEnabled sets the enabled state of the p2p bidder service.

func (*Service) SetRegistrationPending

func (s *Service) SetRegistrationPending()

SetRegistrationPending marks the builder as having a deposit in flight. Called by the lifecycle manager when a deposit is submitted.

func (*Service) Start

func (s *Service) Start(ctx context.Context, builderSvc *payload_builder.Service) error

Start starts the p2p bidder service.

func (*Service) Stop

func (s *Service) Stop()

Stop stops the p2p bidder service.

func (*Service) SubscribeBidSubmissions

func (s *Service) SubscribeBidSubmissions(capacity int) *utils.Subscription[*BidSubmissionEvent]

SubscribeBidSubmissions subscribes to bid submission events.

func (*Service) UpdateConfig

func (s *Service) UpdateConfig(cfg *config.EPBSConfig)

UpdateConfig updates the service configuration at runtime.

type SlotBids

type SlotBids struct {
	Slot       phase0.Slot
	Bids       map[uint64]*TrackedBid // BuilderIndex -> Bid
	HighestBid *TrackedBid
	OurBid     *TrackedBid
	WinningBid *TrackedBid // Set after block inclusion
}

SlotBids holds all bids for a specific slot.

func NewSlotBids

func NewSlotBids(slot phase0.Slot) *SlotBids

NewSlotBids creates a new SlotBids instance for the given slot.

type SlotState

type SlotState struct {
	LastBidTime      time.Time
	LastBidHash      phase0.Hash32
	BidCount         int
	BidsClosed       bool // Block received, no more bids possible
	NoPrefsWarnedFor bool // Missing-preferences skip already reported for this slot
}

SlotState tracks the bidding state for a single slot.

type TrackedBid

type TrackedBid struct {
	Bid          *ExecutionPayloadBid
	BuilderIndex uint64
	ReceivedAt   time.Time
	IsOurs       bool
}

TrackedBid represents a bid being tracked for competition analysis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL