From 541652d81de9a30b2ad2607278da651cc144418c Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 20 Jan 2024 13:46:09 +0100 Subject: [PATCH] fix: improve handling of non-integer builder boost factor values --- .../validator-management/vc-configuration.md | 2 +- packages/cli/src/cmds/validator/handler.ts | 16 +++++++++++++--- packages/cli/src/cmds/validator/options.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/pages/validator-management/vc-configuration.md b/docs/pages/validator-management/vc-configuration.md index cf8f3acae060..a1077997cd77 100644 --- a/docs/pages/validator-management/vc-configuration.md +++ b/docs/pages/validator-management/vc-configuration.md @@ -103,7 +103,7 @@ With Lodestar's `--builder.selection` validator options, you can select: #### Calculating builder boost factor with examples -To calculate the builder boost factor setting, you need to know what percentage you will accept a builder block for against a local execution block using the following formula: `100*100/(100+percentage)`. +To calculate the builder boost factor setting, you need to know what percentage you will accept a builder block for against a local execution block using the following formula: `100*100/(100+percentage)`. The value passed to `--builder.boostFactor` must be a valid number without decimals. Example 1: I will only accept a builder block with 25% more value than the local execution block. ``` diff --git a/packages/cli/src/cmds/validator/handler.ts b/packages/cli/src/cmds/validator/handler.ts index 5eca9bc741d9..91789c99ee3b 100644 --- a/packages/cli/src/cmds/validator/handler.ts +++ b/packages/cli/src/cmds/validator/handler.ts @@ -227,7 +227,7 @@ function getProposerConfigFromArgs( selection: parseBuilderSelection( args["builder.selection"] ?? (args["builder"] ? defaultOptions.builderAliasSelection : undefined) ), - boostFactor: args["builder.boostFactor"] !== undefined ? BigInt(args["builder.boostFactor"]) : undefined, + boostFactor: parseBuilderBoostFactor(args["builder.boostFactor"]), }, }; @@ -266,7 +266,7 @@ function parseBuilderSelection(builderSelection?: string): routes.validator.Buil case "executiononly": break; default: - throw Error("Invalid input for builder selection, check help."); + throw new YargsError("Invalid input for builder selection, check help"); } } return builderSelection as routes.validator.BuilderSelection; @@ -280,9 +280,19 @@ function parseBroadcastValidation(broadcastValidation?: string): routes.beacon.B case "consensus_and_equivocation": break; default: - throw Error("Invalid input for broadcastValidation, check help"); + throw new YargsError("Invalid input for broadcastValidation, check help"); } } 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); +} diff --git a/packages/cli/src/cmds/validator/options.ts b/packages/cli/src/cmds/validator/options.ts index cddb34981ce1..ecc8ad32ca87 100644 --- a/packages/cli/src/cmds/validator/options.ts +++ b/packages/cli/src/cmds/validator/options.ts @@ -45,7 +45,7 @@ export type IValidatorCliArgs = AccountValidatorArgs & builder?: boolean; "builder.selection"?: string; - "builder.boostFactor"?: bigint; + "builder.boostFactor"?: string; useProduceBlockV3?: boolean; broadcastValidation?: string;