Skip to content

Commit 08c71c0

Browse files
committed
fix(gossip): publish beacon topics with fork digest
1 parent d5a1bdd commit 08c71c0

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use actix_web::{
44
HttpResponse, Responder, get, post,
55
web::{Data, Json, Query},
66
};
7+
use alloy_primitives::aliases::B32;
78
use ream_api_types_beacon::{
89
query::AttestationQuery,
910
request::SyncCommitteeRequestItem,
@@ -18,7 +19,7 @@ use ream_consensus_beacon::{
1819
single_attestation::SingleAttestation, voluntary_exit::SignedVoluntaryExit,
1920
};
2021
use ream_consensus_misc::{
21-
constants::beacon::{DOMAIN_SYNC_COMMITTEE, SYNC_COMMITTEE_SIZE},
22+
constants::beacon::{DOMAIN_SYNC_COMMITTEE, FULU_FORK_EPOCH, SYNC_COMMITTEE_SIZE},
2223
misc::{compute_epoch_at_slot, compute_signing_root},
2324
};
2425
use ream_network_manager::{
@@ -48,6 +49,10 @@ use tracing::warn;
4849

4950
use crate::handlers::state::get_state_from_id;
5051

52+
fn gossip_fork_digest(state: &BeaconState) -> B32 {
53+
beacon_network_spec().fork_digest(FULU_FORK_EPOCH, state.genesis_validators_root)
54+
}
55+
5156
/// GET /eth/v1/beacon/pool/bls_to_execution_changes
5257
#[get("/beacon/pool/bls_to_execution_changes")]
5358
pub async fn get_bls_to_execution_changes(
@@ -92,7 +97,7 @@ pub async fn post_bls_to_execution_changes(
9297
.p2p_sender
9398
.send_gossip(GossipMessage {
9499
topic: GossipTopic {
95-
fork: beacon_state.fork.current_version,
100+
fork: gossip_fork_digest(&beacon_state),
96101
kind: GossipTopicKind::BlsToExecutionChange,
97102
},
98103
data: signed_bls_to_execution_change.as_ssz_bytes(),
@@ -145,7 +150,7 @@ pub async fn post_voluntary_exits(
145150
.p2p_sender
146151
.send_gossip(GossipMessage {
147152
topic: GossipTopic {
148-
fork: beacon_state.fork.current_version,
153+
fork: gossip_fork_digest(&beacon_state),
149154
kind: GossipTopicKind::VoluntaryExit,
150155
},
151156
data: signed_voluntary_exit.as_ssz_bytes(),
@@ -195,7 +200,7 @@ pub async fn post_attester_slashings(
195200
})?;
196201
network_manager.p2p_sender.send_gossip(GossipMessage {
197202
topic: GossipTopic {
198-
fork: beacon_state.fork.current_version,
203+
fork: gossip_fork_digest(&beacon_state),
199204
kind: GossipTopicKind::AttesterSlashing,
200205
},
201206
data: attester_slashing.as_ssz_bytes(),
@@ -248,7 +253,7 @@ pub async fn post_proposer_slashings(
248253
network_manager.p2p_sender.send_gossip(GossipMessage {
249254
topic: {
250255
GossipTopic {
251-
fork: beacon_state.fork.current_version,
256+
fork: gossip_fork_digest(&beacon_state),
252257
kind: GossipTopicKind::ProposerSlashing,
253258
}
254259
},
@@ -339,7 +344,7 @@ pub async fn post_attestations(
339344

340345
p2p_sender.send_gossip(GossipMessage {
341346
topic: GossipTopic {
342-
fork: beacon_state.fork.current_version,
347+
fork: gossip_fork_digest(&beacon_state),
343348
kind: GossipTopicKind::BeaconAttestation(subnet_id),
344349
},
345350
data: single_attestation.as_ssz_bytes(),
@@ -489,7 +494,7 @@ pub async fn post_sync_committees(
489494
.insert_sync_committee_message(sync_message.clone(), subcommittee_index);
490495
p2p_sender.send_gossip(GossipMessage {
491496
topic: GossipTopic {
492-
fork: beacon_network_spec().fork_digest(epoch, state.genesis_validators_root),
497+
fork: gossip_fork_digest(&state),
493498
kind: GossipTopicKind::SyncCommittee(subcommittee_index),
494499
},
495500
data: sync_message.as_ssz_bytes(),

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use ream_consensus_misc::{
3838
checkpoint::Checkpoint,
3939
constants::beacon::{
4040
DOMAIN_AGGREGATE_AND_PROOF, DOMAIN_BEACON_ATTESTER, DOMAIN_RANDAO, DOMAIN_SYNC_COMMITTEE,
41-
MAX_COMMITTEES_PER_SLOT, PROPOSER_REWARD_QUOTIENT, SLOTS_PER_EPOCH,
41+
FULU_FORK_EPOCH, MAX_COMMITTEES_PER_SLOT, PROPOSER_REWARD_QUOTIENT, SLOTS_PER_EPOCH,
4242
SYNC_COMMITTEE_PROPOSER_REWARD_QUOTIENT, WHISTLEBLOWER_REWARD_QUOTIENT,
4343
},
4444
deposit::Deposit,
@@ -60,6 +60,7 @@ use ream_execution_rpc_types::{
6060
};
6161
use ream_fork_choice_beacon::store::Store;
6262
use ream_network_manager::gossipsub::validate::sync_committee_contribution_and_proof::get_sync_subcommittee_pubkeys;
63+
use ream_network_spec::networks::beacon_network_spec;
6364
use ream_operation_pool::OperationPool;
6465
use ream_p2p::{
6566
gossipsub::beacon::topics::{GossipTopic, GossipTopicKind},
@@ -98,6 +99,10 @@ use super::state::get_state_from_id;
9899
const ELECTRA_COMMITTEE_INDEX: u64 = 0;
99100
const MAX_VALIDATOR_COUNT: usize = 100;
100101

102+
fn gossip_fork_digest(state: &BeaconState) -> B32 {
103+
beacon_network_spec().fork_digest(FULU_FORK_EPOCH, state.genesis_validators_root)
104+
}
105+
101106
fn build_validator_balances(
102107
validators: &[(Validator, u64)],
103108
filter_ids: Option<&Vec<ValidatorID>>,
@@ -834,7 +839,7 @@ pub async fn post_beacon_committee_subscriptions(
834839
let subnet_id =
835840
compute_subnet_for_attestation(sub.committees_at_slot, sub.slot, sub.committee_index);
836841

837-
let fork = state.fork.current_version;
842+
let fork = gossip_fork_digest(&state);
838843

839844
subnets.insert((subnet_id, fork));
840845
}
@@ -937,7 +942,7 @@ pub async fn post_sync_committee_subscriptions(
937942
)));
938943
}
939944

940-
let fork = state.fork.current_version;
945+
let fork = gossip_fork_digest(&state);
941946
for subnet_id in validator_subnets {
942947
subnets_to_subscribe.insert((subnet_id, fork));
943948
}

0 commit comments

Comments
 (0)