Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/tracker: refactor inclusion checker #2120

Merged
merged 10 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ linters:
- maintidx
- maligned
- musttag
- nestif
- nonamedreturns
- paralleltest
- prealloc
Expand Down
11 changes: 8 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
feeRecipientFunc := func(pubkey core.PubKey) string {
return feeRecipientAddrByCorePubkey[pubkey]
}

sched.SubscribeSlots(setFeeRecipient(eth2Cl, eth2Pubkeys, feeRecipientFunc))
sched.SubscribeSlots(tracker.NewInclDelayFunc(eth2Cl, sched.GetDutyDefinition))

fetch, err := fetcher.New(eth2Cl, feeRecipientFunc)
if err != nil {
Expand Down Expand Up @@ -462,9 +460,15 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
if err != nil {
return err
}

inclusion, err := tracker.NewInclusion(ctx, eth2Cl)
if err != nil {
return err
}

opts := []core.WireOption{
core.WithTracing(),
core.WithTracking(track),
core.WithTracking(track, inclusion.Submitted),
core.WithAsyncRetry(retryer),
}
core.Wire(sched, fetch, cons, dutyDB, vapi, parSigDB, parSigEx, sigAgg, aggSigDB, broadcaster, opts...)
Expand All @@ -482,6 +486,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
life.RegisterStart(lifecycle.AsyncAppCtx, lifecycle.StartP2PConsensus, startCons)
life.RegisterStart(lifecycle.AsyncAppCtx, lifecycle.StartAggSigDB, lifecycle.HookFuncCtx(aggSigDB.Run))
life.RegisterStart(lifecycle.AsyncAppCtx, lifecycle.StartParSigDB, lifecycle.HookFuncCtx(parSigDB.Trim))
life.RegisterStart(lifecycle.AsyncAppCtx, lifecycle.StartTracker, lifecycle.HookFuncCtx(inclusion.Run))
life.RegisterStop(lifecycle.StopScheduler, lifecycle.HookFuncMin(sched.Stop))
life.RegisterStop(lifecycle.StopDutyDB, lifecycle.HookFuncMin(dutyDB.Shutdown))
life.RegisterStop(lifecycle.StopRetryer, lifecycle.HookFuncCtx(retryer.Shutdown))
Expand Down
65 changes: 38 additions & 27 deletions app/eth2wrap/synthproposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,34 +136,31 @@ func (h *synthWrapper) syntheticBlock(ctx context.Context, slot eth2p0.Slot, vId

// Convert signed block into unsigned block with synthetic graffiti and correct slot.

var synthGraffiti [32]byte
copy(synthGraffiti[:], syntheticBlockGraffiti)

feeRecipient := h.getFeeRecipient(vIdx)

block := &spec.VersionedBeaconBlock{Version: signedBlock.Version}

switch signedBlock.Version {
case spec.DataVersionPhase0:
block.Phase0 = signedBlock.Phase0.Message
block.Phase0.Body.Graffiti = synthGraffiti
block.Phase0.Body.Graffiti = GetSyntheticGraffiti()
block.Phase0.Slot = slot
block.Phase0.ProposerIndex = vIdx
case spec.DataVersionAltair:
block.Altair = signedBlock.Altair.Message
block.Altair.Body.Graffiti = synthGraffiti
block.Altair.Body.Graffiti = GetSyntheticGraffiti()
block.Altair.Slot = slot
block.Altair.ProposerIndex = vIdx
case spec.DataVersionBellatrix:
block.Bellatrix = signedBlock.Bellatrix.Message
block.Bellatrix.Body.Graffiti = synthGraffiti
block.Bellatrix.Body.Graffiti = GetSyntheticGraffiti()
block.Bellatrix.Slot = slot
block.Bellatrix.ProposerIndex = vIdx
block.Bellatrix.Body.ExecutionPayload.FeeRecipient = feeRecipient
block.Bellatrix.Body.ExecutionPayload.Transactions = fraction(block.Bellatrix.Body.ExecutionPayload.Transactions)
case spec.DataVersionCapella:
block.Capella = signedBlock.Capella.Message
block.Capella.Body.Graffiti = synthGraffiti
block.Capella.Body.Graffiti = GetSyntheticGraffiti()
block.Capella.Slot = slot
block.Capella.ProposerIndex = vIdx
block.Capella.Body.ExecutionPayload.FeeRecipient = feeRecipient
Expand All @@ -183,28 +180,49 @@ func fraction(transactions []bellatrix.Transaction) []bellatrix.Transaction {

// SubmitBlindedBeaconBlock submits a blinded beacon block or swallows it if marked as synthetic.
func (h *synthWrapper) SubmitBlindedBeaconBlock(ctx context.Context, block *api.VersionedSignedBlindedBeaconBlock) error {
if IsSyntheticBlindedBlock(block) {
log.Debug(ctx, "Synthetic blinded beacon block swallowed")
return nil
}

return h.Client.SubmitBlindedBeaconBlock(ctx, block)
}

// SubmitBeaconBlock submits a beacon block or swallows it if marked as synthetic.
func (h *synthWrapper) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error {
if IsSyntheticBlock(block) {
log.Debug(ctx, "Synthetic beacon block swallowed")
return nil
}

return h.Client.SubmitBeaconBlock(ctx, block)
}

// GetSyntheticGraffiti returns the graffiti used to mark synthetic blocks.
func GetSyntheticGraffiti() [32]byte {
var synthGraffiti [32]byte
copy(synthGraffiti[:], syntheticBlockGraffiti)

return synthGraffiti
}

// IsSyntheticBlindedBlock returns true if the blinded block is a synthetic block.
func IsSyntheticBlindedBlock(block *api.VersionedSignedBlindedBeaconBlock) bool {
var graffiti [32]byte
switch block.Version {
case spec.DataVersionBellatrix:
graffiti = block.Bellatrix.Message.Body.Graffiti
case spec.DataVersionCapella:
graffiti = block.Capella.Message.Body.Graffiti
default:
return errors.New("unknown block version")
}

var synthGraffiti [32]byte
copy(synthGraffiti[:], syntheticBlockGraffiti)
if graffiti == synthGraffiti {
log.Debug(ctx, "Synthetic blinded beacon block swallowed")
return nil
return false
}

return h.Client.SubmitBlindedBeaconBlock(ctx, block)
return graffiti == GetSyntheticGraffiti()
}

// SubmitBeaconBlock submits a beacon block or swallows it if marked as synthetic.
func (h *synthWrapper) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error {
// IsSyntheticBlock returns true if the block is a synthetic block.
func IsSyntheticBlock(block *spec.VersionedSignedBeaconBlock) bool {
var graffiti [32]byte
switch block.Version {
case spec.DataVersionPhase0:
Expand All @@ -216,17 +234,10 @@ func (h *synthWrapper) SubmitBeaconBlock(ctx context.Context, block *spec.Versio
case spec.DataVersionCapella:
graffiti = block.Capella.Message.Body.Graffiti
default:
return errors.New("unknown block version")
}

var synthGraffiti [32]byte
copy(synthGraffiti[:], syntheticBlockGraffiti)
if graffiti == synthGraffiti {
log.Debug(ctx, "Synthetic beacon block swallowed")
return nil
return false
}

return h.Client.SubmitBeaconBlock(ctx, block)
return graffiti == GetSyntheticGraffiti()
}

// synthProposerCache returns a new cache for synthetic proposer duties.
Expand Down
1 change: 0 additions & 1 deletion app/monitoringapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func startReadyChecker(ctx context.Context, tcpNode host.Host, eth2Cl eth2wrap.C
}

syncing, syncDistance, err := beaconNodeSyncing(ctx, eth2Cl)
//nolint:nestif
if err != nil {
err = errReadyBeaconNodeDown
readyzGauge.Set(readyzBeaconNodeDown)
Expand Down
1 change: 0 additions & 1 deletion app/privkeylock/privkeylock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// New creates a private key lock file in path, writing contextStr in it.
// If a private key lock file exists at path New returns an error, a clean-up function otherwise.
func New(path, contextStr string) (func() error, error) {
//nolint:nestif
if _, err := os.Stat(path); err == nil {
readCtxStr, err := os.ReadFile(path)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cluster/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ func (d Definition) NodeIdx(pID peer.ID) (NodeIdx, error) {
}

// VerifySignatures returns true if all config signatures are fully populated and valid. A verified definition is ready for use in DKG.
//
//nolint:nestif
func (d Definition) VerifySignatures() error {
// Skip signature verification for definition versions earlier than v1.3 since there are no EIP712 signatures before v1.3.0.
if !supportEIP712Sigs(d.Version) && !eip712SigsPresent(d.Operators) {
Expand Down
124 changes: 0 additions & 124 deletions core/tracker/incldelay.go

This file was deleted.

Loading