Skip to content

Commit ccc3c31

Browse files
committed
update logging
1 parent feb0bda commit ccc3c31

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

pallets/drand/src/lib.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ pub mod pallet {
231231
if BeaconConfig::<T>::get().is_none() {
232232
if let Err(e) = Self::fetch_drand_config_and_send(block_number) {
233233
log::debug!(
234-
"Failed to fetch chain config from drand, are you sure the chain hash is valid? {:?}",
234+
"Drand: Failed to fetch chain config from drand, are you sure the chain hash is valid? {:?}",
235235
e
236236
);
237237
}
238238
} else {
239239
// otherwise query drand
240240
if let Err(e) = Self::fetch_drand_pulse_and_send_unsigned(block_number) {
241241
log::debug!(
242-
"Failed to fetch pulse from drand, are you sure the chain hash is valid? {:?}",
242+
"Drand: Failed to fetch pulse from drand, are you sure the chain hash is valid? {:?}",
243243
e
244244
);
245245
}
@@ -372,23 +372,23 @@ impl<T: Config> Pallet<T> {
372372
// anyway.
373373
let next_unsigned_at = NextUnsignedAt::<T>::get();
374374
if next_unsigned_at > block_number {
375-
return Err("Too early to send unsigned transaction");
375+
return Err("Drand: Too early to send unsigned transaction");
376376
}
377377

378378
let signer = Signer::<T, T::AuthorityId>::all_accounts();
379379
if !signer.can_sign() {
380380
return Err(
381-
"No local accounts available. Consider adding one via `author_insertKey` RPC.",
381+
"Drand: No local accounts available. Consider adding one via `author_insertKey` RPC.",
382382
)?;
383383
}
384384

385385
let body_str =
386386
Self::fetch_drand_chain_info().map_err(|_| "Failed to fetch drand chain info")?;
387387
let beacon_config: BeaconInfoResponse = serde_json::from_str(&body_str)
388-
.map_err(|_| "Failed to convert response body to beacon configuration")?;
388+
.map_err(|_| "Drand: Failed to convert response body to beacon configuration")?;
389389
let config = beacon_config
390390
.try_into_beacon_config()
391-
.map_err(|_| "Failed to convert BeaconInfoResponse to BeaconConfiguration")?;
391+
.map_err(|_| "Drand: Failed to convert BeaconInfoResponse to BeaconConfiguration")?;
392392

393393
let results = signer.send_unsigned_transaction(
394394
|account| BeaconConfigurationPayload {
@@ -403,13 +403,17 @@ impl<T: Config> Pallet<T> {
403403
);
404404

405405
if results.is_empty() {
406-
log::error!("Empty result from config: {:?}", config);
406+
log::error!("Drand: Empty result from config: {:?}", config);
407407
}
408408

409409
for (acc, res) in &results {
410410
match res {
411-
Ok(()) => log::info!("[{:?}] Submitted new config: {:?}", acc.id, config),
412-
Err(e) => log::error!("[{:?}] Failed to submit transaction: {:?}", acc.id, e),
411+
Ok(()) => log::info!("Drand: [{:?}] Submitted new config: {:?}", acc.id, config),
412+
Err(e) => log::error!(
413+
"Drand: [{:?}] Failed to submit transaction: {:?}",
414+
acc.id,
415+
e
416+
),
413417
}
414418
}
415419

@@ -424,16 +428,16 @@ impl<T: Config> Pallet<T> {
424428
// Ensure we can send an unsigned transaction
425429
let next_unsigned_at = NextUnsignedAt::<T>::get();
426430
if next_unsigned_at > block_number {
427-
return Err("Too early to send unsigned transaction");
431+
return Err("Drand: Too early to send unsigned transaction");
428432
}
429433

430434
let mut last_stored_round = LastStoredRound::<T>::get();
431435
let latest_pulse_body = Self::fetch_drand_latest().map_err(|_| "Failed to query drand")?;
432436
let latest_unbounded_pulse: DrandResponseBody = serde_json::from_str(&latest_pulse_body)
433-
.map_err(|_| "Failed to serialize response body to pulse")?;
437+
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
434438
let latest_pulse = latest_unbounded_pulse
435439
.try_into_pulse()
436-
.map_err(|_| "Received pulse contains invalid data")?;
440+
.map_err(|_| "Drand: Received pulse contains invalid data")?;
437441
let current_round = latest_pulse.round;
438442

439443
// If last_stored_round is zero, set it to current_round - 1
@@ -451,12 +455,12 @@ impl<T: Config> Pallet<T> {
451455

452456
for round in (last_stored_round + 1)..=(last_stored_round + rounds_to_fetch) {
453457
let pulse_body = Self::fetch_drand_by_round(round)
454-
.map_err(|_| "Failed to query drand for round")?;
458+
.map_err(|_| "Drand: Failed to query drand for round")?;
455459
let unbounded_pulse: DrandResponseBody = serde_json::from_str(&pulse_body)
456-
.map_err(|_| "Failed to serialize response body to pulse")?;
460+
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
457461
let pulse = unbounded_pulse
458462
.try_into_pulse()
459-
.map_err(|_| "Received pulse contains invalid data")?;
463+
.map_err(|_| "Drand: Received pulse contains invalid data")?;
460464
pulses.push(pulse);
461465
}
462466

@@ -477,11 +481,15 @@ impl<T: Config> Pallet<T> {
477481
for (acc, res) in &results {
478482
match res {
479483
Ok(()) => log::debug!(
480-
"[{:?}] Submitted new pulses up to round: {:?}",
484+
"Drand: [{:?}] Submitted new pulses up to round: {:?}",
481485
acc.id,
482486
last_stored_round + rounds_to_fetch
483487
),
484-
Err(e) => log::error!("[{:?}] Failed to submit transaction: {:?}", acc.id, e),
488+
Err(e) => log::error!(
489+
"Drand: [{:?}] Failed to submit transaction: {:?}",
490+
acc.id,
491+
e
492+
),
485493
}
486494
}
487495
}
@@ -510,21 +518,21 @@ impl<T: Config> Pallet<T> {
510518
sp_io::offchain::timestamp().add(Duration::from_millis(T::HttpFetchTimeout::get()));
511519
let request = http::Request::get(uri);
512520
let pending = request.deadline(deadline).send().map_err(|_| {
513-
log::warn!("HTTP IO Error");
521+
log::warn!("Drand: HTTP IO Error");
514522
http::Error::IoError
515523
})?;
516524
let response = pending.try_wait(deadline).map_err(|_| {
517-
log::warn!("HTTP Deadline Reached");
525+
log::warn!("Drand: HTTP Deadline Reached");
518526
http::Error::DeadlineReached
519527
})??;
520528

521529
if response.code != 200 {
522-
log::warn!("Unexpected status code: {}", response.code);
530+
log::warn!("Drand: Unexpected status code: {}", response.code);
523531
return Err(http::Error::Unknown);
524532
}
525533
let body = response.body().collect::<Vec<u8>>();
526534
let body_str = alloc::str::from_utf8(&body).map_err(|_| {
527-
log::warn!("No UTF8 body");
535+
log::warn!("Drand: No UTF8 body");
528536
http::Error::Unknown
529537
})?;
530538

0 commit comments

Comments
 (0)