Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: transaction format cleanup #3542

Merged
merged 7 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/bin/pcli/src/command/view/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,13 @@ impl TxCmd {

metadata_table.add_row(vec![
"Transaction Fee",
&tx_info.view.body_view.fee.value().format(&asset_cache),
&tx_info
.view
.body_view
.transaction_parameters
.fee
.value()
.format(&asset_cache),
]);

let memo_view = tx_info.view.body_view.memo_view;
Expand Down
30 changes: 18 additions & 12 deletions crates/core/app/src/action_handler/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ mod tests {
use penumbra_shielded_pool::{Note, OutputPlan, SpendPlan};
use penumbra_tct as tct;
use penumbra_transaction::{
plan::{CluePlan, TransactionPlan},
WitnessData,
plan::{CluePlan, DetectionDataPlan, TransactionPlan},
TransactionParameters, WitnessData,
};
use rand_core::OsRng;

Expand Down Expand Up @@ -151,16 +151,20 @@ mod tests {
// Add a single spend and output to the transaction plan such that the
// transaction balances.
let plan = TransactionPlan {
expiry_height: 0,
fee: Fee::default(),
chain_id: "".into(),
transaction_parameters: TransactionParameters {
expiry_height: 0,
fee: Fee::default(),
chain_id: "".into(),
},
actions: vec![
SpendPlan::new(&mut OsRng, note, auth_path.position()).into(),
SpendPlan::new(&mut OsRng, note2, auth_path2.position()).into(),
OutputPlan::new(&mut OsRng, value, *test_keys::ADDRESS_1).into(),
],
clue_plans: vec![CluePlan::new(&mut OsRng, *test_keys::ADDRESS_1, 1)],
memo_plan: None,
detection_data: Some(DetectionDataPlan {
clue_plans: vec![CluePlan::new(&mut OsRng, *test_keys::ADDRESS_1, 1)],
}),
memo: None,
};

// Build the transaction.
Expand Down Expand Up @@ -213,15 +217,17 @@ mod tests {
// Add a single spend and output to the transaction plan such that the
// transaction balances.
let plan = TransactionPlan {
expiry_height: 0,
fee: Fee::default(),
chain_id: "".into(),
transaction_parameters: TransactionParameters {
expiry_height: 0,
fee: Fee::default(),
chain_id: "".into(),
},
actions: vec![
SpendPlan::new(&mut OsRng, note, auth_path.position()).into(),
OutputPlan::new(&mut OsRng, value, *test_keys::ADDRESS_1).into(),
],
clue_plans: vec![],
memo_plan: None,
detection_data: None,
memo: None,
};

// Build the transaction.
Expand Down
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
2 changes: 0 additions & 2 deletions crates/core/app/src/tests/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use decaf377_rdsa::SigningKey;
use penumbra_asset::Value;
use penumbra_chain::{component::StateWriteExt, EffectHash, TransactionContext};
use penumbra_compact_block::component::CompactBlockManager;
use penumbra_fee::Fee;
use penumbra_keys::{test_keys, PayloadKey};
use penumbra_num::Amount;
use penumbra_sct::component::SourceContext;
Expand Down Expand Up @@ -249,7 +248,6 @@ async fn spend_duplicate_nullifier_same_transaction() {
penumbra_transaction::Action::Output(output),
],
transaction_parameters: TransactionParameters::default(),
fee: Fee::from_staking_token_amount(0u64.into()),
detection_data: None,
memo: None,
};
Expand Down
18 changes: 8 additions & 10 deletions crates/core/component/governance/src/delegator_vote/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl From<DelegatorVoteBody> for pb::DelegatorVoteBody {
vote: Some(value.vote.into()),
value: Some(value.value.into()),
unbonded_amount: Some(value.unbonded_amount.into()),
nullifier: value.nullifier.to_bytes().into(),
rk: value.rk.to_bytes().into(),
nullifier: Some(value.nullifier.into()),
rk: Some(value.rk.into()),
}
}
}
Expand Down Expand Up @@ -72,16 +72,14 @@ impl TryFrom<pb::DelegatorVoteBody> for DelegatorVoteBody {
.try_into()?,
nullifier: msg
.nullifier
.ok_or_else(|| anyhow::anyhow!("missing nullifier in `DelegatorVote`"))?
.try_into()
.context("invalid nullifier in `DelegatorVote`")?,
rk: {
let rk_bytes: [u8; 32] = (msg.rk[..])
.try_into()
.context("expected 32-byte rk in `DelegatorVote`")?;
rk_bytes
.try_into()
.context("invalid rk in `DelegatorVote`")?
},
rk: msg
.rk
.ok_or_else(|| anyhow::anyhow!("missing rk in `DelegatorVote`"))?
.try_into()
.context("invalid rk in `DelegatorVote`")?,
})
}
}
Expand Down
17 changes: 9 additions & 8 deletions crates/core/component/shielded-pool/src/spend/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ impl DomainType for Body {

impl From<Body> for pb::SpendBody {
fn from(msg: Body) -> Self {
let nullifier_bytes: [u8; 32] = msg.nullifier.into();
let rk_bytes: [u8; 32] = msg.rk.into();
pb::SpendBody {
balance_commitment: Some(msg.balance_commitment.into()),
nullifier: nullifier_bytes.to_vec(),
rk: rk_bytes.to_vec(),
nullifier: Some(msg.nullifier.into()),
rk: Some(msg.rk.into()),
}
}
}
Expand All @@ -92,14 +90,17 @@ impl TryFrom<pb::SpendBody> for Body {
.try_into()
.context("malformed balance commitment")?;

let nullifier = (proto.nullifier[..])
let nullifier = proto
.nullifier
.ok_or_else(|| anyhow::anyhow!("missing nullifier"))?
.try_into()
.context("malformed nullifier")?;

let rk_bytes: [u8; 32] = (proto.rk[..])
let rk = proto
.rk
.ok_or_else(|| anyhow::anyhow!("missing rk"))?
.try_into()
.map_err(|_| anyhow::anyhow!("expected 32-byte rk"))?;
let rk = rk_bytes.try_into().context("malformed rk")?;
.context("malformed rk")?;

Ok(Body {
balance_commitment,
Expand Down
37 changes: 37 additions & 0 deletions crates/core/transaction/src/detection_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::Error;
use decaf377_fmd::Clue;
use penumbra_proto::core::transaction::v1alpha1 as pbt;
use penumbra_proto::DomainType;

/// Detection data used by a detection server using Fuzzy Message Detection.
///
/// Only present if outputs are present.
#[derive(Clone, Debug, Default)]
pub struct DetectionData {
pub fmd_clues: Vec<Clue>,
}

impl DomainType for DetectionData {
type Proto = pbt::DetectionData;
}

impl TryFrom<pbt::DetectionData> for DetectionData {
type Error = Error;

fn try_from(proto: pbt::DetectionData) -> anyhow::Result<Self, Self::Error> {
let fmd_clues = proto
.fmd_clues
.into_iter()
.map(|x| x.try_into())
.collect::<Result<Vec<Clue>, Error>>()?;
Ok(DetectionData { fmd_clues })
}
}

impl From<DetectionData> for pbt::DetectionData {
fn from(msg: DetectionData) -> Self {
let fmd_clues = msg.fmd_clues.into_iter().map(|x| x.into()).collect();

pbt::DetectionData { fmd_clues }
}
}
Loading
Loading