Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
beefy: Add LOG_TARGET constant (#13222)
Browse files Browse the repository at this point in the history
* LOG_TARGET const
* fmt
  • Loading branch information
al3mart authored Jan 24, 2023
1 parent ca5a505 commit 84af672
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 102 deletions.
6 changes: 3 additions & 3 deletions client/beefy/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//! Schema for BEEFY state persisted in the aux-db.

use crate::worker::PersistedState;
use crate::{worker::PersistedState, LOG_TARGET};
use codec::{Decode, Encode};
use log::{info, trace};
use sc_client_api::{backend::AuxStore, Backend};
Expand All @@ -31,7 +31,7 @@ const WORKER_STATE: &[u8] = b"beefy_voter_state";
const CURRENT_VERSION: u32 = 1;

pub(crate) fn write_current_version<B: AuxStore>(backend: &B) -> ClientResult<()> {
info!(target: "beefy", "🥩 write aux schema version {:?}", CURRENT_VERSION);
info!(target: LOG_TARGET, "🥩 write aux schema version {:?}", CURRENT_VERSION);
AuxStore::insert_aux(backend, &[(VERSION_KEY, CURRENT_VERSION.encode().as_slice())], &[])
}

Expand All @@ -40,7 +40,7 @@ pub(crate) fn write_voter_state<Block: BlockT, B: AuxStore>(
backend: &B,
state: &PersistedState<Block>,
) -> ClientResult<()> {
trace!(target: "beefy", "🥩 persisting {:?}", state);
trace!(target: LOG_TARGET, "🥩 persisting {:?}", state);
backend.insert_aux(&[(WORKER_STATE, state.encode().as_slice())], &[])
}

Expand Down
15 changes: 9 additions & 6 deletions client/beefy/src/communication/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use log::{debug, trace};
use parking_lot::{Mutex, RwLock};
use wasm_timer::Instant;

use crate::{communication::peers::KnownPeers, keystore::BeefyKeystore};
use crate::{communication::peers::KnownPeers, keystore::BeefyKeystore, LOG_TARGET};
use beefy_primitives::{
crypto::{Public, Signature},
VoteMessage,
Expand Down Expand Up @@ -122,15 +122,15 @@ where
///
/// Noting round will start a live `round`.
pub(crate) fn note_round(&self, round: NumberFor<B>) {
debug!(target: "beefy", "🥩 About to note gossip round #{}", round);
debug!(target: LOG_TARGET, "🥩 About to note gossip round #{}", round);
self.known_votes.write().insert(round);
}

/// Conclude a voting round.
///
/// This can be called once round is complete so we stop gossiping for it.
pub(crate) fn conclude_round(&self, round: NumberFor<B>) {
debug!(target: "beefy", "🥩 About to drop gossip round #{}", round);
debug!(target: LOG_TARGET, "🥩 About to drop gossip round #{}", round);
self.known_votes.write().conclude(round);
}
}
Expand Down Expand Up @@ -174,7 +174,10 @@ where
return ValidationResult::ProcessAndKeep(self.topic)
} else {
// TODO: report peer
debug!(target: "beefy", "🥩 Bad signature on message: {:?}, from: {:?}", msg, sender);
debug!(
target: LOG_TARGET,
"🥩 Bad signature on message: {:?}, from: {:?}", msg, sender
);
}
}

Expand All @@ -192,7 +195,7 @@ where
let round = msg.commitment.block_number;
let expired = !known_votes.is_live(&round);

trace!(target: "beefy", "🥩 Message for round #{} expired: {}", round, expired);
trace!(target: LOG_TARGET, "🥩 Message for round #{} expired: {}", round, expired);

expired
})
Expand Down Expand Up @@ -226,7 +229,7 @@ where
let round = msg.commitment.block_number;
let allowed = known_votes.is_live(&round);

trace!(target: "beefy", "🥩 Message for round #{} allowed: {}", round, allowed);
trace!(target: LOG_TARGET, "🥩 Message for round #{} allowed: {}", round, allowed);

allowed
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_runtime::traits::Block;
use std::{marker::PhantomData, sync::Arc};

use crate::communication::request_response::{
on_demand_justifications_protocol_config, Error, JustificationRequest,
on_demand_justifications_protocol_config, Error, JustificationRequest, BEEFY_SYNC_LOG_TARGET,
};

/// A request coming in, including a sender for sending responses.
Expand Down Expand Up @@ -174,21 +174,21 @@ where

/// Run [`BeefyJustifsRequestHandler`].
pub async fn run(mut self) {
trace!(target: "beefy::sync", "🥩 Running BeefyJustifsRequestHandler");
trace!(target: BEEFY_SYNC_LOG_TARGET, "🥩 Running BeefyJustifsRequestHandler");

while let Ok(request) = self.request_receiver.recv(|| vec![]).await {
let peer = request.peer;
match self.handle_request(request) {
Ok(()) => {
debug!(
target: "beefy::sync",
target: BEEFY_SYNC_LOG_TARGET,
"🥩 Handled BEEFY justification request from {:?}.", peer
)
},
Err(e) => {
// TODO (issue #12293): apply reputation changes here based on error type.
debug!(
target: "beefy::sync",
target: BEEFY_SYNC_LOG_TARGET,
"🥩 Failed to handle BEEFY justification request from {:?}: {}", peer, e,
)
},
Expand Down
2 changes: 2 additions & 0 deletions client/beefy/src/communication/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const JUSTIF_CHANNEL_SIZE: usize = 10;
const MAX_RESPONSE_SIZE: u64 = 1024 * 1024;
const JUSTIF_REQUEST_TIMEOUT: Duration = Duration::from_secs(3);

const BEEFY_SYNC_LOG_TARGET: &str = "beefy::sync";

/// Get the configuration for the BEEFY justifications Request/response protocol.
///
/// Returns a receiver for messages received on this protocol and the requested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp_runtime::traits::{Block, NumberFor};
use std::{collections::VecDeque, result::Result, sync::Arc};

use crate::{
communication::request_response::{Error, JustificationRequest},
communication::request_response::{Error, JustificationRequest, BEEFY_SYNC_LOG_TARGET},
justification::{decode_and_verify_finality_proof, BeefyVersionedFinalityProof},
KnownPeers,
};
Expand Down Expand Up @@ -96,10 +96,8 @@ impl<B: Block> OnDemandJustificationsEngine<B> {

fn request_from_peer(&mut self, peer: PeerId, req_info: RequestInfo<B>) {
debug!(
target: "beefy::sync",
"🥩 requesting justif #{:?} from peer {:?}",
req_info.block,
peer,
target: BEEFY_SYNC_LOG_TARGET,
"🥩 requesting justif #{:?} from peer {:?}", req_info.block, peer,
);

let payload = JustificationRequest::<B> { begin: req_info.block }.encode();
Expand Down Expand Up @@ -132,7 +130,10 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
if let Some(peer) = self.try_next_peer() {
self.request_from_peer(peer, RequestInfo { block, active_set });
} else {
debug!(target: "beefy::sync", "🥩 no good peers to request justif #{:?} from", block);
debug!(
target: BEEFY_SYNC_LOG_TARGET,
"🥩 no good peers to request justif #{:?} from", block
);
}
}

Expand All @@ -141,8 +142,8 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
match &self.state {
State::AwaitingResponse(_, req_info, _) if req_info.block <= block => {
debug!(
target: "beefy::sync", "🥩 cancel pending request for justification #{:?}",
req_info.block
target: BEEFY_SYNC_LOG_TARGET,
"🥩 cancel pending request for justification #{:?}", req_info.block
);
self.state = State::Idle;
},
Expand All @@ -159,17 +160,21 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
response
.map_err(|e| {
debug!(
target: "beefy::sync",
target: BEEFY_SYNC_LOG_TARGET,
"🥩 for on demand justification #{:?}, peer {:?} hung up: {:?}",
req_info.block, peer, e
req_info.block,
peer,
e
);
Error::InvalidResponse
})?
.map_err(|e| {
debug!(
target: "beefy::sync",
target: BEEFY_SYNC_LOG_TARGET,
"🥩 for on demand justification #{:?}, peer {:?} error: {:?}",
req_info.block, peer, e
req_info.block,
peer,
e
);
Error::InvalidResponse
})
Expand All @@ -181,7 +186,7 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
)
.map_err(|e| {
debug!(
target: "beefy::sync",
target: BEEFY_SYNC_LOG_TARGET,
"🥩 for on demand justification #{:?}, peer {:?} responded with invalid proof: {:?}",
req_info.block, peer, e
);
Expand Down Expand Up @@ -213,14 +218,16 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
if let Some(peer) = self.try_next_peer() {
self.request_from_peer(peer, req_info);
} else {
warn!(target: "beefy::sync", "🥩 ran out of peers to request justif #{:?} from", block);
warn!(
target: BEEFY_SYNC_LOG_TARGET,
"🥩 ran out of peers to request justif #{:?} from", block
);
}
})
.map(|proof| {
debug!(
target: "beefy::sync",
"🥩 received valid on-demand justif #{:?} from {:?}",
block, peer
target: BEEFY_SYNC_LOG_TARGET,
"🥩 received valid on-demand justif #{:?} from {:?}", block, peer
);
proof
})
Expand Down
11 changes: 8 additions & 3 deletions client/beefy/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResul
use crate::{
communication::notification::BeefyVersionedFinalityProofSender,
justification::{decode_and_verify_finality_proof, BeefyVersionedFinalityProof},
LOG_TARGET,
};

/// A block-import handler for BEEFY.
Expand Down Expand Up @@ -138,16 +139,20 @@ where
(Some(encoded), ImportResult::Imported(_)) => {
if let Ok(proof) = self.decode_and_verify(&encoded, number, hash) {
// The proof is valid and the block is imported and final, we can import.
debug!(target: "beefy", "🥩 import justif {:?} for block number {:?}.", proof, number);
debug!(
target: LOG_TARGET,
"🥩 import justif {:?} for block number {:?}.", proof, number
);
// Send the justification to the BEEFY voter for processing.
self.justification_sender
.notify(|| Ok::<_, ()>(proof))
.expect("forwards closure result; the closure always returns Ok; qed.");
} else {
debug!(
target: "beefy",
target: LOG_TARGET,
"🥩 error decoding justification: {:?} for imported block {:?}",
encoded, number,
encoded,
number,
);
}
},
Expand Down
9 changes: 7 additions & 2 deletions client/beefy/src/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use beefy_primitives::{
BeefyAuthorityId, KEY_TYPE,
};

use crate::error;
use crate::{error, LOG_TARGET};

/// A BEEFY specific keystore implemented as a `Newtype`. This is basically a
/// wrapper around [`sp_keystore::SyncCryptoStore`] and allows to customize
Expand All @@ -53,7 +53,12 @@ impl BeefyKeystore {
.collect();

if public.len() > 1 {
warn!(target: "beefy", "🥩 Multiple private keys found for: {:?} ({})", public, public.len());
warn!(
target: LOG_TARGET,
"🥩 Multiple private keys found for: {:?} ({})",
public,
public.len()
);
}

public.get(0).cloned()
Expand Down
Loading

0 comments on commit 84af672

Please sign in to comment.