Skip to content

Commit

Permalink
Merge branch 'main' of github.com:subspace/subspace into fix-er-gap
Browse files Browse the repository at this point in the history
  • Loading branch information
NingLin-P committed Jul 24, 2024
2 parents 4d43993 + 5d3be70 commit cda9e51
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 65 deletions.
19 changes: 18 additions & 1 deletion crates/pallet-domains/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use frame_benchmarking::v2::*;
use frame_support::assert_ok;
use frame_support::traits::fungible::Mutate;
use frame_support::traits::fungible::{Inspect, Mutate};
use frame_support::traits::Hooks;
use frame_support::weights::Weight;
use frame_system::{Pallet as System, RawOrigin};
Expand Down Expand Up @@ -861,6 +861,23 @@ mod benchmarks {
assert_eq!(domain_obj.domain_config.operator_allow_list, new_allow_list);
}

#[benchmark]
fn transfer_treasury_funds() {
// Ensure the treasury account has balance
let treasury_amount = 5000u32.into();
let transfer_amount = 500u32.into();
let account = account("slashed_account", 1, SEED);
assert_eq!(T::Currency::balance(&account), 0u32.into());
T::Currency::set_balance(&T::TreasuryAccount::get(), treasury_amount);
#[extrinsic_call]
_(RawOrigin::Root, account.clone(), transfer_amount);
assert_eq!(T::Currency::balance(&account), transfer_amount);
assert_eq!(
T::Currency::balance(&T::TreasuryAccount::get()),
treasury_amount - transfer_amount
);
}

#[benchmark]
fn submit_receipt() {
let domain_id = register_domain::<T>();
Expand Down
52 changes: 35 additions & 17 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ mod pallet {
use domain_runtime_primitives::EVMChainId;
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible::{Inspect, InspectHold, Mutate, MutateHold};
use frame_support::traits::tokens::Preservation;
use frame_support::traits::Randomness as RandomnessT;
use frame_support::weights::Weight;
use frame_support::{Identity, PalletError};
Expand Down Expand Up @@ -1133,23 +1134,6 @@ mod pallet {
SlashedReason::InvalidBundle(confirmed_block_info.domain_block_number),
)
.map_err(Error::<T>::from)?;

if confirmed_block_info.domain_block_number % T::StakeEpochDuration::get()
== Zero::zero()
{
let epoch_transition_res =
do_finalize_domain_current_epoch::<T>(domain_id)
.map_err(Error::<T>::from)?;

Self::deposit_event(Event::DomainEpochCompleted {
domain_id,
completed_epoch_index: epoch_transition_res.completed_epoch_index,
});

actual_weight = actual_weight.saturating_add(
Self::actual_epoch_transition_weight(epoch_transition_res),
);
}
}
}
}
Expand All @@ -1172,6 +1156,22 @@ mod pallet {
.ok_or::<Error<T>>(BlockTreeError::MaxHeadDomainNumber.into())?
.checked_add(&missed_upgrade.into())
.ok_or::<Error<T>>(BlockTreeError::MaxHeadDomainNumber.into())?;

// Trigger epoch transition if any at the first bundle in the block
#[cfg(not(feature = "runtime-benchmarks"))]
if next_number % T::StakeEpochDuration::get() == Zero::zero() {
let epoch_transition_res = do_finalize_domain_current_epoch::<T>(domain_id)
.map_err(Error::<T>::from)?;

Self::deposit_event(Event::DomainEpochCompleted {
domain_id,
completed_epoch_index: epoch_transition_res.completed_epoch_index,
});

actual_weight = actual_weight
.saturating_add(Self::actual_epoch_transition_weight(epoch_transition_res));
}

HeadDomainNumber::<T>::set(domain_id, next_number);
}

Expand Down Expand Up @@ -1643,7 +1643,25 @@ mod pallet {
Ok(Some(actual_weight).into())
}

/// Transfer funds from treasury to given account
#[pallet::call_index(20)]
#[pallet::weight(T::WeightInfo::transfer_treasury_funds())]
pub fn transfer_treasury_funds(
origin: OriginFor<T>,
account_id: T::AccountId,
balance: BalanceOf<T>,
) -> DispatchResult {
ensure_root(origin)?;
T::Currency::transfer(
&T::TreasuryAccount::get(),
&account_id,
balance,
Preservation::Preserve,
)?;
Ok(())
}

#[pallet::call_index(21)]
#[pallet::weight(Pallet::<T>::max_submit_receipt_weight())]
pub fn submit_receipt(
origin: OriginFor<T>,
Expand Down
23 changes: 23 additions & 0 deletions crates/pallet-domains/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub trait WeightInfo {
fn unlock_funds() -> Weight;
fn unlock_nominator() -> Weight;
fn update_domain_operator_allow_list() -> Weight;
fn transfer_treasury_funds() -> Weight;
fn submit_receipt() -> Weight;
}

Expand Down Expand Up @@ -479,6 +480,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn transfer_treasury_funds() -> Weight {
// Proof Size summary in bytes:
// Measured: `140`
// Estimated: `6196`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 6196)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `Domains::HeadReceiptNumber` (r:1 w:1)
/// Proof: `Domains::HeadReceiptNumber` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::NewAddedHeadReceipt` (r:1 w:1)
Expand Down Expand Up @@ -929,6 +941,17 @@ impl WeightInfo for () {
.saturating_add(ParityDbWeight::get().reads(1_u64))
.saturating_add(ParityDbWeight::get().writes(1_u64))
}
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn transfer_treasury_funds() -> Weight {
// Proof Size summary in bytes:
// Measured: `140`
// Estimated: `6196`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 6196)
.saturating_add(ParityDbWeight::get().reads(2_u64))
.saturating_add(ParityDbWeight::get().writes(2_u64))
}
/// Storage: `Domains::HeadReceiptNumber` (r:1 w:1)
/// Proof: `Domains::HeadReceiptNumber` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::NewAddedHeadReceipt` (r:1 w:1)
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-farmer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ target/production/subspace-farmer --help
target/production/subspace-farmer farm --reward-address st... path=/path/to/farm,size=100G
```

`st...` should be replaced with the reward address taken from Polkadot.js wallet (or similar), `/path/to/farm` with location where you want to store plot and `100G` replaced with desired plot size.
`st...` should be replaced with the reward address taken from [Polkadot.js wallet](https://polkadot.js.org/extension/) (or similar), `/path/to/farm` with location where you want to store plot and `100G` replaced with desired plot size.

This will connect to local node and will try to solve on every slot notification, while also plotting all existing and new history of the blockchain in parallel.

Expand Down
12 changes: 4 additions & 8 deletions crates/subspace-farmer/src/farm/plotted_pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,10 @@ where
piece_offset,
};

match self.pieces.entry(piece_index) {
Entry::Occupied(mut entry) => {
entry.get_mut().push(piece_details);
}
Entry::Vacant(entry) => {
entry.insert(vec![piece_details]);
}
}
self.pieces
.entry(piece_index)
.or_default()
.push(piece_details);
}
}

Expand Down
Loading

0 comments on commit cda9e51

Please sign in to comment.