Skip to content

Commit 5bc6392

Browse files
committed
chore: add debug trace
1 parent 58d3831 commit 5bc6392

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

crates/common/chain/beacon/src/beacon_chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl BeaconChain {
8484
"beacon_e2e_trace: failed to process block attestation through fork choice: {err:?}"
8585
);
8686
}
87+
store.operation_pool.remove_attestation(attestation);
8788
}
8889

8990
// Build and Emit Block event

crates/common/consensus/beacon/src/electra/beacon_state.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use ssz_types::{
7777
serde_utils::{quoted_u64_fixed_vec, quoted_u64_var_list},
7878
typenum::{U4, U32, U64, U2048, U8192, U65536, U262144, U16777216, U134217728},
7979
};
80+
use tracing::info;
8081
use tree_hash::TreeHash;
8182
use tree_hash_derive::TreeHash;
8283

@@ -1937,6 +1938,18 @@ impl BeaconState {
19371938
let total_active_balance = self.get_total_active_balance();
19381939
let previous_target_balance = self.get_total_balance(previous_indices);
19391940
let current_target_balance = self.get_total_balance(current_indices);
1941+
info!(
1942+
state_slot = self.slot,
1943+
current_epoch = self.get_current_epoch(),
1944+
previous_epoch = self.get_previous_epoch(),
1945+
total_active_balance,
1946+
previous_target_balance,
1947+
current_target_balance,
1948+
current_justified_epoch = self.current_justified_checkpoint.epoch,
1949+
previous_justified_epoch = self.previous_justified_checkpoint.epoch,
1950+
finalized_epoch = self.finalized_checkpoint.epoch,
1951+
"beacon_e2e_trace: weighing justification balances"
1952+
);
19401953

19411954
self.weigh_justification_and_finalization(
19421955
total_active_balance,
@@ -2024,6 +2037,21 @@ impl BeaconState {
20242037
{
20252038
self.finalized_checkpoint = old_current_justified_checkpoint;
20262039
}
2040+
info!(
2041+
state_slot = self.slot,
2042+
current_epoch,
2043+
previous_epoch,
2044+
previous_epoch_target_balance,
2045+
current_epoch_target_balance,
2046+
total_active_balance,
2047+
justification_bits = ?bits,
2048+
old_previous_justified_epoch = old_previous_justified_checkpoint.epoch,
2049+
old_current_justified_epoch = old_current_justified_checkpoint.epoch,
2050+
previous_justified_epoch = self.previous_justified_checkpoint.epoch,
2051+
current_justified_epoch = self.current_justified_checkpoint.epoch,
2052+
finalized_epoch = self.finalized_checkpoint.epoch,
2053+
"beacon_e2e_trace: weighed justification result"
2054+
);
20272055

20282056
Ok(())
20292057
}
@@ -2158,6 +2186,19 @@ impl BeaconState {
21582186
// Participation flag indices
21592187
let participation_flag_indices =
21602188
self.get_attestation_participation_flag_indices(data, self.slot - data.slot)?;
2189+
let attesting_indices = self.get_attesting_indices(attestation)?;
2190+
info!(
2191+
state_slot = self.slot,
2192+
attestation_slot = data.slot,
2193+
source_epoch = data.source.epoch,
2194+
target_epoch = data.target.epoch,
2195+
beacon_block_root = %data.beacon_block_root,
2196+
target_root = %data.target.root,
2197+
inclusion_delay = self.slot - data.slot,
2198+
participation_flag_indices = ?participation_flag_indices,
2199+
attesting_indices = ?attesting_indices,
2200+
"beacon_e2e_trace: state attestation participation"
2201+
);
21612202
// Verify signature
21622203
ensure!(
21632204
self.is_valid_indexed_attestation(&self.get_indexed_attestation(attestation)?)?,
@@ -2166,7 +2207,7 @@ impl BeaconState {
21662207

21672208
let base_reward_per_increment = self.get_base_reward_per_increment();
21682209
let mut proposer_reward_numerator = 0;
2169-
for index in self.get_attesting_indices(attestation)? {
2210+
for index in attesting_indices {
21702211
let index = index as usize;
21712212
for (flag_index, &weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
21722213
let flag_index = flag_index as u8;

crates/common/operation_pool/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use ream_consensus_beacon::{
1010
voluntary_exit::SignedVoluntaryExit,
1111
};
1212
use ream_consensus_misc::{
13-
constants::beacon::MIN_ATTESTATION_INCLUSION_DELAY, deposit::Deposit,
14-
misc::compute_epoch_at_slot,
13+
constants::beacon::MIN_ATTESTATION_INCLUSION_DELAY,
14+
deposit::Deposit,
15+
misc::{compute_epoch_at_slot, get_committee_indices},
1516
};
1617
use tree_hash::TreeHash;
1718

@@ -204,6 +205,18 @@ impl OperationPool {
204205
}
205206
}
206207

208+
pub fn remove_attestation(&self, attestation: &Attestation) {
209+
let slot = attestation.data.slot;
210+
let attestation_data_root = attestation.data.tree_hash_root();
211+
let committee_indices = get_committee_indices(&attestation.committee_bits);
212+
213+
self.attestations.write().retain(|key, _| {
214+
key.slot != slot
215+
|| key.attestation_data_root != attestation_data_root
216+
|| !committee_indices.contains(&key.committee_index)
217+
});
218+
}
219+
207220
/// Select attestations that can be included in the block.
208221
///
209222
/// Only keep attestations whose target epoch is current or previous, whose minimum inclusion

crates/rpc/beacon/src/handlers/validator.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,25 @@ pub async fn get_blocks_v3(
15301530
.get_all_attester_slashings()
15311531
.try_into()
15321532
.unwrap_or_default();
1533-
let attestations: VariableList<Attestation, U8> = operation_pool
1534-
.get_attestations_for_block(&state)
1535-
.try_into()
1536-
.unwrap_or_default();
1533+
let selected_attestations = operation_pool.get_attestations_for_block(&state);
1534+
info!(
1535+
slot,
1536+
state_slot = state.slot,
1537+
selected_attestations = ?selected_attestations
1538+
.iter()
1539+
.map(|attestation| {
1540+
(
1541+
attestation.data.slot,
1542+
attestation.data.source.epoch,
1543+
attestation.data.target.epoch,
1544+
attestation.aggregation_bits.num_set_bits(),
1545+
)
1546+
})
1547+
.collect::<Vec<_>>(),
1548+
"beacon_e2e_trace: validator selected attestations for block"
1549+
);
1550+
let attestations: VariableList<Attestation, U8> =
1551+
selected_attestations.try_into().unwrap_or_default();
15371552
let deposits: VariableList<Deposit, U16> = operation_pool
15381553
.get_all_deposits()
15391554
.try_into()

0 commit comments

Comments
 (0)