-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create a simple filter builder * Index txid This is useful for fetching utxos for their txid * Implement query logic * query script hashes, not scripts * Move block filters to a dedicated module * Add a simple kv database for cfilters Use a kv bucket to store all filters on disk * feature: allow jsonrpc finding utxos This commit update the gettxout (and removes findtxout) from our json rpc that now uses compact block filters to find any given utxo. We also use the same filters to figure if the TXO is spent or not.
- Loading branch information
1 parent
5783f29
commit f28b87f
Showing
7 changed files
with
191 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::path::PathBuf; | ||
|
||
use bitcoin::util::bip158::BlockFilter; | ||
use kv::{Bucket, Config, Integer}; | ||
|
||
use crate::BlockFilterStore; | ||
|
||
/// Stores the block filters insinde a kv database | ||
#[derive(Clone)] | ||
pub struct KvFilterStore { | ||
bucket: Bucket<'static, Integer, Vec<u8>>, | ||
} | ||
|
||
impl KvFilterStore { | ||
/// Creates a new [KvFilterStore] that stores it's content in `datadir`. | ||
/// | ||
/// If the path does't exist it'll be created. This store uses compression by default, if you | ||
/// want to make more granular configuration over the underlying Kv database, use `with_config` | ||
/// instead. | ||
pub fn new(datadir: &PathBuf) -> Self { | ||
let store = kv::Store::new(kv::Config { | ||
path: datadir.to_owned(), | ||
temporary: false, | ||
use_compression: false, | ||
flush_every_ms: None, | ||
cache_capacity: None, | ||
segment_size: None, | ||
}) | ||
.expect("Could not open store"); | ||
|
||
let bucket = store.bucket(Some("cfilters")).unwrap(); | ||
KvFilterStore { bucket } | ||
} | ||
/// Creates a new [KvFilterStore] that stores it's content with a given config | ||
pub fn with_config(config: Config) -> Self { | ||
let store = kv::Store::new(config).expect("Could not open database"); | ||
let bucket = store.bucket(Some("cffilters")).unwrap(); | ||
KvFilterStore { bucket } | ||
} | ||
} | ||
|
||
impl BlockFilterStore for KvFilterStore { | ||
fn get_filter(&self, block_height: u64) -> Option<bitcoin::util::bip158::BlockFilter> { | ||
let value = self | ||
.bucket | ||
.get(&Integer::from(block_height)) | ||
.ok() | ||
.flatten()?; | ||
Some(BlockFilter::new(&value)) | ||
} | ||
fn put_filter(&self, block_height: u64, block_filter: bitcoin::util::bip158::BlockFilter) { | ||
self.bucket | ||
.set(&Integer::from(block_height), &block_filter.content) | ||
.expect("Bucket should be open"); | ||
} | ||
} |
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
Oops, something went wrong.