diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index c9c387739..704e67a89 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -587,6 +587,13 @@ type defaultValue: "" name: "payload-builder-url" .}: string + # Flag name and semantics borrowed from Prysm + # https://github.com/prysmaticlabs/prysm/pull/12227/files + localBlockValueBoost* {. + desc: "Increase execution layer block values for builder bid comparison by a percentage" + defaultValue: 0 + name: "local-block-value-boost" .}: uint8 + historyMode* {. desc: "Retention strategy for historical data (archive/prune)" defaultValue: HistoryMode.Archive diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index f66103f73..97f396fda 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -821,7 +821,8 @@ proc proposeBlockAux( SBBB: typedesc, EPS: typedesc, node: BeaconNode, validator: AttachedValidator, validator_index: ValidatorIndex, head: BlockRef, slot: Slot, randao: ValidatorSig, fork: Fork, - genesis_validators_root: Eth2Digest): Future[BlockRef] {.async.} = + genesis_validators_root: Eth2Digest, + localBlockValueBoost: uint8): Future[BlockRef] {.async.} = # Collect bids let usePayloadBuilder = if node.config.payloadBuilderEnable: @@ -887,10 +888,24 @@ proc proposeBlockAux( err = engineBlockFut.error.msg false + template builderBetterBid(builderValue: UInt256, engineValue: Wei): bool = + # Scale down to ensure no overflows; if lower few bits would have been + # otherwise decisive, was close enough not to matter. Calibrate to let + # uint8-range percentages avoid overflowing. + const scalingBits = 10 + static: doAssert 1 shl scalingBits > + high(typeof(localBlockValueBoost)).uint16 + 100 + let + scaledBuilderValue = (builderValue shr scalingBits) * 100 + scaledEngineValue = engineValue shr scalingBits + scaledBuilderValue > + scaledEngineValue * (localBlockValueBoost.uint16 + 100).u256 + let useBuilderBlock = if builderBidAvailable: - (not engineBidAvailable) or payloadBuilderBidFut.read.get().blockValue > - engineBlockFut.read.get().blockValue + (not engineBidAvailable) or builderBetterBid( + payloadBuilderBidFut.read.get().blockValue, + engineBlockFut.read.get().blockValue) else: if not engineBidAvailable: return head # errors logged in router @@ -1018,7 +1033,7 @@ proc proposeBlock(node: BeaconNode, template proposeBlockContinuation(type1, type2: untyped): auto = await proposeBlockAux( type1, type2, node, validator, validator_index, head, slot, randao, fork, - genesis_validators_root) + genesis_validators_root, node.config.localBlockValueBoost) return if slot.epoch >= node.dag.cfg.DENEB_FORK_EPOCH: diff --git a/docs/the_nimbus_book/src/options.md b/docs/the_nimbus_book/src/options.md index 525a5db28..ec4c5d2be 100644 --- a/docs/the_nimbus_book/src/options.md +++ b/docs/the_nimbus_book/src/options.md @@ -120,6 +120,8 @@ The following options are available: --suggested-gas-limit Suggested gas limit [=defaultGasLimit]. --payload-builder Enable external payload builder [=false]. --payload-builder-url Payload builder URL. + --local-block-value-boost Increase execution layer block values for builder bid comparison by a percentage + [=0]. --history Retention strategy for historical data (archive/prune) [=HistoryMode.Archive]. ...