Skip to content

Commit 8906016

Browse files
committed
Merge branch 'main' into upd_just
2 parents 7738f21 + 79af6c4 commit 8906016

File tree

2 files changed

+66
-52
lines changed

2 files changed

+66
-52
lines changed

pallets/transaction-storage/src/benchmarking.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use sp_transaction_storage_proof::TransactionStorageProof;
3333
// for _ in 0..DEFAULT_MAX_BLOCK_TRANSACTIONS {
3434
// transactions.push(vec![0; tx_size]);
3535
// }
36-
// let hash = vec![0; 32];
37-
// build_proof(hash.as_slice(), transactions).unwrap().encode()
36+
// let content_hash = vec![0; 32];
37+
// build_proof(content_hash.as_slice(), transactions).unwrap().encode()
3838
// ```
3939
// while hardforcing target chunk key in `build_proof` to [22, 21, 1, 0].
4040
const PROOF: &str = "\
@@ -124,27 +124,27 @@ mod benchmarks {
124124
#[benchmark]
125125
fn store(l: Linear<{ 1 }, { T::MaxTransactionSize::get() }>) -> Result<(), BenchmarkError> {
126126
let data = vec![0u8; l as usize];
127-
let hash = sp_io::hashing::blake2_256(&data);
127+
let content_hash = sp_io::hashing::blake2_256(&data);
128128

129129
#[extrinsic_call]
130130
_(RawOrigin::None, data);
131131

132132
assert!(!BlockTransactions::<T>::get().is_empty());
133-
assert_last_event::<T>(Event::Stored { index: 0, hash }.into());
133+
assert_last_event::<T>(Event::Stored { index: 0, content_hash }.into());
134134
Ok(())
135135
}
136136

137137
#[benchmark]
138138
fn renew() -> Result<(), BenchmarkError> {
139139
let data = vec![0u8; T::MaxTransactionSize::get() as usize];
140-
let hash = sp_io::hashing::blake2_256(&data);
140+
let content_hash = sp_io::hashing::blake2_256(&data);
141141
TransactionStorage::<T>::store(RawOrigin::None.into(), data)?;
142142
run_to_block::<T>(1u32.into());
143143

144144
#[extrinsic_call]
145145
_(RawOrigin::None, BlockNumberFor::<T>::zero(), 0);
146146

147-
assert_last_event::<T>(Event::Renewed { index: 0, hash }.into());
147+
assert_last_event::<T>(Event::Renewed { index: 0, content_hash }.into());
148148
Ok(())
149149
}
150150

@@ -210,30 +210,34 @@ mod benchmarks {
210210
fn authorize_preimage() -> Result<(), BenchmarkError> {
211211
let origin = T::Authorizer::try_successful_origin()
212212
.map_err(|_| BenchmarkError::Stop("unable to compute origin"))?;
213-
let hash = [0u8; 32];
213+
let content_hash = [0u8; 32];
214214
let max_size: u64 = 1024 * 1024;
215215

216216
#[extrinsic_call]
217-
_(origin as T::RuntimeOrigin, hash, max_size);
217+
_(origin as T::RuntimeOrigin, content_hash, max_size);
218218

219-
assert_last_event::<T>(Event::PreimageAuthorized { hash, max_size }.into());
219+
assert_last_event::<T>(Event::PreimageAuthorized { content_hash, max_size }.into());
220220
Ok(())
221221
}
222222

223223
#[benchmark]
224224
fn refresh_preimage_authorization() -> Result<(), BenchmarkError> {
225225
let origin = T::Authorizer::try_successful_origin()
226226
.map_err(|_| BenchmarkError::Stop("unable to compute origin"))?;
227-
let hash = [0u8; 32];
227+
let content_hash = [0u8; 32];
228228
let max_size: u64 = 1024 * 1024;
229229
let origin2 = origin.clone();
230-
TransactionStorage::<T>::authorize_preimage(origin2 as T::RuntimeOrigin, hash, max_size)
231-
.map_err(|_| BenchmarkError::Stop("unable to authorize account"))?;
230+
TransactionStorage::<T>::authorize_preimage(
231+
origin2 as T::RuntimeOrigin,
232+
content_hash,
233+
max_size,
234+
)
235+
.map_err(|_| BenchmarkError::Stop("unable to authorize account"))?;
232236

233237
#[extrinsic_call]
234-
_(origin as T::RuntimeOrigin, hash);
238+
_(origin as T::RuntimeOrigin, content_hash);
235239

236-
assert_last_event::<T>(Event::PreimageAuthorizationRefreshed { hash }.into());
240+
assert_last_event::<T>(Event::PreimageAuthorizationRefreshed { content_hash }.into());
237241
Ok(())
238242
}
239243

@@ -260,18 +264,18 @@ mod benchmarks {
260264
fn remove_expired_preimage_authorization() -> Result<(), BenchmarkError> {
261265
let origin = T::Authorizer::try_successful_origin()
262266
.map_err(|_| BenchmarkError::Stop("unable to compute origin"))?;
263-
let hash = [0; 32];
264-
TransactionStorage::<T>::authorize_preimage(origin, hash, 1)
267+
let content_hash = [0; 32];
268+
TransactionStorage::<T>::authorize_preimage(origin, content_hash, 1)
265269
.map_err(|_| BenchmarkError::Stop("unable to authorize preimage"))?;
266270

267271
let period = T::AuthorizationPeriod::get();
268272
let now = System::<T>::block_number();
269273
run_to_block::<T>(now + period);
270274

271275
#[extrinsic_call]
272-
_(RawOrigin::None, hash);
276+
_(RawOrigin::None, content_hash);
273277

274-
assert_last_event::<T>(Event::ExpiredPreimageAuthorizationRemoved { hash }.into());
278+
assert_last_event::<T>(Event::ExpiredPreimageAuthorizationRemoved { content_hash }.into());
275279
Ok(())
276280
}
277281

pallets/transaction-storage/src/lib.rs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,26 @@ pub mod pallet {
200200
BadDataSize,
201201
/// Too many transactions in the block.
202202
TooManyTransactions,
203-
/// Renewed extrinsic not found.
203+
/// Invalid configuration.
204+
NotConfigured,
205+
/// Renewed extrinsic is not found.
204206
RenewedNotFound,
207+
/// Attempting to store an empty transaction
208+
EmptyTransaction,
205209
/// Proof was not expected in this block.
206210
UnexpectedProof,
207211
/// Proof failed verification.
208212
InvalidProof,
209-
/// Unable to verify proof becasue state data is missing.
213+
/// Missing storage proof.
214+
MissingProof,
215+
/// Unable to verify proof because state data is missing.
210216
MissingStateData,
211217
/// Double proof check in the block.
212218
DoubleCheck,
219+
/// Storage proof was not checked in the block.
220+
ProofNotChecked,
221+
/// Transaction is too large.
222+
TransactionTooLarge,
213223
/// Authorization was not found.
214224
AuthorizationNotFound,
215225
/// Authorization has not expired.
@@ -329,7 +339,7 @@ pub mod pallet {
329339
})
330340
.map_err(|_| Error::<T>::TooManyTransactions)
331341
})?;
332-
Self::deposit_event(Event::Stored { index, hash: content_hash });
342+
Self::deposit_event(Event::Stored { index, content_hash });
333343
Ok(())
334344
}
335345

@@ -378,7 +388,7 @@ pub mod pallet {
378388
})
379389
.map_err(|_| Error::<T>::TooManyTransactions)
380390
})?;
381-
Self::deposit_event(Event::Renewed { index, hash: content_hash });
391+
Self::deposit_event(Event::Renewed { index, content_hash });
382392
Ok(().into())
383393
}
384394

@@ -452,7 +462,7 @@ pub mod pallet {
452462
///
453463
/// Parameters:
454464
///
455-
/// - `hash`: The BLAKE2b hash of the data to be submitted.
465+
/// - `content_hash`: The BLAKE2b hash of the data to be submitted.
456466
/// - `max_size`: The maximum size, in bytes, of the preimage.
457467
///
458468
/// The origin for this call must be the pallet's `Authorizer`. Emits
@@ -461,12 +471,12 @@ pub mod pallet {
461471
#[pallet::weight(T::WeightInfo::authorize_preimage())]
462472
pub fn authorize_preimage(
463473
origin: OriginFor<T>,
464-
hash: ContentHash,
474+
content_hash: ContentHash,
465475
max_size: u64,
466476
) -> DispatchResult {
467477
T::Authorizer::ensure_origin(origin)?;
468-
Self::authorize(AuthorizationScope::Preimage(hash), 1, max_size);
469-
Self::deposit_event(Event::PreimageAuthorized { hash, max_size });
478+
Self::authorize(AuthorizationScope::Preimage(content_hash), 1, max_size);
479+
Self::deposit_event(Event::PreimageAuthorized { content_hash, max_size });
470480
Ok(())
471481
}
472482

@@ -493,7 +503,7 @@ pub mod pallet {
493503
///
494504
/// Parameters:
495505
///
496-
/// - `hash`: The BLAKE2b hash that was authorized.
506+
/// - `content_hash`: The BLAKE2b hash that was authorized.
497507
///
498508
/// Emits
499509
/// [`ExpiredPreimageAuthorizationRemoved`](Event::ExpiredPreimageAuthorizationRemoved)
@@ -502,10 +512,10 @@ pub mod pallet {
502512
#[pallet::weight(T::WeightInfo::remove_expired_preimage_authorization())]
503513
pub fn remove_expired_preimage_authorization(
504514
_origin: OriginFor<T>,
505-
hash: ContentHash,
515+
content_hash: ContentHash,
506516
) -> DispatchResult {
507-
Self::remove_expired_authorization(AuthorizationScope::Preimage(hash))?;
508-
Self::deposit_event(Event::ExpiredPreimageAuthorizationRemoved { hash });
517+
Self::remove_expired_authorization(AuthorizationScope::Preimage(content_hash))?;
518+
Self::deposit_event(Event::ExpiredPreimageAuthorizationRemoved { content_hash });
509519
Ok(())
510520
}
511521

@@ -537,7 +547,7 @@ pub mod pallet {
537547
///
538548
/// Parameters:
539549
///
540-
/// - `hash`: The BLAKE2b hash of the data to be submitted.
550+
/// - `content_hash`: The BLAKE2b hash of the data to be submitted.
541551
///
542552
/// The origin for this call must be the pallet's `Authorizer`. Emits
543553
/// [`PreimageAuthorizationRefreshed`](Event::PreimageAuthorizationRefreshed) when
@@ -546,11 +556,11 @@ pub mod pallet {
546556
#[pallet::weight(T::WeightInfo::refresh_preimage_authorization())]
547557
pub fn refresh_preimage_authorization(
548558
origin: OriginFor<T>,
549-
hash: ContentHash,
559+
content_hash: ContentHash,
550560
) -> DispatchResult {
551561
T::Authorizer::ensure_origin(origin)?;
552-
Self::refresh_authorization(AuthorizationScope::Preimage(hash))?;
553-
Self::deposit_event(Event::PreimageAuthorizationRefreshed { hash });
562+
Self::refresh_authorization(AuthorizationScope::Preimage(content_hash))?;
563+
Self::deposit_event(Event::PreimageAuthorizationRefreshed { content_hash });
554564
Ok(())
555565
}
556566
}
@@ -559,24 +569,24 @@ pub mod pallet {
559569
#[pallet::generate_deposit(pub(super) fn deposit_event)]
560570
pub enum Event<T: Config> {
561571
/// Stored data under specified index.
562-
Stored { index: u32, hash: ContentHash },
572+
Stored { index: u32, content_hash: ContentHash },
563573
/// Renewed data under specified index.
564-
Renewed { index: u32, hash: ContentHash },
574+
Renewed { index: u32, content_hash: ContentHash },
565575
/// Storage proof was successfully checked.
566576
ProofChecked,
567577
/// An account `who` was authorized to store `bytes` bytes in `transactions` transactions.
568578
AccountAuthorized { who: T::AccountId, transactions: u32, bytes: u64 },
569579
/// An authorization for account `who` was refreshed.
570580
AccountAuthorizationRefreshed { who: T::AccountId },
571-
/// Authorization was given for a preimage of `hash` (not exceeding `max_size`) to be
572-
/// stored by anyone.
573-
PreimageAuthorized { hash: ContentHash, max_size: u64 },
574-
/// An authorization for a preimage of `hash` was refreshed.
575-
PreimageAuthorizationRefreshed { hash: ContentHash },
581+
/// Authorization was given for a preimage of `content_hash` (not exceeding `max_size`) to
582+
/// be stored by anyone.
583+
PreimageAuthorized { content_hash: ContentHash, max_size: u64 },
584+
/// An authorization for a preimage of `content_hash` was refreshed.
585+
PreimageAuthorizationRefreshed { content_hash: ContentHash },
576586
/// An expired account authorization was removed.
577587
ExpiredAccountAuthorizationRemoved { who: T::AccountId },
578588
/// An expired preimage authorization was removed.
579-
ExpiredPreimageAuthorizationRemoved { hash: ContentHash },
589+
ExpiredPreimageAuthorizationRemoved { content_hash: ContentHash },
580590
}
581591

582592
/// Authorizations, keyed by scope.
@@ -743,7 +753,7 @@ pub mod pallet {
743753
// In the case of a regular unsigned transaction, pre_dispatch should have checked that
744754
// the authorization exists and has expired
745755
let Some(authorization) = Authorizations::<T>::take(&scope) else {
746-
return Err(Error::<T>::AuthorizationNotFound.into())
756+
return Err(Error::<T>::AuthorizationNotFound.into());
747757
};
748758
ensure!(Self::expired(authorization.expiration), Error::<T>::AuthorizationNotExpired);
749759
Self::authorization_removed(&scope);
@@ -752,7 +762,7 @@ pub mod pallet {
752762

753763
fn authorization_extent(scope: AuthorizationScopeFor<T>) -> AuthorizationExtent {
754764
let Some(authorization) = Authorizations::<T>::get(&scope) else {
755-
return AuthorizationExtent { transactions: 0, bytes: 0 }
765+
return AuthorizationExtent { transactions: 0, bytes: 0 };
756766
};
757767
if Self::expired(authorization.expiration) {
758768
AuthorizationExtent { transactions: 0, bytes: 0 }
@@ -870,7 +880,7 @@ pub mod pallet {
870880
scope: AuthorizationScopeFor<T>,
871881
) -> Result<(), TransactionValidityError> {
872882
let Some(authorization) = Authorizations::<T>::get(&scope) else {
873-
return Err(AUTHORIZATION_NOT_FOUND.into())
883+
return Err(AUTHORIZATION_NOT_FOUND.into());
874884
};
875885
if Self::expired(authorization.expiration) {
876886
Ok(())
@@ -885,11 +895,11 @@ pub mod pallet {
885895
context: CheckContext,
886896
) -> Result<Option<ValidTransaction>, TransactionValidityError> {
887897
if !Self::data_size_ok(size) {
888-
return Err(BAD_DATA_SIZE.into())
898+
return Err(BAD_DATA_SIZE.into());
889899
}
890900

891901
if Self::block_transactions_full() {
892-
return Err(InvalidTransaction::ExhaustsResources.into())
902+
return Err(InvalidTransaction::ExhaustsResources.into());
893903
}
894904

895905
let hash = hash();
@@ -939,13 +949,13 @@ pub mod pallet {
939949
.into()
940950
}))
941951
},
942-
Call::<T>::remove_expired_preimage_authorization { hash } => {
943-
Self::check_authorization_expired(AuthorizationScope::Preimage(*hash))?;
952+
Call::<T>::remove_expired_preimage_authorization { content_hash } => {
953+
Self::check_authorization_expired(AuthorizationScope::Preimage(*content_hash))?;
944954
Ok(context.want_valid_transaction().then(|| {
945955
ValidTransaction::with_tag_prefix(
946956
"TransactionStorageRemoveExpiredPreimageAuthorization",
947957
)
948-
.and_provides(hash)
958+
.and_provides(content_hash)
949959
.priority(T::RemoveExpiredAuthorizationPriority::get())
950960
.longevity(T::RemoveExpiredAuthorizationLongevity::get())
951961
.into()
@@ -970,11 +980,11 @@ pub mod pallet {
970980
};
971981

972982
if !Self::data_size_ok(size) {
973-
return Err(BAD_DATA_SIZE.into())
983+
return Err(BAD_DATA_SIZE.into());
974984
}
975985

976986
if Self::block_transactions_full() {
977-
return Err(InvalidTransaction::ExhaustsResources.into())
987+
return Err(InvalidTransaction::ExhaustsResources.into());
978988
}
979989

980990
Self::check_authorization(

0 commit comments

Comments
 (0)