-
Notifications
You must be signed in to change notification settings - Fork 5
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
STR-881 inscription changes #590
Open
bewakes
wants to merge
15
commits into
main
Choose a base branch
from
STR-807-inscription-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b015b62
Some cleanups
6dfb350
l1tx: Use tags to parse and build l1 payloads
eb4a63f
db: Add IntentEntry and corrensponding db operations, and tests
934a2b9
Support multiple payloads as envelopes
2396c1e
DB changes for payload entries
1f0a5e0
Remove sequencerdb
26dd767
btcio: Add payload bundler
f7a01db
db: rename envelope_db to writer, Add/edit more methods for writer db
88a90e3
Fix bug around intent not being processed
7f7893f
Make unit tests compile
3940b67
Get tests to pass
afc473c
Rename sequencer to writer in db modules
6f67c08
Update tests
7a80b35
Actually parse multiple envelopes
e78e71d
Some renamings
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 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
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,83 @@ | ||
use std::{sync::Arc, time::Duration}; | ||
|
||
use strata_db::types::{BundledPayloadEntry, IntentEntry, IntentStatus}; | ||
use strata_storage::ops::writer::EnvelopeDataOps; | ||
use tokio::time::sleep; | ||
use tracing::*; | ||
|
||
// TODO: get this from config | ||
const BUNDLE_INTERVAL: u64 = 200; // millis | ||
|
||
/// Periodically bundles unbundled intents into payload entries. | ||
pub(crate) async fn bundler_task(ops: Arc<EnvelopeDataOps>) -> anyhow::Result<()> { | ||
let mut last_idx = 0; | ||
loop { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, this |
||
let (unbundled, new_idx) = get_unbundled_intents_after(last_idx, ops.as_ref()).await?; | ||
process_unbundled_entries(ops.as_ref(), unbundled).await?; | ||
last_idx = new_idx; | ||
|
||
let _ = sleep(Duration::from_millis(BUNDLE_INTERVAL)).await; | ||
} | ||
} | ||
|
||
/// Processes and bundles a list of unbundled intents into payload entries. | ||
/// NOTE: The current logic is simply 1-1 mapping between intents and payloads, in future it can | ||
/// be sophisticated. | ||
async fn process_unbundled_entries( | ||
ops: &EnvelopeDataOps, | ||
unbundled: Vec<IntentEntry>, | ||
) -> anyhow::Result<()> { | ||
for mut entry in unbundled { | ||
// NOTE: In future, the logic to create payload will be different. We need to group | ||
// intents and create payload entries accordingly | ||
let payload_entry = BundledPayloadEntry::new_unsigned(vec![entry.payload().clone()]); | ||
|
||
// TODO: the following block till "Atomic Ends" should be atomic. | ||
let idx = ops.get_next_payload_idx_async().await?; | ||
ops.put_payload_entry_async(idx, payload_entry).await?; | ||
|
||
// Set the entry to be bundled so that it won't be processed next time. | ||
entry.status = IntentStatus::Bundled(idx); | ||
ops.put_intent_entry_async(*entry.intent.commitment(), entry) | ||
.await?; | ||
// Atomic Ends. | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Retrieves unbundled intents after a given index in ascending order along with the latest | ||
/// unbundled entry idx. | ||
async fn get_unbundled_intents_after( | ||
idx: u64, | ||
ops: &EnvelopeDataOps, | ||
) -> anyhow::Result<(Vec<IntentEntry>, u64)> { | ||
let latest_idx = ops.get_next_intent_idx_async().await?.saturating_sub(1); | ||
let mut curr_idx = latest_idx; | ||
|
||
let mut unbundled = Vec::new(); | ||
|
||
while curr_idx >= idx { | ||
if let Some(intent) = ops.get_intent_by_idx_async(curr_idx).await? { | ||
match intent.status { | ||
IntentStatus::Unbundled => unbundled.push(intent), | ||
IntentStatus::Bundled(_) => { | ||
// Bundled intent found, no more to scan | ||
break; | ||
} | ||
} | ||
} else { | ||
warn!(%curr_idx, "Could not find expected intent in db"); | ||
break; | ||
} | ||
|
||
if curr_idx == 0 { | ||
break; | ||
} | ||
curr_idx -= 1; | ||
} | ||
|
||
// Reverse the items so that they are in ascending order of index | ||
unbundled.reverse(); | ||
|
||
Ok((unbundled, latest_idx)) | ||
} | ||
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,4 +1,5 @@ | ||
pub mod builder; | ||
mod bundler; | ||
pub(crate) mod context; | ||
mod signer; | ||
mod task; | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that we can do is to make this accept both a single but also multiple
LaPayload
s: