Skip to content

Commit

Permalink
Fix merge conflict with async-trait version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 30, 2024
2 parents b90ad9d + ec9848c commit a6f0b39
Show file tree
Hide file tree
Showing 131 changed files with 1,396 additions and 1,547 deletions.
4 changes: 2 additions & 2 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 Dockerfile-bootstrap-node
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-bootstrap-node.aarch64
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-farmer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-farmer.aarch64
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-node
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-node.aarch64
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-runtime
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04

ARG RUSTC_VERSION=nightly-2024-08-01
ARG RUSTC_VERSION=nightly-2024-09-26
ARG PROFILE=production
ARG RUSTFLAGS
# Workaround for https://github.com/rust-lang/cargo/issues/10583
Expand Down
36 changes: 23 additions & 13 deletions crates/pallet-domains/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::block_tree::{prune_receipt, BlockTreeNode};
use crate::bundle_storage_fund::refund_storage_fee;
use crate::domain_registry::DomainConfig;
use crate::staking::{
do_convert_previous_epoch_deposits, do_mark_operators_as_slashed, do_reward_operators,
OperatorConfig, OperatorStatus, WithdrawStake,
do_convert_previous_epoch_withdrawal, do_mark_operators_as_slashed, do_reward_operators,
Error as StakingError, OperatorConfig, OperatorStatus, WithdrawStake,
};
use crate::staking_epoch::{
do_finalize_domain_current_epoch, do_finalize_domain_epoch_staking, do_slash_operator,
Expand Down Expand Up @@ -725,10 +725,10 @@ mod benchmarks {
/// Benchmark `unlock_funds` extrinsic with the worst possible conditions:
/// - Unlock a full withdrawal which also remove the deposit storage for the nominator
#[benchmark]
fn unlock_funds() {
fn unlock_funds(w: Linear<1, { T::WithdrawalLimit::get() }>) {
let nominator = account("nominator", 1, SEED);
let minimum_nominator_stake = T::MinNominatorStake::get();
let staking_amount = T::MinOperatorStake::get();
let staking_amount = T::MinOperatorStake::get() * 3u32.into();
T::Currency::set_balance(&nominator, staking_amount + T::MinNominatorStake::get());

let domain_id = register_domain::<T>();
Expand All @@ -741,22 +741,32 @@ mod benchmarks {
do_finalize_domain_epoch_staking::<T>(domain_id)
.expect("finalize domain staking should success");

// Withdraw all deposit
let withdraw_amount = {
let mut deposit =
Deposits::<T>::get(operator_id, nominator.clone()).expect("deposit must exist");
do_convert_previous_epoch_deposits::<T>(operator_id, &mut deposit)
.expect("convert must success");
deposit.known.shares
};
// Request `w` number of withdrawal in different epoch and withdraw all the stake in the last one
for _ in 1..w {
assert_ok!(Domains::<T>::withdraw_stake(
RawOrigin::Signed(nominator.clone()).into(),
operator_id,
WithdrawStake::Stake(T::MinOperatorStake::get() / w.into()),
));
do_finalize_domain_epoch_staking::<T>(domain_id)
.expect("finalize domain staking should success");
}
assert_ok!(Domains::<T>::withdraw_stake(
RawOrigin::Signed(nominator.clone()).into(),
operator_id,
WithdrawStake::Share(withdraw_amount),
WithdrawStake::All,
));
do_finalize_domain_epoch_staking::<T>(domain_id)
.expect("finalize domain staking should success");

Withdrawals::<T>::try_mutate(operator_id, nominator.clone(), |maybe_withdrawal| {
let withdrawal = maybe_withdrawal.as_mut().unwrap();
do_convert_previous_epoch_withdrawal::<T>(operator_id, withdrawal)?;
assert_eq!(withdrawal.withdrawals.len() as u32, w);
Ok::<(), StakingError>(())
})
.unwrap();

// Update the `LatestConfirmedDomainExecutionReceipt` so unlock can success
let confirmed_domain_block_number =
Pallet::<T>::latest_confirmed_domain_block_number(domain_id)
Expand Down
24 changes: 23 additions & 1 deletion crates/pallet-domains/src/bundle_storage_fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Error {
FailToDeposit,
WithdrawAndHold,
BalanceTransfer,
FailToWithdraw,
}

/// The type of system account being created.
Expand Down Expand Up @@ -184,7 +185,7 @@ pub fn withdraw_and_hold<T: Config>(
}

let storage_fund_acc = storage_fund_account::<T>(operator_id);
let storage_fund_hold_id = T::HoldIdentifier::storage_fund_withdrawal(operator_id);
let storage_fund_hold_id = T::HoldIdentifier::storage_fund_withdrawal();
T::Currency::transfer_and_hold(
&storage_fund_hold_id,
&storage_fund_acc,
Expand All @@ -197,6 +198,27 @@ pub fn withdraw_and_hold<T: Config>(
.map_err(|_| Error::WithdrawAndHold)
}

/// Transfer the given `withdraw_amount` of balance from the bundle storage fund to the
/// given `dest_account`
pub fn withdraw_to<T: Config>(
operator_id: OperatorId,
dest_account: &T::AccountId,
withdraw_amount: BalanceOf<T>,
) -> Result<BalanceOf<T>, Error> {
if withdraw_amount.is_zero() {
return Ok(Zero::zero());
}

let storage_fund_acc = storage_fund_account::<T>(operator_id);
T::Currency::transfer(
&storage_fund_acc,
dest_account,
withdraw_amount,
Preservation::Expendable,
)
.map_err(|_| Error::FailToWithdraw)
}

/// Return the total balance of the bundle storage fund the given `operator_id`
pub fn total_balance<T: Config>(operator_id: OperatorId) -> BalanceOf<T> {
let storage_fund_acc = storage_fund_account::<T>(operator_id);
Expand Down
10 changes: 7 additions & 3 deletions crates/pallet-domains/src/domain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ pub struct DomainObject<Number, ReceiptHash, AccountId: Ord, Balance> {
pub domain_config: DomainConfig<AccountId, Balance>,
/// Domain runtime specific information.
pub domain_runtime_info: DomainRuntimeInfo,
/// The amount of balance hold on the domain owner account
pub domain_instantiation_deposit: Balance,
}

pub(crate) fn can_instantiate_domain<T: Config>(
Expand Down Expand Up @@ -205,6 +207,7 @@ pub(crate) fn do_instantiate_domain<T: Config>(
) -> Result<DomainId, Error> {
can_instantiate_domain::<T>(&owner_account_id, &domain_config)?;

let domain_instantiation_deposit = T::DomainInstantiationDeposit::get();
let domain_id = NextDomainId::<T>::get();
let runtime_obj = RuntimeRegistry::<T>::mutate(domain_config.runtime_id, |maybe_runtime_obj| {
let mut runtime_object = maybe_runtime_obj
Expand Down Expand Up @@ -277,17 +280,18 @@ pub(crate) fn do_instantiate_domain<T: Config>(
genesis_receipt_hash,
domain_config,
domain_runtime_info,
domain_instantiation_deposit,
};
DomainRegistry::<T>::insert(domain_id, domain_obj);

let next_domain_id = domain_id.checked_add(&1.into()).ok_or(Error::MaxDomainId)?;
NextDomainId::<T>::set(next_domain_id);

// Lock up fund of the domain instance creator
// Lock up `domain_instantiation_deposit` amount of fund of the domain instance creator
T::Currency::hold(
&T::HoldIdentifier::domain_instantiation_id(domain_id),
&T::HoldIdentifier::domain_instantiation_id(),
&owner_account_id,
T::DomainInstantiationDeposit::get(),
domain_instantiation_deposit,
)
.map_err(|_| Error::BalanceFreeze)?;

Expand Down
40 changes: 22 additions & 18 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ use sp_consensus_subspace::WrappedPotOutput;
use sp_core::H256;
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
DomainBlockLimit, DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt,
OpaqueBundle, OperatorId, OperatorPublicKey, OperatorSignature, ProofOfElection, RuntimeId,
SealedSingletonReceipt, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT, EMPTY_EXTRINSIC_ROOT,
DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt, OpaqueBundle, OperatorId,
OperatorPublicKey, OperatorSignature, ProofOfElection, RuntimeId, SealedSingletonReceipt,
DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT, EMPTY_EXTRINSIC_ROOT,
};
use sp_domains_fraud_proof::fraud_proof::{
DomainRuntimeCodeAt, FraudProof, FraudProofVariant, InvalidBlockFeesProof,
Expand Down Expand Up @@ -97,9 +97,9 @@ pub(crate) type FungibleHoldId<T> =
pub(crate) type NominatorId<T> = <T as frame_system::Config>::AccountId;

pub trait HoldIdentifier<T: Config> {
fn staking_staked(operator_id: OperatorId) -> FungibleHoldId<T>;
fn domain_instantiation_id(domain_id: DomainId) -> FungibleHoldId<T>;
fn storage_fund_withdrawal(operator_id: OperatorId) -> FungibleHoldId<T>;
fn staking_staked() -> FungibleHoldId<T>;
fn domain_instantiation_id() -> FungibleHoldId<T>;
fn storage_fund_withdrawal() -> FungibleHoldId<T>;
}

pub trait BlockSlot<T: frame_system::Config> {
Expand Down Expand Up @@ -171,8 +171,6 @@ pub(crate) type StateRootOf<T> = <<T as frame_system::Config>::Hashing as Hash>:

#[frame_support::pallet]
mod pallet {
#![allow(clippy::large_enum_variant)]

#[cfg(not(feature = "runtime-benchmarks"))]
use crate::block_tree::AcceptedReceiptType;
use crate::block_tree::{
Expand Down Expand Up @@ -431,6 +429,12 @@ mod pallet {

/// Hook to handle chain rewards.
type OnChainRewards: OnChainRewards<BalanceOf<Self>>;

/// The max number of withdrawals per nominator that may exist at any time,
/// once this limit is reached, the nominator need to unlock the withdrawal
/// before requesting new withdrawal.
#[pallet::constant]
type WithdrawalLimit: Get<u32>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -545,6 +549,11 @@ mod pallet {
OptionQuery,
>;

/// The amount of balance the nominator hold for a given operator
#[pallet::storage]
pub(super) type DepositOnHold<T: Config> =
StorageMap<_, Identity, (OperatorId, NominatorId<T>), BalanceOf<T>, ValueQuery>;

/// Tracks the nominator count under given operator.
/// This storage is necessary since CountedStorageNMap does not support prefix key count, so
/// cannot use that storage type for `Nominators` storage.
Expand Down Expand Up @@ -613,8 +622,9 @@ mod pallet {
pub(super) type NewAddedHeadReceipt<T: Config> =
StorageMap<_, Identity, DomainId, T::DomainHash, OptionQuery>;

/// The consensus block hash used to verify ER,
/// only store the consensus block hash for a domain
/// Map of consensus block hashes.
///
/// The consensus block hash used to verify ER, only store the consensus block hash for a domain
/// if that consensus block contains bundle of the domain, the hash will be pruned when the ER
/// that point to the consensus block is pruned.
///
Expand Down Expand Up @@ -713,13 +723,15 @@ mod pallet {
pub type DomainRuntimeUpgrades<T> = StorageValue<_, Vec<RuntimeId>, ValueQuery>;

/// Temporary storage to hold the sudo calls meant for the Domains.
///
/// Storage is cleared when there are any successful bundles in the next block.
/// Only one sudo call is allowed per domain per consensus block.
#[pallet::storage]
pub type DomainSudoCalls<T: Config> =
StorageMap<_, Identity, DomainId, DomainSudoCall, ValueQuery>;

/// Storage that hold a list of all frozen domains.
///
/// A frozen domain does not accept the bundles but does accept a fraud proof.
#[pallet::storage]
pub type FrozenDomains<T> = StorageValue<_, BTreeSet<DomainId>, ValueQuery>;
Expand Down Expand Up @@ -2678,14 +2690,6 @@ impl<T: Config> Pallet<T> {
.map(|er| (er.domain_block_number, er.domain_block_hash))
}

/// Returns the domain block limit of the given domain.
pub fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit> {
DomainRegistry::<T>::get(domain_id).map(|domain_obj| DomainBlockLimit {
max_block_size: domain_obj.domain_config.max_block_size,
max_block_weight: domain_obj.domain_config.max_block_weight,
})
}

/// Returns the domain bundle limit of the given domain
pub fn domain_bundle_limit(
domain_id: DomainId,
Expand Down
Loading

0 comments on commit a6f0b39

Please sign in to comment.