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]
|
[package]
|
||||||
name = "ghost-governance"
|
name = "ghost-governance"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
description = "Full-chain and cross-chain governance pallet with early adopter share claims"
|
description = "Full-chain and cross-chain governance pallet with early adopter share claims"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|||||||
@ -32,7 +32,7 @@ mod benchmarks {
|
|||||||
let dummy_evm_address = EvmAddress::from(evm_addr_bytes);
|
let dummy_evm_address = EvmAddress::from(evm_addr_bytes);
|
||||||
|
|
||||||
let target_index = max_proof_depth - 1;
|
let target_index = max_proof_depth - 1;
|
||||||
let claim_package_init = ClaimPackage {
|
let claim_package_init = ClaimPackage::<T> {
|
||||||
shares: dummy_shares,
|
shares: dummy_shares,
|
||||||
merkle_proof: Default::default(),
|
merkle_proof: Default::default(),
|
||||||
token_id: 0,
|
token_id: 0,
|
||||||
|
|||||||
@ -36,8 +36,6 @@ mod benchmarking;
|
|||||||
mod mock;
|
mod mock;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
const MAX_POSSIBLE_PROOF_DEPTH: u32 = 18;
|
|
||||||
|
|
||||||
type TokenId = u128;
|
type TokenId = u128;
|
||||||
type ClaimNonce = u8;
|
type ClaimNonce = u8;
|
||||||
type EvmHash = sp_core::H256;
|
type EvmHash = sp_core::H256;
|
||||||
@ -144,21 +142,36 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Clone, RuntimeDebug, TypeInfo, PartialEq, Eq)]
|
#[derive(Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||||
pub struct ClaimPackage<Balance>
|
#[scale_info(skip_type_params(T))]
|
||||||
where
|
pub struct ClaimPackage<T: pallet::Config> {
|
||||||
Balance: Default + Copy + Clone,
|
|
||||||
{
|
|
||||||
pub index: u32,
|
pub index: u32,
|
||||||
pub token_id: TokenId,
|
pub token_id: TokenId,
|
||||||
pub shares: Balance,
|
pub shares: BalanceOf<T>,
|
||||||
pub merkle_proof: BoundedVec<EvmHash, ConstU32<MAX_POSSIBLE_PROOF_DEPTH>>,
|
pub merkle_proof: BoundedVec<EvmHash, T::MaxProofDepth>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Balance> ClaimPackage<Balance>
|
impl<T: pallet::Config> Clone for ClaimPackage<T> {
|
||||||
where
|
fn clone(&self) -> Self {
|
||||||
Balance: Default + Copy + Clone + UniqueSaturatedInto<u128>,
|
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>(
|
pub fn get_preimage<NetworkId>(
|
||||||
&self,
|
&self,
|
||||||
evm_address: &EvmAddress,
|
evm_address: &EvmAddress,
|
||||||
@ -333,7 +346,7 @@ pub mod pallet {
|
|||||||
pub fn claim(
|
pub fn claim(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
network_id: NetworkIdOf<T>,
|
network_id: NetworkIdOf<T>,
|
||||||
claim_package: ClaimPackage<BalanceOf<T>>,
|
claim_package: ClaimPackage<T>,
|
||||||
evm_address: EvmAddress,
|
evm_address: EvmAddress,
|
||||||
evm_signature: EvmSignature,
|
evm_signature: EvmSignature,
|
||||||
requested_shares: BalanceOf<T>,
|
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> {
|
fn to_ascii_base10<N: PrimInt + UniqueSaturatedInto<u128>>(num: N) -> Vec<u8> {
|
||||||
let zero = N::zero();
|
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 ten = N::from(10).unwrap_or_else(|| N::zero());
|
||||||
let num_u128 = num.unique_saturated_into();
|
let num_u128 = num.unique_saturated_into();
|
||||||
@ -519,7 +532,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
fn verify_merkle_proof(
|
fn verify_merkle_proof(
|
||||||
network_id: &NetworkIdOf<T>,
|
network_id: &NetworkIdOf<T>,
|
||||||
preimage: &[u8],
|
preimage: &[u8],
|
||||||
claim_package: &ClaimPackage<BalanceOf<T>>,
|
claim_package: &ClaimPackage<T>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let network_state = NetworkShares::<T>::get(network_id);
|
let network_state = NetworkShares::<T>::get(network_id);
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ impl Config for Test {
|
|||||||
type NetworkDataHandler = Networks;
|
type NetworkDataHandler = Networks;
|
||||||
|
|
||||||
type MinimumDonation = ConstU128<69>;
|
type MinimumDonation = ConstU128<69>;
|
||||||
type MaxProofDepth = ConstU32<5>;
|
type MaxProofDepth = ConstU32<7>;
|
||||||
type MaxPartialClaims = ConstU8<3>;
|
type MaxPartialClaims = ConstU8<3>;
|
||||||
|
|
||||||
type WeightInfo = ();
|
type WeightInfo = ();
|
||||||
|
|||||||
@ -87,7 +87,7 @@ fn claim_happy_path() {
|
|||||||
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
||||||
let (index, u) = item;
|
let (index, u) = item;
|
||||||
|
|
||||||
let tmp_package = ClaimPackage {
|
let tmp_package = ClaimPackage::<Test> {
|
||||||
shares: u.allowed_shares,
|
shares: u.allowed_shares,
|
||||||
merkle_proof: Default::default(),
|
merkle_proof: Default::default(),
|
||||||
token_id: u.token_id,
|
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 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,
|
shares: current_user.allowed_shares,
|
||||||
merkle_proof: BoundedVec::try_from(proof).unwrap(),
|
merkle_proof: BoundedVec::try_from(proof).unwrap(),
|
||||||
token_id: current_user.token_id,
|
token_id: current_user.token_id,
|
||||||
@ -211,7 +211,7 @@ fn partial_claims_happy_path() {
|
|||||||
|
|
||||||
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
|item: (u8, &NewTestUser)| -> Result<(usize, Vec<u8>), ()> {
|
||||||
let (index, u) = item;
|
let (index, u) = item;
|
||||||
let tmp_package = ClaimPackage {
|
let tmp_package = ClaimPackage::<Test> {
|
||||||
shares: u.allowed_shares,
|
shares: u.allowed_shares,
|
||||||
merkle_proof: Default::default(),
|
merkle_proof: Default::default(),
|
||||||
token_id: u.token_id,
|
token_id: u.token_id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user