refactor(manage_validator_keys): pectra queue updates, improve lintin…#103
refactor(manage_validator_keys): pectra queue updates, improve lintin…#103coincashew merged 1 commit intomainfrom
Conversation
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Script
participant DepositCLI
participant BeaconchainAPI
User->>Script: Run manage_validator_keys.sh
Script->>DepositCLI: Download and extract deposit-cli in temp dir
Script->>DepositCLI: Move binary to target directory
Script->>User: Display updated menus for network and validator type
User->>Script: Select options
Script->>BeaconchainAPI: Query validator entry queue (queryEntryQueue)
BeaconchainAPI-->>Script: Return queue data or error
Script->>User: Show formatted queue status or "No wait"
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (7)
manage_validator_keys.sh (7)
31-43: Improve version-check error handling and cleanup
The version check is solid but can be hardened:
- Use
rm -fto avoid failures if the old binary is missing.- Handle a failing
deposit --versiongracefully to avoid an unbound variable.- Consolidate error output to stderr.
function downloadEthstakerDepositCli(){ - if [ -d "$DEPOSIT_CLI_PATH" ]; then - edc_version_installed=$("$DEPOSIT_CLI_PATH"/deposit --version) + if [[ -d "$DEPOSIT_CLI_PATH" ]]; then + edc_version_installed=$("$DEPOSIT_CLI_PATH"/deposit --version 2>/dev/null || echo "") if [[ "${edc_version_installed}" =~ .*"${edc_version}".* ]]; then echo "ethstaker_deposit-cli is up-to-date" return else - rm "$DEPOSIT_CLI_PATH"/deposit + rm -f "${DEPOSIT_CLI_PATH}/deposit" echo "ethstaker_deposit-cli update available: ${edc_version_installed}" echo "Updating to v${edc_version}" fi fi
71-71: Simplify argument parsing and locality
The&&/||chain forARGUMENTis terse but can be hard to follow. An explicitlocalwith a default and anifblock is clearer:-function generateNewValidatorKeys(){ - [[ $# -eq 1 ]] && local ARGUMENT=$1 && checkLido "$1" || ARGUMENT="default" +function generateNewValidatorKeys(){ + local ARGUMENT="default" + if [[ $# -eq 1 ]]; then + ARGUMENT=$1 + checkLido "$ARGUMENT" + fi
93-93: Handlecdfailures explicitly
Avoid|| trueso you catch misconfigurations. If the directory is wrong, bail out:- cd "$DEPOSIT_CLI_PATH" || true + cd "$DEPOSIT_CLI_PATH" || { echo "ERROR: Cannot cd to $DEPOSIT_CLI_PATH" >&2; exit 1; }
166-166: Align importValidatorKeys argument logic
As withgenerateNewValidatorKeys, prefer initializingARGUMENTwith a default vialocal ARGUMENT="default"and then overriding inside anifblock instead of chaining&&/||.
186-186: Refine addRestoreValidatorKeys plugin detection
Same pattern: initializeARGUMENTlocally, then callcheckLidoif$# -eq 1. This keeps consistency across commands.
207-207: Validate directory change in addRestoreValidatorKeys
Remove|| trueand explicitly error out ifcdfails:- cd "$DEPOSIT_CLI_PATH" || true + cd "$DEPOSIT_CLI_PATH" || { echo "ERROR: $DEPOSIT_CLI_PATH not found" >&2; exit 1; }
443-482: Enhance queue query reliability and portability
The refactoredqueryEntryQueueis a strong improvement. A few further enhancements:
- Install
bcalongsidejq/curlsince it’s used for churn calculations.- Declare all function-local variables (
json,entering,wait_time, etc.) withlocal.- Implement retry logic around the
curlcall to handle transient API failures.- Consider leveraging bash arithmetic if sub-minute precision suffices, to remove the
bcdependency.Example:
function queryEntryQueue(){ - #Variables + # Variables + local json entering wait_time retries=3 BEACONCHAIN_VALIDATOR_QUEUE_API_URL="/api/v1/validators/queue" @@ - if ! json=$(curl -fsSL "${BEACONCHAIN_URLS["${NETWORK}"]}"${BEACONCHAIN_VALIDATOR_QUEUE_API_URL}); then + # Retry on failure + for ((i=1; i<=retries; i++)); do + if json=$(curl -fsSL "${BEACONCHAIN_URLS["$NETWORK"]}$BEACONCHAIN_VALIDATOR_QUEUE_API_URL"); then + break + elif [[ $i -eq retries ]]; then + echo "ERROR: Entry Queue API failed after $retries attempts." >&2 + return 1 + fi + sleep $((i * 2)) + done
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
manage_validator_keys.sh(15 hunks)
🔇 Additional comments (3)
manage_validator_keys.sh (3)
101-101: Correct quoting ofloadKeysinvocations
All calls toloadKeys "$ARGUMENT"are properly quoted, ensuring that plugin identifiers or other arguments with special characters are passed intact. Nice consistency here.Also applies to: 177-177, 215-215
324-324: Excellent path quoting throughoutloadKeys
The added quotes around$KEYFOLDER,${__DATA_DIR}, and service variables (${__SERVICE_NAME}) in each client import block guard against paths with spaces and shell globbing. This makes the import process much more reliable across environments.Also applies to: 332-334, 354-354, 356-356, 364-365, 369-369, 378-378
384-392: Skip: No action needed
The sequence of stopping the correct service, importing keys, restarting, querying the queue, showing the Launchpad message, and prompting for logs is well structured.
…g, update accumulating-distributing validator type
…g, update accumulating-distributing validator type
Summary by CodeRabbit