More progress

This commit is contained in:
dapplion
2025-04-04 03:02:01 -03:00
parent 63a4e378ce
commit 614c01698d
20 changed files with 464 additions and 91 deletions

View File

@@ -203,6 +203,8 @@ pub struct ChainSpec {
pub data_column_sidecar_subnet_count: u64,
pub samples_per_slot: u64,
pub custody_requirement: u64,
pub validator_custody_requirement: u64,
pub balance_per_additional_custody_group: u64,
/*
* Networking
@@ -263,6 +265,12 @@ pub struct ChainSpec {
}
impl ChainSpec {
/// Panics if `self` contains some illegal value
pub fn assert_valid(&self) {
// Tests that balance_per_additional_custody_group is not zero
self.custody_group_by_balance(1);
}
/// Construct a `ChainSpec` from a standard config.
pub fn from_config<E: EthSpec>(config: &Config) -> Option<Self> {
let spec = E::default_spec();
@@ -704,6 +712,7 @@ impl ChainSpec {
Ok(std::cmp::max(custody_column_count, self.samples_per_slot))
}
// TODO(das): delete in favor of custody_group_by_balance
pub fn custody_group_count(&self, is_supernode: bool) -> u64 {
if is_supernode {
self.number_of_custody_groups
@@ -712,6 +721,22 @@ impl ChainSpec {
}
}
pub fn custody_group_by_balance(&self, balance_gwei: u64) -> u64 {
if balance_gwei == 0 {
self.custody_requirement
} else {
std::cmp::min(
std::cmp::max(
balance_gwei
.safe_div(self.balance_per_additional_custody_group)
.expect("balance_per_additional_custody_group must be greater than 0"),
self.validator_custody_requirement,
),
self.number_of_custody_groups,
)
}
}
pub fn all_data_column_sidecar_subnets(&self) -> impl Iterator<Item = DataColumnSubnetId> {
(0..self.data_column_sidecar_subnet_count).map(DataColumnSubnetId::new)
}
@@ -915,6 +940,8 @@ impl ChainSpec {
fulu_fork_version: [0x06, 0x00, 0x00, 0x00],
fulu_fork_epoch: None,
custody_requirement: 4,
validator_custody_requirement: 8,
balance_per_additional_custody_group: 32000000000,
number_of_custody_groups: 128,
data_column_sidecar_subnet_count: 128,
number_of_columns: 128,
@@ -1245,6 +1272,8 @@ impl ChainSpec {
fulu_fork_version: [0x06, 0x00, 0x00, 0x64],
fulu_fork_epoch: None,
custody_requirement: 4,
validator_custody_requirement: 8,
balance_per_additional_custody_group: 32000000000,
number_of_custody_groups: 128,
data_column_sidecar_subnet_count: 128,
number_of_columns: 128,

View File

@@ -0,0 +1,36 @@
use crate::*;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Encode, Decode)]
pub struct CGCUpdates {
initial_value: u64,
updates: VariableList<(Slot, u64), ssz_types::typenum::U131072>,
// TODO(das): Track backfilled CGC
}
impl CGCUpdates {
pub fn new(initial_value: u64) -> Self {
Self {
initial_value,
updates: VariableList::empty(),
}
}
pub fn at_slot(&self, slot: Slot) -> u64 {
// TODO: Test and fix logic
for (update_slot, cgc) in &self.updates {
if slot > *update_slot {
return *cgc;
}
}
self.initial_value
}
pub fn add_latest_update(&mut self, update: (Slot, u64)) -> Result<(), String> {
self.updates
.push(update)
.map_err(|e| format!("Updates list full: {e:?}"))
}
}

View File

@@ -1,9 +1,8 @@
use crate::{ChainSpec, ColumnIndex, DataColumnSubnetId};
use alloy_primitives::U256;
use itertools::Itertools;
use maplit::hashset;
use safe_arith::{ArithError, SafeArith};
use std::collections::HashSet;
use std::collections::{BTreeSet, HashSet};
pub type CustodyIndex = u64;
@@ -24,14 +23,14 @@ pub fn get_custody_groups(
raw_node_id: [u8; 32],
custody_group_count: u64,
spec: &ChainSpec,
) -> Result<HashSet<CustodyIndex>, DataColumnCustodyGroupError> {
) -> Result<Vec<CustodyIndex>, DataColumnCustodyGroupError> {
if custody_group_count > spec.number_of_custody_groups {
return Err(DataColumnCustodyGroupError::InvalidCustodyGroupCount(
custody_group_count,
));
}
let mut custody_groups: HashSet<u64> = hashset![];
let mut custody_groups: BTreeSet<u64> = <_>::default();
let mut current_id = U256::from_be_slice(&raw_node_id);
while custody_groups.len() < custody_group_count as usize {
let mut node_id_bytes = [0u8; 32];
@@ -49,7 +48,7 @@ pub fn get_custody_groups(
current_id = current_id.wrapping_add(U256::from(1u64));
}
Ok(custody_groups)
Ok(custody_groups.into_iter().collect::<Vec<_>>())
}
/// Returns the columns that are associated with a given custody group.

View File

@@ -30,6 +30,7 @@ pub mod checkpoint;
pub mod consolidation_request;
pub mod consts;
pub mod contribution_and_proof;
pub mod custody;
pub mod deposit;
pub mod deposit_data;
pub mod deposit_message;
@@ -148,6 +149,7 @@ pub use crate::config_and_preset::{
};
pub use crate::consolidation_request::ConsolidationRequest;
pub use crate::contribution_and_proof::ContributionAndProof;
pub use crate::custody::CGCUpdates;
pub use crate::data_column_sidecar::{
ColumnIndex, DataColumnIdentifier, DataColumnSidecar, DataColumnSidecarList,
};