make proof size depend only on runtime constant
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
352e3519a8
commit
aa336d9c55
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-governance"
|
||||
version = "0.3.8"
|
||||
version = "0.3.9"
|
||||
description = "Full-chain and cross-chain governance pallet with early adopter share claims"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -32,7 +32,7 @@ mod benchmarks {
|
||||
let dummy_evm_address = EvmAddress::from(evm_addr_bytes);
|
||||
|
||||
let target_index = max_proof_depth - 1;
|
||||
let claim_package_init = ClaimPackage {
|
||||
let claim_package_init = ClaimPackage::<T> {
|
||||
shares: dummy_shares,
|
||||
merkle_proof: Default::default(),
|
||||
token_id: 0,
|
||||
|
||||
@ -36,8 +36,6 @@ mod benchmarking;
|
||||
mod mock;
|
||||
mod tests;
|
||||
|
||||
const MAX_POSSIBLE_PROOF_DEPTH: u32 = 18;
|
||||
|
||||
type TokenId = u128;
|
||||
type ClaimNonce = u8;
|
||||
type EvmHash = sp_core::H256;
|
||||
@ -144,21 +142,36 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Clone, RuntimeDebug, TypeInfo, PartialEq, Eq)]
|
||||
pub struct ClaimPackage<Balance>
|
||||
where
|
||||
Balance: Default + Copy + Clone,
|
||||
{
|
||||
#[derive(Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct ClaimPackage<T: pallet::Config> {
|
||||
pub index: u32,
|
||||
pub token_id: TokenId,
|
||||
pub shares: Balance,
|
||||
pub merkle_proof: BoundedVec<EvmHash, ConstU32<MAX_POSSIBLE_PROOF_DEPTH>>,
|
||||
pub shares: BalanceOf<T>,
|
||||
pub merkle_proof: BoundedVec<EvmHash, T::MaxProofDepth>,
|
||||
}
|
||||
|
||||
impl<Balance> ClaimPackage<Balance>
|
||||
where
|
||||
Balance: Default + Copy + Clone + UniqueSaturatedInto<u128>,
|
||||
{
|
||||
impl<T: pallet::Config> Clone for ClaimPackage<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
index: self.index,
|
||||
token_id: self.token_id,
|
||||
shares: self.shares,
|
||||
merkle_proof: self.merkle_proof.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: pallet::Config> PartialEq for ClaimPackage<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.index == other.index &&
|
||||
self.token_id == other.token_id &&
|
||||
self.shares == other.shares &&
|
||||
self.merkle_proof == other.merkle_proof
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: pallet::Config> ClaimPackage<T> {
|
||||
pub fn get_preimage<NetworkId>(
|
||||
&self,
|
||||
evm_address: &EvmAddress,
|
||||
@ -333,7 +346,7 @@ pub mod pallet {
|
||||
pub fn claim(
|
||||
origin: OriginFor<T>,
|
||||
network_id: NetworkIdOf<T>,
|
||||
claim_package: ClaimPackage<BalanceOf<T>>,
|
||||
claim_package: ClaimPackage<T>,
|
||||
evm_address: EvmAddress,
|
||||
evm_signature: EvmSignature,
|
||||
requested_shares: BalanceOf<T>,
|
||||
@ -425,7 +438,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn to_ascii_base10<N: PrimInt + UniqueSaturatedInto<u128>>(num: N) -> Vec<u8> {
|
||||
let zero = N::zero();
|
||||
if num == zero { return vec![b'0']; }
|
||||
if num == zero { return sp_std::vec![b'0']; }
|
||||
|
||||
let ten = N::from(10).unwrap_or_else(|| N::zero());
|
||||
let num_u128 = num.unique_saturated_into();
|
||||
@ -519,7 +532,7 @@ impl<T: Config> Pallet<T> {
|
||||
fn verify_merkle_proof(
|
||||
network_id: &NetworkIdOf<T>,
|
||||
preimage: &[u8],
|
||||
claim_package: &ClaimPackage<BalanceOf<T>>,
|
||||
claim_package: &ClaimPackage<T>,
|
||||
) -> DispatchResult {
|
||||
let network_state = NetworkShares::<T>::get(network_id);
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ impl Config for Test {
|
||||
type NetworkDataHandler = Networks;
|
||||
|
||||
type MinimumDonation = ConstU128<69>;
|
||||
type MaxProofDepth = ConstU32<5>;
|
||||
type MaxProofDepth = ConstU32<7>;
|
||||
type MaxPartialClaims = ConstU8<3>;
|
||||
|
||||
type WeightInfo = ();
|
||||
|
||||
@ -87,7 +87,7 @@ fn claim_happy_path() {
|
||||
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
||||
let (index, u) = item;
|
||||
|
||||
let tmp_package = ClaimPackage {
|
||||
let tmp_package = ClaimPackage::<Test> {
|
||||
shares: u.allowed_shares,
|
||||
merkle_proof: Default::default(),
|
||||
token_id: u.token_id,
|
||||
@ -118,7 +118,7 @@ fn claim_happy_path() {
|
||||
|
||||
let proof = generate_proof::<SubstrateKeccakHasher, u8>(&merkle_tree, max_index, slot_index as u8);
|
||||
|
||||
let claim_package = ClaimPackage {
|
||||
let claim_package = ClaimPackage::<Test> {
|
||||
shares: current_user.allowed_shares,
|
||||
merkle_proof: BoundedVec::try_from(proof).unwrap(),
|
||||
token_id: current_user.token_id,
|
||||
@ -211,7 +211,7 @@ fn partial_claims_happy_path() {
|
||||
|
||||
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
||||
let (index, u) = item;
|
||||
let tmp_package = ClaimPackage {
|
||||
let tmp_package = ClaimPackage::<Test> {
|
||||
shares: u.allowed_shares,
|
||||
merkle_proof: Default::default(),
|
||||
token_id: u.token_id,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user