-
Notifications
You must be signed in to change notification settings - Fork 390
Introduce evicted-at
/last-evicted
timestamps
#1839
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae0336b
feat(core): Add `TxUpdate::evicted_ats`
evanlinjin a2dfcb9
feat(chain)!: Change `TxGraph` to understand evicted-at & last-evicted
evanlinjin b38569f
feat(core): Add expected txids to `SyncRequest` spks
LagginTimes 64e4100
feat(chain): Add `TxGraph` methods that handle expected spk txids
evanlinjin 3ab4994
feat(electrum): Handle spks with expected txids
evanlinjin f42d5a8
feat(esplora): Handle spks with expected txids
evanlinjin 1f8fc17
feat(core)!: Remove redundant `SyncRequest` methods
evanlinjin 0a20724
feat(examples): Update example crates to use `expected_spk_txids`
evanlinjin 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,13 +1,18 @@ | ||||||
//! Contains the [`IndexedTxGraph`] and associated types. Refer to the | ||||||
//! [`IndexedTxGraph`] documentation for more. | ||||||
use core::fmt::Debug; | ||||||
use core::{ | ||||||
convert::Infallible, | ||||||
fmt::{self, Debug}, | ||||||
ops::RangeBounds, | ||||||
}; | ||||||
|
||||||
use alloc::{sync::Arc, vec::Vec}; | ||||||
use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid}; | ||||||
use bitcoin::{Block, OutPoint, ScriptBuf, Transaction, TxOut, Txid}; | ||||||
|
||||||
use crate::{ | ||||||
spk_txout::SpkTxOutIndex, | ||||||
tx_graph::{self, TxGraph}, | ||||||
Anchor, BlockId, Indexer, Merge, TxPosInBlock, | ||||||
Anchor, BlockId, ChainOracle, Indexer, Merge, TxPosInBlock, | ||||||
}; | ||||||
|
||||||
/// The [`IndexedTxGraph`] combines a [`TxGraph`] and an [`Indexer`] implementation. | ||||||
|
@@ -127,6 +132,19 @@ where | |||||
self.graph.insert_seen_at(txid, seen_at).into() | ||||||
} | ||||||
|
||||||
/// Inserts the given `evicted_at` for `txid`. | ||||||
/// | ||||||
/// The `evicted_at` timestamp represents the last known time when the transaction was observed | ||||||
/// to be missing from the mempool. If `txid` was previously recorded with an earlier | ||||||
/// `evicted_at` value, it is updated only if the new value is greater. | ||||||
pub fn insert_evicted_at(&mut self, txid: Txid, evicted_at: u64) -> ChangeSet<A, I::ChangeSet> { | ||||||
let tx_graph = self.graph.insert_evicted_at(txid, evicted_at); | ||||||
ChangeSet { | ||||||
tx_graph, | ||||||
..Default::default() | ||||||
} | ||||||
} | ||||||
|
||||||
/// Batch insert transactions, filtering out those that are irrelevant. | ||||||
/// | ||||||
/// Relevancy is determined by the [`Indexer::is_tx_relevant`] implementation of `I`. Irrelevant | ||||||
|
@@ -301,6 +319,58 @@ where | |||||
} | ||||||
} | ||||||
|
||||||
impl<A, X> IndexedTxGraph<A, X> | ||||||
where | ||||||
A: Anchor, | ||||||
{ | ||||||
/// List txids that are expected to exist under the given spks. | ||||||
/// | ||||||
/// This is used to fill [`SyncRequestBuilder::expected_spk_txids`](bdk_core::spk_client::SyncRequestBuilder::expected_spk_txids). | ||||||
/// | ||||||
/// The spk index range can be contrained with `range`. | ||||||
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.
Suggested change
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. I wonder how easy it would be to set up CI to check for spelling mistakes. Might save time. |
||||||
/// | ||||||
/// # Error | ||||||
/// | ||||||
/// If the [`ChainOracle`] implementation (`chain`) fails, an error will be returned with the | ||||||
/// returned item. | ||||||
/// | ||||||
/// If the [`ChainOracle`] is infallible, | ||||||
/// [`list_expected_spk_txids`](Self::list_expected_spk_txids) can be used instead. | ||||||
pub fn try_list_expected_spk_txids<'a, C, I>( | ||||||
&'a self, | ||||||
chain: &'a C, | ||||||
chain_tip: BlockId, | ||||||
spk_index_range: impl RangeBounds<I> + 'a, | ||||||
) -> impl Iterator<Item = Result<(ScriptBuf, Txid), C::Error>> + 'a | ||||||
where | ||||||
C: ChainOracle, | ||||||
X: AsRef<SpkTxOutIndex<I>> + 'a, | ||||||
I: fmt::Debug + Clone + Ord + 'a, | ||||||
{ | ||||||
self.graph | ||||||
.try_list_expected_spk_txids(chain, chain_tip, &self.index, spk_index_range) | ||||||
} | ||||||
|
||||||
/// List txids that are expected to exist under the given spks. | ||||||
/// | ||||||
/// This is the infallible version of | ||||||
/// [`try_list_expected_spk_txids`](Self::try_list_expected_spk_txids). | ||||||
pub fn list_expected_spk_txids<'a, C, I>( | ||||||
&'a self, | ||||||
chain: &'a C, | ||||||
chain_tip: BlockId, | ||||||
spk_index_range: impl RangeBounds<I> + 'a, | ||||||
) -> impl Iterator<Item = (ScriptBuf, Txid)> + 'a | ||||||
where | ||||||
C: ChainOracle<Error = Infallible>, | ||||||
X: AsRef<SpkTxOutIndex<I>> + 'a, | ||||||
I: fmt::Debug + Clone + Ord + 'a, | ||||||
{ | ||||||
self.try_list_expected_spk_txids(chain, chain_tip, spk_index_range) | ||||||
.map(|r| r.expect("infallible")) | ||||||
} | ||||||
} | ||||||
|
||||||
impl<A, I> AsRef<TxGraph<A>> for IndexedTxGraph<A, I> { | ||||||
fn as_ref(&self) -> &TxGraph<A> { | ||||||
&self.graph | ||||||
|
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
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.