Skip to content

Migrate to Weights V2#905

Closed
akhilesharora wants to merge 15 commits into
centrifuge:parachainfrom
akhilesharora:parachain
Closed

Migrate to Weights V2#905
akhilesharora wants to merge 15 commits into
centrifuge:parachainfrom
akhilesharora:parachain

Conversation

@akhilesharora

@akhilesharora akhilesharora commented Aug 10, 2022

Copy link
Copy Markdown
Contributor

As @offerijns already mentioned this issue, storage migrations from Vec to BoundedVec for few of the remaining pallets as per Weights V2.

@akhilesharora akhilesharora self-assigned this Aug 10, 2022
@akhilesharora akhilesharora added crcl-runtime Circle runtime related. crcl-protocol Circle protocol related. crcl-cross-chain Circle cross-chain related. labels Aug 10, 2022
@akhilesharora akhilesharora marked this pull request as draft August 10, 2022 10:24
@akhilesharora akhilesharora requested a review from hieronx August 10, 2022 10:34
@akhilesharora akhilesharora changed the title Migrate to Weights V2 [wip] Migrate to Weights V2 Aug 10, 2022
@akhilesharora akhilesharora requested a review from lemunozm August 11, 2022 08:55
@akhilesharora akhilesharora dismissed a stale review via 7f53af4 August 16, 2022 07:02
@akhilesharora akhilesharora marked this pull request as ready for review August 16, 2022 10:16
@akhilesharora akhilesharora changed the title [wip] Migrate to Weights V2 Migrate to Weights V2 Aug 16, 2022

@mustermeiszer mustermeiszer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One unwrap() and castings neeed to be handled. Also, I think the MaxBound is to small


let fee = base_fee
.checked_mul(&pallet_fees::BalanceOf::<T>::from(multiplier))
.checked_mul(&pallet_fees::BalanceOf::<T>::from(multiplier as u8))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the as u8 needed now? I would like to use a try_into().ok_or(ArithmethicError::Overflow) here, as u8 is really small to cast to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sure, well while testing it was complaining about the types. But indeed, I was thinking along the same lines as u8 is really small to cast to.

.ok_or(ArithmeticError::Overflow)
})
.and_then(|put_into_bucket| Ok(T::BlockNumber::from(put_into_bucket)))
.and_then(|put_into_bucket| Ok(T::BlockNumber::from(put_into_bucket as u8)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See abve

Comment on lines +497 to +498
let val: BoundedVec<u8, T::MaxBound> =
(child::root(&key, StateVersion::V0)).try_into().unwrap();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap() should be handled


// Parameterize anchors pallet
parameter_types! {
pub const MaxBound: u32 = 100;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the child root is a H256, so 256 bytes. The bound should allow this size if I am not mistaken. WDYT? @branan

type WeightInfo: WeightInfo;

#[pallet::constant]
type MaxBound: Get<u32>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this name can be renamed to something more relevant for the runtime configurator in order to know what is exactly this bound for. Something like MaxRootOfChildTrieSize.

Because our Vec<u8> is storing the child root (docs say that the hashing algorithm is defined by the Block), seems like its size is something known. I mean, instead of passing a new argument, could we extract it from the current hashing algorithm used?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustermeiszer I just see your comment below regarding the size, what do you think about this? Could it be possible?

@lemunozm lemunozm Aug 26, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it, I think something like the following should work as a bound type for BoundedVec.

ConstU32<sp_std::mem::size_of(T::Hash)>

@mustermeiszer mustermeiszer Aug 27, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea, but is is defined not by T::Hash, but by the type Hash of trait Header as the externalities hasher define this hash type. The Output is currently the same: sp_core::H256. But just to be sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #980

@mustermeiszer mustermeiszer marked this pull request as draft September 2, 2022 10:07
@lemunozm

Copy link
Copy Markdown
Contributor

Closed in favor of #980

@lemunozm lemunozm closed this Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crcl-cross-chain Circle cross-chain related. crcl-protocol Circle protocol related. crcl-runtime Circle runtime related.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants