From 1c0590274c1d1eb6bccf800c3b116c1ad773a12c Mon Sep 17 00:00:00 2001 From: Potuz Date: Wed, 10 Jul 2024 22:16:46 -0300 Subject: [PATCH 1/5] Check locally for min-bid and min-bid-difference --- beacon-chain/node/config.go | 15 +++++++++++++++ .../v1alpha1/validator/proposer_bellatrix.go | 18 ++++++++++++++++++ cmd/beacon-chain/flags/base.go | 17 +++++++++++++++++ cmd/beacon-chain/main.go | 2 ++ cmd/beacon-chain/usage.go | 2 ++ config/params/config.go | 3 ++- 6 files changed, 56 insertions(+), 1 deletion(-) diff --git a/beacon-chain/node/config.go b/beacon-chain/node/config.go index bb2aa2de1049..ead046dccdad 100644 --- a/beacon-chain/node/config.go +++ b/beacon-chain/node/config.go @@ -73,6 +73,21 @@ func configureBuilderCircuitBreaker(cliCtx *cli.Context) error { return err } } + if cliCtx.IsSet(flags.MinBuilderBid.Name) { + c := params.BeaconConfig().Copy() + c.MinBuilderBid = cliCtx.Uint64(flags.MinBuilderBid.Name) + if err := params.SetActive(c); err != nil { + return err + } + } + if cliCtx.IsSet(flags.MinBuilderDiff.Name) { + c := params.BeaconConfig().Copy() + c.MinBuilderDiff = cliCtx.Uint64(flags.MinBuilderBid.Name) + if err := params.SetActive(c); err != nil { + return err + } + } + return nil } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go index e33bc4f2fa70..ae52fd416d68 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go @@ -96,6 +96,24 @@ func setExecutionData(ctx context.Context, blk interfaces.SignedBeaconBlock, loc // Compare payload values between local and builder. Default to the local value if it is higher. localValueGwei := primitives.WeiToGwei(local.Bid) builderValueGwei := primitives.WeiToGwei(bid.Value()) + // Use local block if min bid is not attained + if builderValueGwei < primitives.Gwei(params.BeaconConfig().MinBuilderBid) { + log.WithFields(logrus.Fields{ + "localGweiValue": localValueGwei, + "builderGweiValue": builderValueGwei, + }).Warn("Proposer: using local execution payload because min bid not attained") + return local.Bid, local.BlobsBundle, setLocalExecution(blk, local) + } + + // Use local block if min difference is not attained + if builderValueGwei < localValueGwei+primitives.Gwei(params.BeaconConfig().MinBuilderDiff) { + log.WithFields(logrus.Fields{ + "localGweiValue": localValueGwei, + "builderGweiValue": builderValueGwei, + }).Warn("Proposer: using local execution payload because min difference with local value was not attained") + return local.Bid, local.BlobsBundle, setLocalExecution(blk, local) + } + // Use builder payload if the following in true: // builder_bid_value * builderBoostFactor(default 100) > local_block_value * (local-block-value-boost + 100) boost := primitives.Gwei(params.BeaconConfig().LocalBlockValueBoost) diff --git a/cmd/beacon-chain/flags/base.go b/cmd/beacon-chain/flags/base.go index 4e8c94882043..f2e89e07d269 100644 --- a/cmd/beacon-chain/flags/base.go +++ b/cmd/beacon-chain/flags/base.go @@ -31,6 +31,23 @@ var ( "Boost is an additional percentage to multiple local block value. Use builder block if: builder_bid_value * 100 > local_block_value * (local-block-value-boost + 100)", Value: 10, } + // MinBuilderBid sets an absolute value for the builder bid that this + // node will accept without reverting to local building + MinBuilderBid = &cli.Uint64Flag{ + Name: "min-builder-bid", + Usage: "An absolute value in Gwei that the builder bid has to have in order for this beacon node to use the builder's block. Anything less than this value" + + " and the beacon will revert to local building.", + Value: 0, + } + // MinBuilderDiff sets an absolute value for the difference between the + // builder's bid and the local block value that this node will accept + // without reverting to local building + MinBuilderDiff = &cli.Uint64Flag{ + Name: "min-builder-to-local-difference", + Usage: "An absolute value in Gwei that the builder bid has to have in order for this beacon node to use the builder's block. Anything less than this value" + + " and the beacon will revert to local building.", + Value: 0, + } // ExecutionEngineEndpoint provides an HTTP access endpoint to connect to an execution client on the execution layer ExecutionEngineEndpoint = &cli.StringFlag{ Name: "execution-endpoint", diff --git a/cmd/beacon-chain/main.go b/cmd/beacon-chain/main.go index 19819c8e4316..0f3a42547615 100644 --- a/cmd/beacon-chain/main.go +++ b/cmd/beacon-chain/main.go @@ -82,6 +82,8 @@ var appFlags = []cli.Flag{ flags.MaxBuilderConsecutiveMissedSlots, flags.EngineEndpointTimeoutSeconds, flags.LocalBlockValueBoost, + flags.MinBuilderBid, + flags.MinBuilderDiff, cmd.BackupWebhookOutputDir, cmd.MinimalConfigFlag, cmd.E2EConfigFlag, diff --git a/cmd/beacon-chain/usage.go b/cmd/beacon-chain/usage.go index 6d0f39cc2535..66f7c1013f2f 100644 --- a/cmd/beacon-chain/usage.go +++ b/cmd/beacon-chain/usage.go @@ -131,6 +131,8 @@ var appHelpFlagGroups = []flagGroup{ flags.EngineEndpointTimeoutSeconds, flags.SlasherDirFlag, flags.LocalBlockValueBoost, + flags.MinBuilderBid, + flags.MinBuilderDiff, flags.JwtId, checkpoint.BlockPath, checkpoint.StatePath, diff --git a/config/params/config.go b/config/params/config.go index 5a33bc1a631d..69f7193df13a 100644 --- a/config/params/config.go +++ b/config/params/config.go @@ -222,7 +222,8 @@ type BeaconChainConfig struct { MaxBuilderConsecutiveMissedSlots primitives.Slot // MaxBuilderConsecutiveMissedSlots defines the number of consecutive skip slot to fallback from using relay/builder to local execution engine for block construction. MaxBuilderEpochMissedSlots primitives.Slot // MaxBuilderEpochMissedSlots is defining the number of total skip slot (per epoch rolling windows) to fallback from using relay/builder to local execution engine for block construction. LocalBlockValueBoost uint64 // LocalBlockValueBoost is the value boost for local block construction. This is used to prioritize local block construction over relay/builder block construction. - + MinBuilderBid uint64 // MinBuilderBid is the minimum value that the builder's block can have to be considered by this node. + MinBuilderDiff uint64 // MinBuilderDiff is the minimum value above the local block value that the builder has to bid to be considered by this node // Execution engine timeout value ExecutionEngineTimeoutValue uint64 // ExecutionEngineTimeoutValue defines the seconds to wait before timing out engine endpoints with execution payload execution semantics (newPayload, forkchoiceUpdated). From accf7ecf4e6f3eae512caa5b7df32de2596cce4b Mon Sep 17 00:00:00 2001 From: Potuz Date: Thu, 11 Jul 2024 08:41:33 -0300 Subject: [PATCH 2/5] fix tests --- .../validator/proposer_bellatrix_test.go | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go index 6e79ada339c5..a971d70696de 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go @@ -420,7 +420,41 @@ func TestServer_setExecutionData(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(3), e.BlockNumber()) // Local block - require.LogsContain(t, hook, "builderGweiValue=1 localBoostPercentage=0 localGweiValue=2") + require.LogsContain(t, hook, "\"Proposer: using local execution payload because min difference with local value was not attained\" builderGweiValue=1 localGweiValue=2") + }) + t.Run("Builder configured. Builder block does not achieve min bid", func(t *testing.T) { + cfg := params.BeaconConfig().Copy() + cfg.MinBuilderBid = 5 + params.OverrideBeaconConfig(cfg) + + blk, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlockCapella()) + require.NoError(t, err) + elBid := primitives.Uint64ToWei(2 * 1e9) + ed, err := blocks.NewWrappedExecutionData(&v1.ExecutionPayloadCapella{BlockNumber: 3}) + require.NoError(t, err) + vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, GetPayloadResponse: &blocks.GetPayloadResponse{ExecutionData: ed, Bid: elBid}} + b := blk.Block() + res, err := vs.getLocalPayload(ctx, b, capellaTransitionState) + require.NoError(t, err) + builderBid, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex()) + require.NoError(t, err) + _, err = builderBid.Header() + require.NoError(t, err) + builderKzgCommitments, err := builderBid.BlobKzgCommitments() + if builderBid.Version() >= version.Deneb { + require.NoError(t, err) + } + require.DeepEqual(t, [][]uint8{}, builderKzgCommitments) + _, bundle, err := setExecutionData(context.Background(), blk, res, builderBid, defaultBuilderBoostFactor) + require.NoError(t, err) + require.IsNil(t, bundle) + e, err := blk.Block().Body().Execution() + require.NoError(t, err) + require.Equal(t, uint64(3), e.BlockNumber()) // Local block + + require.LogsContain(t, hook, "\"Proposer: using local execution payload because min bid not attained\" builderGweiValue=1 localGweiValue=2") + cfg.MinBuilderBid = 0 + params.OverrideBeaconConfig(cfg) }) t.Run("Builder configured. Local block and local boost has higher value", func(t *testing.T) { cfg := params.BeaconConfig().Copy() From 7a312e969e853f7a7da679b86e441566ce6ff5cc Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 5 Aug 2024 09:58:09 -0300 Subject: [PATCH 3/5] Terence's fix Co-authored-by: terence --- beacon-chain/node/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/node/config.go b/beacon-chain/node/config.go index ead046dccdad..19f7d74d700a 100644 --- a/beacon-chain/node/config.go +++ b/beacon-chain/node/config.go @@ -82,7 +82,7 @@ func configureBuilderCircuitBreaker(cliCtx *cli.Context) error { } if cliCtx.IsSet(flags.MinBuilderDiff.Name) { c := params.BeaconConfig().Copy() - c.MinBuilderDiff = cliCtx.Uint64(flags.MinBuilderBid.Name) + c.MinBuilderDiff = cliCtx.Uint64(flags.MinBuilderDiff.Name) if err := params.SetActive(c); err != nil { return err } From cf3872905c600c083a5d18743e7bc511844b399e Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 5 Aug 2024 10:07:51 -0300 Subject: [PATCH 4/5] Terence's review --- .../rpc/prysm/v1alpha1/validator/proposer_bellatrix.go | 9 ++++++--- cmd/beacon-chain/flags/base.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go index ae52fd416d68..636858144ae6 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go @@ -96,19 +96,22 @@ func setExecutionData(ctx context.Context, blk interfaces.SignedBeaconBlock, loc // Compare payload values between local and builder. Default to the local value if it is higher. localValueGwei := primitives.WeiToGwei(local.Bid) builderValueGwei := primitives.WeiToGwei(bid.Value()) + minBid := primitives.Gwei(params.BeaconConfig().MinBuilderBid) // Use local block if min bid is not attained - if builderValueGwei < primitives.Gwei(params.BeaconConfig().MinBuilderBid) { + if builderValueGwei < minBid { log.WithFields(logrus.Fields{ - "localGweiValue": localValueGwei, + "minBuilderBid": minBid, "builderGweiValue": builderValueGwei, }).Warn("Proposer: using local execution payload because min bid not attained") return local.Bid, local.BlobsBundle, setLocalExecution(blk, local) } // Use local block if min difference is not attained - if builderValueGwei < localValueGwei+primitives.Gwei(params.BeaconConfig().MinBuilderDiff) { + minDiff := localValueGwei + primitives.Gwei(params.BeaconConfig().MinBuilderDiff) + if builderValueGwei < minDiff { log.WithFields(logrus.Fields{ "localGweiValue": localValueGwei, + "minBidDiff": minDiff, "builderGweiValue": builderValueGwei, }).Warn("Proposer: using local execution payload because min difference with local value was not attained") return local.Bid, local.BlobsBundle, setLocalExecution(blk, local) diff --git a/cmd/beacon-chain/flags/base.go b/cmd/beacon-chain/flags/base.go index f2e89e07d269..731aac2e5c20 100644 --- a/cmd/beacon-chain/flags/base.go +++ b/cmd/beacon-chain/flags/base.go @@ -40,7 +40,7 @@ var ( Value: 0, } // MinBuilderDiff sets an absolute value for the difference between the - // builder's bid and the local block value that this node will accept + // builder's bid and the local block value that this node will accept // without reverting to local building MinBuilderDiff = &cli.Uint64Flag{ Name: "min-builder-to-local-difference", From 48727d9d071b82592bcfe531c8f595f510a6602a Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 5 Aug 2024 10:37:09 -0300 Subject: [PATCH 5/5] fix tests --- .../rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go index a971d70696de..7d02c392539e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go @@ -452,7 +452,7 @@ func TestServer_setExecutionData(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(3), e.BlockNumber()) // Local block - require.LogsContain(t, hook, "\"Proposer: using local execution payload because min bid not attained\" builderGweiValue=1 localGweiValue=2") + require.LogsContain(t, hook, "\"Proposer: using local execution payload because min bid not attained\" builderGweiValue=1 minBuilderBid=5") cfg.MinBuilderBid = 0 params.OverrideBeaconConfig(cfg) })