Skip to content
Open
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
22 changes: 21 additions & 1 deletion pallets/dao-bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ const SEED: u32 = 0;

// Create the pre-requisite information needed to create a dao.
fn setup_dao_payload<T: Config<I>, I: 'static>() -> Vec<u8> {
/// <SBP MR2
///
/// I have a concern about this setup_dao_payload fn that seems to be common for all the
/// benchmarks:
///
/// I understand this function is to initilize the payload for the dao during the benchmarking
/// executions. As per i was able to understand, these values are mostly used by the methods
/// exposed by T:DaoProvider which as far as i have reviewed, it does not execute any o(n)
/// operations, but as the code extense and i don't have it 100% on top of my head i wonder if
/// there is any part of the code where the function being benchmarked is influenced by the size
/// of any of the fields in the json, which are currently hardcoded.
///
/// In case they are not, this comment can be dismissed.
///
/// >
let dao_json = json!({
"name": "name",
"purpose": "purpose",
Expand All @@ -41,7 +56,6 @@ fn setup_dao_payload<T: Config<I>, I: 'static>() -> Vec<u8> {
fn create_dao<T: Config<I>, I: 'static>() -> Result<(), DispatchError> {
let caller = account("caller", 0, SEED);
let data = setup_dao_payload::<T, I>();

T::DaoProvider::create_dao(caller, vec![], vec![], data)?;

let dao_account_id = T::DaoProvider::dao_account_id(0);
Expand Down Expand Up @@ -122,6 +136,12 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

/// <SBP MR2
///
/// Is there any reason why most of the benchmarks do not attach "verify"s functions?
/// I think its healty that every benchmark function verify that its execution was successful.
///
/// >
benchmarks_instance_pallet! {
create_bounty {
create_dao::<T, I>()?;
Expand Down
12 changes: 12 additions & 0 deletions pallets/dao-collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ benchmarks_instance_pallet! {
let bounded = T::Preimages::bound(proposal.clone())?.transmute();
let proposal_hash = T::Hashing::hash_of(&bounded);

/// <SBP MR2
///
/// Why don't generate a vector lenght based oin the ProposalMetadataLimit?
/// Or even sending this as a complexity parameter as you are doing with the other storage items?
///
/// Even if "meta" will not be stored in the DB, the data included in the events will allocate storage from the PoV anyway.
/// >
let meta: Option<Vec<u8>> = Some("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor \
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure \
Expand Down Expand Up @@ -416,6 +423,11 @@ benchmarks_instance_pallet! {
let m in 4 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

/// <SBP MR2
///
/// Is there any reason why this function is not using the b linear parameter as the others?
///
/// >
let bytes = 100;
let bytes_in_storage = bytes + size_of::<u32>() as u32;

Expand Down
6 changes: 6 additions & 0 deletions pallets/dao-collective/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `b` is `[1, 1024]`.
/// The range of component `m` is `[4, 100]`.
/// The range of component `p` is `[1, 50]`.
/// <HB SBP M2 Review
///
/// I don't know the internals, but for some reason the benchmarking macro is really using the bytes parameter for the benchmarking function.
/// There is nothingto do here, but in case you want to optimize this result, this can be a starting point.
///
/// >
fn close_early_approved(_b: u32, m: u32, p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `871 + b * (1 ±0) + m * (64 ±0) + p * (185 ±0)`
Expand Down
9 changes: 9 additions & 0 deletions pallets/dao-subscription/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ benchmarks! {

set_subscription_tier {
let (tier, details) = Subscription::<T>::get_default_tier_details();
/// <SBP MR2
///
/// Is it possible that taking into account that SubscriptionDetailsOf<T> is composed by TokenBalances:
/// pub type TokenBalances<AssetId, Balance, TokenBalancesLimit> = BoundedVec<(AssetId, Balance), TokenBalancesLimit>;
///
/// the call can be called with a different token_prices len size and make a discrepancy with the the default len comming from get_default_tier_details()?
///
///
/// ?
}: _(RawOrigin::Root, tier.clone(), details.clone())
verify {
let subscription_tier = Subscription::<T>::subscription_tiers(tier).unwrap();
Expand Down
35 changes: 31 additions & 4 deletions pallets/dao-subscription/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ pub mod pallet {
tier: VersionedDaoSubscriptionTier,
details: SubscriptionDetailsOf<T>,
) -> DispatchResult {
ensure_root(origin.clone())?;
/// <SBP MR2
/// You can remove this .clone()
/// >
ensure_root(origin)?;

Self::do_set_subscription_tier(tier, details)
}
Expand All @@ -203,6 +206,9 @@ pub mod pallet {
dao_id: DaoId,
reason: SuspensionReason,
) -> DispatchResult {
/// <SBP MR2
/// You can remove this .clone()
/// >
ensure_root(origin.clone())?;

Subscriptions::<T>::try_mutate(
Expand Down Expand Up @@ -295,9 +301,13 @@ pub mod pallet {

extra_check(subscription)?;

subscription.fn_balance = fn_balance
.checked_sub(1)
.ok_or(Error::<T>::FunctionBalanceLow)?;
/// <SBP MR2
///
/// Is this kind of used to assure that at least the account has
/// balance 1 for existencial deposit? It's not wrong but i
/// wonder if there could be an impl fn for this where yoiu don't
/// hardcode the 1 value >
subscription.fn_balance = fn_balance.checked_sub(1).ok_or(Error::<T>::FunctionBalanceLow)?;

let (block_number, fn_calls) = subscription.fn_per_block;

Expand Down Expand Up @@ -330,6 +340,11 @@ pub mod pallet {
T::TreasuryPalletId::get().into_account_truncating()
}

/// <SBP MR2
///
/// As the TODO says, this is a good candidate to be configured in the chain_spec + Defaults
///
/// >
// TODO: try to use default for subscription details
pub fn get_default_tier_details() -> (VersionedDaoSubscriptionTier, SubscriptionDetailsOf<T>)
{
Expand Down Expand Up @@ -467,6 +482,13 @@ impl<T: Config>
fn unsubscribe(dao_id: DaoId) -> Result<(), DispatchError> {
let subscription = Subscriptions::<T>::get(dao_id);
if subscription.is_some() {
///< SBP MR2
///
/// Is this the only required action for subscribing ?
/// What about the opther storage items ? I wonder if it worths to do some cleanup for
/// storage optimization once they unsubscribe happens
///
/// >
Subscriptions::<T>::remove(dao_id);

Self::deposit_event(Event::DaoUnsubscribed { dao_id });
Expand Down Expand Up @@ -549,6 +571,11 @@ impl<T: Config>

Self::pay_for_subscription(account_id, &details, token_id)?;

/// <SBP MR2
///
/// Unnecesary clones ?
///
/// >
subscription.tier = tier.clone();
subscription.details = details.clone();

Expand Down
26 changes: 24 additions & 2 deletions primitives/dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,19 @@ pub enum SuspensionReason {

#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, RuntimeDebug, MaxEncodedLen)]
pub enum DaoSubscriptionStatus<BlockNumber> {
Active { until: BlockNumber },
Suspended { at: BlockNumber, reason: SuspensionReason },
/// <SBP MR2
///
/// Please take into account that in release 1.0 the api for block number changes to
/// frame_system::pallet_prelude::BlockNumberFor;
///
/// >
Active {
until: BlockNumber,
},
Suspended {
at: BlockNumber,
reason: SuspensionReason,
},
}

pub type DaoFunctionBalance = u32;
Expand Down Expand Up @@ -630,6 +641,17 @@ pub struct DaoSubscription<BlockNumber, Tier, Details, AssetId> {
pub subscribed_at: BlockNumber,
pub last_renewed_at: Option<BlockNumber>,
pub status: DaoSubscriptionStatus<BlockNumber>,
/// <SBP M2
///
/// I struggle to understand the purpose of this field since it saw in the tests the folliwing:
///
/// fn_balance: DEFAULT_FUNCTION_CALL_LIMIT,
///
/// i would suggest to rename these fn fields with something more descriptive.
/// Personally, in the code i was expecting kind of a closure assigment in my first read (then
/// i realized it was not the case)
///
/// >
pub fn_balance: DaoFunctionBalance,
pub fn_per_block: FunctionPerBlock<BlockNumber, DaoFunctionBalance>,
}
Expand Down
11 changes: 11 additions & 0 deletions runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ where
}
}


/// < SBP MR2
///
/// This struct can be removed since is not being used anywhere.
///
/// >
// See issue #5233
pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
Expand Down Expand Up @@ -200,6 +206,11 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {

type Barrier = (
TakeWeightCredit,
/// < SBP MR2
///
/// Remove AllowTopLevelPaidExecutionFrom<Everything> duplicated.
///
/// >
AllowTopLevelPaidExecutionFrom<Everything>,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowKnownQueryResponses<PolkadotXcm>,
Expand Down