fix(elections): source validator snapshot from current vset#101
Conversation
…ot elections data
…napshot-uses-adnl-address-from-current-elections
There was a problem hiding this comment.
Pull request overview
Fixes validator snapshot generation so vset-derived fields (pubkey/adnl/key metadata/stake) are sourced from the current validator set and past_elections.frozen_map, avoiding stale election/bid data when a node is validating while also submitting a new bid (SMA-79).
Changes:
- Update
build_validators_snapshotto populate validator-related snapshot fields exclusively from the current vset (p34) +past_elections.frozen_map, returningNonewhen the node is not in the vset. - Extend
find_validator_entriesto return the matchedValidatorEntry(and associated election id) used to correlate node config with the vset. - Add/adjust tests to verify vset sourcing and
Nonebehavior when not in vset.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/node-control/elections/src/runner.rs |
Changes snapshot construction to use vset + frozen stake data; extends find_validator_entries return shape to carry matched config entry data. |
src/node-control/elections/src/runner_tests.rs |
Updates existing snapshot test expectations and adds new tests covering vset-sourced snapshot fields and None fields when not in vset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| && let Some(idx) = | ||
| vset.list().iter().position(|item| item.public_key.as_slice() == &key) | ||
| { | ||
| current_entry = Some((u16::try_from(idx)?, vset.list()[idx].clone())); | ||
| current_entry = | ||
| Some((u16::try_from(idx)?, vset.list()[idx].clone(), *election_id, entry.clone())); |
There was a problem hiding this comment.
In find_validator_entries, the exported public key is copied into a [u8; 32] using copy_from_slice earlier in the loop. If the provider returns a non-32-byte value, this will panic and crash snapshot building. Consider validating the length and returning an error (or skipping the entry with a warning) instead of panicking.
Summary
build_validators_snapshotsourcedadnl,pubkey,key_id,key_election_id,key_expires_at,is_key_active, andstakefrom elections/bid data instead of the active validator set — showing stale or incorrect values when a node is validating AND has submitted a new election bidpast_elections.frozen_map. Extendedfind_validator_entriesto return the matchedValidatorEntryfrom the node's config. Fields areNonewhen the node is not in the validator set.test_validator_snapshot_uses_vset_dataandtest_validator_snapshot_none_when_not_in_vset; updated existingtest_publish_snapshot_validatorsCloses SMA-79