Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit control of padding to the Builder API. #403

Merged
merged 2 commits into from
Dec 19, 2023
Merged

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Dec 8, 2023

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (003619b) 81.07% compared to head (0a257d6) 81.01%.

Files Patch % Lines
src/builder.rs 64.86% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #403      +/-   ##
==========================================
- Coverage   81.07%   81.01%   -0.07%     
==========================================
  Files          31       31              
  Lines        3112     3123      +11     
==========================================
+ Hits         2523     2530       +7     
- Misses        589      593       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nuttycom nuttycom force-pushed the padding_rule branch 3 times, most recently from ce1cb35 to 054e91e Compare December 11, 2023 20:09
@nuttycom nuttycom requested a review from str4d December 11, 2023 20:11
src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
daira
daira previously approved these changes Dec 12, 2023
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated
impl PaddingRule {
/// The default padding rule, which ensures that the constructed bundle will contain at least 2
/// actions if any genuine Orchard spends or outputs are requested.
pub const DEFAULT: PaddingRule = PaddingRule::PadTo(MIN_ACTIONS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the old behaviour is equivalent to PaddingRule::Require(MIN_ACTIONS) (which is why we could always return a bundle).

@nuttycom nuttycom force-pushed the padding_rule branch 2 times, most recently from 0722bd4 to 89bc5cd Compare December 13, 2023 20:48
The term `recipient` is commonly used to refer to the address to which a
note is sent; however, a bundle may include multiple outputs to the same
recipient. This change is intended to clarify this usage.

Co-authored-by: Daira Emma Hopwood <[email protected]>
@nuttycom nuttycom force-pushed the padding_rule branch 4 times, most recently from d9945df to b6bc396 Compare December 15, 2023 00:34
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed as of b6bc396.

@@ -7,7 +7,7 @@ use criterion::{BenchmarkId, Criterion};
use pprof::criterion::{Output, PProfProfiler};

use orchard::{
builder::Builder,
builder::{Builder, PaddingRule},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update these files for the refactor.

src/builder.rs Outdated
Comment on lines 30 to 31
/// An enumeration of rules for construction of dummy actions that may be applied to Orchard bundle
/// construction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An enumeration of rules for construction of dummy actions that may be applied to Orchard bundle
/// construction.
/// An enumeration of rules for Orchard bundle construction.

src/builder.rs Outdated
///
/// The returned bundle will have no proof or signatures; these can be applied with
/// [`Bundle::create_proof`] and [`Bundle::apply_signatures`] respectively.
pub fn build<V: TryFrom<i64>>(
mut self,
mut rng: impl RngCore,
padding_rule: &BundleType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
padding_rule: &BundleType,
bundle_type: &BundleType,

src/builder.rs Outdated
.unwrap();
let num_real_spends = self.spends.len();
let num_real_outputs = self.outputs.len();
let num_actions = padding_rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let num_actions = padding_rule
let num_actions = bundle_type

/// to receive funds.
#[derive(Debug)]
pub struct Builder {
spends: Vec<SpendInfo>,
recipients: Vec<RecipientInfo>,
outputs: Vec<OutputInfo>,
flags: Flags,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To some extent, the flags are related to the BundleType. In particular, if BundleType::Coinbase is used, flags.spends_enabled() must be true (this check is missing from Builder::build; the num_real_spends == 0 check is insufficient). So I'm not sure if this means we should be constructing to builder with BundleType, or ensuring we remember to add all necessary checks in Builder::build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundle type sort of implies the flags; what if BundleType::Transactional actually carried a flags payload, with the coinbase bundle type hardcoding the flags to (false, true)?

Copy link
Contributor Author

@nuttycom nuttycom Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then we check the flags in build rather than in the add_* methods?

@nuttycom nuttycom deleted the padding_rule branch December 21, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants