-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify get/put current source to take in just a transaction ID (#5036)
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 Smoke tests should be sufficient. ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > This state is always initialized before being read, so there's no issue in changing the type we store under this state key ; reviewers should double check this.
- Loading branch information
1 parent
1a5dccb
commit 91e4783
Showing
7 changed files
with
20 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
use async_trait::async_trait; | ||
use cnidarium::StateWrite; | ||
use penumbra_sdk_txhash::TransactionId; | ||
|
||
use crate::{state_key, CommitmentSource}; | ||
use crate::state_key; | ||
|
||
/// A helper trait for placing a `CommitmentSource` as ambient context during execution. | ||
/// A helper trait for placing a transaction id as an ambient source during execution. | ||
#[async_trait] | ||
pub trait SourceContext: StateWrite { | ||
fn put_current_source(&mut self, source: Option<CommitmentSource>) { | ||
fn put_current_source(&mut self, source: Option<TransactionId>) { | ||
if let Some(source) = source { | ||
self.object_put(state_key::ambient::current_source(), source) | ||
} else { | ||
self.object_delete(state_key::ambient::current_source()) | ||
} | ||
} | ||
|
||
fn get_current_source(&self) -> Option<CommitmentSource> { | ||
fn get_current_source(&self) -> Option<TransactionId> { | ||
self.object_get(state_key::ambient::current_source()) | ||
} | ||
|
||
/// Sets a mock source, for testing. | ||
/// | ||
/// The `counter` field allows distinguishing hashes at different stages of the test. | ||
fn put_mock_source(&mut self, counter: u8) { | ||
self.put_current_source(Some(CommitmentSource::Transaction { | ||
id: Some([counter; 32]), | ||
})) | ||
self.put_current_source(Some(TransactionId([counter; 32]))) | ||
} | ||
} | ||
impl<T: StateWrite + ?Sized> SourceContext for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters