Skip to content

Commit d397d71

Browse files
committed
Combine compute_deltas + apply_score_changes into ForkChoiceState::apply_attestations
Addresses review feedback: the two calls are always paired, so encapsulating them in a single method simplifies call sites and prevents accidental misuse.
1 parent c27fe3a commit d397d71

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

crates/blockchain/src/store.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,25 @@ impl ForkChoiceState {
4848
proto_array.on_block(root, parent_root, slot);
4949
}
5050

51-
// Initialize vote tracker with current known attestations
52-
let mut vote_tracker = VoteTracker::new();
53-
let attestations = store.extract_latest_known_attestations();
54-
let mut deltas = vote_tracker.compute_deltas(&attestations, &proto_array);
55-
proto_array.apply_score_changes(&mut deltas);
56-
57-
Self {
51+
let vote_tracker = VoteTracker::new();
52+
let mut fc = Self {
5853
proto_array,
5954
vote_tracker,
60-
}
55+
};
56+
57+
// Initialize weights with current known attestations
58+
let attestations = store.extract_latest_known_attestations();
59+
fc.apply_attestations(&attestations);
60+
61+
fc
62+
}
63+
64+
/// Compute vote deltas and apply them to the proto-array in one step.
65+
pub fn apply_attestations(&mut self, attestations: &HashMap<u64, AttestationData>) {
66+
let mut deltas = self
67+
.vote_tracker
68+
.compute_deltas(attestations, &self.proto_array);
69+
self.proto_array.apply_score_changes(&mut deltas);
6170
}
6271
}
6372

@@ -90,10 +99,7 @@ fn update_head(store: &mut Store, fc: &mut ForkChoiceState, log_tree: bool) {
9099
let justified_root = store.latest_justified().root;
91100

92101
// Incremental fork choice via proto-array
93-
let mut deltas = fc
94-
.vote_tracker
95-
.compute_deltas(&attestations, &fc.proto_array);
96-
fc.proto_array.apply_score_changes(&mut deltas);
102+
fc.apply_attestations(&attestations);
97103
let new_head = fc.proto_array.find_head(justified_root);
98104

99105
// Debug oracle: verify proto-array matches spec implementation

0 commit comments

Comments
 (0)