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

refactor: update the block production race #6241

Merged
merged 41 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
31e489f
Update the promise race implementation
nazarhussain Dec 29, 2023
fdbc32c
Update block production race
nazarhussain Jan 19, 2024
e5dcc96
Fix spelling
nazarhussain Jan 19, 2024
95f088c
Work on feedback
nazarhussain Jan 22, 2024
c0334e7
Update the test file name
nazarhussain Jan 22, 2024
74e6d1e
Update the promise tests
nazarhussain Jan 22, 2024
8149719
Update util to switch
nazarhussain Jan 23, 2024
2c60bf9
chore: add early return on censoring builder or 0 builder boost
wemeetagain Jan 24, 2024
aab884f
Update the promise to extended promise
nazarhussain Jan 26, 2024
70a35b7
Update the builder flow
nazarhussain Jan 26, 2024
535fb23
Merge branch 'nh/6159-block-prod-race' of github.com:ChainSafe/lodest…
nazarhussain Jan 26, 2024
a1e8a0c
Fix the types
nazarhussain Jan 26, 2024
8698e46
Fix lint errors
nazarhussain Jan 26, 2024
c6150bb
Simplify logging
nazarhussain Jan 26, 2024
efd684c
Improve log messages for block values
nazarhussain Jan 26, 2024
6865972
Merge branch 'unstable' into nh/6159-block-prod-race
nazarhussain Jan 26, 2024
9c7942d
Update the promise to be typesafe
nazarhussain Jan 29, 2024
4597d06
Update the validator implementation
nazarhussain Jan 29, 2024
17686b9
Restructure test file for better review
nazarhussain Jan 29, 2024
f4c93e7
Fix lint errors
nazarhussain Jan 29, 2024
3391626
Fix lint error
nazarhussain Jan 29, 2024
73943ee
Make the tyep more flexible
nazarhussain Jan 29, 2024
374aeff
Fix flaky tests
nazarhussain Jan 29, 2024
6196428
Improve log message
nazarhussain Jan 29, 2024
7e6e91c
Simplify implementation
nazarhussain Jan 29, 2024
ddad503
Update log message function
nazarhussain Jan 29, 2024
7a2027a
chore: add review feedback
wemeetagain Jan 29, 2024
806c88f
Merge branch 'unstable' into nh/6159-block-prod-race
wemeetagain Jan 29, 2024
a0dc19f
chore: fix linter error
wemeetagain Jan 30, 2024
ba444cc
chore: address PR comments
wemeetagain Feb 1, 2024
f6e6619
Update packages/beacon-node/src/api/impl/validator/index.ts
wemeetagain Feb 1, 2024
e14889b
chore: address PR comments
wemeetagain Feb 1, 2024
15c7210
Merge branch 'unstable' into nh/6159-block-prod-race
wemeetagain Feb 1, 2024
689e087
chore: clean up selectBlockProductionSource
wemeetagain Feb 1, 2024
72e4a2b
Fix unit tests
nazarhussain Feb 5, 2024
76768b6
Add support for routes.validator.BuilderSelection.ExecutionOnly
nazarhussain Feb 5, 2024
f44fd8a
Fix unit tests
nazarhussain Feb 5, 2024
74fdad3
Increase the timeout for e2e env
nazarhussain Feb 5, 2024
64e6605
Apply suggestions from code review
nazarhussain Feb 5, 2024
9a291fc
Increase the timeout for e2e env
nazarhussain Feb 5, 2024
cb022e4
Revert e2e timeout
nazarhussain Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
362 changes: 197 additions & 165 deletions packages/beacon-node/src/api/impl/validator/index.ts

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion packages/beacon-node/src/api/impl/validator/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {BeaconStateAllForks, computeSlotsSinceEpochStart} from "@lodestar/state-transition";
import {ATTESTATION_SUBNET_COUNT} from "@lodestar/params";
import {BLSPubkey, CommitteeIndex, Slot, ValidatorIndex} from "@lodestar/types";
import {routes} from "@lodestar/api";
import {BLSPubkey, CommitteeIndex, ProducedBlockSource, Slot, ValidatorIndex} from "@lodestar/types";
import {MAX_BUILDER_BOOST_FACTOR} from "@lodestar/validator";

export function computeSubnetForCommitteesAtSlot(
slot: Slot,
Expand Down Expand Up @@ -41,3 +43,30 @@ export function getPubkeysForIndices(

return pubkeys;
}

export function selectBlockProductionSource({
nflaig marked this conversation as resolved.
Show resolved Hide resolved
builderSelection,
engineBlockValue,
builderBlockValue,
builderBoostFactor,
}: {
builderSelection: routes.validator.BuilderSelection;
engineBlockValue: bigint;
builderBlockValue: bigint;
builderBoostFactor: bigint;
}): ProducedBlockSource {
switch (builderSelection) {
case routes.validator.BuilderSelection.ExecutionOnly:
return ProducedBlockSource.engine;

case routes.validator.BuilderSelection.MaxProfit:
return builderBoostFactor !== MAX_BUILDER_BOOST_FACTOR &&
(builderBoostFactor === BigInt(0) || engineBlockValue >= (builderBlockValue * builderBoostFactor) / BigInt(100))
? ProducedBlockSource.engine
: ProducedBlockSource.builder;

default:
// For everything else just select the builder
return ProducedBlockSource.builder;
}
}
12 changes: 12 additions & 0 deletions packages/utils/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ export function truncBytes(root: Uint8Array | string): string {
const str = typeof root === "string" ? root : toHexString(root);
return str.slice(0, 14);
}

/**
* Format a bigint value as a decimal string
*/
export function formatBigDecimal(numerator: bigint, denominator: bigint, maxDecimalFactor: bigint): string {
const full = numerator / denominator;
const fraction = ((numerator - full * denominator) * maxDecimalFactor) / denominator;

// zeros to be added post decimal are number of zeros in maxDecimalFactor - number of digits in fraction
const zerosPostDecimal = String(maxDecimalFactor).length - 1 - String(fraction).length;
return `${full}.${"0".repeat(zerosPostDecimal)}${fraction}`;
}