From 88685bb3bd6fc9f9d8f98a8882fa3c37c526b105 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 2 Jan 2024 18:40:26 +0800 Subject: [PATCH] Fix Up Builder Evaluator (#13395) * fix it up * fix evaluator * fix evaluator again * fix it * gaz --- testing/endtoend/evaluators/BUILD.bazel | 1 + testing/endtoend/evaluators/builder.go | 26 +++++++++++++++++++++++++ testing/middleware/builder/builder.go | 25 ++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/testing/endtoend/evaluators/BUILD.bazel b/testing/endtoend/evaluators/BUILD.bazel index 599910c1b5..20c475d159 100644 --- a/testing/endtoend/evaluators/BUILD.bazel +++ b/testing/endtoend/evaluators/BUILD.bazel @@ -38,6 +38,7 @@ go_library( "//container/slice:go_default_library", "//crypto/bls:go_default_library", "//encoding/bytesutil:go_default_library", + "//encoding/ssz:go_default_library", "//encoding/ssz/detect:go_default_library", "//network/forks:go_default_library", "//network/httputil:go_default_library", diff --git a/testing/endtoend/evaluators/builder.go b/testing/endtoend/evaluators/builder.go index 04e56e0ff8..444762a779 100644 --- a/testing/endtoend/evaluators/builder.go +++ b/testing/endtoend/evaluators/builder.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v4/config/params" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v4/encoding/ssz" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/endtoend/policies" e2etypes "github.com/prysmaticlabs/prysm/v4/testing/endtoend/types" @@ -42,6 +43,10 @@ func builderActive(_ *e2etypes.EvaluationContext, conns ...*grpc.ClientConn) err if lowestBound < params.BeaconConfig().BellatrixForkEpoch { lowestBound = params.BeaconConfig().BellatrixForkEpoch } + emptyRt, err := ssz.TransactionsRoot([][]byte{}) + if err != nil { + return err + } blockCtrs, err := beaconClient.ListBeaconBlocks(context.Background(), ðpb.ListBlocksRequest{QueryFilter: ðpb.ListBlocksRequest_Epoch{Epoch: lowestBound}}) if err != nil { return errors.Wrap(err, "failed to get beacon blocks") @@ -67,6 +72,15 @@ func builderActive(_ *e2etypes.EvaluationContext, conns ...*grpc.ClientConn) err if err != nil { return err } + txRoot, err := execPayload.TransactionsRoot() + if err != nil { + return err + } + if [32]byte(txRoot) == emptyRt && string(execPayload.ExtraData()) != "prysm-builder" { + // If a local payload is built with 0 transactions, builder cannot build a payload with more transactions + // since they both utilize the same EL. + continue + } if string(execPayload.ExtraData()) != "prysm-builder" { return errors.Errorf("block with slot %d was not built by the builder. It has an extra data of %s", b.Block().Slot(), string(execPayload.ExtraData())) } @@ -101,9 +115,21 @@ func builderActive(_ *e2etypes.EvaluationContext, conns ...*grpc.ClientConn) err if err != nil { return err } + txRoot, err := execPayload.TransactionsRoot() + if err != nil { + return err + } + if [32]byte(txRoot) == emptyRt && string(execPayload.ExtraData()) != "prysm-builder" { + // If a local payload is built with 0 transactions, builder cannot build a payload with more transactions + // since they both utilize the same EL. + continue + } if string(execPayload.ExtraData()) != "prysm-builder" { return errors.Errorf("block with slot %d was not built by the builder. It has an extra data of %s", b.Block().Slot(), string(execPayload.ExtraData())) } + if execPayload.GasLimit() == 0 { + return errors.Errorf("block with slot %d has a gas limit of 0, when it should be in the 30M range", b.Block().Slot()) + } } return nil } diff --git a/testing/middleware/builder/builder.go b/testing/middleware/builder/builder.go index acc59a3bf0..02d16db076 100644 --- a/testing/middleware/builder/builder.go +++ b/testing/middleware/builder/builder.go @@ -13,6 +13,7 @@ import ( "net/http" "strconv" "strings" + "sync" "time" "github.com/ethereum/go-ethereum/beacon/engine" @@ -115,6 +116,7 @@ type Builder struct { blobBundle *v1.BlobsBundle mux *gMux.Router validatorMap map[string]*eth.ValidatorRegistrationV1 + valLock sync.RWMutex srv *http.Server } @@ -160,7 +162,9 @@ func New(opts ...Option) (*Builder, error) { p.address = addr p.srv = srv p.execClient = execClient + p.valLock.Lock() p.validatorMap = map[string]*eth.ValidatorRegistrationV1{} + p.valLock.Unlock() p.mux = router return p, nil } @@ -247,7 +251,9 @@ func (p *Builder) handleEngineCalls(req, resp []byte) { p.cfg.logger.Errorf("Could not unmarshal fcu: %v", err) return } - p.currId = result.Result.PayloadId + if result.Result.PayloadId != nil && *result.Result.PayloadId != [8]byte{} { + p.currId = result.Result.PayloadId + } if rpcObj.Method == ForkchoiceUpdatedMethodV3 { attr := &v1.PayloadAttributesV3{} obj, err := json.Marshal(rpcObj.Params[1]) @@ -261,7 +267,17 @@ func (p *Builder) handleEngineCalls(req, resp []byte) { } p.prevBeaconRoot = attr.ParentBeaconBlockRoot } - p.cfg.logger.Infof("Received payload id of %#x", result.Result.PayloadId) + payloadID := [8]byte{} + status := "" + lastValHash := []byte{} + if result.Result.PayloadId != nil { + payloadID = *result.Result.PayloadId + } + if result.Result.Status != nil { + status = result.Result.Status.Status.String() + lastValHash = result.Result.Status.LatestValidHash + } + p.cfg.logger.Infof("Received payload id of %#x and status of %s along with a valid hash of %#x", payloadID, status, lastValHash) } } @@ -281,7 +297,9 @@ func (p *Builder) registerValidators(w http.ResponseWriter, req *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } + p.valLock.Lock() p.validatorMap[r.Message.Pubkey] = msg + p.valLock.Unlock() } // TODO: Verify Signatures from validators w.WriteHeader(http.StatusOK) @@ -664,6 +682,7 @@ func (p *Builder) retrievePendingBlock() (*v1.ExecutionPayload, error) { if err = json.Unmarshal(marshalledOutput, bellatrixPayload); err != nil { return nil, err } + p.currId = nil return bellatrixPayload, nil } @@ -688,6 +707,7 @@ func (p *Builder) retrievePendingBlockCapella() (*v1.ExecutionPayloadCapellaWith if err = json.Unmarshal(marshalledOutput, capellaPayload); err != nil { return nil, err } + p.currId = nil return capellaPayload, nil } @@ -716,6 +736,7 @@ func (p *Builder) retrievePendingBlockDeneb() (*v1.ExecutionPayloadDenebWithValu if err = json.Unmarshal(marshalledOutput, denebPayload); err != nil { return nil, err } + p.currId = nil return denebPayload, nil }