-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bc2844
commit 2c7dad3
Showing
12 changed files
with
161 additions
and
43 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
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,49 @@ | ||
use kaspa_database::prelude::StoreResult; | ||
use kaspa_database::prelude::DB; | ||
use kaspa_database::prelude::{BatchDbWriter, CachedDbItem, DirectDbWriter}; | ||
use kaspa_database::registry::DatabaseStorePrefixes; | ||
use kaspa_hashes::Hash; | ||
use rocksdb::WriteBatch; | ||
use std::sync::Arc; | ||
|
||
/// Reader API for `SelectedTipStore`. | ||
pub trait GoodFinalityPointStoreReader { | ||
fn get(&self) -> StoreResult<Hash>; | ||
} | ||
|
||
pub trait GoodFinalityPointStore: GoodFinalityPointStoreReader { | ||
fn set(&mut self, hash: Hash) -> StoreResult<()>; | ||
} | ||
|
||
/// A DB + cache implementation of `GoodFinalityPointStore` trait | ||
#[derive(Clone)] | ||
pub struct DbGoodFinalityPointStore { | ||
db: Arc<DB>, | ||
access: CachedDbItem<Hash>, | ||
} | ||
|
||
impl DbGoodFinalityPointStore { | ||
pub fn new(db: Arc<DB>) -> Self { | ||
Self { db: Arc::clone(&db), access: CachedDbItem::new(db, DatabaseStorePrefixes::GoodFinalityPoint.into()) } | ||
} | ||
|
||
pub fn clone_with_new_cache(&self) -> Self { | ||
Self::new(Arc::clone(&self.db)) | ||
} | ||
|
||
pub fn set_batch(&mut self, batch: &mut WriteBatch, hash: Hash) -> StoreResult<()> { | ||
self.access.write(BatchDbWriter::new(batch), &hash) | ||
} | ||
} | ||
|
||
impl GoodFinalityPointStoreReader for DbGoodFinalityPointStore { | ||
fn get(&self) -> StoreResult<Hash> { | ||
self.access.read() | ||
} | ||
} | ||
|
||
impl GoodFinalityPointStore for DbGoodFinalityPointStore { | ||
fn set(&mut self, hash: Hash) -> StoreResult<()> { | ||
self.access.write(DirectDbWriter::new(&self.db), &hash) | ||
} | ||
} |
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
Oops, something went wrong.