Skip to content

Commit

Permalink
zcash_primitives: Move StandardFeeRule to zcash_client_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Oct 24, 2024
1 parent 945348d commit 3ecc628
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 60 deletions.
10 changes: 7 additions & 3 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ and this library adheres to Rust's notion of
- `WalletSummary::progress`
- `WalletMeta`
- `impl Default for wallet::input_selection::GreedyInputSelector`
- `zcash_client_backend::fees::SplitPolicy`
- `zcash_client_backend::fees::zip317::MultiOutputChangeStrategy`
- `zcash_client_backend::fees::standard::MultiOutputChangeStrategy`
- `zcash_client_backend::fees`
- `SplitPolicy`
- `StandardFeeRule` has been moved here from `zcash_primitives::fees`. Relative
to that type, the deprecated `PreZip313` and `Zip313` variants have been
removed
- `zip317::MultiOutputChangeStrategy`
- `standard::MultiOutputChangeStrategy`
- A new feature flag, `non-standard-fees`, has been added. This flag is now
required in order to make use of any types or methods that enable non-standard
fee calculation.
Expand Down
4 changes: 2 additions & 2 deletions zcash_client_backend/src/data_api/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use zcash_primitives::{
memo::Memo,
transaction::{
components::{amount::NonNegativeAmount, sapling::zip212_enforcement},
fees::{FeeRule, StandardFeeRule},
fees::FeeRule,
Transaction, TxId,
},
};
Expand All @@ -48,7 +48,7 @@ use crate::{
address::UnifiedAddress,
fees::{
standard::{self, SingleOutputChangeStrategy},
ChangeStrategy, DustOutputPolicy,
ChangeStrategy, DustOutputPolicy, StandardFeeRule,
},
keys::{UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedSpendingKey},
proposal::Proposal,
Expand Down
7 changes: 2 additions & 5 deletions zcash_client_backend/src/data_api/testing/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use zcash_primitives::{
legacy::TransparentAddress,
transaction::{
components::amount::NonNegativeAmount,
fees::{
zip317::{FeeRule as Zip317FeeRule, MARGINAL_FEE, MINIMUM_FEE},
StandardFeeRule,
},
fees::zip317::{FeeRule as Zip317FeeRule, MARGINAL_FEE, MINIMUM_FEE},
Transaction,
},
};
Expand Down Expand Up @@ -53,7 +50,7 @@ use crate::{
fees::{
self,
standard::{self, SingleOutputChangeStrategy},
DustOutputPolicy, SplitPolicy,
DustOutputPolicy, SplitPolicy, StandardFeeRule,
},
scanning::ScanError,
wallet::{Note, NoteId, OvkPolicy, ReceivedNote},
Expand Down
7 changes: 2 additions & 5 deletions zcash_client_backend/src/data_api/testing/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ use crate::{
wallet::input_selection::GreedyInputSelector,
Account as _, InputSource, WalletRead, WalletWrite,
},
fees::{standard, DustOutputPolicy},
fees::{standard, DustOutputPolicy, StandardFeeRule},
wallet::WalletTransparentOutput,
};
use assert_matches::assert_matches;
use sapling::zip32::ExtendedSpendingKey;
use zcash_primitives::{
block::BlockHash,
transaction::{
components::{amount::NonNegativeAmount, OutPoint, TxOut},
fees::StandardFeeRule,
},
transaction::components::{amount::NonNegativeAmount, OutPoint, TxOut},
};

pub fn put_received_transparent_utxo<DSF>(dsf: DSF)
Expand Down
6 changes: 4 additions & 2 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ use crate::{
WalletRead, WalletWrite,
},
decrypt_transaction,
fees::{standard::SingleOutputChangeStrategy, ChangeStrategy, DustOutputPolicy},
fees::{
standard::SingleOutputChangeStrategy, ChangeStrategy, DustOutputPolicy, StandardFeeRule,
},
keys::UnifiedSpendingKey,
proposal::{Proposal, ProposalError, Step, StepOutputIndex},
wallet::{Note, OvkPolicy, Recipient},
Expand All @@ -62,7 +64,7 @@ use zcash_primitives::{
transaction::{
builder::{BuildConfig, BuildResult, Builder},
components::{amount::NonNegativeAmount, sapling::zip212_enforcement, OutPoint},
fees::{FeeRule, StandardFeeRule},
fees::FeeRule,
Transaction, TxId,
},
};
Expand Down
39 changes: 38 additions & 1 deletion zcash_client_backend/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use zcash_primitives::{
memo::MemoBytes,
transaction::{
components::{amount::NonNegativeAmount, OutPoint},
fees::{transparent, FeeRule},
fees::{
transparent::{self, InputSize},
zip317 as prim_zip317, FeeRule,
},
},
};
use zcash_protocol::{PoolType, ShieldedProtocol};
Expand All @@ -27,6 +30,40 @@ pub mod sapling;
pub mod standard;
pub mod zip317;

/// An enumeration of the standard fee rules supported by the wallet backend.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum StandardFeeRule {
Zip317,
}

impl FeeRule for StandardFeeRule {
type Error = prim_zip317::FeeError;

fn fee_required<P: consensus::Parameters>(
&self,
params: &P,
target_height: BlockHeight,
transparent_input_sizes: impl IntoIterator<Item = InputSize>,
transparent_output_sizes: impl IntoIterator<Item = usize>,
sapling_input_count: usize,
sapling_output_count: usize,
orchard_action_count: usize,
) -> Result<NonNegativeAmount, Self::Error> {
#[allow(deprecated)]
match self {
Self::Zip317 => prim_zip317::FeeRule::standard().fee_required(
params,
target_height,
transparent_input_sizes,
transparent_output_sizes,
sapling_input_count,
sapling_output_count,
orchard_action_count,
),
}
}
}

/// `ChangeValue` represents either a proposed change output to a shielded pool
/// (with an optional change memo), or if the "transparent-inputs" feature is
/// enabled, an ephemeral output to the transparent pool.
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/src/fees/standard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Change strategies designed for use with a standard fee.

use zcash_primitives::transaction::fees::StandardFeeRule;
use super::StandardFeeRule;

/// A change strategy that proposes change as a single output. The output pool is chosen
/// as the most current pool that avoids unnecessary pool-crossing (with a specified
Expand Down
3 changes: 2 additions & 1 deletion zcash_client_backend/src/fees/zip317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ use std::marker::PhantomData;
use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::fees::{transparent, zip317 as prim_zip317, FeeRule, StandardFeeRule},
transaction::fees::{transparent, zip317 as prim_zip317, FeeRule},
};
use zcash_protocol::value::{BalanceError, Zatoshis};

use crate::{
data_api::{InputSource, WalletMeta},
fees::StandardFeeRule,
ShieldedProtocol,
};

Expand Down
4 changes: 2 additions & 2 deletions zcash_client_backend/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use zcash_primitives::{
consensus::BlockHeight,
memo::{self, MemoBytes},
merkle_tree::read_commitment_tree,
transaction::{components::amount::NonNegativeAmount, fees::StandardFeeRule, TxId},
transaction::{components::amount::NonNegativeAmount, TxId},
};

use crate::{
data_api::{chain::ChainState, InputSource},
fees::{ChangeValue, TransactionBalance},
fees::{ChangeValue, StandardFeeRule, TransactionBalance},
proposal::{Proposal, ProposalError, ShieldedInputs, Step, StepOutput, StepOutputIndex},
zip321::{TransactionRequest, Zip321Error},
PoolType, ShieldedProtocol,
Expand Down
4 changes: 2 additions & 2 deletions zcash_client_sqlite/src/wallet/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,10 @@ pub(crate) mod tests {
testing::orchard::OrchardPoolTester, wallet::input_selection::GreedyInputSelector,
WalletCommitmentTrees,
},
fees::{standard, DustOutputPolicy},
fees::{standard, DustOutputPolicy, StandardFeeRule},
wallet::OvkPolicy,
},
zcash_primitives::{memo::Memo, transaction::fees::StandardFeeRule},
zcash_primitives::memo::Memo,
};

#[test]
Expand Down
5 changes: 3 additions & 2 deletions zcash_primitives/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ and this library adheres to Rust's notion of
### Changed
- MSRV is now 1.77.0.
- `zcash_primitives::transaction::fees`:
- The deprecated `PreZip313` and `Zip313` variants of `StandardFeeRule` have
been removed.
- The `fixed` module has been moved behind the `non-standard-fees` feature
flag. Using a fixed fee may result in a transaction that cannot be mined on
the current Zcash network. To calculate the ZIP 317 fee, use
Expand All @@ -32,6 +30,9 @@ and this library adheres to Rust's notion of

### Removed
- `zcash_primitives::transaction::fees`:
- `StandardFeeRule` itself has been removed; it was not used in this crate.
Is use in `zcash_client_backend` has been replaced with
`zcash_client_backend::fees::StandardFeeRule`.
- `fixed::FeeRule::standard`. This constructor was misleadingly named: using a
fixed fee does not conform to any current Zcash standard. To calculate the
ZIP 317 fee, use `zip317::FeeRule::standard()`. To preserve the current
Expand Down
34 changes: 0 additions & 34 deletions zcash_primitives/src/transaction/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,3 @@ pub trait FutureFeeRule: FeeRule {
tze_outputs: &[impl tze::OutputView],
) -> Result<NonNegativeAmount, Self::Error>;
}

/// An enumeration of the standard fee rules supported by the wallet.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum StandardFeeRule {
Zip317,
}

impl FeeRule for StandardFeeRule {
type Error = zip317::FeeError;

fn fee_required<P: consensus::Parameters>(
&self,
params: &P,
target_height: BlockHeight,
transparent_input_sizes: impl IntoIterator<Item = InputSize>,
transparent_output_sizes: impl IntoIterator<Item = usize>,
sapling_input_count: usize,
sapling_output_count: usize,
orchard_action_count: usize,
) -> Result<NonNegativeAmount, Self::Error> {
#[allow(deprecated)]
match self {
Self::Zip317 => zip317::FeeRule::standard().fee_required(
params,
target_height,
transparent_input_sizes,
transparent_output_sizes,
sapling_input_count,
sapling_output_count,
orchard_action_count,
),
}
}
}

0 comments on commit 3ecc628

Please sign in to comment.