Skip to content

Commit 0b2c281

Browse files
d4m014MegaRedHand
andauthored
change store::on_gossip_attestation to take a ref to signed attestations (#278)
Closes #271 This pr changes `on_gossip_attestation` in both `store.rs` and `lib.rs` to accept `&SignedAttestation` instead of taking ownership to avoid an unnecessary clone at the call site when self-delivering attestations to `gossip_signatures`, since only the inner data field (a small `AttestationData`) needs to be cloned to construct the Attestation. Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
1 parent 12709ae commit 0b2c281

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

crates/blockchain/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl BlockChainServer {
197197
// this the aggregator never sees its own validator's signature in
198198
// gossip_signatures and it is excluded from aggregated proofs.
199199
if self.is_aggregator {
200-
let _ = store::on_gossip_attestation(&mut self.store, signed_attestation.clone())
200+
let _ = store::on_gossip_attestation(&mut self.store, &signed_attestation)
201201
.inspect_err(|err| {
202202
warn!(%slot, %validator_id, %err, "Self-delivery of attestation failed")
203203
});
@@ -451,7 +451,7 @@ impl BlockChainServer {
451451
}
452452
}
453453

454-
fn on_gossip_attestation(&mut self, attestation: SignedAttestation) {
454+
fn on_gossip_attestation(&mut self, attestation: &SignedAttestation) {
455455
if !self.is_aggregator {
456456
warn!("Received unaggregated attestation but node is not an aggregator");
457457
return;
@@ -516,7 +516,7 @@ impl Handler<NewBlock> for BlockChainServer {
516516

517517
impl Handler<NewAttestation> for BlockChainServer {
518518
async fn handle(&mut self, msg: NewAttestation, _ctx: &Context<Self>) {
519-
self.on_gossip_attestation(msg.attestation);
519+
self.on_gossip_attestation(&msg.attestation);
520520
}
521521
}
522522

crates/blockchain/src/store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,12 @@ pub fn on_tick(
532532
/// at interval 2. Only aggregator nodes receive unaggregated gossip attestations.
533533
pub fn on_gossip_attestation(
534534
store: &mut Store,
535-
signed_attestation: SignedAttestation,
535+
signed_attestation: &SignedAttestation,
536536
) -> Result<(), StoreError> {
537537
let validator_id = signed_attestation.validator_id;
538538
let attestation = Attestation {
539539
validator_id,
540-
data: signed_attestation.data,
540+
data: signed_attestation.data.clone(),
541541
};
542542
validate_attestation_data(store, &attestation.data)
543543
.inspect_err(|_| metrics::inc_attestations_invalid())?;

0 commit comments

Comments
 (0)