Skip to content

Commit 77fed77

Browse files
committed
Rework authorization, add ValidateUnsigned impl and "ValidateSigned" SignedExtension
1 parent 190c7e3 commit 77fed77

File tree

7 files changed

+685
-276
lines changed

7 files changed

+685
-276
lines changed

node/src/benchmarking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn create_benchmark_extrinsic(
8080
)),
8181
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
8282
frame_system::CheckWeight::<runtime::Runtime>::new(),
83+
runtime::ValidateSigned,
8384
);
8485

8586
let raw_payload = runtime::SignedPayload::from_raw(
@@ -93,6 +94,7 @@ pub fn create_benchmark_extrinsic(
9394
best_hash,
9495
(),
9596
(),
97+
(),
9698
),
9799
);
98100
let signature = raw_payload.using_encoded(|e| sender.sign(e));

pallets/transaction-storage/src/benchmarking.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ mod benchmarks {
127127

128128
#[benchmark]
129129
fn store(l: Linear<{ 1 }, { T::MaxTransactionSize::get() }>) -> Result<(), BenchmarkError> {
130-
let caller: T::AccountId = whitelisted_caller();
131-
132130
#[extrinsic_call]
133-
_(RawOrigin::Signed(caller.clone()), vec![0u8; l as usize]);
131+
_(RawOrigin::None, vec![0u8; l as usize]);
134132

135133
assert!(!BlockTransactions::<T>::get().is_empty());
136134
assert_last_event::<T>(Event::Stored { index: 0 }.into());
@@ -139,15 +137,14 @@ mod benchmarks {
139137

140138
#[benchmark]
141139
fn renew() -> Result<(), BenchmarkError> {
142-
let caller: T::AccountId = whitelisted_caller();
143140
TransactionStorage::<T>::store(
144-
RawOrigin::Signed(caller.clone()).into(),
141+
RawOrigin::None.into(),
145142
vec![0u8; T::MaxTransactionSize::get() as usize],
146143
)?;
147144
run_to_block::<T>(1u32.into());
148145

149146
#[extrinsic_call]
150-
_(RawOrigin::Signed(caller.clone()), BlockNumberFor::<T>::zero(), 0);
147+
_(RawOrigin::None, BlockNumberFor::<T>::zero(), 0);
151148

152149
assert_last_event::<T>(Event::Renewed { index: 0 }.into());
153150
Ok(())
@@ -156,10 +153,9 @@ mod benchmarks {
156153
#[benchmark]
157154
fn check_proof() -> Result<(), BenchmarkError> {
158155
run_to_block::<T>(1u32.into());
159-
let caller: T::AccountId = whitelisted_caller();
160156
for _ in 0..T::MaxBlockTransactions::get() {
161157
TransactionStorage::<T>::store(
162-
RawOrigin::Signed(caller.clone()).into(),
158+
RawOrigin::None.into(),
163159
vec![0u8; T::MaxTransactionSize::get() as usize],
164160
)?;
165161
}
@@ -203,5 +199,41 @@ mod benchmarks {
203199
Ok(())
204200
}
205201

202+
#[benchmark]
203+
fn remove_expired_account_authorization() -> Result<(), BenchmarkError> {
204+
let origin = T::Authorizer::try_successful_origin()
205+
.map_err(|_| BenchmarkError::Stop("unable to compute origin"))?;
206+
let who = whitelisted_caller();
207+
TransactionStorage::<T>::authorize_account(origin, who.clone(), 1, 1);
208+
209+
let period = T::AuthorizationPeriod::get();
210+
let now = frame_system::Pallet::<T>::block_number();
211+
run_to_block::<T>(now + period);
212+
213+
#[extrinsic_call]
214+
_(RawOrigin::None, who.clone());
215+
216+
assert_last_event::<T>(Event::AccountAuthorizationRemoved { who });
217+
Ok(())
218+
}
219+
220+
#[benchmark]
221+
fn remove_expired_preimage_authorization() -> Result<(), BenchmarkError> {
222+
let origin = T::Authorizer::try_successful_origin()
223+
.map_err(|_| BenchmarkError::Stop("unable to compute origin"))?;
224+
let hash = [0; 32];
225+
TransactionStorage::<T>::authorize_preimage(origin, hash, 1);
226+
227+
let period = T::AuthorizationPeriod::get();
228+
let now = frame_system::Pallet::<T>::block_number();
229+
run_to_block::<T>(now + period);
230+
231+
#[extrinsic_call]
232+
_(RawOrigin::None, hash);
233+
234+
assert_last_event::<T>(Event::PreimageAuthorizationRemoved { hash });
235+
Ok(())
236+
}
237+
206238
impl_benchmark_test_suite!(TransactionStorage, crate::mock::new_test_ext(), crate::mock::Test);
207239
}

0 commit comments

Comments
 (0)