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

Switch to publishBlockV2 endpoint #492

Merged
merged 1 commit into from
Aug 2, 2023
Merged

Switch to publishBlockV2 endpoint #492

merged 1 commit into from
Aug 2, 2023

Conversation

avalonche
Copy link
Collaborator

@avalonche avalonche commented Aug 1, 2023

📝 Summary

Switching calling publishBlockV1 to publishBlockV2 in the relay. Default broadcast validation is consensus_and_equivocation and can be toggled using env vars.

⛱ Motivation and Context

The new publishBlockV2 endpoint have extra parameters to allow consensus and equivocation checks. This is already implemented in prysm and lighthouse and will be needed for the Deneb upgrades.

📚 References

publishBlockV2 endpoint: https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlockV2


✅ I have run these commands

  • make lint
  • make test-race
  • go mod tidy
  • I have seen and agree to CONTRIBUTING.md

@codecov-commenter
Copy link

Codecov Report

Merging #492 (c3a1829) into main (f729e37) will decrease coverage by 0.15%.
The diff coverage is 9.09%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
- Coverage   30.67%   30.53%   -0.15%     
==========================================
  Files          24       24              
  Lines        4815     4841      +26     
==========================================
+ Hits         1477     1478       +1     
- Misses       3140     3164      +24     
- Partials      198      199       +1     
Flag Coverage Δ
unittests 30.53% <9.09%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
beaconclient/mock_beacon_instance.go 63.15% <0.00%> (ø)
beaconclient/multi_beacon_client.go 40.66% <7.14%> (-1.88%) ⬇️
beaconclient/util.go 24.59% <8.33%> (-5.41%) ⬇️
beaconclient/prod_beacon_instance.go 12.59% <11.76%> (-0.21%) ⬇️

Copy link
Collaborator

@jtraglia jtraglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a minor concern about the hardcoded capella header value.

func (c *ProdBeaconInstance) PublishBlock(block *common.SignedBeaconBlock, broadcastValidation BroadcastValidation) (code int, err error) {
uri := fmt.Sprintf("%s/eth/v2/beacon/blocks?broadcast_validation=%s", c.beaconURI, broadcastValidation.String())
headers := http.Header{}
headers.Add("Eth-Consensus-Version", common.ForkVersionStringCapella)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work with deneb? Could we un-hardcode this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, as part of #489 planning to switch over to a VersionedSignedBeaconBlock in order to get the consensus version

)

func (b BroadcastValidation) String() string {
return [...]string{"gossip", "consensus", "consensus_and_equivocation"}[b]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: technically BroadcastValidation is just an int and could be any int value, which wouldn't work so well here. But I don't think it's worth changing though, as parseBroadcastValidationString is safe & you'd have to intentionally make this mistake.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a simple if int(b) >= len(broadcastValidationStrings) { will suffice, will add as part of future PR

@avalonche avalonche merged commit 10859e6 into main Aug 2, 2023
@avalonche avalonche deleted the publish-block-v2 branch August 2, 2023 00:06
@@ -19,7 +20,17 @@ var (
StateIDJustified = "justified"
)

func fetchBeacon(method, url string, payload, dst any, timeout *time.Duration) (code int, err error) {
func parseBroadcastValidationString(s string) (BroadcastValidation, bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment about what this function does would be nice. also a test

@@ -80,6 +94,18 @@ func NewMultiBeaconClient(log *logrus.Entry, beaconInstances []IBeaconInstance)
client.ffAllowSyncingBeaconNode = true
}

if os.Getenv("BROADCAST_VALIDATION") != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document!

also don't call os.Getenv twice, rather once and then work on the string

@@ -64,6 +76,7 @@ type MultiBeaconClient struct {

// feature flags
ffAllowSyncingBeaconNode bool
ffBroadcastValidation BroadcastValidation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ff prefix means feature flag, usually bool

this should probably be broadcastMode

@metachris
Copy link
Collaborator

Note: these changes may or may not work with current CL clients. Currently testing with:

  • Lighthouse: v4.3.0
  • Prysm: v4.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants