Skip to content

Commit

Permalink
charge byte fees for notes (#1649)
Browse files Browse the repository at this point in the history
* charge byte fees for notes

* explicitly charge zero for permissioned calls
  • Loading branch information
brenzi authored Nov 13, 2024
1 parent 15f967d commit 8c76062
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app-libs/stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ pub mod trusted_call;
pub(crate) const ENCLAVE_ACCOUNT_KEY: &str = "Enclave_Account_Key";
pub const STF_SHIELDING_FEE_AMOUNT_DIVIDER: Balance = 571; // approx 0.175%
pub const STF_TX_FEE_UNIT_DIVIDER: Balance = 100; // 0.01 tokens
pub const STF_BYTE_FEE_UNIT_DIVIDER: Balance = 10_000; // 0.0001 tokens per byte of certain payload

pub const STF_GUESS_FEE_UNIT_DIVIDER: Balance = 10; // 0.1 tokens
12 changes: 11 additions & 1 deletion app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,19 @@ fn get_fee_for(tc: &TrustedCallSigned) -> Balance {
let one = MinimalChainSpec::one_unit(shielding_target_genesis_hash().unwrap_or_default());
match &tc.call {
TrustedCall::balance_transfer(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER,
TrustedCall::balance_transfer_with_note(_, _, _, note) =>
one / crate::STF_TX_FEE_UNIT_DIVIDER
+ (one.saturating_mul(Balance::from(note.len() as u32)))
/ crate::STF_BYTE_FEE_UNIT_DIVIDER,
TrustedCall::balance_unshield(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER * 3,
TrustedCall::guess_the_number(call) => crate::guess_the_number::get_fee_for(call),
_ => Balance::from(0u32),
TrustedCall::note_bloat(..) => Balance::from(0u32),
TrustedCall::waste_time(..) => Balance::from(0u32),
TrustedCall::timestamp_set(..) => Balance::from(0u32),
TrustedCall::balance_shield(..) => Balance::from(0u32), //will be charged on recipient, elsewhere
#[cfg(any(feature = "test", test))]
TrustedCall::balance_set_balance(..) => Balance::from(0u32),
_ => one / crate::STF_TX_FEE_UNIT_DIVIDER,
}
}

Expand Down

0 comments on commit 8c76062

Please sign in to comment.