Skip to content

Commit 4e1cafb

Browse files
committed
Remove UncheckedExtrinsic::function field
1 parent e61ccaf commit 4e1cafb

File tree

12 files changed

+133
-101
lines changed

12 files changed

+133
-101
lines changed

substrate/client/offchain/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ mod tests {
473473
// then
474474
assert_eq!(pool.status().ready, 1);
475475
assert!(matches!(
476-
pool.ready().next().unwrap().data().function,
476+
pool.ready().next().unwrap().data().call.try_decode().unwrap(),
477477
RuntimeCall::SubstrateTest(PalletCall::storage_change { .. })
478478
));
479479
}

substrate/client/transaction-pool/src/common/tests.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use parking_lot::Mutex;
2424
use sc_transaction_pool_api::error;
2525
use sp_blockchain::{HashAndNumber, TreeRoute};
2626
use sp_runtime::{
27-
generic::BlockId,
28-
traits::{Block as BlockT, Hash},
27+
generic::{BlockId, FullUncheckedExtrinsicRef},
28+
traits::{Block as BlockT, Hash, LazyExtrinsic},
2929
transaction_validity::{
3030
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
3131
},
@@ -79,14 +79,14 @@ impl ChainApi for TestApi {
7979
_source: TransactionSource,
8080
uxt: ExtrinsicFor<Self>,
8181
) -> Self::ValidationFuture {
82-
let uxt = (*uxt).clone();
82+
let mut uxt = (*uxt).clone();
8383
self.validation_requests.lock().push(uxt.clone());
8484
let hash = self.hash_and_length(&uxt).0;
8585
let block_number = self.block_id_to_number(&BlockId::Hash(at)).unwrap().unwrap();
8686

87-
let res = match uxt {
88-
Extrinsic {
89-
function: RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }),
87+
let res = match uxt.expect_as_full() {
88+
FullUncheckedExtrinsicRef {
89+
call: &RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }),
9090
..
9191
} => {
9292
let TransferData { nonce, .. } = (&uxt).try_into().unwrap();
@@ -132,8 +132,8 @@ impl ChainApi for TestApi {
132132
Ok(transaction)
133133
}
134134
},
135-
Extrinsic {
136-
function: RuntimeCall::SubstrateTest(PalletCall::include_data { .. }),
135+
FullUncheckedExtrinsicRef {
136+
call: &RuntimeCall::SubstrateTest(PalletCall::include_data { .. }),
137137
..
138138
} => Ok(ValidTransaction {
139139
priority: 9001,
@@ -142,8 +142,8 @@ impl ChainApi for TestApi {
142142
longevity: 9001,
143143
propagate: false,
144144
}),
145-
Extrinsic {
146-
function: RuntimeCall::SubstrateTest(PalletCall::indexed_call { .. }),
145+
FullUncheckedExtrinsicRef {
146+
call: &RuntimeCall::SubstrateTest(PalletCall::indexed_call { .. }),
147147
..
148148
} => Ok(ValidTransaction {
149149
priority: 9001,

substrate/frame/election-provider-multi-block/src/mock/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use sp_core::{
5353
use sp_npos_elections::EvaluateSupport;
5454
use sp_runtime::{
5555
bounded_vec,
56-
traits::{BlakeTwo256, IdentityLookup},
56+
traits::{BlakeTwo256, IdentityLookup, LazyExtrinsic},
5757
BuildStorage, PerU16, Perbill,
5858
};
5959
pub use staking::*;
@@ -625,8 +625,12 @@ pub fn roll_to_with_ocw(n: BlockNumber, maybe_pool: Option<Arc<RwLock<PoolState>
625625
.clone()
626626
.into_iter()
627627
.map(|uxt| <Extrinsic as codec::Decode>::decode(&mut &*uxt).unwrap())
628-
.for_each(|xt| {
629-
xt.function.dispatch(frame_system::RawOrigin::None.into()).unwrap();
628+
.for_each(|mut xt| {
629+
xt.expect_as_full()
630+
.call
631+
.clone()
632+
.dispatch(frame_system::RawOrigin::None.into())
633+
.unwrap();
630634
});
631635
pool.try_write().unwrap().transactions.clear();
632636
}

substrate/frame/election-provider-multi-block/src/unsigned/miner.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1620,12 +1620,13 @@ mod base_miner {
16201620

16211621
#[cfg(test)]
16221622
mod offchain_worker_miner {
1623-
use crate::{verifier::Verifier, CommonError};
1624-
use frame_support::traits::Hooks;
1625-
use sp_runtime::offchain::storage_lock::{BlockAndTime, StorageLock};
1626-
16271623
use super::*;
1628-
use crate::mock::*;
1624+
use crate::{mock::*, verifier::Verifier, CommonError};
1625+
use frame_support::traits::Hooks;
1626+
use sp_runtime::{
1627+
offchain::storage_lock::{BlockAndTime, StorageLock},
1628+
traits::LazyExtrinsic,
1629+
};
16291630

16301631
#[test]
16311632
fn lock_prevents_frequent_execution() {
@@ -1751,11 +1752,11 @@ mod offchain_worker_miner {
17511752
// OCW must have submitted now
17521753

17531754
let encoded = pool.read().transactions[0].clone();
1754-
let extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1755-
let call = extrinsic.function;
1755+
let mut extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1756+
let call = extrinsic.expect_as_full().call;
17561757
assert!(matches!(
17571758
call,
1758-
crate::mock::RuntimeCall::UnsignedPallet(
1759+
&crate::mock::RuntimeCall::UnsignedPallet(
17591760
crate::unsigned::Call::submit_unsigned { .. }
17601761
)
17611762
));

substrate/frame/election-provider-multi-phase/src/unsigned.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ mod tests {
11021102
use sp_runtime::{
11031103
bounded_vec,
11041104
offchain::storage_lock::{BlockAndTime, StorageLock},
1105-
traits::{Dispatchable, ValidateUnsigned, Zero},
1105+
traits::{Dispatchable, LazyExtrinsic, ValidateUnsigned, Zero},
11061106
ModuleError, PerU16,
11071107
};
11081108

@@ -1891,9 +1891,9 @@ mod tests {
18911891
// OCW must have submitted now
18921892

18931893
let encoded = pool.read().transactions[0].clone();
1894-
let extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1895-
let call = extrinsic.function;
1896-
assert!(matches!(call, RuntimeCall::MultiPhase(Call::submit_unsigned { .. })));
1894+
let mut extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1895+
let call = extrinsic.expect_as_full().call;
1896+
assert!(matches!(call, &RuntimeCall::MultiPhase(Call::submit_unsigned { .. })));
18971897
})
18981898
}
18991899

@@ -1908,8 +1908,8 @@ mod tests {
19081908
crate::Round::<Runtime>::mutate(|round| *round += 1);
19091909

19101910
let encoded = pool.read().transactions[0].clone();
1911-
let extrinsic = Extrinsic::decode(&mut &*encoded).unwrap();
1912-
let call = match extrinsic.function {
1911+
let mut extrinsic = Extrinsic::decode(&mut &*encoded).unwrap();
1912+
let call = match extrinsic.expect_as_full().call {
19131913
RuntimeCall::MultiPhase(call @ Call::submit_unsigned { .. }) => call,
19141914
_ => panic!("bad call: unexpected submission"),
19151915
};

substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use sp_runtime::{
3232
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
3333
},
3434
testing,
35-
traits::Zero,
35+
traits::{LazyExtrinsic, Zero},
3636
transaction_validity, BuildStorage, PerU16, Perbill, Percent,
3737
};
3838
use sp_staking::{
@@ -730,14 +730,16 @@ pub fn roll_to_with_ocw(n: BlockNumber, pool: Arc<RwLock<PoolState>>, delay_solu
730730
// decode submit_unsigned callable that may be queued in the pool by ocw. skip all
731731
// other extrinsics in the pool.
732732
for encoded in &pool.read().transactions {
733-
let extrinsic = Extrinsic::decode(&mut &encoded[..]).unwrap();
733+
let mut extrinsic = Extrinsic::decode(&mut &encoded[..]).unwrap();
734734

735-
let _ = match extrinsic.function {
735+
let _ = match extrinsic.expect_as_full().call {
736736
RuntimeCall::ElectionProviderMultiPhase(
737737
call @ Call::submit_unsigned { .. },
738738
) => {
739739
// call submit_unsigned callable in OCW pool.
740-
crate::assert_ok!(call.dispatch_bypass_filter(RuntimeOrigin::none()));
740+
crate::assert_ok!(call
741+
.clone()
742+
.dispatch_bypass_filter(RuntimeOrigin::none()));
741743
},
742744
_ => (),
743745
};

substrate/frame/examples/offchain-worker/src/tests.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use sp_core::{
3737
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystoreExt};
3838
use sp_runtime::{
3939
testing::TestXt,
40-
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
40+
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, LazyExtrinsic, Verify},
4141
RuntimeAppPublic,
4242
};
4343

@@ -245,9 +245,12 @@ fn should_submit_signed_transaction_on_chain() {
245245
// then
246246
let tx = pool_state.write().transactions.pop().unwrap();
247247
assert!(pool_state.read().transactions.is_empty());
248-
let tx = Extrinsic::decode(&mut &*tx).unwrap();
248+
let mut tx = Extrinsic::decode(&mut &*tx).unwrap();
249249
assert!(matches!(tx.preamble, sp_runtime::generic::Preamble::Signed(0, (), (),)));
250-
assert_eq!(tx.function, RuntimeCall::Example(crate::Call::submit_price { price: 15523 }));
250+
assert_eq!(
251+
tx.expect_as_full().call,
252+
&RuntimeCall::Example(crate::Call::submit_price { price: 15523 })
253+
);
251254
});
252255
}
253256

@@ -285,12 +288,12 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() {
285288
Example::fetch_price_and_send_unsigned_for_any_account(1).unwrap();
286289
// then
287290
let tx = pool_state.write().transactions.pop().unwrap();
288-
let tx = Extrinsic::decode(&mut &*tx).unwrap();
291+
let mut tx = Extrinsic::decode(&mut &*tx).unwrap();
289292
assert!(tx.is_inherent());
290293
if let RuntimeCall::Example(crate::Call::submit_price_unsigned_with_signed_payload {
291294
price_payload: body,
292295
signature,
293-
}) = tx.function
296+
}) = tx.expect_as_full().call.clone()
294297
{
295298
assert_eq!(body, price_payload);
296299

@@ -340,12 +343,12 @@ fn should_submit_unsigned_transaction_on_chain_for_all_accounts() {
340343
Example::fetch_price_and_send_unsigned_for_all_accounts(1).unwrap();
341344
// then
342345
let tx = pool_state.write().transactions.pop().unwrap();
343-
let tx = Extrinsic::decode(&mut &*tx).unwrap();
346+
let mut tx = Extrinsic::decode(&mut &*tx).unwrap();
344347
assert!(tx.is_inherent());
345348
if let RuntimeCall::Example(crate::Call::submit_price_unsigned_with_signed_payload {
346349
price_payload: body,
347350
signature,
348-
}) = tx.function
351+
}) = tx.expect_as_full().call.clone()
349352
{
350353
assert_eq!(body, price_payload);
351354

@@ -381,10 +384,10 @@ fn should_submit_raw_unsigned_transaction_on_chain() {
381384
// then
382385
let tx = pool_state.write().transactions.pop().unwrap();
383386
assert!(pool_state.read().transactions.is_empty());
384-
let tx = Extrinsic::decode(&mut &*tx).unwrap();
387+
let mut tx = Extrinsic::decode(&mut &*tx).unwrap();
385388
assert!(tx.is_inherent());
386389
assert_eq!(
387-
tx.function,
390+
tx.expect_as_full().call.clone(),
388391
RuntimeCall::Example(crate::Call::submit_price_unsigned {
389392
block_number: 1,
390393
price: 15523

substrate/frame/im-online/src/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use sp_core::offchain::{
2626
testing::{TestOffchainExt, TestTransactionPoolExt},
2727
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
2828
};
29-
use sp_runtime::testing::UintAuthorityId;
29+
use sp_runtime::{testing::UintAuthorityId, traits::LazyExtrinsic};
3030

3131
#[test]
3232
fn test_unresponsiveness_slash_fraction() {
@@ -224,16 +224,16 @@ fn should_generate_heartbeats() {
224224
assert_eq!(state.read().transactions.len(), 2);
225225

226226
// check stuff about the transaction.
227-
let ex: Extrinsic = Decode::decode(&mut &*transaction).unwrap();
228-
let heartbeat = match ex.function {
227+
let mut ex: Extrinsic = Decode::decode(&mut &*transaction).unwrap();
228+
let heartbeat = match ex.expect_as_full().call {
229229
crate::mock::RuntimeCall::ImOnline(crate::Call::heartbeat { heartbeat, .. }) =>
230230
heartbeat,
231231
e => panic!("Unexpected call: {:?}", e),
232232
};
233233

234234
assert_eq!(
235235
heartbeat,
236-
Heartbeat {
236+
&Heartbeat {
237237
block_number: block,
238238
session_index: 2,
239239
authority_index: 2,
@@ -338,16 +338,16 @@ fn should_not_send_a_report_if_already_online() {
338338
// All validators have `0` as their session key, but we should only produce 1 heartbeat.
339339
assert_eq!(pool_state.read().transactions.len(), 0);
340340
// check stuff about the transaction.
341-
let ex: Extrinsic = Decode::decode(&mut &*transaction).unwrap();
342-
let heartbeat = match ex.function {
341+
let mut ex: Extrinsic = Decode::decode(&mut &*transaction).unwrap();
342+
let heartbeat = match ex.expect_as_full().call {
343343
crate::mock::RuntimeCall::ImOnline(crate::Call::heartbeat { heartbeat, .. }) =>
344344
heartbeat,
345345
e => panic!("Unexpected call: {:?}", e),
346346
};
347347

348348
assert_eq!(
349349
heartbeat,
350-
Heartbeat { block_number: 4, session_index: 2, authority_index: 0, validators_len: 3 }
350+
&Heartbeat { block_number: 4, session_index: 2, authority_index: 0, validators_len: 3 }
351351
);
352352
});
353353
}

substrate/frame/support/src/traits/misc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ impl<Address, Call, Signature, Extra> InherentBuilder
921921
for sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extra>
922922
where
923923
Address: TypeInfo,
924-
Call: Clone + DecodeWithMemTracking + TypeInfo,
924+
Call: DecodeWithMemTracking + TypeInfo,
925925
Signature: TypeInfo,
926926
Extra: TypeInfo,
927927
{
@@ -950,7 +950,7 @@ impl<Address, Call, Signature, Extension> SignedTransactionBuilder
950950
for sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extension>
951951
where
952952
Address: TypeInfo,
953-
Call: Clone + DecodeWithMemTracking + TypeInfo,
953+
Call: DecodeWithMemTracking + TypeInfo,
954954
Signature: TypeInfo,
955955
Extension: TypeInfo,
956956
{

0 commit comments

Comments
 (0)