mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
* Revert "Build block without checking signatures (#4916)"
This reverts commit e50f610907.
* Some further clean ups
This commit is contained in:
@@ -80,15 +80,13 @@ use frame_support::{
|
||||
weights::{GetDispatchInfo, WeighBlock, DispatchInfo}
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::Digest,
|
||||
ApplyExtrinsicResult,
|
||||
generic::Digest, ApplyExtrinsicResult,
|
||||
traits::{
|
||||
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize,
|
||||
NumberFor, Block as BlockT, OffchainWorker, Dispatchable, Saturating, OnRuntimeUpgrade,
|
||||
},
|
||||
transaction_validity::TransactionValidity,
|
||||
};
|
||||
use sp_runtime::generic::CheckSignature;
|
||||
use sp_runtime::traits::ValidateUnsigned;
|
||||
use codec::{Codec, Encode};
|
||||
use frame_system::{extrinsics_root, DigestOf};
|
||||
@@ -263,22 +261,13 @@ where
|
||||
pub fn apply_extrinsic(uxt: Block::Extrinsic) -> ApplyExtrinsicResult {
|
||||
let encoded = uxt.encode();
|
||||
let encoded_len = encoded.len();
|
||||
Self::apply_extrinsic_with_len(uxt, encoded_len, Some(encoded), CheckSignature::Yes)
|
||||
}
|
||||
|
||||
/// Apply extrinsic outside of the block execution function.
|
||||
///
|
||||
/// Same as `apply_extrinsic`, but skips signature checks.
|
||||
pub fn apply_trusted_extrinsic(uxt: Block::Extrinsic) -> ApplyExtrinsicResult {
|
||||
let encoded = uxt.encode();
|
||||
let encoded_len = encoded.len();
|
||||
Self::apply_extrinsic_with_len(uxt, encoded_len, Some(encoded), CheckSignature::No)
|
||||
Self::apply_extrinsic_with_len(uxt, encoded_len, Some(encoded))
|
||||
}
|
||||
|
||||
/// Apply an extrinsic inside the block execution function.
|
||||
fn apply_extrinsic_no_note(uxt: Block::Extrinsic) {
|
||||
let l = uxt.encode().len();
|
||||
match Self::apply_extrinsic_with_len(uxt, l, None, CheckSignature::Yes) {
|
||||
match Self::apply_extrinsic_with_len(uxt, l, None) {
|
||||
Ok(_) => (),
|
||||
Err(e) => { let err: &'static str = e.into(); panic!(err) },
|
||||
}
|
||||
@@ -289,13 +278,9 @@ where
|
||||
uxt: Block::Extrinsic,
|
||||
encoded_len: usize,
|
||||
to_note: Option<Vec<u8>>,
|
||||
check_signature: CheckSignature,
|
||||
) -> ApplyExtrinsicResult {
|
||||
// Verify that the signature is good.
|
||||
let xt = uxt.check(
|
||||
check_signature,
|
||||
&Default::default(),
|
||||
)?;
|
||||
let xt = uxt.check(&Default::default())?;
|
||||
|
||||
// We don't need to make sure to `note_extrinsic` only after we know it's going to be
|
||||
// executed to prevent it from leaking in storage since at this point, it will either
|
||||
@@ -343,7 +328,7 @@ where
|
||||
/// Changes made to storage should be discarded.
|
||||
pub fn validate_transaction(uxt: Block::Extrinsic) -> TransactionValidity {
|
||||
let encoded_len = uxt.using_encoded(|d| d.len());
|
||||
let xt = uxt.check(CheckSignature::Yes, &Default::default())?;
|
||||
let xt = uxt.check(&Default::default())?;
|
||||
|
||||
let dispatch_info = xt.get_dispatch_info();
|
||||
xt.validate::<UnsignedValidator>(dispatch_info, encoded_len)
|
||||
@@ -541,8 +526,8 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn sign_extra(who: u64, nonce: u64, fee: u64) -> (u64, SignedExtra) {
|
||||
(who, extra(nonce, fee))
|
||||
fn sign_extra(who: u64, nonce: u64, fee: u64) -> Option<(u64, SignedExtra)> {
|
||||
Some((who, extra(nonce, fee)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -551,7 +536,7 @@ mod tests {
|
||||
pallet_balances::GenesisConfig::<Runtime> {
|
||||
balances: vec![(1, 211)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
let xt = TestXt::new_signed(sign_extra(1, 0, 0), Call::Balances(BalancesCall::transfer(2, 69)));
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(2, 69)), sign_extra(1, 0, 0));
|
||||
let weight = xt.get_dispatch_info().weight as u64;
|
||||
let mut t = sp_io::TestExternalities::new(t);
|
||||
t.execute_with(|| {
|
||||
@@ -631,7 +616,7 @@ mod tests {
|
||||
fn bad_extrinsic_not_inserted() {
|
||||
let mut t = new_test_ext(1);
|
||||
// bad nonce check!
|
||||
let xt = TestXt::new_signed(sign_extra(1, 30, 0), Call::Balances(BalancesCall::transfer(33, 69)));
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(33, 69)), sign_extra(1, 30, 0));
|
||||
t.execute_with(|| {
|
||||
Executive::initialize_block(&Header::new(
|
||||
1,
|
||||
@@ -649,7 +634,7 @@ mod tests {
|
||||
fn block_weight_limit_enforced() {
|
||||
let mut t = new_test_ext(10000);
|
||||
// given: TestXt uses the encoded len as fixed Len:
|
||||
let xt = TestXt::new_signed(sign_extra(1, 0, 0), Call::Balances(BalancesCall::transfer(33, 0)));
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 0, 0));
|
||||
let encoded = xt.encode();
|
||||
let encoded_len = encoded.len() as Weight;
|
||||
let limit = AvailableBlockRatio::get() * MaximumBlockWeight::get() - 175;
|
||||
@@ -666,8 +651,8 @@ mod tests {
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), 175);
|
||||
|
||||
for nonce in 0..=num_to_exhaust_block {
|
||||
let xt = TestXt::new_signed(
|
||||
sign_extra(1, nonce.into(), 0), Call::Balances(BalancesCall::transfer(33, 0)),
|
||||
let xt = TestXt::new(
|
||||
Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, nonce.into(), 0),
|
||||
);
|
||||
let res = Executive::apply_extrinsic(xt);
|
||||
if nonce != num_to_exhaust_block {
|
||||
@@ -686,9 +671,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn block_weight_and_size_is_stored_per_tx() {
|
||||
let xt = TestXt::new_signed(sign_extra(1, 0, 0), Call::Balances(BalancesCall::transfer(33, 0)));
|
||||
let x1 = TestXt::new_signed(sign_extra(1, 1, 0), Call::Balances(BalancesCall::transfer(33, 0)));
|
||||
let x2 = TestXt::new_signed(sign_extra(1, 2, 0), Call::Balances(BalancesCall::transfer(33, 0)));
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 0, 0));
|
||||
let x1 = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 1, 0));
|
||||
let x2 = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 2, 0));
|
||||
let len = xt.clone().encode().len() as u32;
|
||||
let mut t = new_test_ext(1);
|
||||
t.execute_with(|| {
|
||||
@@ -712,7 +697,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn validate_unsigned() {
|
||||
let xt = TestXt::new_unsigned(Call::Balances(BalancesCall::set_balance(33, 69, 69)));
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::set_balance(33, 69, 69)), None);
|
||||
let mut t = new_test_ext(1);
|
||||
|
||||
t.execute_with(|| {
|
||||
@@ -721,45 +706,6 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsigned_weight_is_noted_when_applied() {
|
||||
let xt = TestXt::new_unsigned(Call::Balances(BalancesCall::set_balance(33, 69, 69)));
|
||||
let len = xt.clone().encode().len() as u32;
|
||||
let mut t = new_test_ext(1);
|
||||
t.execute_with(|| {
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), 0);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 0);
|
||||
|
||||
// This is okay -- balances transfer will panic since it requires ensure_signed.
|
||||
assert_eq!(Executive::apply_extrinsic(xt), Ok(Err(DispatchError::BadOrigin)));
|
||||
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight(), len);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), len);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_trusted_skips_signature_check_but_not_others() {
|
||||
let xt1 = TestXt::new_signed(sign_extra(1, 0, 0), Call::Balances(BalancesCall::transfer(33, 0)))
|
||||
.badly_signed();
|
||||
|
||||
let mut t = new_test_ext(1);
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(Executive::apply_trusted_extrinsic(xt1), Ok(Ok(())));
|
||||
});
|
||||
|
||||
let xt2 = TestXt::new_signed(sign_extra(1, 0, 0), Call::Balances(BalancesCall::transfer(33, 0)))
|
||||
.invalid(TransactionValidityError::Invalid(InvalidTransaction::Call));
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(
|
||||
Executive::apply_trusted_extrinsic(xt2),
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_pay_for_tx_fee_on_full_lock() {
|
||||
let id: LockIdentifier = *b"0 ";
|
||||
@@ -772,9 +718,9 @@ mod tests {
|
||||
110,
|
||||
lock,
|
||||
);
|
||||
let xt = TestXt::new_signed(
|
||||
sign_extra(1, 0, 0),
|
||||
let xt = TestXt::new(
|
||||
Call::System(SystemCall::remark(vec![1u8])),
|
||||
sign_extra(1, 0, 0),
|
||||
);
|
||||
let weight = xt.get_dispatch_info().weight as u64;
|
||||
Executive::initialize_block(&Header::new(
|
||||
|
||||
Reference in New Issue
Block a user