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

adding builder boost factor to get block v3 #13409

Merged
merged 15 commits into from
Jan 4, 2024
2 changes: 2 additions & 0 deletions beacon-chain/rpc/eth/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ go_library(
"@io_opencensus_go//trace:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
"@org_golang_google_protobuf//types/known/wrapperspb:go_default_library",
],
)

Expand Down Expand Up @@ -94,5 +95,6 @@ go_test(
"@com_github_gorilla_mux//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@org_golang_google_protobuf//types/known/wrapperspb:go_default_library",
],
)
34 changes: 30 additions & 4 deletions beacon-chain/rpc/eth/validator/handlers_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"net/http"
"strconv"
"strings"

"github.com/pkg/errors"
Expand All @@ -19,6 +21,7 @@ import (
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
"go.opencensus.io/trace"
"google.golang.org/protobuf/types/known/wrapperspb"
)

type blockType uint8
Expand Down Expand Up @@ -155,6 +158,12 @@ func (s *Server) ProduceBlockV3(w http.ResponseWriter, r *http.Request) {
rawGraffiti := r.URL.Query().Get("graffiti")
rawSkipRandaoVerification := r.URL.Query().Get("skip_randao_verification")

bbFactor, err := processBuilderBoostFactor(r.URL.Query().Get("builder_boost_factor"))
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
return
}

slot, valid := shared.ValidateUint(w, "slot", rawSlot)
if !valid {
return
Expand Down Expand Up @@ -182,13 +191,30 @@ func (s *Server) ProduceBlockV3(w http.ResponseWriter, r *http.Request) {
}

s.produceBlockV3(ctx, w, r, &eth.BlockRequest{
Slot: primitives.Slot(slot),
RandaoReveal: randaoReveal,
Graffiti: graffiti,
SkipMevBoost: false,
Slot: primitives.Slot(slot),
RandaoReveal: randaoReveal,
Graffiti: graffiti,
SkipMevBoost: false,
BuilderBoostFactor: &wrapperspb.UInt64Value{Value: bbFactor},
}, any)
}

func processBuilderBoostFactor(raw string) (uint64, error) {
trimmed := strings.ReplaceAll(raw, " ", "")
switch trimmed {
case "": // default to 100 if it's not provided
return 100, nil
case "2**64-1":
Copy link
Contributor

Choose a reason for hiding this comment

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

Lol I thought that the user would have to specify explicitly 18446744073709551615

return math.MaxUint64, nil
default:
number, err := strconv.ParseUint(trimmed, 10, 64)
if err != nil {
return 0, errors.Wrap(err, "Unable to decode builder boost factor")
}
return number, nil
}
}

func (s *Server) produceBlockV3(ctx context.Context, w http.ResponseWriter, r *http.Request, v1alpha1req *eth.BlockRequest, requiredType blockType) {
isSSZ := httputil.SszRequested(r)
v1alpha1resp, err := s.V1Alpha1Server.GetBeaconBlock(ctx, v1alpha1req)
Expand Down
Loading
Loading