Skip to content

Commit

Permalink
migrate logging according to paritytech/substrate#8128
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Brenzikofer committed Mar 17, 2021
1 parent 642b455 commit ed81701
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 395 deletions.
760 changes: 414 additions & 346 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
num-traits = { version = "0.2.8", default-features = false }
impl-trait-for-tuples = "0.1.3"
log = { version = "0.4.14", default-features = false }

[dependencies.encointer-primitives]
default-features = false
Expand Down
3 changes: 1 addition & 2 deletions balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl<T: Config> Module<T> {
who: &T::AccountId,
amount: BalanceType,
) -> DispatchResult {
debug::RuntimeLogger::init();
let mut entry_who = Self::balance_entry_updated(community_id, who);
let mut entry_tot = Self::total_issuance_entry_updated(community_id);
ensure!(
Expand All @@ -193,7 +192,7 @@ impl<T: Config> Module<T> {
entry_tot.principal += amount;
<TotalIssuance<T>>::insert(community_id, entry_tot);
<Balance<T>>::insert(community_id, who, entry_who);
debug::debug!(target: LOG, "issue {:?} for {:?}", amount, who);
log::debug!(target: LOG, "issue {:?} for {:?}", amount, who);
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions bazaar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["encointer.org <alain@encointer.org>"]
edition = "2018"

[dependencies]
log = { version = "0.4.14", default-features = false }

[dependencies.rstd]
default-features = false
Expand Down
1 change: 1 addition & 0 deletions ceremonies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["encointer.org <alain@encointer.org>"]
edition = "2018"

[dependencies]
log = { version = "0.4.14", default-features = false }

[dependencies.rstd]
default-features = false
Expand Down
55 changes: 26 additions & 29 deletions ceremonies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,17 @@ decl_module! {

#[weight = 10_000]
pub fn grant_reputation(origin, cid: CommunityIdentifier, reputable: T::AccountId) -> DispatchResult {
debug::RuntimeLogger::init();
log::RuntimeLogger::init();
let sender = ensure_signed(origin)?;
ensure!(sender == <encointer_scheduler::Module<T>>::ceremony_master(), "only the CeremonyMaster can call this function");
let cindex = <encointer_scheduler::Module<T>>::current_ceremony_index();
<ParticipantReputation<T>>::insert(&(cid, cindex-1), reputable, Reputation::VerifiedUnlinked);
debug::info!(target: LOG, "granting reputation to {:?}", sender);
log::info!(target: LOG, "granting reputation to {:?}", sender);
Ok(())
}

#[weight = 10_000]
pub fn register_participant(origin, cid: CommunityIdentifier, proof: Option<ProofOfAttendance<T::Signature, T::AccountId>>) -> DispatchResult {
debug::RuntimeLogger::init();
let sender = ensure_signed(origin)?;
ensure!(<encointer_scheduler::Module<T>>::current_phase() == CeremonyPhaseType::REGISTERING,
"registering participants can only be done during REGISTERING phase");
Expand Down Expand Up @@ -164,13 +163,12 @@ decl_module! {
<ParticipantIndex<T>>::insert((cid, cindex), &sender, &new_count);
<ParticipantCount>::insert((cid, cindex), new_count);

debug::debug!(target: LOG, "registered participant: {:?}", sender);
log::debug!(target: LOG, "registered participant: {:?}", sender);
Ok(())
}

#[weight = 10_000]
pub fn register_attestations(origin, attestations: Vec<Attestation<T::Signature, T::AccountId, T::Moment>>) -> DispatchResult {
debug::RuntimeLogger::init();
let sender = ensure_signed(origin)?;
ensure!(<encointer_scheduler::Module<T>>::current_phase() == CeremonyPhaseType::ATTESTING,
"registering attestations can only be done during ATTESTING phase");
Expand All @@ -193,57 +191,57 @@ decl_module! {
{ l } else { return Err(<Error<T>>::MeetupLocationNotFound.into()) };
let mtime = if let Some(t) = Self::get_meetup_time(&cid, meetup_index)
{ t } else { return Err(<Error<T>>::MeetupTimeCalculationError.into()) };
debug::debug!(target: LOG, "meetup {} at location {:?} should happen at {:?} for cid {:?}",
log::debug!(target: LOG, "meetup {} at location {:?} should happen at {:?} for cid {:?}",
meetup_index, mlocation, mtime, cid);
for attestation in attestations.iter() {
let attestation_account = &attestation.public;
if !meetup_participants.contains(attestation_account) {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring attestation that isn't a meetup participant: {:?}",
attestation_account);
continue };
if attestation.claim.ceremony_index != cindex {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim with wrong ceremony index: {}",
attestation.claim.ceremony_index);
continue };
if attestation.claim.community_identifier != cid {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim with wrong community identifier: {:?}",
attestation.claim.community_identifier);
continue };
if attestation.claim.meetup_index != meetup_index {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim with wrong meetup index: {}",
attestation.claim.meetup_index);
continue };
if !<encointer_communities::Module<T>>::is_valid_geolocation(
&attestation.claim.location) {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim with illegal geolocation: {:?}",
attestation.claim.location);
continue };
if <encointer_communities::Module<T>>::haversine_distance(
&mlocation, &attestation.claim.location) > Self::location_tolerance() {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim beyond location tolerance: {:?}",
attestation.claim.location);
continue };
if let Some(dt) = mtime.checked_sub(&attestation.claim.timestamp) {
if dt > Self::time_tolerance() {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim beyond time tolerance (too early): {:?}",
attestation.claim.timestamp);
continue };
} else if let Some(dt) = attestation.claim.timestamp.checked_sub(&mtime) {
if dt > Self::time_tolerance() {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"ignoring claim beyond time tolerance (too late): {:?}",
attestation.claim.timestamp);
continue };
}
if Self::verify_attestation_signature(attestation.clone()).is_err() {
debug::warn!(target: LOG, "ignoring attestation with bad signature for {:?}", sender);
log::warn!(target: LOG, "ignoring attestation with bad signature for {:?}", sender);
continue };
// attestation is legit. insert it!
verified_attestation_accounts.insert(0, attestation_account.clone());
Expand All @@ -267,15 +265,14 @@ decl_module! {
<AttestationRegistry<T>>::insert((cid, cindex), &idx, &verified_attestation_accounts);
<AttestationIndex<T>>::insert((cid, cindex), &sender, &idx);
<MeetupParticipantCountVote<T>>::insert((cid, cindex), &sender, &claim_n_participants);
debug::debug!(target: LOG,
log::debug!(target: LOG,
"sucessfully registered {} attestations for {:?}",
verified_attestation_accounts.len(), sender);
Ok(())
}

#[weight = 10_000]
pub fn endorse_newcomer(origin, cid: CommunityIdentifier, newbie: T::AccountId) -> DispatchResult {
debug::RuntimeLogger::init();
let sender = ensure_signed(origin)?;

ensure!(<encointer_communities::Module<T>>::community_identifiers().contains(&cid),
Expand All @@ -295,7 +292,7 @@ decl_module! {
"newbie is already endorsed");

<BurnedBootstrapperNewbieTickets<T>>::mutate(&cid, sender,|b| *b += 1);
debug::debug!(target: LOG, "endorsed newbie: {:?}", newbie);
log::debug!(target: LOG, "endorsed newbie: {:?}", newbie);
<Endorsees<T>>::insert((cid, cindex), newbie, ());
<EndorseesCount>::mutate((cid, cindex), |c| *c += 1);
Ok(())
Expand Down Expand Up @@ -340,7 +337,7 @@ impl<T: Config> Module<T> {
<AttestationCount>::insert((cid, cindex), 0);
<MeetupParticipantCountVote<T>>::remove_prefix((cid, cindex));
}
debug::debug!(target: LOG, "purged registry for ceremony {}", cindex);
log::debug!(target: LOG, "purged registry for ceremony {}", cindex);
}

/* this is for a more recent revision of substrate....
Expand Down Expand Up @@ -401,7 +398,7 @@ impl<T: Config> Module<T> {
n += endorsees.len();

if n < 3 {
debug::debug!(target: LOG, "no meetups assigned for cid {:?}", cid);
log::debug!(target: LOG, "no meetups assigned for cid {:?}", cid);
continue;
}

Expand All @@ -410,7 +407,7 @@ impl<T: Config> Module<T> {

// capping the amount a participants prevents assigning more meetups than there are locations.
if n > n_locations * 12 {
debug::warn!(target: LOG, "Meetup Locations exhausted for cid: {:?}", cid);
log::warn!(target: LOG, "Meetup Locations exhausted for cid: {:?}", cid);
n = n_locations * 12;
}

Expand Down Expand Up @@ -446,14 +443,14 @@ impl<T: Config> Module<T> {
<MeetupRegistry<T>>::insert((cid, cindex), &_idx, m.clone());
}
};
debug::debug!(
log::debug!(
target: LOG,
"assigned {} meetups for cid {:?}",
meetups.len(),
cid
);
}
debug::debug!(target: LOG, "meetup assignments done");
log::debug!(target: LOG, "meetup assignments done");
}

fn verify_attestation_signature(
Expand Down Expand Up @@ -504,7 +501,7 @@ impl<T: Config> Module<T> {
match Self::ballot_meetup_n_votes(cid, cindex, m) {
Some(nn) => nn,
_ => {
debug::warn!(
log::warn!(
target: LOG,
"ignoring meetup {} because votes are not dependable",
m
Expand All @@ -515,7 +512,7 @@ impl<T: Config> Module<T> {
let meetup_participants = Self::meetup_registry((cid, cindex), &m);
for p in meetup_participants {
if Self::meetup_participant_count_vote((cid, cindex), &p) != n_confirmed {
debug::debug!(
log::debug!(
target: LOG,
"skipped participant because of wrong participant count vote: {:?}",
p
Expand All @@ -529,7 +526,7 @@ impl<T: Config> Module<T> {
if attestations.len() < (n_honest_participants - 1) as usize
|| attestations.is_empty()
{
debug::debug!(
log::debug!(
target: LOG,
"skipped participant because of too few attestations ({}): {:?}",
attestations.len(),
Expand All @@ -548,14 +545,14 @@ impl<T: Config> Module<T> {
}
}
if has_attested < (n_honest_participants - 1) {
debug::debug!(
log::debug!(
target: LOG,
"skipped participant because didn't testify for honest peers: {:?}",
p
);
continue;
}
debug::trace!(target: LOG, "participant merits reward: {:?}", p);
log::trace!(target: LOG, "participant merits reward: {:?}", p);
if <encointer_balances::Module<T>>::issue(*cid, &p, reward).is_ok() {
<ParticipantReputation<T>>::insert(
(cid, cindex),
Expand All @@ -566,7 +563,7 @@ impl<T: Config> Module<T> {
}
}
}
debug::info!(target: LOG, "issuing rewards completed");
log::info!(target: LOG, "issuing rewards completed");
}

fn ballot_meetup_n_votes(
Expand Down
3 changes: 3 additions & 0 deletions communities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.3.9"
authors = ["encointer.org <alain@encointer.org>"]
edition = "2018"

[dependencies]
log = { version = "0.4.14", default-features = false }

[dependencies.encointer-primitives]
default-features = false
package = "encointer-primitives"
Expand Down
11 changes: 5 additions & 6 deletions communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

// use host_calls::runtime_interfaces;
use frame_support::{
debug, decl_error, decl_event, decl_module, decl_storage,
decl_error, decl_event, decl_module, decl_storage,
dispatch::DispatchResult,
ensure,
storage::{StorageMap, StorageValue},
Expand Down Expand Up @@ -68,7 +68,6 @@ decl_module! {
// this should be run off-chain in substraTEE-worker later
#[weight = 10_000]
pub fn new_community(origin, loc: Vec<Location>, bootstrappers: Vec<T::AccountId>) -> DispatchResult {
debug::RuntimeLogger::init();
let sender = ensure_signed(origin)?;
let cid = CommunityIdentifier::from(blake2_256(&(loc.clone(), bootstrappers.clone()).encode()));
let cids = Self::community_identifiers();
Expand All @@ -84,20 +83,20 @@ decl_module! {
// prohibit proximity to poles
if Self::haversine_distance(&l1, &NORTH_POLE) < DATELINE_DISTANCE_M
|| Self::haversine_distance(&l1, &SOUTH_POLE) < DATELINE_DISTANCE_M {
debug::warn!(target: LOG, "location too close to pole: {:?}", l1);
log::warn!(target: LOG, "location too close to pole: {:?}", l1);
return Err(<Error<T>>::MinimumDistanceViolationToPole.into());
}
// prohibit proximity to dateline
let dateline_proxy = Location { lat: l1.lat, lon: DATELINE_LON };
if Self::haversine_distance(&l1, &dateline_proxy) < DATELINE_DISTANCE_M {
debug::warn!(target: LOG, "location too close to dateline: {:?}", l1);
log::warn!(target: LOG, "location too close to dateline: {:?}", l1);
return Err(<Error<T>>::MinimumDistanceViolationToDateLine.into());
}
// test against all other communities globally
for other in cids.iter() {
for l2 in Self::locations(other) {
if Self::solar_trip_time(&l1, &l2) < MIN_SOLAR_TRIP_TIME_S {
debug::warn!(target: LOG,
log::warn!(target: LOG,
"location {:?} too close to previously registered location {:?} with cid {:?}",
l1, l2, other);
return Err(<Error<T>>::MinimumDistanceViolationToOtherCommunity.into());
Expand All @@ -117,7 +116,7 @@ decl_module! {
}
);
Self::deposit_event(RawEvent::CommunityRegistered(sender, cid));
debug::info!(target: LOG, "registered community with cid: {:?}", cid);
log::info!(target: LOG, "registered community with cid: {:?}", cid);
Ok(())
}
}
Expand Down
3 changes: 3 additions & 0 deletions personhood-oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.3.9"
authors = ["encointer.org <alain@encointer.org>"]
edition = "2018"

[dependencies]
log = { version = "0.4.14", default-features = false }

[dependencies.encointer-primitives]
default-features = false
package = "encointer-primitives"
Expand Down
7 changes: 3 additions & 4 deletions personhood-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ decl_module! {
requested_response: u8,
sender_sybil_gate: u8
) {
debug::RuntimeLogger::init();
let sender = ensure_signed(origin)?;
let para_id: u32 = Sibling::try_from_account(&sender)
.ok_or(<Error<T>>::UnableToDecodeRequest)?
.into();
let request = <Vec<ProofOfAttendanceOf<T>>>::decode(&mut rating_request.as_slice())
.map_err(|_| <Error<T>>::UnableToDecodeRequest)?;

debug::debug!(target: LOG, "received proof of personhood-oracle from parachain: {:?}", para_id);
debug::debug!(target: LOG, "received proof of personhood-oracle request: {:?}", request);
log::debug!(target: LOG, "received proof of personhood-oracle from parachain: {:?}", para_id);
log::debug!(target: LOG, "received proof of personhood-oracle request: {:?}", request);

let confidence = Self::verify(request).unwrap_or_else(|_| PersonhoodUniquenessRating::default());

Expand Down Expand Up @@ -130,7 +129,7 @@ impl<T: Config> Module<T> {
if !<encointer_communities::Module<T>>::community_identifiers()
.contains(&proof.community_identifier)
{
debug::warn!(
log::warn!(
target: LOG,
"Received ProofOfAttendance for unknown cid: {:?}",
proof.community_identifier
Expand Down
3 changes: 3 additions & 0 deletions scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.3.9"
authors = ["encointer.org <alain@encointer.org>"]
edition = "2018"

[dependencies]
log = { version = "0.4.14", default-features = false }

[dependencies.encointer-primitives]
default-features = false
package = "encointer-primitives"
Expand Down
Loading

0 comments on commit ed81701

Please sign in to comment.