Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit b0e4858

Browse files
authored
Add logging for validate_unsigned (#277)
1 parent d0b6e87 commit b0e4858

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

pallets/cash/src/internal/validate_trx.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::{
99

1010
use codec::Encode;
1111
use frame_support::storage::{IterableStorageMap, StorageDoubleMap, StorageValue};
12-
use our_std::RuntimeDebug;
12+
use our_std::{log, RuntimeDebug};
1313
use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity, ValidTransaction};
1414

15-
#[derive(Eq, PartialEq, RuntimeDebug)]
15+
#[derive(Eq, PartialEq, RuntimeDebug, Clone, Copy)]
1616
pub enum ValidationError {
1717
InvalidInternalOnly,
1818
InvalidNextCode,
@@ -25,6 +25,16 @@ pub enum ValidationError {
2525
InvalidTrxRequest(Reason),
2626
}
2727

28+
pub fn check_validation_failure<T: Config>(
29+
call: &Call<T>,
30+
res: Result<TransactionValidity, ValidationError>,
31+
) -> Result<TransactionValidity, ValidationError> {
32+
if let Err(err) = res {
33+
log!("validate_unsigned: call = {:#?}, error = {:#?}", call, err);
34+
}
35+
res
36+
}
37+
2838
pub fn validate_unsigned<T: Config>(
2939
source: TransactionSource,
3040
call: &Call<T>,

pallets/cash/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,10 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
688688
/// here we make sure that some particular calls (the ones produced by offchain worker)
689689
/// are being whitelisted and marked as valid.
690690
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
691-
internal::validate_trx::validate_unsigned::<T>(source, call)
692-
.unwrap_or(InvalidTransaction::Call.into())
691+
internal::validate_trx::check_validation_failure(
692+
call,
693+
internal::validate_trx::validate_unsigned::<T>(source, call),
694+
)
695+
.unwrap_or(InvalidTransaction::Call.into())
693696
}
694697
}

pallets/oracle/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
163163
/// here we make sure that some particular calls (the ones produced by offchain worker)
164164
/// are being whitelisted and marked as valid.
165165
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
166-
validate_trx::validate_unsigned::<T>(source, call)
167-
.unwrap_or(InvalidTransaction::Call.into())
166+
validate_trx::check_validation_failure(
167+
call,
168+
validate_trx::validate_unsigned::<T>(source, call),
169+
)
170+
.unwrap_or(InvalidTransaction::Call.into())
168171
}
169172
}

pallets/oracle/src/validate_trx.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::{error::OracleError, oracle, Call, Config};
22
use codec::Decode;
33
use codec::Encode;
4-
use our_std::RuntimeDebug;
4+
use our_std::{log, RuntimeDebug};
55
use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity, ValidTransaction};
66

77
const MAX_EXTERNAL_PAIRS: usize = 30;
88
const UNSIGNED_TXS_PRIORITY: u64 = 100;
99
const UNSIGNED_TXS_LONGEVITY: u64 = 32;
1010

11-
#[derive(Encode, Eq, PartialEq, RuntimeDebug)]
11+
#[derive(Encode, Eq, PartialEq, RuntimeDebug, Clone, Copy)]
1212
#[cfg_attr(feature = "std", derive(Decode))]
1313
pub enum ValidationError {
1414
InvalidInternalOnly,
@@ -18,6 +18,16 @@ pub enum ValidationError {
1818
ExcessivePrices,
1919
}
2020

21+
pub fn check_validation_failure<T: Config>(
22+
call: &Call<T>,
23+
res: Result<TransactionValidity, ValidationError>,
24+
) -> Result<TransactionValidity, ValidationError> {
25+
if let Err(err) = res {
26+
log!("validate_unsigned: call = {:#?}, error = {:#?}", call, err);
27+
}
28+
res
29+
}
30+
2131
pub fn validate_unsigned<T: Config>(
2232
source: TransactionSource,
2333
call: &Call<T>,

0 commit comments

Comments
 (0)