mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Addresses #8218
A simplified version of #8241 for the initial release.
I've tried to minimise the logic change in this PR, although introducing the `NodeCustodyType` enum still result in quite a bit a of diff, but the actual logic change in `CustodyContext` is quite small.
The main changes are in the `CustdoyContext` struct
* ~~combining `validator_custody_count` and `current_is_supernode` fields into a single `custody_group_count_at_head` field. We persist the cgc of the initial cli values into the `custody_group_count_at_head` field and only allow for increase (same behaviour as before).~~
* I noticed the above approach caused a backward compatibility issue, I've [made a fix](15569bc085) and changed the approach slightly (which was actually what I had originally in mind):
* when initialising, only override the `validator_custody_count` value if either flag `--supernode` or `--semi-supernode` is used; otherwise leave it as the existing default `0`. Most other logic remains unchanged.
All existing validator custody unit tests are still all passing, and I've added additional tests to cover semi-supernode, and restoring `CustodyContext` from disk.
Note: I've added a `WARN` if the user attempts to switch to a `--semi-supernode` or `--supernode` - this currently has no effect, but once @eserilev column backfill is merged, we should be able to support this quite easily.
Things to test
- [x] cgc in metadata / enr
- [x] cgc in metrics
- [x] subscribed subnets
- [x] getBlobs endpoint
Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
use crate::custody_context::CustodyContextSsz;
|
|
use ssz::{Decode, Encode};
|
|
use std::sync::Arc;
|
|
use store::{DBColumn, Error as StoreError, HotColdDB, ItemStore, StoreItem};
|
|
use types::{EthSpec, Hash256};
|
|
|
|
/// 32-byte key for accessing the `CustodyContext`. All zero because `CustodyContext` has its own column.
|
|
pub const CUSTODY_DB_KEY: Hash256 = Hash256::ZERO;
|
|
|
|
pub struct PersistedCustody(pub CustodyContextSsz);
|
|
|
|
pub fn load_custody_context<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
|
|
store: Arc<HotColdDB<E, Hot, Cold>>,
|
|
) -> Option<CustodyContextSsz> {
|
|
let res: Result<Option<PersistedCustody>, _> =
|
|
store.get_item::<PersistedCustody>(&CUSTODY_DB_KEY);
|
|
// Load context from the store
|
|
match res {
|
|
Ok(Some(c)) => Some(c.0),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// Attempt to persist the custody context object to `self.store`.
|
|
pub fn persist_custody_context<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
|
|
store: Arc<HotColdDB<E, Hot, Cold>>,
|
|
custody_context: CustodyContextSsz,
|
|
) -> Result<(), store::Error> {
|
|
store.put_item(&CUSTODY_DB_KEY, &PersistedCustody(custody_context))
|
|
}
|
|
|
|
impl StoreItem for PersistedCustody {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::CustodyContext
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.0.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
|
|
let custody_context = CustodyContextSsz::from_ssz_bytes(bytes)?;
|
|
|
|
Ok(PersistedCustody(custody_context))
|
|
}
|
|
}
|