Skip to content

Commit 79af6c4

Browse files
Rename variables to content_hash (#129)
* Align Events between Bulletin and SDK * Rename variables to content_hash * Update comments
1 parent 7ba5484 commit 79af6c4

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

pallets/transaction-storage/src/benchmarking.rs

Lines changed: 18 additions & 14 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 = "\
@@ -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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ pub mod pallet {
462462
///
463463
/// Parameters:
464464
///
465-
/// - `hash`: The BLAKE2b hash of the data to be submitted.
465+
/// - `content_hash`: The BLAKE2b hash of the data to be submitted.
466466
/// - `max_size`: The maximum size, in bytes, of the preimage.
467467
///
468468
/// The origin for this call must be the pallet's `Authorizer`. Emits
@@ -471,12 +471,12 @@ pub mod pallet {
471471
#[pallet::weight(T::WeightInfo::authorize_preimage())]
472472
pub fn authorize_preimage(
473473
origin: OriginFor<T>,
474-
hash: ContentHash,
474+
content_hash: ContentHash,
475475
max_size: u64,
476476
) -> DispatchResult {
477477
T::Authorizer::ensure_origin(origin)?;
478-
Self::authorize(AuthorizationScope::Preimage(hash), 1, max_size);
479-
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 });
480480
Ok(())
481481
}
482482

@@ -503,7 +503,7 @@ pub mod pallet {
503503
///
504504
/// Parameters:
505505
///
506-
/// - `hash`: The BLAKE2b hash that was authorized.
506+
/// - `content_hash`: The BLAKE2b hash that was authorized.
507507
///
508508
/// Emits
509509
/// [`ExpiredPreimageAuthorizationRemoved`](Event::ExpiredPreimageAuthorizationRemoved)
@@ -512,10 +512,10 @@ pub mod pallet {
512512
#[pallet::weight(T::WeightInfo::remove_expired_preimage_authorization())]
513513
pub fn remove_expired_preimage_authorization(
514514
_origin: OriginFor<T>,
515-
hash: ContentHash,
515+
content_hash: ContentHash,
516516
) -> DispatchResult {
517-
Self::remove_expired_authorization(AuthorizationScope::Preimage(hash))?;
518-
Self::deposit_event(Event::ExpiredPreimageAuthorizationRemoved { hash });
517+
Self::remove_expired_authorization(AuthorizationScope::Preimage(content_hash))?;
518+
Self::deposit_event(Event::ExpiredPreimageAuthorizationRemoved { content_hash });
519519
Ok(())
520520
}
521521

@@ -547,7 +547,7 @@ pub mod pallet {
547547
///
548548
/// Parameters:
549549
///
550-
/// - `hash`: The BLAKE2b hash of the data to be submitted.
550+
/// - `content_hash`: The BLAKE2b hash of the data to be submitted.
551551
///
552552
/// The origin for this call must be the pallet's `Authorizer`. Emits
553553
/// [`PreimageAuthorizationRefreshed`](Event::PreimageAuthorizationRefreshed) when
@@ -556,11 +556,11 @@ pub mod pallet {
556556
#[pallet::weight(T::WeightInfo::refresh_preimage_authorization())]
557557
pub fn refresh_preimage_authorization(
558558
origin: OriginFor<T>,
559-
hash: ContentHash,
559+
content_hash: ContentHash,
560560
) -> DispatchResult {
561561
T::Authorizer::ensure_origin(origin)?;
562-
Self::refresh_authorization(AuthorizationScope::Preimage(hash))?;
563-
Self::deposit_event(Event::PreimageAuthorizationRefreshed { hash });
562+
Self::refresh_authorization(AuthorizationScope::Preimage(content_hash))?;
563+
Self::deposit_event(Event::PreimageAuthorizationRefreshed { content_hash });
564564
Ok(())
565565
}
566566
}
@@ -578,15 +578,15 @@ pub mod pallet {
578578
AccountAuthorized { who: T::AccountId, transactions: u32, bytes: u64 },
579579
/// An authorization for account `who` was refreshed.
580580
AccountAuthorizationRefreshed { who: T::AccountId },
581-
/// Authorization was given for a preimage of `hash` (not exceeding `max_size`) to be
582-
/// stored by anyone.
583-
PreimageAuthorized { hash: ContentHash, max_size: u64 },
584-
/// An authorization for a preimage of `hash` was refreshed.
585-
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 },
586586
/// An expired account authorization was removed.
587587
ExpiredAccountAuthorizationRemoved { who: T::AccountId },
588588
/// An expired preimage authorization was removed.
589-
ExpiredPreimageAuthorizationRemoved { hash: ContentHash },
589+
ExpiredPreimageAuthorizationRemoved { content_hash: ContentHash },
590590
}
591591

592592
/// Authorizations, keyed by scope.
@@ -753,7 +753,7 @@ pub mod pallet {
753753
// In the case of a regular unsigned transaction, pre_dispatch should have checked that
754754
// the authorization exists and has expired
755755
let Some(authorization) = Authorizations::<T>::take(&scope) else {
756-
return Err(Error::<T>::AuthorizationNotFound.into())
756+
return Err(Error::<T>::AuthorizationNotFound.into());
757757
};
758758
ensure!(Self::expired(authorization.expiration), Error::<T>::AuthorizationNotExpired);
759759
Self::authorization_removed(&scope);
@@ -762,7 +762,7 @@ pub mod pallet {
762762

763763
fn authorization_extent(scope: AuthorizationScopeFor<T>) -> AuthorizationExtent {
764764
let Some(authorization) = Authorizations::<T>::get(&scope) else {
765-
return AuthorizationExtent { transactions: 0, bytes: 0 }
765+
return AuthorizationExtent { transactions: 0, bytes: 0 };
766766
};
767767
if Self::expired(authorization.expiration) {
768768
AuthorizationExtent { transactions: 0, bytes: 0 }
@@ -880,7 +880,7 @@ pub mod pallet {
880880
scope: AuthorizationScopeFor<T>,
881881
) -> Result<(), TransactionValidityError> {
882882
let Some(authorization) = Authorizations::<T>::get(&scope) else {
883-
return Err(AUTHORIZATION_NOT_FOUND.into())
883+
return Err(AUTHORIZATION_NOT_FOUND.into());
884884
};
885885
if Self::expired(authorization.expiration) {
886886
Ok(())
@@ -895,11 +895,11 @@ pub mod pallet {
895895
context: CheckContext,
896896
) -> Result<Option<ValidTransaction>, TransactionValidityError> {
897897
if !Self::data_size_ok(size) {
898-
return Err(BAD_DATA_SIZE.into())
898+
return Err(BAD_DATA_SIZE.into());
899899
}
900900

901901
if Self::block_transactions_full() {
902-
return Err(InvalidTransaction::ExhaustsResources.into())
902+
return Err(InvalidTransaction::ExhaustsResources.into());
903903
}
904904

905905
let hash = hash();
@@ -949,13 +949,13 @@ pub mod pallet {
949949
.into()
950950
}))
951951
},
952-
Call::<T>::remove_expired_preimage_authorization { hash } => {
953-
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))?;
954954
Ok(context.want_valid_transaction().then(|| {
955955
ValidTransaction::with_tag_prefix(
956956
"TransactionStorageRemoveExpiredPreimageAuthorization",
957957
)
958-
.and_provides(hash)
958+
.and_provides(content_hash)
959959
.priority(T::RemoveExpiredAuthorizationPriority::get())
960960
.longevity(T::RemoveExpiredAuthorizationLongevity::get())
961961
.into()
@@ -980,11 +980,11 @@ pub mod pallet {
980980
};
981981

982982
if !Self::data_size_ok(size) {
983-
return Err(BAD_DATA_SIZE.into())
983+
return Err(BAD_DATA_SIZE.into());
984984
}
985985

986986
if Self::block_transactions_full() {
987-
return Err(InvalidTransaction::ExhaustsResources.into())
987+
return Err(InvalidTransaction::ExhaustsResources.into());
988988
}
989989

990990
Self::check_authorization(

0 commit comments

Comments
 (0)