Skip to content

Commit

Permalink
feat(subnet_emission): add validation to token_emission
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed Nov 12, 2024
1 parent ce6f7f3 commit 37741c2
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions pallets/subnet_emission/src/subnet_consensus/util/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,8 @@ pub fn extract_bonds<T: Config>(
.collect()
}

// TODO: add the `EmittedMoreThanExpected` err
// previous impl can be found here https://github.com/renlabs-dev/subspace-network/blob/main/pallets/subnet_emission/src/subnet_consensus/yuma.rs#L348
//
//
// it will look something like this
//
// ensure!(
// self.total_emitted <= self.founder_emission.saturating_add(params.token_emission),
// EmissionError::EmittedMoreThanExpected {
// emitted,
// expected: self.params.founder_emission.saturating_add(self.params.token_emission)
// }
// );
pub fn calculate_final_emissions<T: Config>(
token_emission: u64,
founder_emission: u64,
subnet_id: u16,
result: Vec<(ModuleKey<T::AccountId>, u64, u64)>,
Expand Down Expand Up @@ -129,6 +117,13 @@ pub fn calculate_final_emissions<T: Config>(
}
}

if emitted > founder_emission.saturating_add(token_emission) {
return Err(EmissionError::EmittedMoreThanExpected {
emitted,
expected: founder_emission.saturating_add(token_emission),
});
}

Ok((emissions, emitted))
}

Expand Down Expand Up @@ -644,8 +639,12 @@ pub fn process_consensus_output<T: Config>(
));
}

let (emission_map, total_emitted) =
calculate_final_emissions::<T>(params.founder_emission, subnet_id, result)?;
let (emission_map, total_emitted) = calculate_final_emissions::<T>(
params.token_emission,
params.founder_emission,
subnet_id,
result,
)?;
log::debug!(
"finished yuma for {} with distributed: {emission_map:?}",
subnet_id
Expand Down

0 comments on commit 37741c2

Please sign in to comment.