-
Notifications
You must be signed in to change notification settings - Fork 220
[marshal] Start at Anchor #3855
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
31ef410
spike
patrick-ogrady ef7d41a
more
patrick-ogrady da1717e
spike
patrick-ogrady cb882d2
nits
patrick-ogrady 1f947d1
nits
patrick-ogrady 122ecc6
lint
patrick-ogrady a1bd005
nits
patrick-ogrady ce762fb
move around
patrick-ogrady e4fb1c6
nits
patrick-ogrady 7d48f44
lint
patrick-ogrady 6bc59d2
Merge remote-tracking branch 'origin/main' into set-floor-h
patrick-ogrady 553d949
nits
patrick-ogrady 9e7b8a9
add conformance
patrick-ogrady 28f62e0
lint
patrick-ogrady f87ceb0
nits
patrick-ogrady 9b7053d
lint
patrick-ogrady c388a59
make clearer
patrick-ogrady a9e5e44
simplify
patrick-ogrady 92e519b
nit
patrick-ogrady 0073489
nit
patrick-ogrady e1a1c73
nits
patrick-ogrady File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| use crate::types::Height; | ||
| use commonware_storage::{ | ||
| metadata::{self, Metadata}, | ||
| Context, | ||
| }; | ||
| use commonware_utils::sequence::U64; | ||
|
|
||
| /// The key used to store the last processed height in the metadata store. | ||
| const LATEST_KEY: U64 = U64::new(0xFF); | ||
|
|
||
| /// Last block acknowledged by the application. | ||
| #[derive(Clone, Copy)] | ||
| enum State { | ||
| Unprocessed, | ||
| Processed(Height), | ||
| } | ||
|
|
||
| impl State { | ||
| const fn new(processed_height: Option<Height>) -> Self { | ||
| match processed_height { | ||
| Some(height) => Self::Processed(height), | ||
| None => Self::Unprocessed, | ||
| } | ||
| } | ||
|
|
||
| const fn processed_height(self) -> Option<Height> { | ||
| match self { | ||
| Self::Unprocessed => None, | ||
| Self::Processed(height) => Some(height), | ||
| } | ||
| } | ||
|
|
||
| const fn next_height(self) -> Height { | ||
| match self { | ||
| Self::Unprocessed => Height::zero(), | ||
| Self::Processed(height) => height.next(), | ||
| } | ||
| } | ||
|
|
||
| const fn acknowledge(&mut self, height: Height) { | ||
| *self = Self::Processed(height); | ||
| } | ||
| } | ||
|
|
||
| /// Application delivery stream progress and durable metadata. | ||
| pub(super) struct Stream<E: Context> { | ||
| metadata: Metadata<E, U64, Height>, | ||
| state: State, | ||
| } | ||
|
|
||
| impl<E: Context> Stream<E> { | ||
| pub(super) async fn new(context: E, partition_prefix: &str) -> Self { | ||
| let metadata = Metadata::init( | ||
| context, | ||
| metadata::Config { | ||
| partition: format!("{partition_prefix}-application-metadata"), | ||
|
patrick-ogrady marked this conversation as resolved.
Outdated
|
||
| codec_config: (), | ||
| }, | ||
| ) | ||
| .await | ||
| .expect("failed to initialize application metadata"); | ||
| let state = State::new(metadata.get(&LATEST_KEY).copied()); | ||
| Self { metadata, state } | ||
| } | ||
|
|
||
| pub(super) const fn processed_height(&self) -> Option<Height> { | ||
| self.state.processed_height() | ||
| } | ||
|
|
||
| pub(super) const fn next_height(&self) -> Height { | ||
| self.state.next_height() | ||
| } | ||
|
|
||
| pub(super) fn acknowledge(&mut self, height: Height) { | ||
| self.state.acknowledge(height); | ||
| self.metadata.put(LATEST_KEY, height); | ||
| } | ||
|
|
||
| pub(super) async fn sync(&self) -> Result<(), metadata::Error> { | ||
| self.metadata.sync().await | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.