zcash_primitives: Remove `StandardFeeRule::{PreZip313, Zip313}`

Co-authored-by: Daira-Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
Kris Nuttycombe 2024-10-23 22:18:21 -06:00
parent 57fc8095fd
commit b8ca26bf6e
8 changed files with 33 additions and 107 deletions

View File

@ -61,6 +61,9 @@ and this library adheres to Rust's notion of
- `fixed::SingleOutputChangeStrategy::new`
- `standard::SingleOutputChangeStrategy::new`
- `zip317::SingleOutputChangeStrategy::new`
- `zcash_client_backend::proto::ProposalDecodingError` has modified variants.
`ProposalDecodingError::FeeRuleNotSpecified` has been removed, and
`ProposalDecodingError::FeeRuleNotSupported` has been added to replace it.
### Removed
- `zcash_client_backend::data_api`:

View File

@ -18,8 +18,7 @@ use zcash_primitives::{
transaction::{
components::amount::NonNegativeAmount,
fees::{
fixed::FeeRule as FixedFeeRule,
zip317::{FeeRule as Zip317FeeRule, MINIMUM_FEE},
zip317::{FeeRule as Zip317FeeRule, MARGINAL_FEE, MINIMUM_FEE},
StandardFeeRule,
},
Transaction,
@ -1025,7 +1024,7 @@ where
assert_matches!(
st.propose_standard_transfer::<Infallible>(
account_id,
StandardFeeRule::PreZip313,
StandardFeeRule::Zip317,
NonZeroU32::new(1).unwrap(),
&to,
NonNegativeAmount::const_from_u64(1),
@ -1592,10 +1591,8 @@ pub fn external_address_change_spends_detected_in_restore_from_seed<T: ShieldedP
])
.unwrap();
#[allow(deprecated)]
let fee_rule = FixedFeeRule::non_standard(MINIMUM_FEE);
let change_strategy = fees::fixed::SingleOutputChangeStrategy::new(
fee_rule,
let change_strategy = fees::standard::SingleOutputChangeStrategy::new(
StandardFeeRule::Zip317,
None,
T::SHIELDED_PROTOCOL,
DustOutputPolicy::default(),
@ -1613,7 +1610,7 @@ pub fn external_address_change_spends_detected_in_restore_from_seed<T: ShieldedP
)
.unwrap()[0];
let amount_left = (value - (amount_sent + fee_rule.fixed_fee()).unwrap()).unwrap();
let amount_left = (value - (amount_sent + MINIMUM_FEE + MARGINAL_FEE).unwrap()).unwrap();
let pending_change = (amount_left - amount_legacy_change).unwrap();
// The "legacy change" is not counted by get_pending_change().

View File

@ -1,11 +1,12 @@
use crate::{
data_api::{
testing::{AddressType, TestBuilder, TestState},
testing::{DataStoreFactory, ShieldedProtocol, TestCache},
testing::{
AddressType, DataStoreFactory, ShieldedProtocol, TestBuilder, TestCache, TestState,
},
wallet::input_selection::GreedyInputSelector,
Account as _, InputSource, WalletRead, WalletWrite,
},
fees::{fixed, DustOutputPolicy},
fees::{standard, DustOutputPolicy},
wallet::WalletTransparentOutput,
};
use assert_matches::assert_matches;
@ -14,7 +15,7 @@ use zcash_primitives::{
block::BlockHash,
transaction::{
components::{amount::NonNegativeAmount, OutPoint, TxOut},
fees::fixed::FeeRule as FixedFeeRule,
fees::StandardFeeRule,
},
};
@ -198,9 +199,8 @@ where
// Shield the output.
let input_selector = GreedyInputSelector::new();
let change_strategy = fixed::SingleOutputChangeStrategy::new(
#[allow(deprecated)]
FixedFeeRule::non_standard(NonNegativeAmount::ZERO),
let change_strategy = standard::SingleOutputChangeStrategy::new(
StandardFeeRule::Zip317,
None,
ShieldedProtocol::Sapling,
DustOutputPolicy::default(),

View File

@ -203,33 +203,6 @@ pub enum ChangeError<E, NoteRefT> {
BundleError(&'static str),
}
impl<E, NoteRefT> ChangeError<E, NoteRefT> {
pub(crate) fn map<E0, F: FnOnce(E) -> E0>(self, f: F) -> ChangeError<E0, NoteRefT> {
match self {
ChangeError::InsufficientFunds {
available,
required,
} => ChangeError::InsufficientFunds {
available,
required,
},
ChangeError::DustInputs {
transparent,
sapling,
#[cfg(feature = "orchard")]
orchard,
} => ChangeError::DustInputs {
transparent,
sapling,
#[cfg(feature = "orchard")]
orchard,
},
ChangeError::StrategyError(e) => ChangeError::StrategyError(f(e)),
ChangeError::BundleError(e) => ChangeError::BundleError(e),
}
}
}
impl<CE: fmt::Display, N: fmt::Display> fmt::Display for ChangeError<CE, N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {

View File

@ -5,21 +5,17 @@ use std::marker::PhantomData;
use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{
components::amount::NonNegativeAmount,
fees::{
fixed::FeeRule as FixedFeeRule,
transparent,
zip317::{FeeError as Zip317FeeError, FeeRule as Zip317FeeRule},
StandardFeeRule,
},
transaction::fees::{
transparent,
zip317::{FeeError as Zip317FeeError, FeeRule as Zip317FeeRule},
StandardFeeRule,
},
};
use crate::{data_api::InputSource, ShieldedProtocol};
use super::{
fixed, sapling as sapling_fees, zip317, ChangeError, ChangeStrategy, DustOutputPolicy,
sapling as sapling_fees, zip317, ChangeError, ChangeStrategy, DustOutputPolicy,
EphemeralBalance, TransactionBalance,
};
@ -92,42 +88,6 @@ impl<I: InputSource> ChangeStrategy for SingleOutputChangeStrategy<I> {
) -> Result<TransactionBalance, ChangeError<Self::Error, NoteRefT>> {
#[allow(deprecated)]
match self.fee_rule() {
StandardFeeRule::PreZip313 => fixed::SingleOutputChangeStrategy::<I>::new(
FixedFeeRule::non_standard(NonNegativeAmount::const_from_u64(10000)),
self.change_memo.clone(),
self.fallback_change_pool,
self.dust_output_policy,
)
.compute_balance(
params,
target_height,
transparent_inputs,
transparent_outputs,
sapling,
#[cfg(feature = "orchard")]
orchard,
ephemeral_balance,
wallet_meta,
)
.map_err(|e| e.map(Zip317FeeError::Balance)),
StandardFeeRule::Zip313 => fixed::SingleOutputChangeStrategy::<I>::new(
FixedFeeRule::non_standard(NonNegativeAmount::const_from_u64(1000)),
self.change_memo.clone(),
self.fallback_change_pool,
self.dust_output_policy,
)
.compute_balance(
params,
target_height,
transparent_inputs,
transparent_outputs,
sapling,
#[cfg(feature = "orchard")]
orchard,
ephemeral_balance,
wallet_meta,
)
.map_err(|e| e.map(Zip317FeeError::Balance)),
StandardFeeRule::Zip317 => zip317::SingleOutputChangeStrategy::<I>::new(
Zip317FeeRule::standard(),
self.change_memo.clone(),

View File

@ -356,8 +356,8 @@ pub enum ProposalDecodingError<DbError> {
MemoInvalid(memo::Error),
/// The serialization version returned by the protobuf was not recognized.
VersionInvalid(u32),
/// The proposal did not correctly specify a standard fee rule.
FeeRuleNotSpecified,
/// The fee rule specified by the proposal is not supported by the wallet.
FeeRuleNotSupported(proposal::FeeRule),
/// The proposal violated balance or structural constraints.
ProposalInvalid(ProposalError),
/// An inputs field for the given protocol was present, but contained no input note references.
@ -409,8 +409,12 @@ impl<E: Display> Display for ProposalDecodingError<E> {
ProposalDecodingError::VersionInvalid(v) => {
write!(f, "Unrecognized proposal version {}", v)
}
ProposalDecodingError::FeeRuleNotSpecified => {
write!(f, "Proposal did not specify a known fee rule.")
ProposalDecodingError::FeeRuleNotSupported(r) => {
write!(
f,
"Fee calculation using the {:?} fee rule is not supported.",
r
)
}
ProposalDecodingError::ProposalInvalid(err) => write!(f, "{}", err),
ProposalDecodingError::EmptyShieldedInputs(protocol) => write!(
@ -600,8 +604,6 @@ impl proposal::Proposal {
proposal::Proposal {
proto_version: PROPOSAL_SER_V1,
fee_rule: match value.fee_rule() {
StandardFeeRule::PreZip313 => proposal::FeeRule::PreZip313,
StandardFeeRule::Zip313 => proposal::FeeRule::Zip313,
StandardFeeRule::Zip317 => proposal::FeeRule::Zip317,
}
.into(),
@ -624,11 +626,9 @@ impl proposal::Proposal {
PROPOSAL_SER_V1 => {
#[allow(deprecated)]
let fee_rule = match self.fee_rule() {
proposal::FeeRule::PreZip313 => StandardFeeRule::PreZip313,
proposal::FeeRule::Zip313 => StandardFeeRule::Zip313,
proposal::FeeRule::Zip317 => StandardFeeRule::Zip317,
proposal::FeeRule::NotSpecified => {
return Err(ProposalDecodingError::FeeRuleNotSpecified);
other => {
return Err(ProposalDecodingError::FeeRuleNotSupported(other));
}
};

View File

@ -9,6 +9,9 @@ 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. All clients should now use `StandardFeeRule::Zip317`.
### Deprecated
- `zcash_primitives::transaction::fees`:

View File

@ -62,14 +62,6 @@ pub trait FutureFeeRule: FeeRule {
/// An enumeration of the standard fee rules supported by the wallet.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum StandardFeeRule {
#[deprecated(
note = "Using this fee rule violates ZIP 317, and might cause transactions built with it to fail. Use `StandardFeeRule::Zip317` instead."
)]
PreZip313,
#[deprecated(
note = "Using this fee rule violates ZIP 317, and might cause transactions built with it to fail. Use `StandardFeeRule::Zip317` instead."
)]
Zip313,
Zip317,
}
@ -88,8 +80,6 @@ impl FeeRule for StandardFeeRule {
) -> Result<NonNegativeAmount, Self::Error> {
#[allow(deprecated)]
match self {
Self::PreZip313 => Ok(zip317::MINIMUM_FEE),
Self::Zip313 => Ok(NonNegativeAmount::const_from_u64(1000)),
Self::Zip317 => zip317::FeeRule::standard().fee_required(
params,
target_height,