!5417fix/validator-preprovisioned-keyring → developbf375e1a5d

fix(scripts): allow validator and genesis startup with pre-provisioned keyring

AI-generatedEverything on this page was written by an AI agent from the diff: the summaries, the narration, the diagrams, the flags and the glossary. It can be wrong or incomplete, so check it against the code before you rely on it.

2commits
3files
214lines changed
21lines to read
2startup scripts gated
7new startup tests

Where the diff is

Tests1 files · 193 lines

…/scripts/tests/test_validator_startup.py+193 −0
1stub thornode on PATH2run validator.sh / genesis.sh3assert boot or exit 1

1-minute explainer

What changed

Seed file only when needed

Restarts with both keys skip SIGNER_SEED_PHRASE_FILE.

startkeys present?skip seed

Two-key gate

keys show and ed25519 must both succeed, else old path.

secp256k1 signer keyed25519 key (stdin empty)

Startup tests

Seven cases: boot, restart, fail closed, recover from seed.

bootrestartfail closedrecover

Look here first

Keyring gate skips seed validationWith both keys present, the seed phrase is never read or validated; a mismatched mounted seed file is now silently ignored.validator.sh:17 ↗careful
99 . "$(dirname "$0")/core-unsafe.sh"
1010 fi
1111
12−resolve_signer_seed_phrase
12+# The seed phrase is only needed when the file keyring does not yet contain both
13+# the signer secp256k1 key and the ed25519 key (e.g. standalone boots without a
14+# keyring-init step). Once both keys exist in the keyring, validator startup and
15+# restarts do not require SIGNER_SEED_PHRASE_FILE.
16+if ! {
17+ echo "$SIGNER_PASSWD" | thornode keys show "$SIGNER_NAME" --keyring-backend file >/dev/null 2>&1 &&
18+ thornode ed25519 </dev/null >/dev/null 2>&1
19+}; then
20+ resolve_signer_seed_phrase
21+fi
1322
1423 PEER="${PEER:=none}" # the hostname of a seed node set as tendermint persistent peer
1524 PEER_API="${PEER_API:=$PEER}" # the hostname of a seed node API if different
1625
1726 # Inspect registration before init_chain can create a temporary genesis file.
1827 # Existing initialized volumes without a marker retain their normal startup. An
1928 # incomplete registration resumes from the state already committed on chain.
2029 registration_state=""
2130 registration_state_file="$HOME/.thornode/mocknet-registration.state"
ed25519 probe must not create a keyRelies on empty stdin making input.GetString fail, so a missing ed25519 key errors rather than being derived from a blank mnemonic.validator.sh:18 ↗verify
1010 fi
1111
12−resolve_signer_seed_phrase
12+# The seed phrase is only needed when the file keyring does not yet contain both
13+# the signer secp256k1 key and the ed25519 key (e.g. standalone boots without a
14+# keyring-init step). Once both keys exist in the keyring, validator startup and
15+# restarts do not require SIGNER_SEED_PHRASE_FILE.
16+if ! {
17+ echo "$SIGNER_PASSWD" | thornode keys show "$SIGNER_NAME" --keyring-backend file >/dev/null 2>&1 &&
18+ thornode ed25519 </dev/null >/dev/null 2>&1
19+}; then
20+ resolve_signer_seed_phrase
21+fi
1322
1423 PEER="${PEER:=none}" # the hostname of a seed node set as tendermint persistent peer
1524 PEER_API="${PEER_API:=$PEER}" # the hostname of a seed node API if different
1625
1726 # Inspect registration before init_chain can create a temporary genesis file.
1827 # Existing initialized volumes without a marker retain their normal startup. An
1928 # incomplete registration resumes from the state already committed on chain.
2029 registration_state=""
2130 registration_state_file="$HOME/.thornode/mocknet-registration.state"
2231 if [ "$NET" = "mocknet" ] && [ -e "$registration_state_file" ]; then
Same gate duplicated in genesisIdentical block in two scripts; keep in sync, or move into core.sh as a helper.genesis.sh:16 ↗look
88 echo "Loading unsafe init for mocknet..."
99 . "$(dirname "$0")/core-unsafe.sh"
1010 fi
1111
12−resolve_signer_seed_phrase
12+# The seed phrase is only needed when the file keyring does not yet contain both
13+# the signer secp256k1 key and the ed25519 key. Once both keys exist in the
14+# keyring, startup and restarts do not require SIGNER_SEED_PHRASE_FILE.
15+if ! {
16+ echo "$SIGNER_PASSWD" | thornode keys show "$SIGNER_NAME" --keyring-backend file >/dev/null 2>&1 &&
17+ thornode ed25519 </dev/null >/dev/null 2>&1
18+}; then
19+ resolve_signer_seed_phrase
20+fi
1321
1422 ########################################################################################
1523 # Genesis Init
1624 ########################################################################################
1725
1826 genesis_init() {
1927 init_chain
2028 create_thor_user "$SIGNER_NAME" "$SIGNER_PASSWD" "$SIGNER_SEED_PHRASE"
2129
Missing-ed25519 fail-closed testCovers the partial keyring case against a stub; the stub, not real thornode, decides the probe result.test_validator_startup.py:154 ↗look
145+ self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
146+ self.assertEqual(self.events(), ["render-config", "start"])
147+
148+def test_validator_without_keyring_and_without_seed_file_fails_closed(self):
149+ res = self.run_script("validator.sh")
150+ self.assertNotEqual(res.returncode, 0)
151+ self.assertTrue("SIGNER_SEED_PHRASE_FILE" in (res.stdout + res.stderr))
152+ self.assertEqual(self.events(), [])
153+
154+def test_validator_missing_ed25519_key_without_seed_file_fails_closed(self):
155+ self.provision_keyring(secp256k1=True, ed25519=False)
156+ res = self.run_script("validator.sh")
157+ self.assertNotEqual(res.returncode, 0)
158+ self.assertTrue("SIGNER_SEED_PHRASE_FILE" in (res.stdout + res.stderr))
159+ self.assertEqual(self.events(), [])
160+
161+def test_validator_without_keyring_with_seed_file_recovers_keys_and_starts(self):
162+ seed_file = self.root / "seed"
163+ seed_file.write_text("abandon " * 23 + "art\n")
164+ res = self.run_script("validator.sh", SIGNER_SEED_PHRASE_FILE=str(seed_file))
165+ self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
166+ self.assertEqual(
167+ self.events(),

Ask an AI about this change

Chat assistantClaude, ChatGPT, … (reads a link)

Coding agentClaude Code, Cursor, … (reads the repo)

The context file is context.md. Use Copy with context for an AI that can't open links; it pastes the whole file in.

Glossary

File keyring
Cosmos SDK key store on disk, opened with SIGNER_PASSWD; holds the node's signer keys. common/cosmos/cosmos.go ↗
keyring-init
node-launcher step that provisions the keyring before the runtime container starts.
SIGNER_SEED_PHRASE_FILE
Path to the mounted mnemonic file; resolve_signer_seed_phrase reads and validates it. build/scripts/core.sh ↗
thornode ed25519
Prints the ed25519 pubkey from the keyring, creating the key from a stdin mnemonic if missing. ed25519_keys.go ↗