Skip to content

Commit

Permalink
protos: move the transaction fee out of the transaction body and into…
Browse files Browse the repository at this point in the history
… the transaction parameters
  • Loading branch information
aubrika committed Dec 6, 2023
1 parent ab12795 commit 1a286f5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 68 deletions.
8 changes: 7 additions & 1 deletion crates/core/app/src/action_handler/transaction/stateful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ pub(super) async fn fee_greater_than_base_fee<S: StateRead>(

let transaction_base_price = current_gas_prices.price(&transaction.gas_cost());

if transaction.transaction_body().fee.amount() >= transaction_base_price {
if transaction
.transaction_body()
.transaction_parameters
.fee
.amount()
>= transaction_base_price
{
Ok(())
} else {
Err(anyhow::anyhow!(
Expand Down
3 changes: 2 additions & 1 deletion crates/core/transaction/src/effect_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TransactionBody {

// Hash the fixed data of the transaction body.
state.update(self.transaction_parameters.effect_hash().as_bytes());
state.update(self.fee.effect_hash().as_bytes());
state.update(self.transaction_parameters.fee.effect_hash().as_bytes());
if self.memo.is_some() {
let memo_ciphertext = self.memo.clone();
state.update(
Expand Down Expand Up @@ -107,6 +107,7 @@ impl TransactionPlan {
let tx_params = TransactionParameters {
chain_id: self.chain_id.clone(),
expiry_height: self.expiry_height,
fee: self.fee.clone(),
};
state.update(tx_params.effect_hash().as_bytes());
state.update(self.fee.effect_hash().as_bytes());
Expand Down
2 changes: 1 addition & 1 deletion crates/core/transaction/src/plan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl TransactionPlan {
transaction_parameters: TransactionParameters {
expiry_height: self.expiry_height,
chain_id: self.chain_id,
fee: self.fee,
},
fee: self.fee,
detection_data,
memo,
};
Expand Down
24 changes: 13 additions & 11 deletions crates/core/transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::{
pub struct TransactionBody {
pub actions: Vec<Action>,
pub transaction_parameters: TransactionParameters,
pub fee: Fee,
pub detection_data: Option<DetectionData>,
pub memo: Option<MemoCiphertext>,
}
Expand All @@ -49,6 +48,7 @@ pub struct TransactionBody {
pub struct TransactionParameters {
pub expiry_height: u64,
pub chain_id: String,
pub fee: Fee,
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -279,7 +279,7 @@ impl Transaction {
body_view: TransactionBodyView {
action_views,
transaction_parameters: self.transaction_parameters(),
fee: self.transaction_body().fee,
fee: self.transaction_parameters().fee,
detection_data,
memo_view,
},
Expand Down Expand Up @@ -507,7 +507,11 @@ impl Transaction {

// Add fee into binding verification key computation.
let fee_v_blinding = Fr::zero();
let fee_value_commitment = self.transaction_body.fee.commit(fee_v_blinding);
let fee_value_commitment = self
.transaction_body
.transaction_parameters
.fee
.commit(fee_v_blinding);
balance_commitments += fee_value_commitment.0;

let binding_verification_key_bytes: VerificationKeyBytes<Binding> =
Expand Down Expand Up @@ -537,6 +541,11 @@ impl TryFrom<pbt::TransactionParameters> for TransactionParameters {
Ok(TransactionParameters {
expiry_height: proto.expiry_height,
chain_id: proto.chain_id,
fee: Fee(proto
.fee
.ok_or_else(|| anyhow::anyhow!("transaction parameters missing fee"))?
.try_into()
.context("fee malformed")?),
})
}
}
Expand All @@ -546,6 +555,7 @@ impl From<TransactionParameters> for pbt::TransactionParameters {
pbt::TransactionParameters {
expiry_height: msg.expiry_height,
chain_id: msg.chain_id,
fee: Some(msg.fee.value().into()),
}
}
}
Expand Down Expand Up @@ -593,7 +603,6 @@ impl From<TransactionBody> for pbt::TransactionBody {
pbt::TransactionBody {
actions: msg.actions.into_iter().map(|x| x.into()).collect(),
transaction_parameters: Some(msg.transaction_parameters.into()),
fee: Some(msg.fee.into()),
detection_data: msg.detection_data.map(|x| x.into()),
memo_data: Some(encrypted_memo),
}
Expand All @@ -613,12 +622,6 @@ impl TryFrom<pbt::TransactionBody> for TransactionBody {
);
}

let fee: Fee = proto
.fee
.ok_or_else(|| anyhow::anyhow!("transaction body missing fee"))?
.try_into()
.context("fee malformed")?;

let encrypted_memo = proto
.memo_data
.ok_or_else(|| anyhow::anyhow!("transaction body missing memo data field"))?
Expand Down Expand Up @@ -651,7 +654,6 @@ impl TryFrom<pbt::TransactionBody> for TransactionBody {
Ok(TransactionBody {
actions,
transaction_parameters,
fee,
detection_data,
memo,
})
Expand Down
10 changes: 6 additions & 4 deletions crates/core/transaction/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl TransactionView {
transaction_body: TransactionBody {
actions,
transaction_parameters,
fee: self.body_view.fee.clone(),
detection_data,
memo: memo_ciphertext.cloned(),
},
Expand Down Expand Up @@ -143,11 +142,14 @@ impl TryFrom<pbt::TransactionBodyView> for TransactionBodyView {
action_views.push(av.try_into()?);
}

let fee = body_view
let fee = Fee(body_view
.transaction_parameters
.clone()
.ok_or_else(|| anyhow::anyhow!("transaction view missing transaction parameters view"))?
.fee
.ok_or_else(|| anyhow::anyhow!("transaction view missing fee"))?
.try_into()
.context("transaction fee malformed")?;
.context("transaction fee malformed")?);

let memo_view: Option<MemoView> = match body_view.memo_view {
Some(mv) => match mv.memo_view {
Expand Down Expand Up @@ -182,6 +184,7 @@ impl TryFrom<pbt::TransactionBodyView> for TransactionBodyView {

let transaction_parameters = body_view
.transaction_parameters
.clone()
.ok_or_else(|| anyhow::anyhow!("transaction view missing transaction parameters view"))?
.try_into()?;

Expand Down Expand Up @@ -223,7 +226,6 @@ impl From<TransactionBodyView> for pbt::TransactionBodyView {
Self {
action_views: v.action_views.into_iter().map(Into::into).collect(),
transaction_parameters: Some(v.transaction_parameters.into()),
fee: Some(v.fee.into()),
detection_data: v.detection_data.map(Into::into),
memo_view: v.memo_view.map(|m| m.into()),
}
Expand Down
15 changes: 6 additions & 9 deletions crates/proto/src/gen/penumbra.core.transaction.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ pub struct TransactionBody {
/// Parameters determining if a transaction should be accepted by this chain.
#[prost(message, optional, tag = "2")]
pub transaction_parameters: ::core::option::Option<TransactionParameters>,
/// The transaction fee.
#[prost(message, optional, tag = "3")]
pub fee: ::core::option::Option<super::super::component::fee::v1alpha1::Fee>,
/// Detection data for use with Fuzzy Message Detection
#[prost(message, optional, tag = "4")]
#[prost(message, optional, tag = "3")]
pub detection_data: ::core::option::Option<DetectionData>,
/// Sub-message containing memo ciphertext if a memo was added to the transaction.
#[prost(message, optional, tag = "5")]
#[prost(message, optional, tag = "4")]
pub memo_data: ::core::option::Option<MemoData>,
}
impl ::prost::Name for TransactionBody {
Expand Down Expand Up @@ -91,6 +88,9 @@ pub struct TransactionParameters {
/// replaying a transaction on one chain onto a different chain.
#[prost(string, tag = "2")]
pub chain_id: ::prost::alloc::string::String,
/// The transaction fee.
#[prost(message, optional, tag = "3")]
pub fee: ::core::option::Option<super::super::asset::v1alpha1::Value>,
}
impl ::prost::Name for TransactionParameters {
const NAME: &'static str = "TransactionParameters";
Expand Down Expand Up @@ -304,15 +304,12 @@ impl ::prost::Name for TransactionView {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TransactionBodyView {
/// A list views into of actions (state changes) performed by this transaction.
/// A list of views into of actions (state changes) performed by this transaction.
#[prost(message, repeated, tag = "1")]
pub action_views: ::prost::alloc::vec::Vec<ActionView>,
/// Transaction parameters.
#[prost(message, optional, tag = "2")]
pub transaction_parameters: ::core::option::Option<TransactionParameters>,
/// The transaction fee.
#[prost(message, optional, tag = "3")]
pub fee: ::core::option::Option<super::super::component::fee::v1alpha1::Fee>,
/// The detection data in this transaction, only populated if
/// there are outputs in the actions of this transaction.
#[prost(message, optional, tag = "4")]
Expand Down
Loading

0 comments on commit 1a286f5

Please sign in to comment.