Skip to content

Commit 000d75c

Browse files
committed
Remove UncheckedExtrinsic::function field
1 parent 657e253 commit 000d75c

14 files changed

Lines changed: 173 additions & 131 deletions

File tree

cumulus/primitives/core/src/parachain_block_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ mod tests {
214214
let v0 = ParachainBlockDataV0::<TestBlock> {
215215
header: Header::new_from_number(10),
216216
extrinsics: vec![
217-
TestExtrinsic::new_bare(MockCallU64(10)),
218-
TestExtrinsic::new_bare(MockCallU64(100)),
217+
TestExtrinsic::new_bare(MockCallU64(10)).with_encoded_call(),
218+
TestExtrinsic::new_bare(MockCallU64(100)).with_encoded_call(),
219219
],
220220
storage_proof: CompactProof { encoded_nodes: vec![vec![10u8; 200], vec![20u8; 30]] },
221221
};
@@ -244,8 +244,8 @@ mod tests {
244244
blocks: vec![TestBlock::new(
245245
Header::new_from_number(10),
246246
vec![
247-
TestExtrinsic::new_bare(MockCallU64(10)),
248-
TestExtrinsic::new_bare(MockCallU64(100)),
247+
TestExtrinsic::new_bare(MockCallU64(10)).with_encoded_call(),
248+
TestExtrinsic::new_bare(MockCallU64(100)).with_encoded_call(),
249249
],
250250
)],
251251
proof: CompactProof { encoded_nodes: vec![vec![10u8; 200], vec![20u8; 30]] },

substrate/client/db/src/lib.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,17 +3794,19 @@ pub(crate) mod tests {
37943794
assert_eq!(None, bc.body(blocks[1]).unwrap());
37953795
assert_eq!(None, bc.body(blocks[2]).unwrap());
37963796
assert_eq!(
3797-
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
3797+
Some(vec![UncheckedXt::new_transaction(3.into(), ()).with_encoded_call()]),
37983798
bc.body(blocks[3]).unwrap()
37993799
);
38003800
assert_eq!(
3801-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
3801+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
38023802
bc.body(blocks[4]).unwrap()
38033803
);
38043804
} else {
38053805
for i in 0..5 {
38063806
assert_eq!(
3807-
Some(vec![UncheckedXt::new_transaction((i as u64).into(), ())]),
3807+
Some(vec![
3808+
UncheckedXt::new_transaction((i as u64).into(), ()).with_encoded_call()
3809+
]),
38083810
bc.body(blocks[i]).unwrap()
38093811
);
38103812
}
@@ -3869,7 +3871,7 @@ pub(crate) mod tests {
38693871

38703872
let bc = backend.blockchain();
38713873
assert_eq!(
3872-
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
3874+
Some(vec![UncheckedXt::new_transaction(2.into(), ()).with_encoded_call()]),
38733875
bc.body(fork_hash_root).unwrap()
38743876
);
38753877

@@ -3886,25 +3888,27 @@ pub(crate) mod tests {
38863888
assert_eq!(None, bc.body(blocks[2]).unwrap());
38873889

38883890
assert_eq!(
3889-
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
3891+
Some(vec![UncheckedXt::new_transaction(3.into(), ()).with_encoded_call()]),
38903892
bc.body(blocks[3]).unwrap()
38913893
);
38923894
assert_eq!(
3893-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
3895+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
38943896
bc.body(blocks[4]).unwrap()
38953897
);
38963898
} else {
38973899
for i in 0..5 {
38983900
assert_eq!(
3899-
Some(vec![UncheckedXt::new_transaction((i as u64).into(), ())]),
3901+
Some(vec![
3902+
UncheckedXt::new_transaction((i as u64).into(), ()).with_encoded_call()
3903+
]),
39003904
bc.body(blocks[i]).unwrap()
39013905
);
39023906
}
39033907
}
39043908

39053909
if matches!(pruning, BlocksPruning::KeepAll) {
39063910
assert_eq!(
3907-
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
3911+
Some(vec![UncheckedXt::new_transaction(2.into(), ()).with_encoded_call()]),
39083912
bc.body(fork_hash_root).unwrap()
39093913
);
39103914
} else {
@@ -3965,19 +3969,19 @@ pub(crate) mod tests {
39653969
assert_eq!(None, bc.body(block_1b).unwrap());
39663970
assert_eq!(None, bc.body(block_2b).unwrap());
39673971
assert_eq!(
3968-
Some(vec![UncheckedXt::new_transaction(0x00.into(), ())]),
3972+
Some(vec![UncheckedXt::new_transaction(0x00.into(), ()).with_encoded_call()]),
39693973
bc.body(block_0).unwrap()
39703974
);
39713975
assert_eq!(
3972-
Some(vec![UncheckedXt::new_transaction(0x1a.into(), ())]),
3976+
Some(vec![UncheckedXt::new_transaction(0x1a.into(), ()).with_encoded_call()]),
39733977
bc.body(block_1a).unwrap()
39743978
);
39753979
assert_eq!(
3976-
Some(vec![UncheckedXt::new_transaction(0x2a.into(), ())]),
3980+
Some(vec![UncheckedXt::new_transaction(0x2a.into(), ()).with_encoded_call()]),
39773981
bc.body(block_2a).unwrap()
39783982
);
39793983
assert_eq!(
3980-
Some(vec![UncheckedXt::new_transaction(0x3a.into(), ())]),
3984+
Some(vec![UncheckedXt::new_transaction(0x3a.into(), ()).with_encoded_call()]),
39813985
bc.body(block_3a).unwrap()
39823986
);
39833987
}
@@ -4646,7 +4650,7 @@ pub(crate) mod tests {
46464650
// Check that we can properly access values when there is reference count
46474651
// but no value.
46484652
assert_eq!(
4649-
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
4653+
Some(vec![UncheckedXt::new_transaction(1.into(), ()).with_encoded_call()]),
46504654
bc.body(blocks[1]).unwrap()
46514655
);
46524656

@@ -4666,12 +4670,12 @@ pub(crate) mod tests {
46664670
// Block 0, 1, 2, 3 are pinned, so all values should be cached.
46674671
// Block 4 is inside the pruning window, its value is in db.
46684672
assert_eq!(
4669-
Some(vec![UncheckedXt::new_transaction(0.into(), ())]),
4673+
Some(vec![UncheckedXt::new_transaction(0.into(), ()).with_encoded_call()]),
46704674
bc.body(blocks[0]).unwrap()
46714675
);
46724676

46734677
assert_eq!(
4674-
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
4678+
Some(vec![UncheckedXt::new_transaction(1.into(), ()).with_encoded_call()]),
46754679
bc.body(blocks[1]).unwrap()
46764680
);
46774681
assert_eq!(
@@ -4680,7 +4684,7 @@ pub(crate) mod tests {
46804684
);
46814685

46824686
assert_eq!(
4683-
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
4687+
Some(vec![UncheckedXt::new_transaction(2.into(), ()).with_encoded_call()]),
46844688
bc.body(blocks[2]).unwrap()
46854689
);
46864690
assert_eq!(
@@ -4689,7 +4693,7 @@ pub(crate) mod tests {
46894693
);
46904694

46914695
assert_eq!(
4692-
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
4696+
Some(vec![UncheckedXt::new_transaction(3.into(), ()).with_encoded_call()]),
46934697
bc.body(blocks[3]).unwrap()
46944698
);
46954699
assert_eq!(
@@ -4698,7 +4702,7 @@ pub(crate) mod tests {
46984702
);
46994703

47004704
assert_eq!(
4701-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
4705+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
47024706
bc.body(blocks[4]).unwrap()
47034707
);
47044708
assert_eq!(
@@ -4732,7 +4736,7 @@ pub(crate) mod tests {
47324736

47334737
// Block 4 is inside the pruning window and still kept
47344738
assert_eq!(
4735-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
4739+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
47364740
bc.body(blocks[4]).unwrap()
47374741
);
47384742
assert_eq!(
@@ -4767,15 +4771,15 @@ pub(crate) mod tests {
47674771
assert!(bc.body(blocks[3]).unwrap().is_none());
47684772

47694773
assert_eq!(
4770-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
4774+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
47714775
bc.body(blocks[4]).unwrap()
47724776
);
47734777
assert_eq!(
47744778
Some(Justifications::from(build_justification(4))),
47754779
bc.justifications(blocks[4]).unwrap()
47764780
);
47774781
assert_eq!(
4778-
Some(vec![UncheckedXt::new_transaction(5.into(), ())]),
4782+
Some(vec![UncheckedXt::new_transaction(5.into(), ()).with_encoded_call()]),
47794783
bc.body(blocks[5]).unwrap()
47804784
);
47814785
assert!(bc.header(blocks[5]).ok().flatten().is_some());
@@ -4810,7 +4814,7 @@ pub(crate) mod tests {
48104814
backend.commit_operation(op).unwrap();
48114815

48124816
assert_eq!(
4813-
Some(vec![UncheckedXt::new_transaction(5.into(), ())]),
4817+
Some(vec![UncheckedXt::new_transaction(5.into(), ()).with_encoded_call()]),
48144818
bc.body(blocks[5]).unwrap()
48154819
);
48164820
assert!(bc.header(blocks[5]).ok().flatten().is_some());
@@ -4891,31 +4895,31 @@ pub(crate) mod tests {
48914895

48924896
let bc = backend.blockchain();
48934897
assert_eq!(
4894-
Some(vec![UncheckedXt::new_transaction(0.into(), ())]),
4898+
Some(vec![UncheckedXt::new_transaction(0.into(), ()).with_encoded_call()]),
48954899
bc.body(blocks[0]).unwrap()
48964900
);
48974901
assert_eq!(
4898-
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
4902+
Some(vec![UncheckedXt::new_transaction(1.into(), ()).with_encoded_call()]),
48994903
bc.body(blocks[1]).unwrap()
49004904
);
49014905
assert_eq!(
4902-
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
4906+
Some(vec![UncheckedXt::new_transaction(2.into(), ()).with_encoded_call()]),
49034907
bc.body(blocks[2]).unwrap()
49044908
);
49054909
assert_eq!(
4906-
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
4910+
Some(vec![UncheckedXt::new_transaction(3.into(), ()).with_encoded_call()]),
49074911
bc.body(blocks[3]).unwrap()
49084912
);
49094913
assert_eq!(
4910-
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
4914+
Some(vec![UncheckedXt::new_transaction(4.into(), ()).with_encoded_call()]),
49114915
bc.body(blocks[4]).unwrap()
49124916
);
49134917
// Check the fork hashes.
49144918
assert_eq!(None, bc.body(fork_hash_root).unwrap());
49154919
assert_eq!(
49164920
Some(vec![
4917-
UncheckedXt::new_transaction(3.into(), ()),
4918-
UncheckedXt::new_transaction(11.into(), ())
4921+
UncheckedXt::new_transaction(3.into(), ()).with_encoded_call(),
4922+
UncheckedXt::new_transaction(11.into(), ()).with_encoded_call()
49194923
]),
49204924
bc.body(fork_hash_3).unwrap()
49214925
);

substrate/client/offchain/src/lib.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use parking_lot::Mutex;
2828
use sc_transaction_pool_api::error;
2929
use sp_blockchain::{HashAndNumber, TreeRoute};
3030
use sp_runtime::{
31-
generic::BlockId,
32-
traits::{Block as BlockT, Hash},
31+
generic::{BlockId, UncheckedExtrinsicRef},
32+
traits::{Block as BlockT, Hash, LazyExtrinsic},
3333
transaction_validity::{
3434
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
3535
},
@@ -83,14 +83,14 @@ impl ChainApi for TestApi {
8383
uxt: ExtrinsicFor<Self>,
8484
_: ValidateTransactionPriority,
8585
) -> Result<TransactionValidity, Self::Error> {
86-
let uxt = (*uxt).clone();
86+
let mut uxt = (*uxt).clone();
8787
self.validation_requests.lock().push(uxt.clone());
8888
let hash = self.hash_and_length(&uxt).0;
8989
let block_number = self.block_id_to_number(&BlockId::Hash(at)).unwrap().unwrap();
9090

91-
let res = match uxt {
92-
Extrinsic {
93-
function: RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }),
91+
let res = match uxt.expect_as_ref() {
92+
UncheckedExtrinsicRef {
93+
call: &RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }),
9494
..
9595
} => {
9696
let TransferData { nonce, .. } = (&uxt).try_into().unwrap();
@@ -136,8 +136,8 @@ impl ChainApi for TestApi {
136136
Ok(transaction)
137137
}
138138
},
139-
Extrinsic {
140-
function: RuntimeCall::SubstrateTest(PalletCall::include_data { .. }),
139+
UncheckedExtrinsicRef {
140+
call: &RuntimeCall::SubstrateTest(PalletCall::include_data { .. }),
141141
..
142142
} => Ok(ValidTransaction {
143143
priority: 9001,
@@ -146,8 +146,8 @@ impl ChainApi for TestApi {
146146
longevity: 9001,
147147
propagate: false,
148148
}),
149-
Extrinsic {
150-
function: RuntimeCall::SubstrateTest(PalletCall::indexed_call { .. }),
149+
UncheckedExtrinsicRef {
150+
call: &RuntimeCall::SubstrateTest(PalletCall::indexed_call { .. }),
151151
..
152152
} => Ok(ValidTransaction {
153153
priority: 9001,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ pub fn roll_to_with_ocw(n: BlockNumber, maybe_pool: Option<Arc<RwLock<PoolState>
733733
.into_iter()
734734
.map(|uxt| <Extrinsic as codec::Decode>::decode(&mut &*uxt).unwrap())
735735
.for_each(|xt| {
736-
xt.function.dispatch(frame_system::RawOrigin::None.into()).unwrap();
736+
let call = xt.call.try_decode().unwrap();
737+
call.dispatch(frame_system::RawOrigin::None.into()).unwrap();
737738
});
738739
pool.try_write().unwrap().transactions.clear();
739740
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,12 +1854,13 @@ mod base_miner {
18541854

18551855
#[cfg(test)]
18561856
mod offchain_worker_miner {
1857-
use crate::{verifier::Verifier, CommonError};
1858-
use frame_support::traits::Hooks;
1859-
use sp_runtime::offchain::storage_lock::{BlockAndTime, StorageLock};
1860-
18611857
use super::*;
1862-
use crate::mock::*;
1858+
use crate::{mock::*, verifier::Verifier, CommonError};
1859+
use frame_support::traits::Hooks;
1860+
use sp_runtime::{
1861+
offchain::storage_lock::{BlockAndTime, StorageLock},
1862+
traits::LazyExtrinsicCall,
1863+
};
18631864

18641865
#[test]
18651866
fn lock_prevents_frequent_execution() {
@@ -1983,11 +1984,11 @@ mod offchain_worker_miner {
19831984
// OCW must have submitted now
19841985

19851986
let encoded = pool.read().transactions[0].clone();
1986-
let extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1987-
let call = extrinsic.function;
1987+
let mut extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1988+
let call = extrinsic.try_get_or_decode_call().unwrap();
19881989
assert!(matches!(
19891990
call,
1990-
crate::mock::RuntimeCall::UnsignedPallet(
1991+
&crate::mock::RuntimeCall::UnsignedPallet(
19911992
crate::unsigned::Call::submit_unsigned { .. }
19921993
)
19931994
));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ mod tests {
11091109
use sp_runtime::{
11101110
bounded_vec,
11111111
offchain::storage_lock::{BlockAndTime, StorageLock},
1112-
traits::{Dispatchable, ValidateUnsigned, Zero},
1112+
traits::{Dispatchable, LazyExtrinsic, ValidateUnsigned, Zero},
11131113
ModuleError, PerU16,
11141114
};
11151115

@@ -1898,9 +1898,9 @@ mod tests {
18981898
// OCW must have submitted now
18991899

19001900
let encoded = pool.read().transactions[0].clone();
1901-
let extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1902-
let call = extrinsic.function;
1903-
assert!(matches!(call, RuntimeCall::MultiPhase(Call::submit_unsigned { .. })));
1901+
let mut extrinsic: Extrinsic = codec::Decode::decode(&mut &*encoded).unwrap();
1902+
let call = extrinsic.expect_as_ref().call;
1903+
assert!(matches!(call, &RuntimeCall::MultiPhase(Call::submit_unsigned { .. })));
19041904
})
19051905
}
19061906

@@ -1915,8 +1915,8 @@ mod tests {
19151915
crate::Round::<Runtime>::mutate(|round| *round += 1);
19161916

19171917
let encoded = pool.read().transactions[0].clone();
1918-
let extrinsic = Extrinsic::decode(&mut &*encoded).unwrap();
1919-
let call = match extrinsic.function {
1918+
let mut extrinsic = Extrinsic::decode(&mut &*encoded).unwrap();
1919+
let call = match extrinsic.expect_as_ref().call {
19201920
RuntimeCall::MultiPhase(call @ Call::submit_unsigned { .. }) => call,
19211921
_ => panic!("bad call: unexpected submission"),
19221922
};

0 commit comments

Comments
 (0)