diff --git a/core/src/mantle/gas.rs b/core/src/mantle/gas.rs index a4b77a699..48e1603ec 100644 --- a/core/src/mantle/gas.rs +++ b/core/src/mantle/gas.rs @@ -107,18 +107,18 @@ impl Display for GasCost { } } -pub trait GasCalculator { +pub trait TxGasCalculator { type Context; /// Returns the gas cost of this operation. - fn total_gas_cost( + fn total_gas_cost( &self, context: &Self::Context, ) -> Result; fn storage_gas_cost(&self, context: &Self::Context) -> Result; - fn execution_gas_consumption( + fn execution_gas_consumption( &self, context: &Self::Context, ) -> Result; @@ -130,80 +130,29 @@ pub trait GasCalculator { #[error("Gas overflow")] pub struct GasOverflow; -impl GasCalculator for &T { - type Context = T::Context; - - fn total_gas_cost( - &self, - context: &Self::Context, - ) -> Result { - T::total_gas_cost::(self, context) - } - - fn storage_gas_cost(&self, context: &Self::Context) -> Result { - T::storage_gas_cost(self, context) - } - - fn execution_gas_consumption( - &self, - context: &Self::Context, - ) -> Result { - T::execution_gas_consumption::(self, context) - } - - fn storage_gas_consumption(&self, context: &Self::Context) -> Result { - T::storage_gas_consumption(self, context) - } +mod private { + pub trait Sealed {} } -pub trait GasConstants { - /// Verify the proof of ownership and relative balance. - const TRANSFER: Gas; +pub trait GasProfile: private::Sealed {} - /// Verify the inscription signature. - const CHANNEL_INSCRIBE: Gas; +pub struct MainnetGasProfile; +impl private::Sealed for MainnetGasProfile {} +impl GasProfile for MainnetGasProfile {} - /// Verify the administrator signature. - const CHANNEL_CONFIG: Gas; - - /// Verify the deposit signature. - const CHANNEL_DEPOSIT: Gas; - - /// Verify the withdrawal signature. - const CHANNEL_WITHDRAW: Gas; - - /// Verify the transfer signature. - const CHANNEL_TRANSFER: Gas; - - /// Verify the proof of ownership. - const SDP_DECLARE: Gas; - - /// Verify the proof of ownership. - const SDP_WITHDRAW: Gas; - - /// Store the active message. - const SDP_ACTIVE: Gas; - - /// Consume a reward ticket. - const LEADER_CLAIM: Gas; - - /// Claim a `PoW` reward - const CLAIM_POW_REWARD: Gas; +pub trait OperationGas { + const GAS_COST: Gas; } -pub struct MainnetGasConstants; +pub trait SignedOperationExecutionGas { + /// The factor `execution_gas` scales the operation's base gas cost by. + fn gas_multiplier(&self) -> Value; -impl GasConstants for MainnetGasConstants { - const TRANSFER: Gas = Gas(590); - const CHANNEL_INSCRIBE: Gas = Gas(56); - const CHANNEL_CONFIG: Gas = Gas(56); - const CHANNEL_DEPOSIT: Gas = Gas(590); - const CHANNEL_WITHDRAW: Gas = Gas(56); - const CHANNEL_TRANSFER: Gas = Gas(56); - const SDP_DECLARE: Gas = Gas(646); - const SDP_WITHDRAW: Gas = Gas(590); - const SDP_ACTIVE: Gas = Gas(590); - const LEADER_CLAIM: Gas = Gas(580); - // TODO: Fix this value once decided - const CLAIM_POW_REWARD: Gas = Gas(1); + /// Calculates the execution gas. + fn execution_gas(&self) -> Result + where + Self: OperationGas, + { + Self::GAS_COST.checked_mul(self.gas_multiplier()) + } } diff --git a/core/src/mantle/mod.rs b/core/src/mantle/mod.rs index 0865033a8..69e2217c3 100644 --- a/core/src/mantle/mod.rs +++ b/core/src/mantle/mod.rs @@ -9,7 +9,7 @@ pub mod transactions; mod channel_notes; mod fixtures; -pub use gas::{GasCalculator, GasConstants}; +pub use gas::{GasProfile, TxGasCalculator}; pub use ledger::{Note, NoteId, Utxo, Value}; pub use ops::{Op, OpProof}; pub use transactions::{ diff --git a/core/src/mantle/ops/channel/channel_transfer.rs b/core/src/mantle/ops/channel/channel_transfer.rs index acd6e9db4..108a9fae8 100644 --- a/core/src/mantle/ops/channel/channel_transfer.rs +++ b/core/src/mantle/ops/channel/channel_transfer.rs @@ -4,17 +4,18 @@ use serde::{Deserialize, Serialize}; use crate::{ events::TxEvent, mantle::{ - TxHash, + TxHash, Value, channel::{Channels, Error}, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, Inputs, Outputs, PreverifiableOperation, ProvableOperation, Utxo, - Utxos, VerifiableOperation, verification_mode, + Utxos, VerifiableOperation, verification_mode, verification_mode::VerificationMode, }, ops::{ - OpId, + OpId, SignedOp, channel::{ChannelId, verification::verify_channel_multi_sig}, }, - transactions::{OperationVerificationHelper, hash::TxHashView}, + transactions::{OperationVerificationHelper, hash::TxHashView, states::VerificationState}, }, proofs::channel_multi_sig_proof::ChannelMultiSigProof, sdp::locked_notes::LockedNotes, @@ -56,9 +57,15 @@ pub struct ChannelTransferExecutionContext { } impl ProvableOperation for ChannelTransferOp { + // `SignedOperationExecutionGas::gas_multiplier` below reads this proof's + // signature count. If this changes, update that too. type Proof = ChannelMultiSigProof; } +impl OperationGas for ChannelTransferOp { + const GAS_COST: Gas = Gas::new(56); +} + impl PreverifiableOperation for ChannelTransferOp { type Context<'a> = (); type Error = Error; @@ -168,3 +175,13 @@ impl ExecutableOperation for ChannelTransferOp { Ok((context, Vec::new())) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + let signature_count = self.proof().signatures().len(); + Value::try_from(signature_count) + .expect("Channel multi-signature proofs are bound to u16::MAX signatures.") + } +} diff --git a/core/src/mantle/ops/channel/config.rs b/core/src/mantle/ops/channel/config.rs index c72a3a16b..426af5de9 100644 --- a/core/src/mantle/ops/channel/config.rs +++ b/core/src/mantle/ops/channel/config.rs @@ -8,12 +8,15 @@ use crate::{ crypto::{Digest as _, Hasher}, events::TxEvent, mantle::{ + Value, channel::{ChannelState, Channels, Error, SlotTimeframe, SlotTimeout}, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, PreverifiableOperation, ProvableOperation, VerifiableOperation, - verification_mode, + verification_mode, verification_mode::VerificationMode, }, - transactions::hash::TxHashView, + ops::SignedOp, + transactions::{hash::TxHashView, states::VerificationState}, }, proofs::channel_multi_sig_proof::ChannelMultiSigProof, }; @@ -51,9 +54,15 @@ pub struct ChannelConfigExecutionContext { } impl ProvableOperation for ChannelConfigOp { + // `SignedOperationExecutionGas::gas_multiplier` below reads this proof's + // signature count. If this changes, update that too. type Proof = ChannelMultiSigProof; } +impl OperationGas for ChannelConfigOp { + const GAS_COST: Gas = Gas::new(56); +} + impl PreverifiableOperation for ChannelConfigOp { type Context<'a> = (); type Error = Error; @@ -152,3 +161,13 @@ impl ExecutableOperation for ChannelConfigOp { Ok((context, Vec::new())) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + let signature_count = self.proof().signatures().len(); + Value::try_from(signature_count) + .expect("Channel multi-signature proofs are bound to u16::MAX signatures.") + } +} diff --git a/core/src/mantle/ops/channel/deposit.rs b/core/src/mantle/ops/channel/deposit.rs index ab334ff52..2d87fb535 100644 --- a/core/src/mantle/ops/channel/deposit.rs +++ b/core/src/mantle/ops/channel/deposit.rs @@ -6,13 +6,19 @@ use serde::{Deserialize, Serialize}; use crate::{ events::{DepositRecreatedNotes, TxEvent, TxEventPayload}, mantle::{ + Value, channel::{Channels, Error}, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, Inputs, InputsError, Outputs, PreverifiableOperation, ProvableOperation, Utxos, VerifiableOperation, verification_mode, + verification_mode::VerificationMode, + }, + ops::{OpId, SignedOp, channel::ChannelId}, + transactions::{ + hash::{TxHash, TxHashView}, + states::VerificationState, }, - ops::{OpId, channel::ChannelId}, - transactions::hash::{TxHash, TxHashView}, }, sdp::locked_notes::LockedNotes, }; @@ -68,6 +74,10 @@ impl ProvableOperation for DepositOp { type Proof = ZkSignature; } +impl OperationGas for DepositOp { + const GAS_COST: Gas = Gas::new(590); +} + impl PreverifiableOperation for DepositOp { type Context<'a> = (); type Error = Error; @@ -151,3 +161,11 @@ impl ExecutableOperation for DepositOp { Ok((context, events)) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} diff --git a/core/src/mantle/ops/channel/inscribe.rs b/core/src/mantle/ops/channel/inscribe.rs index a2d2dceb2..ccbf07fb2 100644 --- a/core/src/mantle/ops/channel/inscribe.rs +++ b/core/src/mantle/ops/channel/inscribe.rs @@ -12,13 +12,15 @@ use crate::{ crypto::{Digest as _, Hasher}, events::TxEvent, mantle::{ + Value, channel::{ChannelState, Channels, Error}, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, PreverifiableOperation, ProvableOperation, VerifiableOperation, - verification_mode, + verification_mode, verification_mode::VerificationMode, }, - ops::channel::config::Keys, - transactions::hash::TxHashView, + ops::{SignedOp, channel::config::Keys}, + transactions::{hash::TxHashView, states::VerificationState}, }, }; @@ -88,6 +90,10 @@ impl ProvableOperation for InscriptionOp { type Proof = Ed25519Signature; } +impl OperationGas for InscriptionOp { + const GAS_COST: Gas = Gas::new(56); +} + impl PreverifiableOperation for InscriptionOp { type Context<'a> = InscriptionPreverificationContext<'a>; type Error = Error; @@ -189,6 +195,14 @@ impl ExecutableOperation for InscriptionOp { } } +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} + #[cfg(test)] mod tests { use lb_utils::bounded::BoundedError; diff --git a/core/src/mantle/ops/channel/withdraw.rs b/core/src/mantle/ops/channel/withdraw.rs index d68f5f6a5..a082fa54b 100644 --- a/core/src/mantle/ops/channel/withdraw.rs +++ b/core/src/mantle/ops/channel/withdraw.rs @@ -4,17 +4,18 @@ use serde::{Deserialize, Serialize}; use crate::{ events::TxEvent, mantle::{ - TxHash, + TxHash, Value, channel::{Channels, Error}, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, Inputs, PreverifiableOperation, ProvableOperation, Utxos, - VerifiableOperation, verification_mode, + VerifiableOperation, verification_mode, verification_mode::VerificationMode, }, ops::{ - OpId, + OpId, SignedOp, channel::{ChannelId, verification::verify_channel_multi_sig}, }, - transactions::{OperationVerificationHelper, hash::TxHashView}, + transactions::{OperationVerificationHelper, hash::TxHashView, states::VerificationState}, }, proofs::channel_multi_sig_proof::ChannelMultiSigProof, sdp::locked_notes::LockedNotes, @@ -48,9 +49,15 @@ pub struct WithdrawExecutionContext { } impl ProvableOperation for ChannelWithdrawOp { + // `SignedOperationExecutionGas::gas_multiplier` below reads this proof's + // signature count. If this changes, update that too. type Proof = ChannelMultiSigProof; } +impl OperationGas for ChannelWithdrawOp { + const GAS_COST: Gas = Gas::new(56); +} + impl PreverifiableOperation for ChannelWithdrawOp { type Context<'a> = (); type Error = Error; @@ -142,3 +149,13 @@ impl ExecutableOperation for ChannelWithdrawOp { Ok((context, Vec::new())) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + let signature_count = self.proof().signatures().len(); + Value::try_from(signature_count) + .expect("Channel multi-signature proofs are bound to u16::MAX signatures.") + } +} diff --git a/core/src/mantle/ops/leader_claim.rs b/core/src/mantle/ops/leader_claim.rs index 093b965ce..62b8dfd0f 100644 --- a/core/src/mantle/ops/leader_claim.rs +++ b/core/src/mantle/ops/leader_claim.rs @@ -12,12 +12,16 @@ use crate::{ events::{TxEvent, TxEventPayload}, mantle::{ Note, Utxo, Value, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ ExecutableOperation, PreverifiableOperation, ProvableOperation, Utxos, - VerifiableOperation, verification_mode, + VerifiableOperation, verification_mode, verification_mode::VerificationMode, + }, + ops::{OpId, SignedOp}, + transactions::{ + hash::{TxHash, TxHashView}, + states::VerificationState, }, - ops::OpId, - transactions::hash::{TxHash, TxHashView}, }, proofs::leader_claim_proof::{ Groth16LeaderClaimProof, LeaderClaimProof as _, LeaderClaimPublic, @@ -182,6 +186,10 @@ impl ProvableOperation for LeaderClaimOp { type Proof = Groth16LeaderClaimProof; } +impl OperationGas for LeaderClaimOp { + const GAS_COST: Gas = Gas::new(580); +} + impl PreverifiableOperation for LeaderClaimOp { type Context<'a> = LeaderClaimPreverificationContext<'a>; type Error = LeaderClaimError; @@ -266,6 +274,14 @@ impl ExecutableOperation for LeaderClaimOp { } } +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} + #[cfg(test)] mod tests { use lb_mmr::MerkleMountainRange; diff --git a/core/src/mantle/ops/mod.rs b/core/src/mantle/ops/mod.rs index 28d17a0c9..582158ac7 100644 --- a/core/src/mantle/ops/mod.rs +++ b/core/src/mantle/ops/mod.rs @@ -22,7 +22,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub use signed_op::SignedOp; use super::{ - gas::{Gas, GasConstants}, + gas::{Gas, GasProfile}, ops::{ leader_claim::LeaderClaimOp, sdp::{SDPActiveOp, SDPDeclareOp, SDPWithdrawOp}, @@ -30,10 +30,13 @@ use super::{ }; use crate::{ crypto::{Digest as _, Hash, Hasher}, - mantle::ops::{ - internal::{OpDe, OpSer}, - pow::ClaimPowRewardOp, - transfer::TransferOp, + mantle::{ + gas::OperationGas, + ops::{ + internal::{OpDe, OpSer}, + pow::ClaimPowRewardOp, + transfer::TransferOp, + }, }, proofs::{ channel_multi_sig_proof::ChannelMultiSigProof, leader_claim_proof::Groth16LeaderClaimProof, @@ -203,6 +206,14 @@ impl BinaryDecode for Op { } } +const fn gas_constant_of(_op: &Op) -> Gas +where + Profile: GasProfile, + Op: OperationGas, +{ + Op::GAS_COST +} + // We just check that the enum discriminant tag is encoded correctly, so a // single fixture is fine here. // TODO: Remove once the `BinaryCodec` macro supports enums. @@ -226,19 +237,19 @@ impl Op { } #[must_use] - pub const fn execution_gas(&self) -> Gas { + pub const fn execution_gas(&self) -> Gas { match self { - Self::ChannelInscribe(_) => Constants::CHANNEL_INSCRIBE, - Self::ChannelConfig(_) => Constants::CHANNEL_CONFIG, - Self::ChannelDeposit(_) => Constants::CHANNEL_DEPOSIT, - Self::ChannelWithdraw(_) => Constants::CHANNEL_WITHDRAW, - Self::ChannelTransfer(_) => Constants::CHANNEL_TRANSFER, - Self::SDPDeclare(_) => Constants::SDP_DECLARE, - Self::SDPWithdraw(_) => Constants::SDP_WITHDRAW, - Self::SDPActive(_) => Constants::SDP_ACTIVE, - Self::LeaderClaim(_) => Constants::LEADER_CLAIM, - Self::Transfer(_) => Constants::TRANSFER, - Self::ClaimPowReward(_) => Constants::CLAIM_POW_REWARD, + Self::ChannelInscribe(op) => gas_constant_of(op), + Self::ChannelConfig(op) => gas_constant_of(op), + Self::ChannelDeposit(op) => gas_constant_of(op), + Self::ChannelWithdraw(op) => gas_constant_of(op), + Self::ChannelTransfer(op) => gas_constant_of(op), + Self::SDPDeclare(op) => gas_constant_of(op), + Self::SDPWithdraw(op) => gas_constant_of(op), + Self::SDPActive(op) => gas_constant_of(op), + Self::LeaderClaim(op) => gas_constant_of(op), + Self::Transfer(op) => gas_constant_of(op), + Self::ClaimPowReward(op) => gas_constant_of(op), } } diff --git a/core/src/mantle/ops/pow.rs b/core/src/mantle/ops/pow.rs index 8e4d0e4e5..bd25a7c20 100644 --- a/core/src/mantle/ops/pow.rs +++ b/core/src/mantle/ops/pow.rs @@ -12,6 +12,7 @@ use crate::{ events::{TxEvent, TxEventPayload}, mantle::{ Note, TxHash, Utxo, Value, + gas::{Gas, MainnetGasProfile, OperationGas}, ledger::{ ExecutableOperation, PreverifiableOperation, ProvableOperation, Utxos, VerifiableOperation, verification_mode, @@ -266,6 +267,10 @@ impl ProvableOperation for ClaimPowRewardOp { type Proof = NoOpProof; } +impl OperationGas for ClaimPowRewardOp { + const GAS_COST: Gas = Gas::new(1); +} + impl PreverifiableOperation for ClaimPowRewardOp { type Context<'a> = (); type Error = ClaimPowRewardError; diff --git a/core/src/mantle/ops/sdp/active.rs b/core/src/mantle/ops/sdp/active.rs index bfdf512f7..825a42278 100644 --- a/core/src/mantle/ops/sdp/active.rs +++ b/core/src/mantle/ops/sdp/active.rs @@ -7,11 +7,14 @@ use super::{SDPActiveOp, SdpError}; use crate::{ events::TxEvent, mantle::{ + Value, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ Declarations, ExecutableOperation, PreverifiableOperation, ProvableOperation, - VerifiableOperation, verification_mode, + VerifiableOperation, verification_mode, verification_mode::VerificationMode, }, - transactions::hash::TxHashView, + ops::SignedOp, + transactions::{hash::TxHashView, states::VerificationState}, }, }; @@ -32,6 +35,10 @@ impl ProvableOperation for SDPActiveOp { type Proof = ZkSignature; } +impl OperationGas for SDPActiveOp { + const GAS_COST: Gas = Gas::new(590); +} + impl PreverifiableOperation for SDPActiveOp { type Context<'a> = (); type Error = SdpError; @@ -110,3 +117,11 @@ impl ExecutableOperation for SDPActiveOp { Ok((context, Vec::new())) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} diff --git a/core/src/mantle/ops/sdp/declare.rs b/core/src/mantle/ops/sdp/declare.rs index 1d243f362..3b6be5753 100644 --- a/core/src/mantle/ops/sdp/declare.rs +++ b/core/src/mantle/ops/sdp/declare.rs @@ -5,14 +5,15 @@ use super::{SDPDeclareOp, SdpError}; use crate::{ events::TxEvent, mantle::{ - Note, + Note, Value, channel::Channels, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ Declarations, ExecutableOperation, PreverifiableOperation, ProvableOperation, Utxos, - VerifiableOperation, verification_mode, + VerifiableOperation, verification_mode, verification_mode::VerificationMode, }, - ops::ZkAndEd25519Proof, - transactions::hash::TxHashView, + ops::{SignedOp, ZkAndEd25519Proof}, + transactions::{hash::TxHashView, states::VerificationState}, }, sdp::{Declaration, MinStake, locked_notes::LockedNotes}, }; @@ -158,6 +159,10 @@ impl ProvableOperation for SDPDeclareOp { type Proof = ZkAndEd25519Proof; } +impl OperationGas for SDPDeclareOp { + const GAS_COST: Gas = Gas::new(646); +} + impl PreverifiableOperation for SDPDeclareOp { type Context<'a> = SDPDeclarePreverificationContext<'a>; type Error = SdpError; @@ -249,6 +254,14 @@ impl ExecutableOperation for SDPDeclareOp { } } +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} + #[cfg(test)] mod tests { use lb_cryptarchia_engine::Epoch; diff --git a/core/src/mantle/ops/sdp/withdraw.rs b/core/src/mantle/ops/sdp/withdraw.rs index aa90c4a49..cd44af139 100644 --- a/core/src/mantle/ops/sdp/withdraw.rs +++ b/core/src/mantle/ops/sdp/withdraw.rs @@ -7,11 +7,14 @@ use super::{SDPWithdrawOp, SdpError}; use crate::{ events::TxEvent, mantle::{ + Value, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ Declarations, ExecutableOperation, PreverifiableOperation, ProvableOperation, - VerifiableOperation, verification_mode, + VerifiableOperation, verification_mode, verification_mode::VerificationMode, }, - transactions::hash::TxHashView, + ops::SignedOp, + transactions::{hash::TxHashView, states::VerificationState}, }, sdp::{self, locked_notes::LockedNotes}, }; @@ -35,6 +38,10 @@ impl ProvableOperation for SDPWithdrawOp { type Proof = ZkSignature; } +impl OperationGas for SDPWithdrawOp { + const GAS_COST: Gas = Gas::new(590); +} + impl PreverifiableOperation for SDPWithdrawOp { type Context<'a> = (); type Error = SdpError; @@ -145,3 +152,11 @@ impl ExecutableOperation for SDPWithdrawOp { Ok((context, Vec::new())) } } + +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} diff --git a/core/src/mantle/ops/signed_op.rs b/core/src/mantle/ops/signed_op.rs index 2597bdc32..36cff9a7a 100644 --- a/core/src/mantle/ops/signed_op.rs +++ b/core/src/mantle/ops/signed_op.rs @@ -3,6 +3,8 @@ use std::marker::PhantomData; use crate::{ events::TxEvent, mantle::{ + GasProfile, + gas::{Gas, OperationGas}, ledger::{ ExecutableOperation, Operation, PreverifiableOperation, ProvableOperation, VerifiableOperation, verification_mode::VerificationMode, @@ -91,3 +93,13 @@ impl, Mode: VerificationMode> SignedOp { self.operation.execute(context) } } + +impl OperationGas for SignedOp +where + Profile: GasProfile, + T: OperationGas + ProvableOperation, + State: VerificationState, + Mode: VerificationMode, +{ + const GAS_COST: Gas = T::GAS_COST; +} diff --git a/core/src/mantle/ops/transfer.rs b/core/src/mantle/ops/transfer.rs index 2a79767e9..238557c25 100644 --- a/core/src/mantle/ops/transfer.rs +++ b/core/src/mantle/ops/transfer.rs @@ -6,13 +6,16 @@ use thiserror::Error; use crate::{ events::TxEvent, mantle::{ + Value, channel::Channels, + gas::{Gas, MainnetGasProfile, OperationGas, SignedOperationExecutionGas}, ledger::{ self, ExecutableOperation, Inputs, Outputs, PreverifiableOperation, ProvableOperation, Utxo, Utxos, VerifiableOperation, verification_mode, + verification_mode::VerificationMode, }, - ops::OpId, - transactions::hash::TxHashView, + ops::{OpId, SignedOp}, + transactions::{hash::TxHashView, states::VerificationState}, }, sdp::locked_notes::LockedNotes, }; @@ -88,6 +91,10 @@ impl ProvableOperation for TransferOp { type Proof = ZkSignature; } +impl OperationGas for TransferOp { + const GAS_COST: Gas = Gas::new(590); +} + impl PreverifiableOperation for TransferOp { type Context<'a> = (); type Error = TransferError; @@ -147,6 +154,14 @@ impl ExecutableOperation for TransferOp { } } +impl SignedOperationExecutionGas + for SignedOp +{ + fn gas_multiplier(&self) -> Value { + 1 + } +} + #[cfg(test)] mod test { use lb_poseidon2::Fr; diff --git a/core/src/mantle/traits/mantle_tx.rs b/core/src/mantle/traits/mantle_tx.rs index a941c1f4f..ac064986a 100644 --- a/core/src/mantle/traits/mantle_tx.rs +++ b/core/src/mantle/traits/mantle_tx.rs @@ -1,5 +1,5 @@ use crate::mantle::{ - GasCalculator, Op, OpProof, + Op, OpProof, TxGasCalculator, traits::{Hashable, StorageSize}, transactions::{hash::TxHash, mantle_tx::RawMantleTx}, }; @@ -7,7 +7,7 @@ use crate::mantle::{ pub type OpWithProof<'a> = (&'a Op, &'a OpProof); // TODO: Supertrait to MantleTx and propagate -pub trait MantleTxWithProofs: Hashable + GasCalculator + StorageSize { +pub trait MantleTxWithProofs: Hashable + TxGasCalculator + StorageSize { /// Returns the underlying `MantleTx` that this transaction represents. fn mantle_tx(&self) -> &RawMantleTx; @@ -15,13 +15,3 @@ pub trait MantleTxWithProofs: Hashable + GasCalculator + StorageS /// in this transaction. fn ops_with_proof(&self) -> impl Iterator>; } - -impl MantleTxWithProofs for &T { - fn mantle_tx(&self) -> &RawMantleTx { - T::mantle_tx(self) - } - - fn ops_with_proof(&self) -> impl Iterator> { - T::ops_with_proof(self) - } -} diff --git a/core/src/mantle/traits/preverified_tx.rs b/core/src/mantle/traits/preverified_tx.rs index 128e52ea7..35fea244f 100644 --- a/core/src/mantle/traits/preverified_tx.rs +++ b/core/src/mantle/traits/preverified_tx.rs @@ -4,9 +4,3 @@ pub trait PreverifiedMantleTx: MantleTxWithProofs { /// Returns the cursor to the verified operations in this transaction. fn verified_ops(&self) -> VerifiedOps<'_>; } - -impl PreverifiedMantleTx for &T { - fn verified_ops(&self) -> VerifiedOps<'_> { - T::verified_ops(self) - } -} diff --git a/core/src/mantle/transactions/builder.rs b/core/src/mantle/transactions/builder.rs index 88236b5ae..b0c0a3442 100644 --- a/core/src/mantle/transactions/builder.rs +++ b/core/src/mantle/transactions/builder.rs @@ -7,7 +7,7 @@ use thiserror::Error; use crate::{ mantle::{ - GasConstants, Note, NoteId, Op, Utxo, Value, + GasProfile, Note, NoteId, Op, Utxo, Value, gas::{GasCost, GasOverflow}, ledger::{BoundedUtxos, Inputs, Outputs}, ops::{channel::ChannelId, transfer::TransferOp}, @@ -141,7 +141,7 @@ impl MantleTxBuilder { /// `priority_fee` is deliberately left unreturned: the resulting excess /// balance above the mandatory fee is the transaction's execution tip. - pub fn return_change( + pub fn return_change( self, context: &MantleTxContext, change_pk: ZkPublicKey, @@ -222,7 +222,7 @@ impl MantleTxBuilder { /// Predicts the minimum gas cost of the transaction once signed. /// See [`RawMantleTx::minimum_total_gas_cost`] to understand why this is /// only a minimum, not an exact cost. - pub fn minimum_gas_cost( + pub fn minimum_gas_cost( &self, context: &MantleTxContext, ) -> Result { @@ -246,7 +246,7 @@ impl MantleTxBuilder { Ok(build.minimum_total_gas_cost::(&context.gas_context)?) } - pub fn funding_delta( + pub fn funding_delta( &self, context: &MantleTxContext, ) -> Result { @@ -307,7 +307,7 @@ mod tests { use super::*; use crate::{ mantle::{ - gas::MainnetGasConstants, + gas::MainnetGasProfile, ops::{ channel::{ deposit::{DepositOp, Metadata}, @@ -376,7 +376,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 ); @@ -408,7 +408,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 ); @@ -439,7 +439,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 ); @@ -467,7 +467,7 @@ mod tests { leader_reward_amount: 0, }; - let result = builder.minimum_gas_cost::(&context); + let result = builder.minimum_gas_cost::(&context); assert!(matches!( result, @@ -501,7 +501,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 ); @@ -528,14 +528,14 @@ mod tests { assert_eq!(builder.net_balance(), 10); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 10 // zero gas price for now ); // Add change note let builder = builder - .return_change::(&context, ZkPublicKey::zero(), 0) + .return_change::(&context, ZkPublicKey::zero(), 0) .unwrap() .unwrap(); @@ -543,7 +543,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 // zero gas price for now ); @@ -593,7 +593,7 @@ mod tests { assert_eq!(builder.net_balance(), -40); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), -40 // zero gas price for now ); @@ -607,7 +607,7 @@ mod tests { assert_eq!(builder.net_balance(), 0); assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .unwrap(), 0 // zero gas price for now ); diff --git a/core/src/mantle/transactions/genesis_tx.rs b/core/src/mantle/transactions/genesis_tx.rs index b21ebf67b..28e162f41 100644 --- a/core/src/mantle/transactions/genesis_tx.rs +++ b/core/src/mantle/transactions/genesis_tx.rs @@ -10,7 +10,7 @@ use crate::{ crypto::{Digest as _, Hasher}, mantle::{ OpProof, SignedMantleTx, - gas::{Gas, GasCalculator, GasConstants, GasCost, GasOverflow}, + gas::{Gas, GasCost, GasOverflow, GasProfile, TxGasCalculator}, ops::{ Op, channel::{ChannelId, MsgId, inscribe::InscriptionOp}, @@ -160,10 +160,10 @@ impl Hashable for GenesisTx { } } -impl GasCalculator for GenesisTx { +impl TxGasCalculator for GenesisTx { type Context = (); - fn total_gas_cost( + fn total_gas_cost( &self, _context: &Self::Context, ) -> Result { @@ -176,7 +176,7 @@ impl GasCalculator for GenesisTx { Ok(0.into()) } - fn execution_gas_consumption( + fn execution_gas_consumption( &self, _context: &Self::Context, ) -> Result { diff --git a/core/src/mantle/transactions/mantle_tx.rs b/core/src/mantle/transactions/mantle_tx.rs index 5892c06b8..49c903169 100644 --- a/core/src/mantle/transactions/mantle_tx.rs +++ b/core/src/mantle/transactions/mantle_tx.rs @@ -8,7 +8,7 @@ use crate::{ block::MAX_BLOCK_TRANSACTIONS_SIZE, crypto::{Digest as _, Hasher}, mantle::{ - GasConstants, Op, SignedMantleTx, TxHash, Value, + GasProfile, Op, SignedMantleTx, TxHash, Value, channel::Channels, gas::{Gas, GasCost, GasOverflow}, ops::{ @@ -31,12 +31,12 @@ impl RawMantleTx { /// Predicts the minimum total gas cost of the transaction once signed. /// /// See [`minimum_signed_mantle_tx_size`] for why this doesn't implement - /// [`crate::mantle::GasCalculator`] which calculates an exact gas cost. - pub fn minimum_total_gas_cost( + /// [`crate::mantle::TxGasCalculator`] which calculates an exact gas cost. + pub fn minimum_total_gas_cost( &self, context: &MantleTxGasContext, ) -> Result { - let execution_gas = self.minimum_execution_gas_consumption::(context)?; + let execution_gas = self.minimum_execution_gas_consumption::(context)?; let execution_gas_cost = GasCost::calculate(execution_gas, context.gas_prices.execution_base_gas_price)?; let storage_gas_cost = self.minimum_storage_gas_cost(context)?; @@ -46,13 +46,13 @@ impl RawMantleTx { /// Predicts the minimum execution gas the transaction will consume once /// signed. - pub fn minimum_execution_gas_consumption( + pub fn minimum_execution_gas_consumption( &self, context: &MantleTxGasContext, ) -> Result { self.ops() .iter() - .map(|op| contextual_op_execution_gas::(op, context)) + .map(|op| contextual_op_execution_gas::(op, context)) .try_fold(Gas::from(0), |total, gas| total.checked_add(gas?)) } @@ -117,7 +117,7 @@ impl StorageSize for RawMantleTx { } } -fn contextual_op_execution_gas( +fn contextual_op_execution_gas( op: &Op, context: &MantleTxGasContext, ) -> Result { @@ -133,10 +133,10 @@ fn contextual_op_execution_gas( Op::ChannelTransfer(operation) => context .transfer_threshold(&operation.channel_id) .unwrap_or(0), - _ => return Ok(op.execution_gas::()), + _ => return Ok(op.execution_gas::()), }; - op.execution_gas::() + op.execution_gas::() .checked_mul(Value::from(multiplier)) } diff --git a/core/src/mantle/transactions/signed_mantle_tx.rs b/core/src/mantle/transactions/signed_mantle_tx.rs index bea8e654f..e2769a977 100644 --- a/core/src/mantle/transactions/signed_mantle_tx.rs +++ b/core/src/mantle/transactions/signed_mantle_tx.rs @@ -6,7 +6,7 @@ use crate::{ crypto::{Digest as _, Hasher}, mantle::{ RawMantleTx, Value, VerificationError, - gas::{Gas, GasCalculator, GasConstants, GasCost, GasOverflow}, + gas::{Gas, GasCost, GasOverflow, GasProfile, TxGasCalculator}, ledger::{PreverifiableOperation, VerifiableOperation, verification_mode::StandardMode}, ops::{ Op, OpProof, @@ -391,27 +391,27 @@ impl MantleTxWithProofs for SignedMantleTx { } } -impl GasCalculator for SignedMantleTx { +impl TxGasCalculator for SignedMantleTx { type Context = GasPrices; - fn total_gas_cost( + fn total_gas_cost( &self, context: &Self::Context, ) -> Result { - let execution_gas = GasCalculator::execution_gas_consumption::(&self, context)?; + let execution_gas = TxGasCalculator::execution_gas_consumption::(self, context)?; let execution_gas_cost = GasCost::calculate(execution_gas, context.execution_base_gas_price)?; - let storage_gas_cost = GasCalculator::storage_gas_cost(self, context)?; + let storage_gas_cost = TxGasCalculator::storage_gas_cost(self, context)?; execution_gas_cost.checked_add(storage_gas_cost) } fn storage_gas_cost(&self, context: &Self::Context) -> Result { - let storage_gas = GasCalculator::storage_gas_consumption(&self, context)?; + let storage_gas = TxGasCalculator::storage_gas_consumption(self, context)?; GasCost::calculate(storage_gas, context.storage_gas_price) } - fn execution_gas_consumption( + fn execution_gas_consumption( &self, _context: &Self::Context, ) -> Result { @@ -419,7 +419,7 @@ impl GasCalculator for SignedMantleTx { .ops() .iter() .zip(self.ops_proofs.iter()) - .map(|(op, proof)| signed_op_execution_gas::(op, proof)) + .map(|(op, proof)| signed_op_execution_gas::(op, proof)) .try_fold(Gas::from(0), |total, gas| total.checked_add(gas?)) } @@ -428,7 +428,7 @@ impl GasCalculator for SignedMantleTx { } } -fn signed_op_execution_gas( +fn signed_op_execution_gas( op: &Op, proof: &OpProof, ) -> Result { @@ -440,12 +440,12 @@ fn signed_op_execution_gas( Op::ChannelConfig(_) | Op::ChannelWithdraw(_) | Op::ChannelTransfer(_), OpProof::ChannelMultiSigProof(proof), ) => proof.signatures().len(), - _ => return Ok(op.execution_gas::()), + _ => return Ok(op.execution_gas::()), }; let multiplier = Value::try_from(signature_count) .expect("channel multi-signature proofs are bounded to u16::MAX signatures"); - op.execution_gas::().checked_mul(multiplier) + op.execution_gas::().checked_mul(multiplier) } impl StorageSize for SignedMantleTx { @@ -635,7 +635,7 @@ mod tests { use crate::mantle::{ Note, NoteId, Utxo, channel::Error, - gas::MainnetGasConstants, + gas::MainnetGasProfile, ledger::{Inputs, Outputs, OutputsError}, ops::{ channel::{ @@ -700,7 +700,7 @@ mod tests { ); let gas = mantle_tx - .minimum_execution_gas_consumption::(&context) + .minimum_execution_gas_consumption::(&context) .unwrap(); let expected_config_gas = u64::from(config_threshold) * 56; @@ -751,7 +751,7 @@ mod tests { ); let gas_prices = GasPrices::new(1, 0); - let gas = GasCalculator::execution_gas_consumption::( + let gas = TxGasCalculator::execution_gas_consumption::( &signed_tx, &gas_prices, ) diff --git a/ledger/src/cryptarchia/mod.rs b/ledger/src/cryptarchia/mod.rs index f8176e6ae..02a979112 100644 --- a/ledger/src/cryptarchia/mod.rs +++ b/ledger/src/cryptarchia/mod.rs @@ -9,7 +9,7 @@ use lb_core::{ events::TxEvent, mantle::{ NoteId, Utxo, Value, - gas::{Gas, GasConstants, GasCost, GasOverflow, GasPrice}, + gas::{Gas, GasCost, GasOverflow, GasPrice, GasProfile}, ledger::ExecutableOperation as _, ops::transfer::TransferOp, traits::GenesisTx, @@ -465,7 +465,7 @@ impl LedgerState { .increment_block_density(slot)) } - pub fn try_apply_transfer( + pub fn try_apply_transfer( mut self, transfer_op: &TransferOp, ) -> Result<(Self, Balance, Vec), LedgerError> { @@ -740,10 +740,10 @@ pub mod tests { use lb_core::{ crypto::{Digest as _, Hasher}, mantle::{ - GasCalculator as _, Note, Op, + Note, Op, OpProof::ZkSig, - RawMantleTx, SignedMantleTx, - gas::MainnetGasConstants, + RawMantleTx, SignedMantleTx, TxGasCalculator as _, + gas::MainnetGasProfile, ledger::{Inputs, Outputs}, ops::{leader_claim::VoucherCm, sdp::SDPDeclareOp}, traits::Hashable as _, @@ -856,7 +856,7 @@ pub mod tests { .update_epoch_state::(slot, &SdpLedger::new(0.into()), ledger.config())?; let id = make_id(parent, slot, utxo); let proof = generate_proof(&ledger_state, &utxo, slot); - let (_, state, _) = ledger.prepare_update::<_, _, MainnetGasConstants>( + let (_, state, _) = ledger.prepare_update::<_, _, MainnetGasProfile>( id, parent, slot, @@ -1607,8 +1607,8 @@ pub mod tests { vec![output_note], ); - let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); - let result = ledger_state.try_apply_transfer::<(), MainnetGasConstants>(&transfer_op); + let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); + let result = ledger_state.try_apply_transfer::<(), MainnetGasProfile>(&transfer_op); assert!(result.is_err()); } @@ -1632,9 +1632,9 @@ pub mod tests { let (tx, transfer_op, _transfer_sig) = create_tx_with_transfer(&[(¬e_sk, &input_utxo)], vec![output_note1, output_note2]); - let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); + let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); let (new_state, balance, events) = ledger_state - .try_apply_transfer::<(), MainnetGasConstants>(&transfer_op) + .try_apply_transfer::<(), MainnetGasProfile>(&transfer_op) .unwrap(); assert_eq!( @@ -1664,9 +1664,9 @@ pub mod tests { vec![], ); - let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); + let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); let (final_state, final_balance, events) = new_state - .try_apply_transfer::<(), MainnetGasConstants>(&transfer_op) + .try_apply_transfer::<(), MainnetGasProfile>(&transfer_op) .unwrap(); assert_eq!( @@ -1719,7 +1719,7 @@ pub mod tests { create_tx_with_transfer(&[(&ZkKey::zero(), &non_existent_utxo)], vec![]); let result = ledger_state .clone() - .try_apply_transfer::<(), MainnetGasConstants>(&transfer_op); + .try_apply_transfer::<(), MainnetGasProfile>(&transfer_op); assert!(matches!(result, Err(LedgerError::Mantle(_)))); } } @@ -1742,7 +1742,7 @@ pub mod tests { let (_, balance, events) = ledger_state .clone() - .try_apply_transfer::<(), MainnetGasConstants>(&transfer_op) + .try_apply_transfer::<(), MainnetGasProfile>(&transfer_op) .unwrap(); assert_eq!(balance, -1); assert!(events.is_empty()); @@ -1751,7 +1751,7 @@ pub mod tests { create_tx_with_transfer(&[(&input_sk, &input_utxo)], vec![output_note]); assert_eq!( ledger_state - .try_apply_transfer::<(), MainnetGasConstants>(&transfer_op,) + .try_apply_transfer::<(), MainnetGasProfile>(&transfer_op,) .unwrap() .1, 0 @@ -1772,8 +1772,8 @@ pub mod tests { let (tx, transfer_op, _transfer_sig) = create_tx_with_transfer(&[(&input_sk, &input_utxo)], vec![]); - let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); - let result = ledger_state.try_apply_transfer::<(), MainnetGasConstants>(&transfer_op); + let _fees = tx.total_gas_cost::(&GasPrices::new(0, 0)); + let result = ledger_state.try_apply_transfer::<(), MainnetGasProfile>(&transfer_op); assert!(result.is_ok()); let (new_state, balance, events) = result.unwrap(); diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index c4797c9fc..3d1b0232c 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -17,7 +17,7 @@ use lb_core::{ events::{Events, HeaderEvent, TxEvent, TxEventPayload}, mantle::{ NoteId, Op, Utxo, Value, VerificationError, - gas::{Gas, GasConstants, GasCost, GasOverflow}, + gas::{Gas, GasCost, GasOverflow, GasProfile}, ledger::ExecutableOperation as _, ops::{ channel::{ @@ -152,7 +152,7 @@ where /// /// On success, a new [`LedgerState`] is returned, which can then be /// committed by calling [`Self::commit_update`]. - pub fn prepare_update<'tx, Tx, LeaderProof, Constants>( + pub fn prepare_update<'tx, Tx, LeaderProof, Profile>( &self, id: Id, parent_id: Id, @@ -163,7 +163,7 @@ where where Tx: PreverifiedMantleTx + 'tx, LeaderProof: leader_proof::LeaderProof, - Constants: GasConstants, + Profile: GasProfile, Id: Into, { let parent_state = self @@ -171,7 +171,7 @@ where .get(&parent_id) .ok_or(LedgerError::ParentNotFound(parent_id))?; - let (new_state, events) = parent_state.clone().try_update::<_, _, _, Constants>( + let (new_state, events) = parent_state.clone().try_update::<_, _, _, Profile>( id, slot, proof, @@ -225,7 +225,7 @@ pub struct LedgerState { } impl LedgerState { - fn try_update<'tx, Tx, LeaderProof, Id, Constants>( + fn try_update<'tx, Tx, LeaderProof, Id, Profile>( self, block_id: Id, slot: Slot, @@ -236,7 +236,7 @@ impl LedgerState { where Tx: PreverifiedMantleTx + 'tx, LeaderProof: leader_proof::LeaderProof, - Constants: GasConstants, + Profile: GasProfile, Id: Into, { let (mut state, header_events) = self.try_apply_header(slot, proof, config)?; @@ -245,7 +245,7 @@ impl LedgerState { // block's id is known — unlike a proposer's direct // `try_apply_header` call for a block still being built. state.mantle_ledger.add_seen_block(block_id.into(), slot); - let (mut state, tx_events) = state.try_apply_contents::<_, _, Constants>(config, txs)?; + let (mut state, tx_events) = state.try_apply_contents::<_, _, Profile>(config, txs)?; state.update_pow_difficulty( // count all claimed rewards tx_events @@ -412,7 +412,7 @@ impl LedgerState { } /// Apply the contents of an update to the ledger state. - pub fn try_apply_contents<'tx, Tx, Id, Constants: GasConstants>( + pub fn try_apply_contents<'tx, Tx, Id, Profile: GasProfile>( mut self, config: &Config, txs: impl Iterator, @@ -429,7 +429,7 @@ impl LedgerState { for tx in txs { let balance; let events; - (self, balance, events) = self.try_apply_tx::<_, _, Constants>(config, tx)?; + (self, balance, events) = self.try_apply_tx::<_, _, Profile>(config, tx)?; tx_events.extend(events); let gas_prices = GasPrices { @@ -437,7 +437,7 @@ impl LedgerState { storage_gas_price: *self.cryptarchia_ledger.storage_gas_price(), }; // Check the transaction is balanced - let total_gas_cost = tx.total_gas_cost::(&gas_prices)?; + let total_gas_cost = tx.total_gas_cost::(&gas_prices)?; tracing::debug!( balance, total_gas_cost = total_gas_cost.into_inner(), @@ -454,7 +454,7 @@ impl LedgerState { // Update the total of fee burned and tipped in the block let tx_fee_burned = GasCost::calculate( - tx.execution_gas_consumption::(&gas_prices)?, + tx.execution_gas_consumption::(&gas_prices)?, gas_prices.execution_base_gas_price, )? .checked_add(tx.storage_gas_cost(&gas_prices)?)?; @@ -463,7 +463,7 @@ impl LedgerState { total_fee_burned = total_fee_burned.checked_add(tx_fee_burned)?; total_fee_tip = total_fee_tip.checked_add(tx_fee_tip)?; total_block_execution_gas = total_block_execution_gas - .checked_add(tx.execution_gas_consumption::(&gas_prices)?)?; + .checked_add(tx.execution_gas_consumption::(&gas_prices)?)?; total_block_storage_gas = total_block_storage_gas.checked_add(tx.storage_gas_consumption(&gas_prices)?)?; @@ -584,7 +584,7 @@ impl LedgerState { clippy::too_many_lines, reason = "This will be refactored in an upcoming PR." )] - fn try_apply_op( + fn try_apply_op( mut self, op: &Op, config: &Config, @@ -693,7 +693,7 @@ impl LedgerState { let events; (self.cryptarchia_ledger, transfer_balance, events) = self.cryptarchia_ledger - .try_apply_transfer::<_, Constants>(op)?; + .try_apply_transfer::<_, Profile>(op)?; balance = balance .checked_add(transfer_balance) .ok_or(LedgerError::BalanceOverflow)?; @@ -740,7 +740,7 @@ impl LedgerState { /// /// If any operation fails verification or execution, returns a /// [`LedgerError`] describing the failure. - fn try_apply_tx<'tx, Tx, Id, Constants: GasConstants>( + fn try_apply_tx<'tx, Tx, Id, Profile: GasProfile>( mut self, config: &Config, tx: &'tx Tx, @@ -762,7 +762,7 @@ impl LedgerState { let Some(op) = verified_ops.next(&helper).transpose()? else { break; }; - (self, balance, tx_events) = self.try_apply_op::<_, Constants>( + (self, balance, tx_events) = self.try_apply_op::<_, Profile>( op, config, verified_ops.tx_hash_view().tx_hash(), @@ -784,8 +784,8 @@ mod tests { use cryptarchia::tests::{config, generate_proof, utxo}; use lb_core::{ mantle::{ - GasCalculator as _, Note, OpProof, RawMantleTx, SignedMantleTx, - gas::MainnetGasConstants, + Note, OpProof, RawMantleTx, SignedMantleTx, TxGasCalculator as _, + gas::MainnetGasProfile, ledger::{Inputs, Outputs, Utxos, VerifiableOperation as _}, ops::{ OpId as _, @@ -959,7 +959,7 @@ mod tests { &Key::Ed25519(signing_key.clone()), ); ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(config, &tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(config, &tx) .unwrap() .0 } @@ -1029,7 +1029,7 @@ mod tests { let default_gas_prices = GasPrices::default(); let fees = tx - .total_gas_cost::(&default_gas_prices) + .total_gas_cost::(&default_gas_prices) .unwrap(); output_note.value = utxo.note.value - fees.into_inner(); @@ -1048,7 +1048,7 @@ mod tests { let new_id = [1; 32]; let (_, state, events) = ledger - .prepare_update::<_, _, MainnetGasConstants>( + .prepare_update::<_, _, MainnetGasProfile>( new_id, genesis_id, Slot::from(1u64), @@ -1087,7 +1087,7 @@ mod tests { }; let tx = create_signed_tx(Op::ChannelInscribe(inscribe_op), &Key::Ed25519(signing_key)); - let result = state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx); + let result = state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx); assert!(result.is_ok()); let (new_state, _, events) = result.unwrap(); @@ -1132,7 +1132,7 @@ mod tests { Op::ChannelConfig(config_op), &Key::MultiSequencer(config_proof), ); - let result = state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx); + let result = state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx); assert!(result.is_ok()); let (new_state, _, events) = result.unwrap(); @@ -1188,8 +1188,7 @@ mod tests { }; let ops = vec![Op::ChannelDeposit(deposit.clone())]; let tx = create_multi_signed_tx(ops, vec![&Key::Zk(sk)]); - let result = - ledger_state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx); + let result = ledger_state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx); let (new_state, balance, events) = result.unwrap(); // The deposited note is consumed and re-created as a channel note under // a new NoteId. @@ -1267,7 +1266,7 @@ mod tests { let deposit_ops = vec![Op::ChannelDeposit(deposit)]; let tx = create_multi_signed_tx(deposit_ops, vec![&Key::Zk(sk)]); ledger_state = ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx) .unwrap() .0; @@ -1301,7 +1300,7 @@ mod tests { ); let result = - ledger_state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &signed_tx); + ledger_state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &signed_tx); assert!(result.is_ok()); let (new_state, tx_balance, events) = result.unwrap(); @@ -1342,7 +1341,7 @@ mod tests { let deposit_tx = create_multi_signed_tx(vec![Op::ChannelDeposit(deposit)], vec![&Key::Zk(sk)]); ledger_state = ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &deposit_tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &deposit_tx) .unwrap() .0; @@ -1368,15 +1367,15 @@ mod tests { vec![&Key::MultiSequencer(withdraw_proof)], ); ledger_state = ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &signed_withdraw) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &signed_withdraw) .unwrap() .0; assert!(!ledger_state.latest_utxos().contains(&utxo.id())); // Replaying the signed deposit fails: its input no longer exists. - let result = ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &deposit_tx); + let result = + ledger_state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &deposit_tx); assert!(result.is_err()); } @@ -1406,7 +1405,7 @@ mod tests { let deposit_ops = vec![Op::ChannelDeposit(deposit)]; let tx = create_multi_signed_tx(deposit_ops, vec![&Key::Zk(sk)]); ledger_state = ledger_state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx) .unwrap() .0; // The deposit re-created the note as a channel note @@ -1441,7 +1440,7 @@ mod tests { let err = ledger_state .clone() - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &signed_tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &signed_tx) .unwrap_err(); assert_eq!( err, @@ -1479,7 +1478,7 @@ mod tests { &Key::Ed25519(signing_key.clone()), ); state = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &first_tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &first_tx) .unwrap() .0; @@ -1498,7 +1497,7 @@ mod tests { ); let result = state .clone() - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &second_tx); + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &second_tx); assert!(matches!( result, Err(LedgerError::VerificationError( @@ -1522,7 +1521,7 @@ mod tests { &Key::Ed25519(signing_key), ); let empty_result = - state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &empty_tx); + state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &empty_tx); assert!(matches!( empty_result, Err(LedgerError::VerificationError( @@ -1555,7 +1554,7 @@ mod tests { &Key::Ed25519(signing_key), ); state = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &first_tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &first_tx) .unwrap() .0; @@ -1571,8 +1570,7 @@ mod tests { Op::ChannelInscribe(second_inscribe), &Key::Ed25519(unauthorized_signing_key), ); - let result = - state.try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &second_tx); + let result = state.try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &second_tx); assert!(matches!( result, Err(LedgerError::VerificationError( @@ -1657,7 +1655,7 @@ mod tests { ); let result = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&test_config, &tx) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&test_config, &tx) .unwrap() .0; @@ -1799,7 +1797,7 @@ mod tests { ); // Pays 2925 fees = 2705 execution base fee + 0 execution tip + 220 storage let fees = tx - .total_gas_cost::(&ledger.get_gas_prices()) + .total_gas_cost::(&ledger.get_gas_prices()) .unwrap(); output_note.value = utxo.note.value - fees.into_inner(); let tx = create_tx(vec![utxo.id()], vec![output_note], &[sk]) @@ -1808,7 +1806,7 @@ mod tests { let result = ledger .clone() - .try_apply_contents::<_, HeaderId, MainnetGasConstants>(&config, std::iter::once(&tx)); + .try_apply_contents::<_, HeaderId, MainnetGasProfile>(&config, std::iter::once(&tx)); // The `unwrap` should succeed because the user pays at least the base fee of // 2705 result.unwrap(); @@ -1816,7 +1814,7 @@ mod tests { ledger.cryptarchia_ledger = ledger.cryptarchia_ledger.set_execution_base_fee(10.into()); let err = ledger - .try_apply_contents::<_, HeaderId, MainnetGasConstants>(&config, std::iter::once(&tx)) + .try_apply_contents::<_, HeaderId, MainnetGasProfile>(&config, std::iter::once(&tx)) .unwrap_err(); // The transaction should be rejected because the price indicated for execution // doesn't cover the base fee that cost 27 050 @@ -1840,7 +1838,7 @@ mod tests { // The tx pays 794 fees = 590 execution base fee + 0 execution tip + 204 // storage let fees = tx - .total_gas_cost::(&ledger.get_gas_prices()) + .total_gas_cost::(&ledger.get_gas_prices()) .unwrap(); output_note.value = utxo.note.value - fees.into_inner(); let tx = create_tx( @@ -1853,7 +1851,7 @@ mod tests { let result = ledger .clone() - .try_apply_contents::<_, HeaderId, MainnetGasConstants>(&config, std::iter::once(&tx)); + .try_apply_contents::<_, HeaderId, MainnetGasProfile>(&config, std::iter::once(&tx)); // The `unwrap` should succeed because the user pays at least the base fee of // 794 let (no_priority_fee_ledger, events) = result.unwrap(); @@ -1871,7 +1869,7 @@ mod tests { .unwrap(); let result = ledger - .try_apply_contents::<_, HeaderId, MainnetGasConstants>(&config, std::iter::once(&tx)); + .try_apply_contents::<_, HeaderId, MainnetGasProfile>(&config, std::iter::once(&tx)); // The `unwrap` should succeed because the user pays at least the base fee of // 794 let (priority_fee_ledger, events) = result.unwrap(); @@ -1913,7 +1911,7 @@ mod tests { assert!(storage_gas.into_inner() > 0); let (applied, _) = ledger - .try_apply_contents::<_, HeaderId, MainnetGasConstants>(&config, std::iter::once(&tx)) + .try_apply_contents::<_, HeaderId, MainnetGasProfile>(&config, std::iter::once(&tx)) .unwrap(); // Storage gas consumed by the tx should be accumulated in the ledger @@ -2174,7 +2172,7 @@ mod tests { assert_eq!(state.mantle_ledger.pow.epoch_reward(), 0); let err = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&config, &claim_tx()) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&config, &claim_tx()) .expect_err("claim should fail validation"); assert!(matches!( @@ -2193,7 +2191,7 @@ mod tests { let (state, config) = pow_ledger_state(1_000); let err = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&config, &claim_tx()) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&config, &claim_tx()) .expect_err("claim should fail validation"); assert!(matches!( @@ -2230,7 +2228,7 @@ mod tests { let epoch_reward = state.mantle_ledger.pow.epoch_reward(); let (state, _balance, events) = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&config, &claim_tx()) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&config, &claim_tx()) .expect("claim should validate and execute"); assert_eq!( @@ -2269,11 +2267,11 @@ mod tests { // during tx-level validation. let (state, config) = claim_accepting_state(); let (state, _, _) = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&config, &claim_tx()) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&config, &claim_tx()) .expect("first claim should succeed"); let err = state - .try_apply_tx::<_, HeaderId, MainnetGasConstants>(&config, &claim_tx()) + .try_apply_tx::<_, HeaderId, MainnetGasProfile>(&config, &claim_tx()) .expect_err("second claim should be rejected"); assert!(matches!( @@ -2303,7 +2301,7 @@ mod tests { let tx_hash = TxHash::from([9u8; 32]); let (state, _balance, events) = state - .try_apply_op::( + .try_apply_op::( &Op::ClaimPowReward(op.clone()), &config, &tx_hash, @@ -2372,22 +2370,10 @@ mod tests { let tx_hash = TxHash::from([9u8; 32]); let (state, _, _) = state - .try_apply_op::( - &op, - &config, - &tx_hash, - 0, - Vec::new(), - ) + .try_apply_op::(&op, &config, &tx_hash, 0, Vec::new()) .expect("first claim should succeed"); let (state, _, _) = state - .try_apply_op::( - &op, - &config, - &tx_hash, - 0, - Vec::new(), - ) + .try_apply_op::(&op, &config, &tx_hash, 0, Vec::new()) .expect("second claim currently also succeeds (no validation)"); assert_eq!( diff --git a/services/chain/chain-leader/src/lib.rs b/services/chain/chain-leader/src/lib.rs index e0ae89ab1..6ea1e83a1 100644 --- a/services/chain/chain-leader/src/lib.rs +++ b/services/chain/chain-leader/src/lib.rs @@ -21,7 +21,7 @@ use lb_core::{ header::HeaderId, mantle::{ SignedMantleTx, - gas::MainnetGasConstants, + gas::MainnetGasProfile, traits::{Hashable, MantleTxWithProofs, StorageSize}, transactions::{hash::TxHash, states::Preverified}, }, @@ -619,7 +619,7 @@ where for tx in pending { match ledger_state .clone() - .try_apply_contents::<_, HeaderId, MainnetGasConstants>( + .try_apply_contents::<_, HeaderId, MainnetGasProfile>( ledger_config, iter::once(&tx), ) { diff --git a/services/chain/chain-service/src/lib.rs b/services/chain/chain-service/src/lib.rs index 7e1ddefb1..3cbec021a 100644 --- a/services/chain/chain-service/src/lib.rs +++ b/services/chain/chain-service/src/lib.rs @@ -27,7 +27,7 @@ use lb_core::{ events::Events, header::HeaderId, mantle::{ - gas::MainnetGasConstants, + gas::MainnetGasProfile, traits::{MantleTxWithProofs, PreverifiedMantleTx}, transactions::GasPrices, }, @@ -379,7 +379,7 @@ impl Cryptarchia { // A block number of this block if it's applied to the chain. let (_, state, events) = self .ledger - .prepare_update::<_, _, MainnetGasConstants>( + .prepare_update::<_, _, MainnetGasProfile>( id, parent, slot, diff --git a/services/wallet/src/lib.rs b/services/wallet/src/lib.rs index 64c2ecef5..2383ad8ac 100644 --- a/services/wallet/src/lib.rs +++ b/services/wallet/src/lib.rs @@ -17,7 +17,7 @@ use lb_core::{ header::HeaderId, mantle::{ NoteId, Op, OpProof, SignedMantleTx, TxHash, Utxo, Value, VerificationError, - gas::{GasCost, GasOverflow, MainnetGasConstants}, + gas::{GasCost, GasOverflow, MainnetGasProfile}, ledger::Inputs, ops::{ NoOpProof, ZkAndEd25519Proof, @@ -557,7 +557,7 @@ where } }; - let funded = match state.fund_tx::( + let funded = match state.fund_tx::( tip, &tx_builder, change_pk, @@ -1267,7 +1267,7 @@ where pk: request.funding_pk, }))?; - let funded_tx_builder = state.fund_tx::( + let funded_tx_builder = state.fund_tx::( request.tip, &tx_builder, request.funding_pk, @@ -1299,7 +1299,7 @@ where ) -> Result, WalletServiceError> { let context = ledger.tx_context(); let net_balance = funded_tx_builder.net_balance(); - let gas_cost = funded_tx_builder.minimum_gas_cost::(&context)?; + let gas_cost = funded_tx_builder.minimum_gas_cost::(&context)?; debug!( target: LOG_TARGET, net_balance, diff --git a/services/wallet/src/states.rs b/services/wallet/src/states.rs index d9a3e02df..62cb1d95a 100644 --- a/services/wallet/src/states.rs +++ b/services/wallet/src/states.rs @@ -6,7 +6,7 @@ use std::{ use lb_core::{ header::HeaderId, mantle::{ - GasConstants, NoteId, Value, + GasProfile, NoteId, Value, ops::leader_claim::{VoucherCm, VoucherNullifier}, transactions::{MantleTxBuilder, MantleTxContext}, }, @@ -360,7 +360,7 @@ impl<'u> ServiceState<'u> { /// Fund `tx_builder` from the wallet's UTXOs at `tip`, excluding notes /// already reserved for in-flight transactions. `priority_fee` is left /// as excess balance above the mandatory fee (the execution tip). - pub fn fund_tx( + pub fn fund_tx( &self, tip: HeaderId, tx_builder: &MantleTxBuilder, diff --git a/tests/src/common/fee_spec.rs b/tests/src/common/fee_spec.rs index 73a3c9dee..fa263f90f 100644 --- a/tests/src/common/fee_spec.rs +++ b/tests/src/common/fee_spec.rs @@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet}; use lb_common_http_client::ApiBlock; use lb_core::mantle::{ Note, Op, SignedMantleTx, Utxo, - gas::{GasCalculator as _, MainnetGasConstants}, + gas::{MainnetGasProfile, TxGasCalculator as _}, traits::Hashable as _, transactions::{ GasPrices, MantleTxBuilder, MantleTxContext, MantleTxGasContext, @@ -157,7 +157,7 @@ pub fn self_transfer_paying_fee_at( let fee_for_output = |output_value: u64| { i128::from( builder_with_output(output_value) - .minimum_gas_cost::(&context) + .minimum_gas_cost::(&context) .expect("gas cost should calculate") .into_inner(), ) @@ -199,7 +199,7 @@ pub fn self_transfer_paying_fee_at( assert_eq!( builder - .funding_delta::(&context) + .funding_delta::(&context) .expect("funding delta should calculate"), tip, "the built transaction must carry exactly the requested tip" @@ -284,7 +284,7 @@ pub fn fee_surplus_at( ) -> Result { let paid = net_balance_against(genesis_utxos, tx)?; let required = tx - .total_gas_cost::(prices) + .total_gas_cost::(prices) .map_err(|source| format!("transaction gas cost calculation failed: {source}"))?; Ok(i128::from(paid) - i128::from(required.into_inner())) diff --git a/tests/src/common/wallet/funding_from_chain.rs b/tests/src/common/wallet/funding_from_chain.rs index 78bb2f7d4..695fc30ea 100644 --- a/tests/src/common/wallet/funding_from_chain.rs +++ b/tests/src/common/wallet/funding_from_chain.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use lb_common_http_client::Error as HttpClientError; use lb_core::mantle::{ Op, OpProof, SignedMantleTx, TxHash, Utxo, - gas::MainnetGasConstants, + gas::MainnetGasProfile, ops::channel::{ChannelId, ChannelKeyIndex}, traits::Hashable as _, transactions::{ @@ -74,7 +74,7 @@ pub async fn funded_signed_tx( let funded_builder = fund_builder_from_wallet_source(&funding_source, &tx_builder, &tx_context) .expect("funding transaction should succeed"); let fee = funded_builder - .minimum_gas_cost::(&tx_context) + .minimum_gas_cost::(&tx_context) .expect("funded tx gas cost should calculate") .into_inner(); diff --git a/tests/src/common/wallet/transaction/builder_funding.rs b/tests/src/common/wallet/transaction/builder_funding.rs index 31344c4d8..bc4440018 100644 --- a/tests/src/common/wallet/transaction/builder_funding.rs +++ b/tests/src/common/wallet/transaction/builder_funding.rs @@ -4,7 +4,7 @@ use std::{cmp::Ordering, collections::HashSet}; use lb_core::mantle::{ Note, Op, Utxo, - gas::MainnetGasConstants, + gas::MainnetGasProfile, ledger::{Inputs, Outputs}, ops::transfer::TransferOp, transactions::{MantleTxBuilder, MantleTxContext}, @@ -25,7 +25,7 @@ pub fn fund_builder_from_wallet_source( tx_builder: &MantleTxBuilder, context: &MantleTxContext, ) -> Result { - wallet_state_from_utxos(source.available_utxos().to_vec()).fund_tx::( + wallet_state_from_utxos(source.available_utxos().to_vec()).fund_tx::( tx_builder, source.public_key(), [source.public_key()], @@ -222,13 +222,13 @@ fn evaluate_standard_funding_inputs( let funded_builder = extend_wallet_funding_inputs(tx_builder, selected_inputs)?; match funded_builder - .funding_delta::(context)? + .funding_delta::(context)? .cmp(&0) { Ordering::Less => Ok(WalletFundingOutcome::NeedsMoreInputs), Ordering::Equal => Ok(WalletFundingOutcome::Funded(funded_builder)), Ordering::Greater => Ok(funded_builder - .return_change::(context, change_pk, 0)? + .return_change::(context, change_pk, 0)? .map_or( WalletFundingOutcome::NeedsMoreInputs, WalletFundingOutcome::Funded, @@ -354,7 +354,7 @@ fn funding_delta_for_chunked_builder( ) -> Result { let gas_cost = u128::from( tx_builder - .minimum_gas_cost::(context)? + .minimum_gas_cost::(context)? .into_inner(), ); Ok(i128::try_from(input_sum) @@ -401,7 +401,7 @@ mod tests { .expect("inscription test builder should fit op bounds"); assert_eq!( tx_builder - .funding_delta::(&context) + .funding_delta::(&context) .expect("zero-gas inscription funding delta should calculate"), 0 ); @@ -422,7 +422,7 @@ mod tests { assert_eq!(funded_builder.ledger_inputs(), &[funding_utxo]); assert_eq!( funded_builder - .funding_delta::(&context) + .funding_delta::(&context) .expect("funded inscription delta should calculate"), 0 ); diff --git a/tests/src/common/wallet/transaction/signing.rs b/tests/src/common/wallet/transaction/signing.rs index 61a3cd2fd..851b760af 100644 --- a/tests/src/common/wallet/transaction/signing.rs +++ b/tests/src/common/wallet/transaction/signing.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use lb_core::mantle::{ - GasCalculator as _, NoteId, Op, OpProof, RawMantleTx, SignedMantleTx, TxHash, - gas::MainnetGasConstants, + NoteId, Op, OpProof, RawMantleTx, SignedMantleTx, TxGasCalculator as _, TxHash, + gas::MainnetGasProfile, traits::Hashable as _, transactions::{MantleTxBuilder, MantleTxContext, OpsProofs, mantle_tx::MantleTx as _}, }; @@ -31,7 +31,7 @@ pub(super) fn sign_prepared_wallet_transaction( let signed_tx = SignedMantleTx::new(mantle_tx, op_proofs).preverify()?; let spent_fee = signed_tx - .total_gas_cost::(&gas_prices)? + .total_gas_cost::(&gas_prices)? .into_inner(); Ok(SignedWalletTransaction::new( diff --git a/tests/src/cucumber/steps/manual_transactions/drain_wallets.rs b/tests/src/cucumber/steps/manual_transactions/drain_wallets.rs index b952937c0..c965779da 100644 --- a/tests/src/cucumber/steps/manual_transactions/drain_wallets.rs +++ b/tests/src/cucumber/steps/manual_transactions/drain_wallets.rs @@ -6,7 +6,7 @@ use std::{ use lb_core::mantle::{ Note, Utxo, - gas::{GasCost, MainnetGasConstants}, + gas::{GasCost, MainnetGasProfile}, ledger::MAX_TRANSACTION_INPUTS, transactions::{ GENESIS_EXECUTION_GAS_PRICE, GasPrices, MantleTxBuilder, MantleTxContext, @@ -480,7 +480,7 @@ fn finalize_fee(builder: &MantleTxBuilder) -> Result { ..MantleTxContext::default() }; builder - .minimum_gas_cost::(&context) + .minimum_gas_cost::(&context) .map(GasCost::into_inner) .map_err(|error| StepError::LogicalError { message: error.to_string(), diff --git a/tests/testing_framework/src/workloads/transaction/workload.rs b/tests/testing_framework/src/workloads/transaction/workload.rs index f0aac8449..ad51d30b1 100644 --- a/tests/testing_framework/src/workloads/transaction/workload.rs +++ b/tests/testing_framework/src/workloads/transaction/workload.rs @@ -10,7 +10,7 @@ use std::{ use async_trait::async_trait; use lb_core::mantle::{ Note, OpProof, SignedMantleTx, Utxo, - gas::MainnetGasConstants, + gas::MainnetGasProfile, ops::OpId as _, traits::{GenesisTx as _, Hashable as _}, transactions::{GasPrices, MantleTxBuilder, MantleTxGasContext, states::Preverified}, @@ -289,7 +289,7 @@ fn build_wallet_transaction( .map_err(|err| format!("failed to build provisional tx: {err}"))?; let fee = provisional_tx - .minimum_total_gas_cost::(gas_context)? + .minimum_total_gas_cost::(gas_context)? .into_inner(); let output_value = input.utxo.note.value.checked_sub(fee).ok_or_else(|| { format!( diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 39721c979..6009a89ef 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -15,7 +15,7 @@ use lb_core::{ events::{Event, Events, HeaderEvent, TxEvent, TxEventPayload}, header::HeaderId, mantle::{ - GasConstants, NoteId, TxHash, Utxo, Value, + GasProfile, NoteId, TxHash, Utxo, Value, ops::{ Op, OpId as _, channel::{ @@ -234,7 +234,7 @@ impl WalletState { /// Funds the transaction so its excess balance is exactly /// `priority_fee` above the mandatory fee — the excess is the /// transaction's execution tip. `0` funds to the exact minimum. - pub fn fund_tx( + pub fn fund_tx( &self, tx_builder: &MantleTxBuilder, change_pk: ZkPublicKey, @@ -791,7 +791,7 @@ where clippy::too_many_arguments, reason = "thin passthrough to `WalletState::fund_tx` plus the tip" )] - pub fn fund_tx( + pub fn fund_tx( &self, tip: HeaderId, tx_builder: &MantleTxBuilder, @@ -873,7 +873,7 @@ mod tests { mantle::{ Note, OpProof, RawMantleTx, SignedMantleTx, channel::Channels, - gas::MainnetGasConstants as Gas, + gas::MainnetGasProfile as Gas, ledger::{Inputs, Outputs}, ops::channel::{ ChannelId, MsgId,