-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
funding: LQT nullifier set for epoch (#5034)
## Describe your changes state key for epoch-scoped nullifier set (mapping nullifiers with their associated transaction id), serving as a precursor for performing the necessary stateful [nullifier check](https://github.com/penumbra-zone/penumbra/pull/5033/files#diff-a0986b8d223ab5b1c5536ba06bde1ede6d08f635eb97b386549ecfb55a4f2a4bR112). Additionally, augments the transaction context with `TransactionId`. ## Issue ticket number and link references #5029 ## 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: > LQT branch
- Loading branch information
Showing
8 changed files
with
76 additions
and
4 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
1 change: 1 addition & 0 deletions
1
crates/core/component/funding/src/component/liquidity_tournament/mod.rs
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod nullifier; |
53 changes: 53 additions & 0 deletions
53
crates/core/component/funding/src/component/liquidity_tournament/nullifier/mod.rs
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use async_trait::async_trait; | ||
use penumbra_sdk_txhash::TransactionId; | ||
|
||
use crate::component::state_key; | ||
use cnidarium::{StateRead, StateWrite}; | ||
use penumbra_sdk_proto::{StateReadProto, StateWriteProto}; | ||
use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier}; | ||
|
||
#[allow(dead_code)] | ||
#[async_trait] | ||
pub trait NullifierRead: StateRead { | ||
/// Returns the `TransactionId` if the nullifier has been spent; otherwise, returns None. | ||
async fn get_lqt_spent_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> { | ||
// Grab the ambient epoch index. | ||
let epoch_index = self | ||
.get_current_epoch() | ||
.await | ||
.expect("epoch is always set") | ||
.index; | ||
|
||
let nullifier_key = &state_key::lqt::v1::nullifier::key(epoch_index, &nullifier); | ||
|
||
let tx_id: Option<TransactionId> = self | ||
.nonverifiable_get(&nullifier_key.as_bytes()) | ||
.await | ||
.expect(&format!( | ||
"failed to retrieve key {} from non-verifiable storage", | ||
nullifier_key, | ||
)); | ||
|
||
tx_id | ||
} | ||
} | ||
|
||
impl<T: StateRead + ?Sized> NullifierRead for T {} | ||
|
||
#[allow(dead_code)] | ||
#[async_trait] | ||
pub trait NullifierWrite: StateWrite { | ||
/// Sets the LQT nullifier in the NV storage. | ||
fn put_lqt_spent_nullifier( | ||
&mut self, | ||
epoch_index: u64, | ||
nullifier: Nullifier, | ||
tx_id: TransactionId, | ||
) { | ||
let nullifier_key = state_key::lqt::v1::nullifier::key(epoch_index, &nullifier); | ||
|
||
self.nonverifiable_put(nullifier_key.into(), tx_id); | ||
} | ||
} | ||
|
||
impl<T: StateWrite + ?Sized> NullifierWrite 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
pub fn funding_parameters() -> &'static str { | ||
"funding/parameters" | ||
} | ||
|
||
pub mod lqt { | ||
pub mod v1 { | ||
pub mod nullifier { | ||
use penumbra_sdk_sct::Nullifier; | ||
|
||
/// A nullifier set indexed by epoch, mapping each epoch to its corresponding `TransactionId`. | ||
pub(crate) fn key(epoch_index: u64, nullifier: &Nullifier) -> String { | ||
format!("funding/lqt/v1/nullifier/{epoch_index:020}/lookup/{nullifier}") | ||
} | ||
} | ||
} | ||
} |
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