Custody persist fix (#7661)

N/A


  Persist the epoch -> cgc values. This is to ensure that `ValidatorRegistrations::latest_validator_custody_requirement` always returns a `Some` value post restart assuming the `epoch_validator_custody_requirements` map has been updated in the previous runs.
This commit is contained in:
Pawan Dhananjay
2025-06-30 23:06:37 -07:00
committed by GitHub
parent 257d270718
commit e305cb1b92
7 changed files with 131 additions and 12 deletions

View File

@@ -163,7 +163,13 @@ impl CustodyContext {
validator_custody_count: AtomicU64::new(ssz_context.validator_custody_at_head),
current_is_supernode: is_supernode,
persisted_is_supernode: ssz_context.persisted_is_supernode,
validator_registrations: Default::default(),
validator_registrations: RwLock::new(ValidatorRegistrations {
validators: Default::default(),
epoch_validator_custody_requirements: ssz_context
.epoch_validator_custody_requirements
.into_iter()
.collect(),
}),
}
}
@@ -263,8 +269,9 @@ pub struct CustodyCountChanged {
/// The custody information that gets persisted across runs.
#[derive(Debug, Encode, Decode, Clone)]
pub struct CustodyContextSsz {
validator_custody_at_head: u64,
persisted_is_supernode: bool,
pub validator_custody_at_head: u64,
pub persisted_is_supernode: bool,
pub epoch_validator_custody_requirements: Vec<(Epoch, u64)>,
}
impl From<&CustodyContext> for CustodyContextSsz {
@@ -272,6 +279,13 @@ impl From<&CustodyContext> for CustodyContextSsz {
CustodyContextSsz {
validator_custody_at_head: context.validator_custody_count.load(Ordering::Relaxed),
persisted_is_supernode: context.persisted_is_supernode,
epoch_validator_custody_requirements: context
.validator_registrations
.read()
.epoch_validator_custody_requirements
.iter()
.map(|(epoch, count)| (*epoch, *count))
.collect(),
}
}
}