Skip to content

Commit

Permalink
feat: allow builder boost factor to be configured via proposer config…
Browse files Browse the repository at this point in the history
… file (#6357)

* feat: allow builder boost factor to be configured via proposer config file

* reuse parseBuilderBoostFactor fn

* re-shuffle fns and add builder selection validation
  • Loading branch information
g11tech committed Jan 26, 2024
1 parent 01d47b9 commit 347c95f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
29 changes: 1 addition & 28 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {GlobalArgs} from "../../options/index.js";
import {YargsError, cleanOldLogFiles, getDefaultGraffiti, mkdir, parseLoggerArgs} from "../../util/index.js";
import {onGracefulShutdown, parseFeeRecipient, parseProposerConfig} from "../../util/index.js";
import {getVersionData} from "../../util/version.js";
import {parseBuilderSelection, parseBuilderBoostFactor} from "../../util/proposerConfig.js";
import {getAccountPaths, getValidatorPaths} from "./paths.js";
import {IValidatorCliArgs, validatorMetricsDefaultOptions, validatorMonitoringDefaultOptions} from "./options.js";
import {getSignersFromArgs} from "./signers/index.js";
Expand Down Expand Up @@ -254,24 +255,6 @@ function getProposerConfigFromArgs(
return valProposerConfig;
}

function parseBuilderSelection(builderSelection?: string): routes.validator.BuilderSelection | undefined {
if (builderSelection) {
switch (builderSelection) {
case "maxprofit":
break;
case "builderalways":
break;
case "builderonly":
break;
case "executiononly":
break;
default:
throw new YargsError("Invalid input for builder selection, check help");
}
}
return builderSelection as routes.validator.BuilderSelection;
}

function parseBroadcastValidation(broadcastValidation?: string): routes.beacon.BroadcastValidation | undefined {
if (broadcastValidation) {
switch (broadcastValidation) {
Expand All @@ -286,13 +269,3 @@ function parseBroadcastValidation(broadcastValidation?: string): routes.beacon.B

return broadcastValidation as routes.beacon.BroadcastValidation;
}

function parseBuilderBoostFactor(boostFactor?: string): bigint | undefined {
if (boostFactor === undefined) return;

if (!/^\d+$/.test(boostFactor)) {
throw new YargsError("Invalid input for builder boost factor, must be a valid number without decimals");
}

return BigInt(boostFactor);
}
38 changes: 36 additions & 2 deletions packages/cli/src/util/proposerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {routes} from "@lodestar/api";
import {parseFeeRecipient} from "./feeRecipient.js";

import {readFile} from "./file.js";
import {YargsError} from "./index.js";

type ProposerConfig = ValidatorProposerConfig["defaultConfig"];

Expand All @@ -20,6 +21,7 @@ type ProposerConfigFileSection = {
// for js-yaml
gas_limit?: number;
selection?: routes.validator.BuilderSelection;
boost_factor?: bigint;
};
};

Expand Down Expand Up @@ -57,7 +59,7 @@ function parseProposerConfigSection(
overrideConfig?: ProposerConfig
): ProposerConfig {
const {graffiti, strict_fee_recipient_check, fee_recipient, builder} = proposerFileSection;
const {gas_limit, selection: builderSelection} = builder || {};
const {gas_limit, selection: builderSelection, boost_factor} = builder || {};

if (graffiti !== undefined && typeof graffiti !== "string") {
throw Error("graffiti is not 'string");
Expand All @@ -79,6 +81,9 @@ function parseProposerConfigSection(
throw Error("(Number.isNaN(Number(gas_limit)) 2");
}
}
if (boost_factor !== undefined && typeof boost_factor !== "string") {
throw Error("boost_factor is not 'string");
}

return {
graffiti: overrideConfig?.graffiti ?? graffiti,
Expand All @@ -88,7 +93,8 @@ function parseProposerConfigSection(
feeRecipient: overrideConfig?.feeRecipient ?? (fee_recipient ? parseFeeRecipient(fee_recipient) : undefined),
builder: {
gasLimit: overrideConfig?.builder?.gasLimit ?? (gas_limit !== undefined ? Number(gas_limit) : undefined),
selection: overrideConfig?.builder?.selection ?? builderSelection,
selection: overrideConfig?.builder?.selection ?? parseBuilderSelection(builderSelection),
boostFactor: overrideConfig?.builder?.boostFactor ?? parseBuilderBoostFactor(boost_factor),
},
};
}
Expand All @@ -98,3 +104,31 @@ export function readProposerConfigDir(filepath: string, filename: string): Propo
const proposerConfigJSON = JSON.parse(proposerConfigStr) as ProposerConfigFileSection;
return proposerConfigJSON;
}

export function parseBuilderSelection(builderSelection?: string): routes.validator.BuilderSelection | undefined {
if (builderSelection) {
switch (builderSelection) {
case "maxprofit":
break;
case "builderalways":
break;
case "builderonly":
break;
case "executiononly":
break;
default:
throw new YargsError("Invalid input for builder selection, check help");
}
}
return builderSelection as routes.validator.BuilderSelection;
}

export function parseBuilderBoostFactor(boostFactor?: string): bigint | undefined {
if (boostFactor === undefined) return;

if (!/^\d+$/.test(boostFactor)) {
throw new YargsError("Invalid input for builder boost factor, must be a valid number without decimals");
}

return BigInt(boostFactor);
}
3 changes: 3 additions & 0 deletions packages/cli/test/unit/validator/parseProposerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const testValue = {
builder: {
gasLimit: 30000000,
selection: undefined,
boostFactor: undefined,
},
},
"0xa4855c83d868f772a579133d9f23818008417b743e8447e235d8eb78b1d8f8a9f63f98c551beb7de254400f89592314d": {
Expand All @@ -26,6 +27,7 @@ const testValue = {
builder: {
gasLimit: 35000000,
selection: routes.validator.BuilderSelection.MaxProfit,
boostFactor: BigInt(18446744073709551616),
},
},
},
Expand All @@ -36,6 +38,7 @@ const testValue = {
builder: {
gasLimit: 30000000,
selection: routes.validator.BuilderSelection.BuilderAlways,
boostFactor: BigInt(100),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ proposer_config:
builder:
gas_limit: "35000000"
selection: "maxprofit"
boost_factor: "18446744073709551616"
default_config:
graffiti: 'default graffiti'
strict_fee_recipient_check: "true"
fee_recipient: '0xcccccccccccccccccccccccccccccccccccccccc'
builder:
gas_limit: "30000000"
selection: "builderalways"
boost_factor: "100"

0 comments on commit 347c95f

Please sign in to comment.