Skip to content

Commit

Permalink
Merge branch 'main' into gateway-http-server
Browse files Browse the repository at this point in the history
  • Loading branch information
shamil-gadelshin committed Dec 6, 2024
2 parents 3f810b9 + d284076 commit fa4ef90
Show file tree
Hide file tree
Showing 60 changed files with 985 additions and 750 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions crates/pallet-domains/src/bundle_storage_fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ pub fn refund_storage_fee<T: Config>(
}

// Drop any dust and deregistered/slashed operator's bundle storage fee to the treasury
if !remaining_fee.is_zero() {
mint_into_treasury::<T>(remaining_fee).ok_or(Error::MintBalance)?;
}
mint_into_treasury::<T>(remaining_fee).map_err(|_| Error::MintBalance)?;

Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions crates/pallet-domains/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ pub(crate) fn do_cleanup_operator<T: Config>(
.map_err(Error::BundleStorageFund)?;

// transfer any remaining amount to treasury
mint_into_treasury::<T>(total_stake).ok_or(Error::MintBalance)?;
mint_into_treasury::<T>(total_stake)?;

// remove OperatorOwner Details
OperatorIdOwner::<T>::remove(operator_id);
Expand Down Expand Up @@ -1335,7 +1335,6 @@ pub(crate) fn do_reward_operators<T: Config>(
.checked_sub(&allocated_rewards)
.ok_or(Error::BalanceUnderflow)?,
)
.ok_or(Error::MintBalance)
})
}

Expand Down
23 changes: 12 additions & 11 deletions crates/pallet-domains/src/staking_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ pub(crate) fn operator_take_reward_tax_and_stake<T: Config>(
})?;
}

if !to_treasury.is_zero() {
mint_into_treasury::<T>(to_treasury).ok_or(TransitionError::MintBalance)?;
}
mint_into_treasury::<T>(to_treasury)?;

Ok(())
})
Expand Down Expand Up @@ -306,23 +304,26 @@ pub(crate) fn mint_funds<T: Config>(
Ok(())
}

pub(crate) fn mint_into_treasury<T: Config>(amount: BalanceOf<T>) -> Option<()> {
let existing_funds = AccumulatedTreasuryFunds::<T>::get();
let total_funds = existing_funds.checked_add(&amount)?;
if total_funds.is_zero() {
return Some(());
pub(crate) fn mint_into_treasury<T: Config>(amount: BalanceOf<T>) -> Result<(), TransitionError> {
if amount.is_zero() {
return Ok(());
}

let total_funds = AccumulatedTreasuryFunds::<T>::get()
.checked_add(&amount)
.ok_or(TransitionError::BalanceOverflow)?;

match T::Currency::can_deposit(&T::TreasuryAccount::get(), total_funds, Provenance::Minted) {
// Deposit is possible, so we mint the funds into treasury.
DepositConsequence::Success => {
T::Currency::mint_into(&T::TreasuryAccount::get(), total_funds).ok()?;
T::Currency::mint_into(&T::TreasuryAccount::get(), total_funds)
.map_err(|_| TransitionError::MintBalance)?;
AccumulatedTreasuryFunds::<T>::kill();
}
// Deposit cannot be done to treasury, so hold the funds until we can.
_ => AccumulatedTreasuryFunds::<T>::set(total_funds),
}
Some(())
Ok(())
}

/// Slashes any pending slashed operators.
Expand Down Expand Up @@ -436,7 +437,7 @@ pub(crate) fn do_slash_operator<T: Config>(
.checked_sub(&amount_to_slash_in_holding)
.ok_or(TransitionError::BalanceUnderflow)?;

mint_into_treasury::<T>(nominator_reward).ok_or(TransitionError::MintBalance)?;
mint_into_treasury::<T>(nominator_reward)?;

total_stake = total_stake.saturating_sub(nominator_staked_amount);
total_shares = total_shares.saturating_sub(nominator_shares);
Expand Down
6 changes: 3 additions & 3 deletions crates/pallet-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use subspace_core_primitives::pos::PosSeed;
use subspace_core_primitives::pot::PotOutput;
use subspace_core_primitives::sectors::SectorId;
use subspace_core_primitives::segments::{
ArchivedBlockProgress, ArchivedHistorySegment, HistorySize, LastArchivedBlock,
RecordedHistorySegment, SegmentCommitment, SegmentHeader, SegmentIndex,
ArchivedBlockProgress, HistorySize, LastArchivedBlock, RecordedHistorySegment,
SegmentCommitment, SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{BlockNumber, PublicKey, SlotNumber, REWARD_SIGNING_CONTEXT};
Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn create_signed_vote(
slot: Slot,
proof_of_time: PotOutput,
future_proof_of_time: PotOutput,
archived_history_segment: &ArchivedHistorySegment,
archived_history_segment: &NewArchivedSegment,
reward_address: <Test as frame_system::Config>::AccountId,
solution_range: SolutionRange,
vote_solution_range: SolutionRange,
Expand Down
50 changes: 25 additions & 25 deletions crates/pallet-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ fn vote_after_genesis() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -381,7 +381,7 @@ fn vote_too_low_height() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -412,7 +412,7 @@ fn vote_past_future_height() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand All @@ -433,7 +433,7 @@ fn vote_past_future_height() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -463,7 +463,7 @@ fn vote_wrong_parent() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -504,7 +504,7 @@ fn vote_past_future_slot() {
2.into(),
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand All @@ -529,7 +529,7 @@ fn vote_past_future_slot() {
4.into(),
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand All @@ -553,7 +553,7 @@ fn vote_past_future_slot() {
2.into(),
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -595,7 +595,7 @@ fn vote_same_slot() {
Subspace::current_slot(),
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand All @@ -615,7 +615,7 @@ fn vote_same_slot() {
Subspace::current_slot(),
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -645,7 +645,7 @@ fn vote_bad_reward_signature() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -676,7 +676,7 @@ fn vote_unknown_segment_commitment() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -710,7 +710,7 @@ fn vote_outside_of_solution_range() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
SolutionRange::MAX,
Expand Down Expand Up @@ -752,7 +752,7 @@ fn vote_solution_quality_too_high() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand All @@ -770,7 +770,7 @@ fn vote_solution_quality_too_high() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
SolutionRange::MIN,
// Create vote for block level of quality
Expand Down Expand Up @@ -835,7 +835,7 @@ fn vote_invalid_proof_of_time() {
slot + 1,
test_proof_of_time,
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -863,7 +863,7 @@ fn vote_invalid_proof_of_time() {
slot + 1,
test_proof_of_time,
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand All @@ -881,7 +881,7 @@ fn vote_invalid_proof_of_time() {
slot,
test_proof_of_time,
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -909,7 +909,7 @@ fn vote_invalid_proof_of_time() {
slot,
test_proof_of_time,
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -937,7 +937,7 @@ fn vote_invalid_proof_of_time() {
slot,
test_proof_of_time,
test_future_proof_of_time,
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -975,7 +975,7 @@ fn vote_correct_signature() {
Subspace::current_slot() + 1,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
1,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -1014,7 +1014,7 @@ fn vote_equivocation_current_block_plus_vote() {
slot,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
reward_address,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -1072,7 +1072,7 @@ fn vote_equivocation_parent_block_plus_vote() {
slot,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
reward_address,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -1132,7 +1132,7 @@ fn vote_equivocation_current_voters_duplicate() {
slot,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
reward_address,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down Expand Up @@ -1212,7 +1212,7 @@ fn vote_equivocation_parent_voters_duplicate() {
slot,
Default::default(),
Default::default(),
&archived_segment.pieces,
archived_segment,
reward_address,
pallet::SolutionRanges::<Test>::get().current,
pallet::SolutionRanges::<Test>::get().voting_current,
Expand Down
Loading

0 comments on commit fa4ef90

Please sign in to comment.