Skip to content

Commit

Permalink
remove 1 rule check, fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Apr 28, 2023
1 parent 98f57ed commit 00b03ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 48 deletions.
7 changes: 1 addition & 6 deletions zebra-chain/src/transaction/unmined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,7 @@ impl VerifiedUnminedTx {
let fee_weight_ratio = zip317::conventional_fee_weight_ratio(&transaction, miner_fee);
let unpaid_actions = zip317::unpaid_actions(&transaction, miner_fee);

zip317::mempool_checks(
unpaid_actions,
miner_fee,
transaction.conventional_fee,
transaction.size,
)?;
zip317::mempool_checks(unpaid_actions, miner_fee, transaction.size)?;

Ok(Self {
transaction,
Expand Down
23 changes: 9 additions & 14 deletions zebra-chain/src/transaction/unmined/zip317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ fn conventional_actions(transaction: &Transaction) -> u32 {
pub fn mempool_checks(
unpaid_actions: u32,
miner_fee: Amount<NonNegative>,
conventional_fee: Amount<NonNegative>,
transaction_size: usize,
) -> Result<(), Error> {
// # Standard Rule
Expand All @@ -189,18 +188,17 @@ pub fn mempool_checks(
// > conventional fee as specified in this ZIP.
//
// <https://zips.z.cash/zip-0317#transaction-relaying>
if miner_fee < conventional_fee {
return Err(Error::FeeBelowConventional);
}

// # Standard rule
//
// > Minimum Fee Rate
// >
// > Transactions must pay a fee of at least 100 zatoshis per 1000 bytes of serialized size,
// > with a maximum fee of 1000 zatoshis. In zcashd this is `DEFAULT_MIN_RELAY_TX_FEE`.
// In Zebra, we use a similar minimum fee rate to `zcashd` v5.5.0 and later.
// Transactions must pay a fee of at least 100 zatoshis per 1000 bytes of serialized size,
// with a maximum fee of 1000 zatoshis.
//
// <https://github.com/zcash/zcash/blob/9e856cfc5b81aa2607a16a23ff5584ea10014de6/src/amount.cpp#L24-L37>
//
// <https://github.com/ZcashFoundation/zebra/issues/5336#issuecomment-1506748801>
// In zcashd this is `DEFAULT_MIN_RELAY_TX_FEE` and `LEGACY_DEFAULT_FEE`:
// <https://github.com/zcash/zcash/blob/f512291ff20098291442e83713de89bcddc07546/src/main.h#L71-L72>
// <https://github.com/zcash/zcash/blob/9e856cfc5b81aa2607a16a23ff5584ea10014de6/src/amount.h#L35-L36>

const KILOBYTE: usize = 1000;

// This calculation can't overflow, because transactions are limited to 2 MB,
Expand Down Expand Up @@ -232,9 +230,6 @@ pub enum Error {
#[error("Unpaid actions is higher than the limit")]
UnpaidActions,

#[error("Transaction fee is below the conventional fee for the transaction")]
FeeBelowConventional,

#[error("Transaction fee is below the minimum fee rate")]
FeeBelowMinimumRate,
}
27 changes: 2 additions & 25 deletions zebra-chain/src/transaction/unmined/zip317/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,15 @@
use super::{mempool_checks, Amount, Error};
#[test]
fn zip317_unpaid_actions_err() {
let check = mempool_checks(
51,
Amount::try_from(1).unwrap(),
Amount::try_from(10000).unwrap(),
1,
);
let check = mempool_checks(51, Amount::try_from(1).unwrap(), 1);

assert!(check.is_err());
assert_eq!(check.err(), Some(Error::UnpaidActions));
}

#[test]
fn zip317_convetional_fee_err() {
let check = mempool_checks(
50,
Amount::try_from(1).unwrap(),
Amount::try_from(10000).unwrap(),
1,
);

assert!(check.is_err());
assert_eq!(check.err(), Some(Error::FeeBelowConventional));
}

#[test]
fn zip317_minimum_rate_fee_err() {
let check = mempool_checks(
50,
Amount::try_from(1).unwrap(),
Amount::try_from(1).unwrap(),
1000,
);
let check = mempool_checks(50, Amount::try_from(1).unwrap(), 1000);

assert!(check.is_err());
assert_eq!(check.err(), Some(Error::FeeBelowMinimumRate));
Expand Down
4 changes: 1 addition & 3 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2886,9 +2886,7 @@ async fn mempool_zip317_error() {
assert!(verifier_response.is_err());
assert_eq!(
verifier_response.err(),
Some(TransactionError::Zip317(
zip317::Error::FeeBelowConventional
))
Some(TransactionError::Zip317(zip317::Error::FeeBelowMinimumRate))
);
}

Expand Down

0 comments on commit 00b03ad

Please sign in to comment.