remove references to sled from service.rs
This commit is contained in:
parent
5a6a9fd51e
commit
65a605520f
|
@ -193,9 +193,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.55.1"
|
version = "0.54.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443"
|
checksum = "66c0bb6167449588ff70803f4127f0684f9063097eca5016f37eb52b92c2cf36"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cexpr",
|
"cexpr",
|
||||||
|
@ -430,9 +430,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clang-sys"
|
name = "clang-sys"
|
||||||
version = "1.0.1"
|
version = "0.29.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133"
|
checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -1468,11 +1468,11 @@ checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.6.5"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0"
|
checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cc",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3337,9 +3337,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_script"
|
name = "zcash_script"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f50ddde89b1a9ae1677de9eaff3578a005da42879622ddef1a057b037e0ff834"
|
checksum = "8bf1995ddb0c827f160357922a96c0cd34c6dd759757cb2b799128d6f420c91e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"blake2b_simd",
|
"blake2b_simd",
|
||||||
|
|
|
@ -8,7 +8,7 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zcash_script = "0.1.3"
|
zcash_script = "0.1.4"
|
||||||
zebra-chain = { path = "../zebra-chain" }
|
zebra-chain = { path = "../zebra-chain" }
|
||||||
thiserror = "1.0.22"
|
thiserror = "1.0.22"
|
||||||
displaydoc = "0.1.7"
|
displaydoc = "0.1.7"
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub struct QueuedBlock {
|
||||||
|
|
||||||
struct StateService {
|
struct StateService {
|
||||||
/// Holds data relating to finalized chain state.
|
/// Holds data relating to finalized chain state.
|
||||||
sled: FinalizedState,
|
disk: FinalizedState,
|
||||||
/// Holds data relating to non-finalized chain state.
|
/// Holds data relating to non-finalized chain state.
|
||||||
mem: NonFinalizedState,
|
mem: NonFinalizedState,
|
||||||
/// Blocks awaiting their parent blocks for contextual verification.
|
/// Blocks awaiting their parent blocks for contextual verification.
|
||||||
|
@ -63,13 +63,13 @@ impl StateService {
|
||||||
const PRUNE_INTERVAL: Duration = Duration::from_secs(30);
|
const PRUNE_INTERVAL: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
pub fn new(config: Config, network: Network) -> Self {
|
pub fn new(config: Config, network: Network) -> Self {
|
||||||
let sled = FinalizedState::new(&config, network);
|
let disk = FinalizedState::new(&config, network);
|
||||||
let mem = NonFinalizedState::default();
|
let mem = NonFinalizedState::default();
|
||||||
let queued_blocks = QueuedBlocks::default();
|
let queued_blocks = QueuedBlocks::default();
|
||||||
let pending_utxos = utxo::PendingUtxos::default();
|
let pending_utxos = utxo::PendingUtxos::default();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
sled,
|
disk,
|
||||||
mem,
|
mem,
|
||||||
queued_blocks,
|
queued_blocks,
|
||||||
pending_utxos,
|
pending_utxos,
|
||||||
|
@ -121,13 +121,13 @@ impl StateService {
|
||||||
|
|
||||||
while self.mem.best_chain_len() > crate::constants::MAX_BLOCK_REORG_HEIGHT {
|
while self.mem.best_chain_len() > crate::constants::MAX_BLOCK_REORG_HEIGHT {
|
||||||
let finalized = self.mem.finalize();
|
let finalized = self.mem.finalize();
|
||||||
self.sled
|
self.disk
|
||||||
.commit_finalized_direct(finalized)
|
.commit_finalized_direct(finalized)
|
||||||
.expect("expected that sled errors would not occur");
|
.expect("expected that disk errors would not occur");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.queued_blocks
|
self.queued_blocks
|
||||||
.prune_by_height(self.sled.finalized_tip_height().expect(
|
.prune_by_height(self.disk.finalized_tip_height().expect(
|
||||||
"Finalized state must have at least one block before committing non-finalized state",
|
"Finalized state must have at least one block before committing non-finalized state",
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ impl StateService {
|
||||||
self.check_contextual_validity(&block)?;
|
self.check_contextual_validity(&block)?;
|
||||||
let parent_hash = block.header.previous_block_hash;
|
let parent_hash = block.header.previous_block_hash;
|
||||||
|
|
||||||
if self.sled.finalized_tip_hash() == parent_hash {
|
if self.disk.finalized_tip_hash() == parent_hash {
|
||||||
self.mem.commit_new_chain(block);
|
self.mem.commit_new_chain(block);
|
||||||
} else {
|
} else {
|
||||||
self.mem.commit_block(block);
|
self.mem.commit_block(block);
|
||||||
|
@ -151,7 +151,7 @@ impl StateService {
|
||||||
|
|
||||||
/// Returns `true` if `hash` is a valid previous block hash for new non-finalized blocks.
|
/// Returns `true` if `hash` is a valid previous block hash for new non-finalized blocks.
|
||||||
fn can_fork_chain_at(&self, hash: &block::Hash) -> bool {
|
fn can_fork_chain_at(&self, hash: &block::Hash) -> bool {
|
||||||
self.mem.any_chain_contains(hash) || &self.sled.finalized_tip_hash() == hash
|
self.mem.any_chain_contains(hash) || &self.disk.finalized_tip_hash() == hash
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given hash has been committed to either the finalized
|
/// Returns true if the given hash has been committed to either the finalized
|
||||||
|
@ -162,7 +162,7 @@ impl StateService {
|
||||||
.coinbase_height()
|
.coinbase_height()
|
||||||
.expect("coinbase heights should be valid");
|
.expect("coinbase heights should be valid");
|
||||||
|
|
||||||
self.mem.any_chain_contains(&hash) || self.sled.hash(height) == Some(hash)
|
self.mem.any_chain_contains(&hash) || self.disk.hash(height) == Some(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to validate and commit all queued blocks whose parents have
|
/// Attempt to validate and commit all queued blocks whose parents have
|
||||||
|
@ -192,7 +192,7 @@ impl StateService {
|
||||||
check::block_is_contextually_valid(
|
check::block_is_contextually_valid(
|
||||||
block,
|
block,
|
||||||
self.network,
|
self.network,
|
||||||
self.sled.finalized_tip_height(),
|
self.disk.finalized_tip_height(),
|
||||||
self.chain(block.header.previous_block_hash),
|
self.chain(block.header.previous_block_hash),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -217,13 +217,13 @@ impl StateService {
|
||||||
|
|
||||||
/// Return the tip of the current best chain.
|
/// Return the tip of the current best chain.
|
||||||
pub fn tip(&self) -> Option<(block::Height, block::Hash)> {
|
pub fn tip(&self) -> Option<(block::Height, block::Hash)> {
|
||||||
self.mem.tip().or_else(|| self.sled.tip())
|
self.mem.tip().or_else(|| self.disk.tip())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the depth of block `hash` in the current best chain.
|
/// Return the depth of block `hash` in the current best chain.
|
||||||
pub fn depth(&self, hash: block::Hash) -> Option<u32> {
|
pub fn depth(&self, hash: block::Hash) -> Option<u32> {
|
||||||
let tip = self.tip()?.0;
|
let tip = self.tip()?.0;
|
||||||
let height = self.mem.height(hash).or_else(|| self.sled.height(hash))?;
|
let height = self.mem.height(hash).or_else(|| self.disk.height(hash))?;
|
||||||
|
|
||||||
Some(tip.0 - height.0)
|
Some(tip.0 - height.0)
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ impl StateService {
|
||||||
pub fn block(&self, hash_or_height: HashOrHeight) -> Option<Arc<Block>> {
|
pub fn block(&self, hash_or_height: HashOrHeight) -> Option<Arc<Block>> {
|
||||||
self.mem
|
self.mem
|
||||||
.block(hash_or_height)
|
.block(hash_or_height)
|
||||||
.or_else(|| self.sled.block(hash_or_height))
|
.or_else(|| self.disk.block(hash_or_height))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the transaction identified by `hash` if it exists in the current
|
/// Return the transaction identified by `hash` if it exists in the current
|
||||||
|
@ -241,24 +241,24 @@ impl StateService {
|
||||||
pub fn transaction(&self, hash: transaction::Hash) -> Option<Arc<Transaction>> {
|
pub fn transaction(&self, hash: transaction::Hash) -> Option<Arc<Transaction>> {
|
||||||
self.mem
|
self.mem
|
||||||
.transaction(hash)
|
.transaction(hash)
|
||||||
.or_else(|| self.sled.transaction(hash))
|
.or_else(|| self.disk.transaction(hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the hash for the block at `height` in the current best chain.
|
/// Return the hash for the block at `height` in the current best chain.
|
||||||
pub fn hash(&self, height: block::Height) -> Option<block::Hash> {
|
pub fn hash(&self, height: block::Height) -> Option<block::Hash> {
|
||||||
self.mem.hash(height).or_else(|| self.sled.hash(height))
|
self.mem.hash(height).or_else(|| self.disk.hash(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the height for the block at `hash` in any chain.
|
/// Return the height for the block at `hash` in any chain.
|
||||||
pub fn height_by_hash(&self, hash: block::Hash) -> Option<block::Height> {
|
pub fn height_by_hash(&self, hash: block::Hash) -> Option<block::Height> {
|
||||||
self.mem
|
self.mem
|
||||||
.height_by_hash(hash)
|
.height_by_hash(hash)
|
||||||
.or_else(|| self.sled.height(hash))
|
.or_else(|| self.disk.height(hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the utxo pointed to by `outpoint` if it exists in any chain.
|
/// Return the utxo pointed to by `outpoint` if it exists in any chain.
|
||||||
pub fn utxo(&self, outpoint: &transparent::OutPoint) -> Option<transparent::Output> {
|
pub fn utxo(&self, outpoint: &transparent::OutPoint) -> Option<transparent::Output> {
|
||||||
self.mem.utxo(outpoint).or_else(|| self.sled.utxo(outpoint))
|
self.mem.utxo(outpoint).or_else(|| self.disk.utxo(outpoint))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return an iterator over the relevant chain of the block identified by
|
/// Return an iterator over the relevant chain of the block identified by
|
||||||
|
@ -312,7 +312,7 @@ impl Iter<'_> {
|
||||||
IterState::Finished => unreachable!(),
|
IterState::Finished => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(block) = service.sled.block(hash_or_height) {
|
if let Some(block) = service.disk.block(hash_or_height) {
|
||||||
let height = block
|
let height = block
|
||||||
.coinbase_height()
|
.coinbase_height()
|
||||||
.expect("valid blocks have a coinbase height");
|
.expect("valid blocks have a coinbase height");
|
||||||
|
@ -402,7 +402,7 @@ impl Service<Request> for StateService {
|
||||||
let (rsp_tx, rsp_rx) = oneshot::channel();
|
let (rsp_tx, rsp_rx) = oneshot::channel();
|
||||||
|
|
||||||
self.pending_utxos.check_block(&block);
|
self.pending_utxos.check_block(&block);
|
||||||
self.sled
|
self.disk
|
||||||
.queue_and_commit_finalized_blocks(QueuedBlock { block, rsp_tx });
|
.queue_and_commit_finalized_blocks(QueuedBlock { block, rsp_tx });
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
@ -449,7 +449,7 @@ impl Service<Request> for StateService {
|
||||||
|
|
||||||
/// Initialize a state service from the provided [`Config`].
|
/// Initialize a state service from the provided [`Config`].
|
||||||
///
|
///
|
||||||
/// Each `network` has its own separate sled database.
|
/// Each `network` has its own separate on-disk database.
|
||||||
///
|
///
|
||||||
/// To share access to the state, wrap the returned service in a `Buffer`. It's
|
/// To share access to the state, wrap the returned service in a `Buffer`. It's
|
||||||
/// possible to construct multiple state services in the same application (as
|
/// possible to construct multiple state services in the same application (as
|
||||||
|
|
Loading…
Reference in New Issue