-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
feat: allow builder boost factor to be configured via proposer config file #6357
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"]; | ||
|
||
|
@@ -20,6 +21,7 @@ type ProposerConfigFileSection = { | |
// for js-yaml | ||
gas_limit?: number; | ||
selection?: routes.validator.BuilderSelection; | ||
boost_factor?: bigint; | ||
}; | ||
}; | ||
|
||
|
@@ -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"); | ||
|
@@ -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, | ||
|
@@ -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), | ||
}, | ||
}; | ||
} | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just came to my mind that we might wanna use a normal Error here now as this can be thrown from multiple places and not just strictly from the CLI (yargs). Having a stacktrace might also be helpful for users to identify the error in that case. I can address this in another PR, wanted to look into adding |
||
} | ||
|
||
return BigInt(boostFactor); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny how
boost_factor
has typebigint | undefined
yet we check for a string here. Looks confusing along with string checks on other config fields. Anyway it looks fine for the purpose of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bigint is jsoned as a string as its not number safe