Skip to content

Commit bb50e69

Browse files
committed
Modify get/put current source to take in just a transaction ID
Right now this is only ever a transaction id, and for LQT work, we need to be able to just use a transaction ID, so it's better to reify that, and change a few uses to wrap it in a source, versus having to unwrap it, introducing a spurious failure case
1 parent 1a5dccb commit bb50e69

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

crates/core/app/src/action_handler/transaction.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::Result;
44
use async_trait::async_trait;
55
use cnidarium::{StateRead, StateWrite};
66
use penumbra_sdk_fee::component::FeePay as _;
7-
use penumbra_sdk_sct::{component::source::SourceContext, CommitmentSource};
7+
use penumbra_sdk_sct::component::source::SourceContext;
88
use penumbra_sdk_shielded_pool::component::ClueManager;
99
use penumbra_sdk_transaction::{gas::GasCost as _, Transaction};
1010
use tokio::task::JoinSet;
@@ -107,10 +107,7 @@ impl AppActionHandler for Transaction {
107107
async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
108108
// While we have access to the full Transaction, hash it to
109109
// obtain a NoteSource we can cache for various actions.
110-
let source = CommitmentSource::Transaction {
111-
id: Some(self.id().0),
112-
};
113-
state.put_current_source(Some(source));
110+
state.put_current_source(Some(self.id()));
114111

115112
// Check and record the transaction's fee payment,
116113
// before doing the rest of execution.

crates/core/component/dex/src/component/action_handler/swap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl ActionHandler for Swap {
5555
// Record the swap commitment in the state.
5656
let source = state.get_current_source().expect("source is set");
5757
state
58-
.add_swap_payload(self.body.payload.clone(), source)
58+
.add_swap_payload(self.body.payload.clone(), source.into())
5959
.await;
6060

6161
// Mark the assets for the swap's trading pair as accessed during this block.

crates/core/component/dex/src/component/action_handler/swap_claim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ impl ActionHandler for SwapClaim {
8787
.expect("source is set during tx execution");
8888

8989
state
90-
.add_rolled_up_payload(self.body.output_1_commitment, source.clone())
90+
.add_rolled_up_payload(self.body.output_1_commitment, source.into())
9191
.await;
9292
state
93-
.add_rolled_up_payload(self.body.output_2_commitment, source.clone())
93+
.add_rolled_up_payload(self.body.output_2_commitment, source.into())
9494
.await;
9595

96-
state.nullify(self.body.nullifier, source).await;
96+
state.nullify(self.body.nullifier, source.into()).await;
9797

9898
state.record_proto(event::EventSwapClaim::from(self).to_proto());
9999

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
use async_trait::async_trait;
22
use cnidarium::StateWrite;
3+
use penumbra_sdk_txhash::TransactionId;
34

4-
use crate::{state_key, CommitmentSource};
5+
use crate::state_key;
56

6-
/// A helper trait for placing a `CommitmentSource` as ambient context during execution.
7+
/// A helper trait for placing a transaction id as an ambient source during execution.
78
#[async_trait]
89
pub trait SourceContext: StateWrite {
9-
fn put_current_source(&mut self, source: Option<CommitmentSource>) {
10+
fn put_current_source(&mut self, source: Option<TransactionId>) {
1011
if let Some(source) = source {
1112
self.object_put(state_key::ambient::current_source(), source)
1213
} else {
1314
self.object_delete(state_key::ambient::current_source())
1415
}
1516
}
1617

17-
fn get_current_source(&self) -> Option<CommitmentSource> {
18+
fn get_current_source(&self) -> Option<TransactionId> {
1819
self.object_get(state_key::ambient::current_source())
1920
}
2021

2122
/// Sets a mock source, for testing.
2223
///
2324
/// The `counter` field allows distinguishing hashes at different stages of the test.
2425
fn put_mock_source(&mut self, counter: u8) {
25-
self.put_current_source(Some(CommitmentSource::Transaction {
26-
id: Some([counter; 32]),
27-
}))
26+
self.put_current_source(Some(TransactionId([counter; 32])))
2827
}
2928
}
3029
impl<T: StateWrite + ?Sized> SourceContext for T {}

crates/core/component/sct/src/source.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ impl TryFrom<pb::CommitmentSource> for CommitmentSource {
141141
})
142142
}
143143
}
144+
145+
impl From<TransactionId> for CommitmentSource {
146+
fn from(id: TransactionId) -> Self {
147+
Self::Transaction { id: Some(id.0) }
148+
}
149+
}

crates/core/component/shielded-pool/src/component/action_handler/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ActionHandler for Output {
3131
.expect("source should be set during execution");
3232

3333
state
34-
.add_note_payload(self.body.note_payload.clone(), source)
34+
.add_note_payload(self.body.note_payload.clone(), source.into())
3535
.await;
3636

3737
state.record_proto(

crates/core/component/shielded-pool/src/component/action_handler/spend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl ActionHandler for Spend {
4646

4747
let source = state.get_current_source().expect("source should be set");
4848

49-
state.nullify(self.body.nullifier, source).await;
49+
state.nullify(self.body.nullifier, source.into()).await;
5050

5151
// Also record an ABCI event for transaction indexing.
5252
state.record_proto(

0 commit comments

Comments
 (0)