This repository was archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Add SSE subscription to builder #53
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
27c13dd
Add SSE subscription to builder
avalonche 0bd6488
withdrawals marshalling
avalonche 18c472d
add stop channel
avalonche ab0434c
pr comments
avalonche f51d92f
Add handling multiple beacon clients (#57)
Ruteri fd689ce
linting
avalonche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,13 +37,6 @@ type ValidatorData struct { | |
| GasLimit uint64 | ||
| } | ||
|
|
||
| type IBeaconClient interface { | ||
| isValidator(pubkey PubkeyHex) bool | ||
| getProposerForNextSlot(requestedSlot uint64) (PubkeyHex, error) | ||
| Start() error | ||
| Stop() | ||
| } | ||
|
|
||
| type IRelay interface { | ||
| SubmitBlock(msg *boostTypes.BuilderSubmitBlockRequest, vd ValidatorData) error | ||
| SubmitBlockCapella(msg *capellaapi.SubmitBlockRequest, vd ValidatorData) error | ||
|
|
@@ -64,6 +57,7 @@ type Builder struct { | |
| eth IEthereumService | ||
| dryRun bool | ||
| validator *blockvalidation.BlockValidationAPI | ||
| beaconClient IBeaconClient | ||
| builderSecretKey *bls.SecretKey | ||
| builderPublicKey boostTypes.PublicKey | ||
| builderSigningDomain boostTypes.Domain | ||
|
|
@@ -75,9 +69,11 @@ type Builder struct { | |
| slotAttrs []types.BuilderPayloadAttributes | ||
| slotCtx context.Context | ||
| slotCtxCancel context.CancelFunc | ||
|
|
||
| stop chan struct{} | ||
| } | ||
|
|
||
| func NewBuilder(sk *bls.SecretKey, ds flashbotsextra.IDatabaseService, relay IRelay, builderSigningDomain boostTypes.Domain, eth IEthereumService, dryRun bool, validator *blockvalidation.BlockValidationAPI) *Builder { | ||
| func NewBuilder(sk *bls.SecretKey, ds flashbotsextra.IDatabaseService, relay IRelay, builderSigningDomain boostTypes.Domain, eth IEthereumService, dryRun bool, validator *blockvalidation.BlockValidationAPI, beaconClient IBeaconClient) *Builder { | ||
| pkBytes := bls.PublicKeyFromSecretKey(sk).Compress() | ||
| pk := boostTypes.PublicKey{} | ||
| pk.FromSlice(pkBytes) | ||
|
|
@@ -89,6 +85,7 @@ func NewBuilder(sk *bls.SecretKey, ds flashbotsextra.IDatabaseService, relay IRe | |
| eth: eth, | ||
| dryRun: dryRun, | ||
| validator: validator, | ||
| beaconClient: beaconClient, | ||
| builderSecretKey: sk, | ||
| builderPublicKey: pk, | ||
| builderSigningDomain: builderSigningDomain, | ||
|
|
@@ -97,14 +94,42 @@ func NewBuilder(sk *bls.SecretKey, ds flashbotsextra.IDatabaseService, relay IRe | |
| slot: 0, | ||
| slotCtx: slotCtx, | ||
| slotCtxCancel: slotCtxCancel, | ||
|
|
||
| stop: make(chan struct{}, 1), | ||
| } | ||
| } | ||
|
|
||
| func (b *Builder) Start() error { | ||
| // Start regular payload attributes updates | ||
| go func() { | ||
| c := make(chan types.BuilderPayloadAttributes) | ||
| go b.beaconClient.SubscribeToPayloadAttributesEvents(c) | ||
|
|
||
| currentSlot := uint64(0) | ||
|
|
||
| for { | ||
| select { | ||
| case <-b.stop: | ||
| return | ||
| case payloadAttributes := <-c: | ||
| // Right now we are building only on a single head. This might change in the future! | ||
| if payloadAttributes.Slot < currentSlot { | ||
| continue | ||
| } else if payloadAttributes.Slot == currentSlot { | ||
| b.OnPayloadAttribute(&payloadAttributes) | ||
| } else if payloadAttributes.Slot > currentSlot { | ||
| currentSlot = payloadAttributes.Slot | ||
| b.OnPayloadAttribute(&payloadAttributes) | ||
| } | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| return b.relay.Start() | ||
| } | ||
|
|
||
| func (b *Builder) Stop() error { | ||
| close(b.stop) | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -277,18 +302,19 @@ func (b *Builder) OnPayloadAttribute(attrs *types.BuilderPayloadAttributes) erro | |
| b.slotMu.Lock() | ||
| defer b.slotMu.Unlock() | ||
|
|
||
| if b.slot != attrs.Slot { | ||
| if b.slotCtxCancel != nil { | ||
| b.slotCtxCancel() | ||
| } | ||
| // Forcibly cancel previous building job, build on top of reorgable blocks as this is the behaviour relays expect. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please explain why "buidling on multiple tips" is no longer necessary?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, it just doesn't work with how relays are set up. This will come back shortly after Capella. |
||
| // This will change in the future | ||
|
|
||
| slotCtx, slotCtxCancel := context.WithTimeout(context.Background(), 12*time.Second) | ||
| b.slot = attrs.Slot | ||
| b.slotAttrs = nil | ||
| b.slotCtx = slotCtx | ||
| b.slotCtxCancel = slotCtxCancel | ||
| if b.slotCtxCancel != nil { | ||
| b.slotCtxCancel() | ||
| } | ||
|
|
||
| slotCtx, slotCtxCancel := context.WithTimeout(context.Background(), 12*time.Second) | ||
| b.slot = attrs.Slot | ||
| b.slotAttrs = nil | ||
| b.slotCtx = slotCtx | ||
| b.slotCtxCancel = slotCtxCancel | ||
|
|
||
| for _, currentAttrs := range b.slotAttrs { | ||
| if attrs.Equal(¤tAttrs) { | ||
| log.Debug("ignoring known payload attribute", "slot", attrs.Slot, "hash", attrs.HeadHash) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.