Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: upgrade1020 misc 2 #1532

Merged
merged 8 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async-trait = "0.1"
clap = { version = "4.0.9", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0", default-features = false }
futures = "0.3.25"
hex-literal = "0.2.1"
hex-literal = "0.3.4"
jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
log = "0.4.8"
serde = { version = "1.0.119", features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use sp_core::{bounded::BoundedVec, ConstU32, H160, H256, U256};
use sp_runtime::{DispatchError, DispatchResult};
use sp_std::vec::Vec;

pub use crate::weights::WeightInfo;

pub const MAX_SOURCE_CHAIN_BYTES: u32 = 128;
pub const MAX_SOURCE_ADDRESS_BYTES: u32 = 32;
pub const MAX_TOKEN_SYMBOL_BYTES: u32 = 32;
Expand All @@ -33,6 +35,8 @@ pub type Bytes<const U32: u32> = BoundedBytes<ConstU32<U32>>;

pub use pallet::*;

pub mod weights;

#[derive(
PartialEq,
Clone,
Expand Down Expand Up @@ -90,6 +94,7 @@ pub mod pallet {
use sp_core::{H160, H256};

use super::SourceConverter;
use crate::weights::WeightInfo;

// Simple declaration of the `Pallet` type. It is placeholder we use to
// implement traits and method.
Expand All @@ -106,6 +111,8 @@ pub mod pallet {
/// The origin that is allowed to set the gateway address we accept
/// messageas from
type AdminOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;

type WeightInfo: WeightInfo;
}

#[pallet::storage]
Expand Down Expand Up @@ -162,7 +169,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
#[pallet::weight(<T as Config>::WeightInfo::set_gateway())]
#[pallet::call_index(0)]
pub fn set_gateway(origin: OriginFor<T>, address: H160) -> DispatchResult {
<T as Config>::AdminOrigin::ensure_origin(origin)?;
Expand All @@ -174,7 +181,7 @@ pub mod pallet {
Ok(())
}

#[pallet::weight(0)]
#[pallet::weight(<T as Config>::WeightInfo::set_converter())]
#[pallet::call_index(1)]
pub fn set_converter(
origin: OriginFor<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023 Centrifuge Foundation (centrifuge.io).
//
// This file is part of the Centrifuge chain project.
// Centrifuge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version (see http://www.gnu.org/licenses).
// Centrifuge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use frame_support::weights::{constants::RocksDbWeight, Weight};

pub trait WeightInfo {
fn set_gateway() -> Weight;
fn set_converter() -> Weight;
}

impl WeightInfo for () {
fn set_gateway() -> Weight {
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn set_converter() -> Weight {
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}
}
66 changes: 59 additions & 7 deletions pallets/liquidity-pools-gateway/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use frame_support::weights::Weight;
use frame_support::weights::{constants::RocksDbWeight, Weight};

pub trait WeightInfo {
fn set_domain_router() -> Weight;
Expand All @@ -21,28 +21,80 @@ pub trait WeightInfo {
fn process_msg() -> Weight;
}

// NOTE: We use temporary weights here. `execute_epoch` is by far our heaviest
// extrinsic. N denotes the number of tranches. 4 is quite heavy and
// should be enough.
const N: u64 = 4;

impl WeightInfo for () {
fn set_domain_router() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn add_instance() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn remove_instance() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn add_relayer() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn remove_relayer() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK CORRECTLY
//
// NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve`
// This one has one read and one write for sure and possible one
// read for `AdminOrigin`
Weight::from_parts(17_000_000, 5991)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn process_msg() -> Weight {
Weight::from_ref_time(10_000_000)
// TODO: BENCHMARK AND USE REAL WEIGHTS
//
// NOTE: For reference this weight compared to our maximum weight
// * This weight { ref_time: 4333558693, proof_size: 91070 }
// * Maximum weight { ref_time: 500000000000, proof_size: 5242880 }
//
Weight::from_parts(78_019_565, 19974)
.saturating_add(Weight::from_ref_time(38_884_782).saturating_mul(N))
.saturating_add(RocksDbWeight::get().reads(8))
.saturating_add(RocksDbWeight::get().reads((7_u64).saturating_mul(N)))
.saturating_add(RocksDbWeight::get().writes(8))
.saturating_add(RocksDbWeight::get().writes((6_u64).saturating_mul(N)))
.saturating_add(Weight::from_proof_size(17774).saturating_mul(N))
Comment on lines +92 to +98
Copy link
Contributor

@wischli wischli Sep 6, 2023

Choose a reason for hiding this comment

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

Note: I made sure this default weight and PoV size for liquidity pool extrinsics is still executable. It is.

I do believe though we should increase it when we introduce foreign investments or did you factor that in already?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did too ^^

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I think we should increase it.

}
}
Loading
Loading