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

allow users to publish blobs #14442

Merged
merged 12 commits into from
Oct 1, 2024
Merged

Conversation

0w3n-d
Copy link
Contributor

@0w3n-d 0w3n-d commented Sep 11, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

Allowing users to publish blobs before publishing blocks, gives the blobs a head start. They can begin to propagate around the network while the block is being validated.

Which issues(s) does this PR fix?

Fixes #

Other notes for review

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have made an appropriate entry to CHANGELOG.md.
  • I have added a description to this PR with sufficient context for reviewers to understand this PR.

@0w3n-d 0w3n-d requested a review from a team as a code owner September 11, 2024 18:06
@CLAassistant
Copy link

CLAassistant commented Sep 11, 2024

CLA assistant check
All committers have signed the CLA.

@@ -558,6 +559,16 @@ func (s *Service) beaconEndpoints(
handler: server.PublishBlockV2,
methods: []string{http.MethodPost},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

since this isn't a beacon-api https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/ this should probably go under prysmBeaconEndpoints ( line 930 and below in the same file) and be under that namespace with the prysm subpath

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -31,6 +31,7 @@ func Test_endpoints(t *testing.T) {
"/eth/v2/beacon/blinded_blocks": {http.MethodPost},
"/eth/v1/beacon/blocks": {http.MethodPost},
"/eth/v2/beacon/blocks": {http.MethodPost},
"/eth/v2/beacon/blobs": {http.MethodPost},
Copy link
Contributor

Choose a reason for hiding this comment

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

path would be affected based on my previous comment

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

return
}

readOnlySc, err := blocks.NewROBlobWithRoot(sc, beaconRoot)
Copy link
Contributor

Choose a reason for hiding this comment

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

we have a helper function bytesutil.ToBytes32 maybe don't need lines 981/982

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


type PublishBlobsRequest struct {
BlobSidecars *BlobSidecars `json:"blob_sidecars"`
BeaconRoot string `json:"beacon_root"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be called either block_root or beacon_block_root since there is no such thing as a beacon root

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -959,6 +959,54 @@ func (s *Server) publishBlock(ctx context.Context, w http.ResponseWriter, r *htt
httputil.HandleError(w, "Body does not represent a valid block type", http.StatusBadRequest)
}

func (s *Server) PublishBlobs(w http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Echoing what @james-prysm said, this handler should be placed in /home/radek/go/prysm/beacon-chain/rpc/prysm/beacon/handlers.go since it's not an official Beacon API endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -558,6 +559,16 @@ func (s *Service) beaconEndpoints(
handler: server.PublishBlockV2,
methods: []string{http.MethodPost},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -31,6 +31,7 @@ func Test_endpoints(t *testing.T) {
"/eth/v2/beacon/blinded_blocks": {http.MethodPost},
"/eth/v1/beacon/blocks": {http.MethodPost},
"/eth/v2/beacon/blocks": {http.MethodPost},
"/eth/v2/beacon/blobs": {http.MethodPost},
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

copy(beaconRoot[:], root)

for _, blobSidecar := range req.BlobSidecars.Sidecars {

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


root, err := bytesutil.DecodeHexWithLength(req.BeaconRoot, 32)
if err != nil {
httputil.HandleError(w, "Could not decode beacon root", http.StatusBadRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
httputil.HandleError(w, "Could not decode beacon root", http.StatusBadRequest)
httputil.HandleError(w, "Could not decode block root", http.StatusBadRequest)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


sc, err := blobSidecar.ToConsensus()
if err != nil {
http.Error(w, "Could not decode blob sidecar", http.StatusBadRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use httputil.HandleError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


readOnlySc, err := blocks.NewROBlobWithRoot(sc, beaconRoot)
if err != nil {
http.Error(w, "Could not create read-only blob", http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use httputil.HandleError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


verifiedBlob := blocks.NewVerifiedROBlob(readOnlySc)
if err := s.BlobReceiver.ReceiveBlob(ctx, verifiedBlob); err != nil {
http.Error(w, "Could not receive blob", http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use httputil.HandleError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@0w3n-d 0w3n-d force-pushed the publish_blobs branch 3 times, most recently from abb5e6d to e7017f0 Compare September 12, 2024 15:35

go_library(
name = "go_default_library",
testonly = True,
Copy link
Member

Choose a reason for hiding this comment

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

Nice. Thanks for marking this as testonly = True.

@@ -18,12 +18,15 @@ go_library(
"//beacon-chain/rpc/eth/helpers:go_default_library",
"//beacon-chain/rpc/eth/shared:go_default_library",
"//beacon-chain/rpc/lookup:go_default_library",
Copy link
Member

Choose a reason for hiding this comment

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

This file is missing somethings. Please run bazel run //:gazelle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

beacon-chain/rpc/prysm/beacon/handlers.go Show resolved Hide resolved
@james-prysm
Copy link
Contributor

waiting for conflicts to resolve before next review

@0w3n-d
Copy link
Contributor Author

0w3n-d commented Sep 17, 2024

waiting for conflicts to resolve before next review

Conflicts resolved now

}
}`, Blob)

var PublishBlobsRequestEmptySidecarsList = fmt.Sprintf(`{
Copy link
Contributor

Choose a reason for hiding this comment

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

linter complaining here

@james-prysm
Copy link
Contributor

There are linting errors

@0w3n-d
Copy link
Contributor Author

0w3n-d commented Sep 30, 2024

There are linting errors

linting should be fixed now

@james-prysm
Copy link
Contributor

seems like stuff is still broken

Allowing users to publish blobs before publishing blocks, gives the blobs a head start. They can begin to propagate around the network while the block is being validated.
@0w3n-d
Copy link
Contributor Author

0w3n-d commented Oct 1, 2024

seems like stuff is still broken

OK hopefully It's fixed now. I've also squashed the commits as it was getting a bit long.

@prestonvanloon
Copy link
Member

Please run gazelle

@0w3n-d
Copy link
Contributor Author

0w3n-d commented Oct 1, 2024

Please run gazelle

Done

prestonvanloon
prestonvanloon previously approved these changes Oct 1, 2024
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
rkapka
rkapka previously approved these changes Oct 1, 2024
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
beacon-chain/rpc/prysm/beacon/handlers.go Outdated Show resolved Hide resolved
@rkapka rkapka enabled auto-merge October 1, 2024 20:01
@rkapka rkapka added this pull request to the merge queue Oct 1, 2024
Merged via the queue into prysmaticlabs:develop with commit 2e29164 Oct 1, 2024
18 checks passed
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.

5 participants