allow for biasing comparisons between engine/builder api bids (#4847)

This commit is contained in:
tersec 2023-04-23 19:10:34 +00:00 committed by GitHub
parent b390911e93
commit ed7ad56d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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:

View File

@ -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].
...