| 326 | |
| 327 | /// Assert that all validators share the same state trie root. |
| 328 | pub async fn assert_state_root_consensus( |
| 329 | queries: &HashMap<usize, FinalizerMailbox<MultisigScheme, Block>>, |
| 330 | ) { |
| 331 | assert_state_root_consensus_skip(queries, &[]).await; |
| 332 | } |
| 333 | |
| 334 | /// Assert that all validators (except those in `skip`) share the same state trie root. |
| 335 | /// |
| 336 | /// Validators that have exited the committee may have stale state, so they should |
| 337 | /// be included in the `skip` list. |
| 338 | pub async fn assert_state_root_consensus_skip( |
| 339 | queries: &HashMap<usize, FinalizerMailbox<MultisigScheme, Block>>, |
| 340 | skip: &[usize], |
| 341 | ) { |
| 342 | let mut roots: Vec<(usize, [u8; 32])> = Vec::new(); |
| 343 | for (&idx, mailbox) in queries.iter() { |
| 344 | if skip.contains(&idx) { |
| 345 | continue; |
| 346 | } |
| 347 | let (root, _el_block_number) = mailbox.get_state_root().await; |
| 348 | roots.push((idx, root)); |
| 349 | } |
| 350 | assert!( |
| 351 | roots.len() >= 2, |
| 352 | "need at least 2 active validators to compare state roots" |
| 353 | ); |
| 354 | let (first_idx, first_root) = roots[0]; |
| 355 | for &(idx, root) in &roots[1..] { |
| 356 | assert_eq!( |
| 357 | root, first_root, |
| 358 | "state root mismatch: validator {idx} differs from validator {first_idx}" |
| 359 | ); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | pub fn get_domain() -> Digest { |
| 364 | let genesis_hash = from_hex_formatted(GENESIS_HASH).expect("failed to decode genesis hash"); |
| 365 | let genesis_hash: [u8; 32] = genesis_hash |
| 366 | .try_into() |
| 367 | .expect("failed to convert genesis hash"); |
| 368 | deposit_signature_domain(genesis_hash, b"_SUMMIT") |
| 369 | } |
| 370 | |
| 371 | pub fn get_initial_state( |
| 372 | genesis_hash: [u8; 32], |
| 373 | committee: &Vec<(PublicKey, bls12381::PublicKey)>, |
| 374 | withdrawal_credentials: Option<&Vec<Address>>, |
| 375 | checkpoint: Option<ConsensusState>, |
| 376 | balance: u64, |
| 377 | ) -> ConsensusState { |
| 378 | let addresses = vec![Address::ZERO; committee.len()]; |
| 379 | let addresses = withdrawal_credentials.unwrap_or(&addresses); |
| 380 | let genesis_hash: B256 = genesis_hash.into(); |
| 381 | checkpoint.unwrap_or_else(|| { |
| 382 | let forkchoice = ForkchoiceState { |