Skip to content

Commit

Permalink
Merge branch 'sc-platform/filter-voting-outputs' of https://github.co…
Browse files Browse the repository at this point in the history
…m/iotaledger/iota into dev-tools/simplify-filters
DaughterOfMars committed Dec 18, 2024
2 parents af4350a + f3a439d commit 13c34b0
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions crates/iota-genesis-builder/src/stardust/process_outputs.rs
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ pub fn scale_amount_for_iota(amount: u64) -> Result<u64> {

// Check if the output is basic and has a feature Tag using the Participation
// Tag: https://github.com/iota-community/treasury/blob/main/specifications/hornet-participation-plugin.md
pub fn is_voting_output(output: &Output) -> bool {
pub fn is_participation_output(output: &Output) -> bool {
if let Some(feat) = output.features() {
if output.is_basic() && !feat.is_empty() {
if let Some(tag) = feat.tag() {
@@ -44,12 +44,12 @@ pub fn is_voting_output(output: &Output) -> bool {
}

/// Processes outputs from a Hornet snapshot considering 3 filters:
/// - the `ScaleIotaAmountFilter` scales balances of IOTA Toksns from micro to
/// - the `ScaleIotaAmountFilter` scales balances of IOTA Tokens from micro to
/// nano
/// - the `UnlockedVestingOutputFilter` takes vesting outputs that can be
/// unlocked and merges them into a unique basic output.
/// - the `VotingOutputFilter` removes all features from the basic outputs with
/// a participation tag.
/// - the `ParticipationOutputFilter` removes all features from the basic
/// outputs with a participation tag.
pub fn process_outputs_for_iota<'a>(
target_milestone_timestamp: u32,
outputs: impl Iterator<Item = Result<(OutputHeader, Output)>> + 'a,
@@ -76,7 +76,7 @@ struct HornetFilterIterator<I> {
snapshot_timestamp_s: u32,
/// Output picked to be merged
vesting_outputs: Vec<OutputId>,
voting_outputs: Vec<OutputId>,
participation_outputs: Vec<OutputId>,
num_vesting_outputs: u64,
num_scaled_outputs: u64,
}
@@ -93,7 +93,7 @@ where
vesting_outputs: Default::default(),
num_vesting_outputs: Default::default(),
num_scaled_outputs: Default::default(),
voting_outputs: Default::default(),
participation_outputs: Default::default(),
}
}

@@ -107,8 +107,11 @@ where
"Number of vesting outputs after merging: {}",
self.num_vesting_outputs
);
debug!("Number of voting outputs: {}", self.voting_outputs.len());
debug!("Voting outputs: {:?}", self.voting_outputs);
debug!(
"Number of participation outputs: {}",
self.participation_outputs.len()
);
debug!("participation outputs: {:?}", self.participation_outputs);
}

/// Get the next filtered output
@@ -119,7 +122,7 @@ where
if !self.filter_unlocked_vesting_output(&output) {
continue;
}
self.filter_voting_output(&mut output);
self.filter_participation_output(&mut output);
return Some(output);
}
None
@@ -227,10 +230,10 @@ where
true
}

fn filter_voting_output(&mut self, output: &mut Result<(OutputHeader, Output)>) {
fn filter_participation_output(&mut self, output: &mut Result<(OutputHeader, Output)>) {
if let Ok((header, inner)) = output {
if is_voting_output(inner) {
self.voting_outputs.push(header.output_id());
if is_participation_output(inner) {
self.participation_outputs.push(header.output_id());
// replace the inner output
*inner = BasicOutputBuilder::from(inner.as_basic())
.clear_features()

0 comments on commit 13c34b0

Please sign in to comment.