Skip to content

Commit

Permalink
rename(state): do additional renaming for clarification purposes (#6967)
Browse files Browse the repository at this point in the history
* do renames by script

```
git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/CommitFinalized/CommitCheckpointVerified/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/commit_finalized_block/commit_checkpoint_verified/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/drain_queue_and_commit_finalized/drain_finalized_queue_and_commit/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queue_and_commit_finalized/queue_and_commit_to_finalized_state/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queued_finalized_blocks/finalized_state_queued_blocks/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/max_queued_finalized_height/max_finalized_queue_height/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/send_finalized_block_error/send_checkpoint_verified_block_error/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/QueuedFinalized/QueuedCheckpointVerified/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queue_and_commit_non_finalized/queue_and_commit_to_non_finalized_state/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queued_non_finalized_blocks/non_finalized_state_queued_blocks/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/send_non_finalized_block_error/send_semantically_verified_block_error/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/QueuedNonFinalized/QueuedSemanticallyVerified/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/last_sent_finalized_block_hash/finalized_block_write_last_sent_hash/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/sent_non_finalized_block_hashes/non_finalized_block_write_sent_hashes/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/invalid_block_reset_receiver/invalid_block_write_reset_receiver/g'

cargo fmt --all
```

* add missing log renames by script

```
git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queued finalized block/finalized state queue block/g'

git ls-tree --full-tree -r --name-only HEAD | \
grep -v 'book' | grep -v 'CHANGELOG.md' | \
xargs sed -i 's/queued non-finalized block/non-finalized state queue block/g'

cargo fmt --all
```
  • Loading branch information
oxarbitrage authored Jun 15, 2023
1 parent e748d9a commit 8a7c871
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 106 deletions.
14 changes: 7 additions & 7 deletions zebra-consensus/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ pub enum VerifyCheckpointError {
#[error("checkpoint verifier was dropped")]
Dropped,
#[error(transparent)]
CommitFinalized(BoxError),
CommitCheckpointVerified(BoxError),
#[error(transparent)]
Tip(BoxError),
#[error(transparent)]
Expand Down Expand Up @@ -1084,19 +1084,19 @@ where
// we don't reject the entire checkpoint.
// Instead, we reset the verifier to the successfully committed state tip.
let state_service = self.state_service.clone();
let commit_finalized_block = tokio::spawn(async move {
let commit_checkpoint_verified = tokio::spawn(async move {
let hash = req_block
.rx
.await
.map_err(Into::into)
.map_err(VerifyCheckpointError::CommitFinalized)
.map_err(VerifyCheckpointError::CommitCheckpointVerified)
.expect("CheckpointVerifier does not leave dangling receivers")?;

// We use a `ServiceExt::oneshot`, so that every state service
// `poll_ready` has a corresponding `call`. See #1593.
match state_service
.oneshot(zs::Request::CommitCheckpointVerifiedBlock(req_block.block))
.map_err(VerifyCheckpointError::CommitFinalized)
.map_err(VerifyCheckpointError::CommitCheckpointVerified)
.await?
{
zs::Response::Committed(committed_hash) => {
Expand All @@ -1110,18 +1110,18 @@ where
let state_service = self.state_service.clone();
let reset_sender = self.reset_sender.clone();
async move {
let result = commit_finalized_block.await;
let result = commit_checkpoint_verified.await;
// Avoid a panic on shutdown
//
// When `zebrad` is terminated using Ctrl-C, the `commit_finalized_block` task
// When `zebrad` is terminated using Ctrl-C, the `commit_checkpoint_verified` task
// can return a `JoinError::Cancelled`. We expect task cancellation on shutdown,
// so we don't need to panic here. The persistent state is correct even when the
// task is cancelled, because block data is committed inside transactions, in
// height order.
let result = if zebra_chain::shutdown::is_shutting_down() {
Err(VerifyCheckpointError::ShuttingDown)
} else {
result.expect("commit_finalized_block should not panic")
result.expect("commit_checkpoint_verified should not panic")
};
if result.is_err() {
// If there was an error committing the block, then this verifier
Expand Down
167 changes: 89 additions & 78 deletions zebra-state/src/service.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions zebra-state/src/service/finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use zebra_chain::{block, parameters::Network};

use crate::{
request::ContextuallyVerifiedBlockWithTrees,
service::{check, QueuedFinalized},
service::{check, QueuedCheckpointVerified},
BoxError, CheckpointVerifiedBlock, CloneError, Config,
};

Expand Down Expand Up @@ -167,7 +167,7 @@ impl FinalizedState {
/// order.
pub fn commit_finalized(
&mut self,
ordered_block: QueuedFinalized,
ordered_block: QueuedCheckpointVerified,
) -> Result<CheckpointVerifiedBlock, BoxError> {
let (checkpoint_verified, rsp_tx) = ordered_block;
let result = self.commit_finalized_direct(
Expand Down
21 changes: 12 additions & 9 deletions zebra-state/src/service/queued_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::{BoxError, CheckpointVerifiedBlock, SemanticallyVerifiedBlock};
#[cfg(test)]
mod tests;

/// A queued finalized block, and its corresponding [`Result`] channel.
pub type QueuedFinalized = (
/// A finalized state queue block, and its corresponding [`Result`] channel.
pub type QueuedCheckpointVerified = (
CheckpointVerifiedBlock,
oneshot::Sender<Result<block::Hash, BoxError>>,
);

/// A queued non-finalized block, and its corresponding [`Result`] channel.
pub type QueuedNonFinalized = (
/// A non-finalized state queue block, and its corresponding [`Result`] channel.
pub type QueuedSemanticallyVerified = (
SemanticallyVerifiedBlock,
oneshot::Sender<Result<block::Hash, BoxError>>,
);
Expand All @@ -31,7 +31,7 @@ pub type QueuedNonFinalized = (
#[derive(Debug, Default)]
pub struct QueuedBlocks {
/// Blocks awaiting their parent blocks for contextual verification.
blocks: HashMap<block::Hash, QueuedNonFinalized>,
blocks: HashMap<block::Hash, QueuedSemanticallyVerified>,
/// Hashes from `queued_blocks`, indexed by parent hash.
by_parent: HashMap<block::Hash, HashSet<block::Hash>>,
/// Hashes from `queued_blocks`, indexed by block height.
Expand All @@ -47,7 +47,7 @@ impl QueuedBlocks {
///
/// - if a block with the same `block::Hash` has already been queued.
#[instrument(skip(self), fields(height = ?new.0.height, hash = %new.0.hash))]
pub fn queue(&mut self, new: QueuedNonFinalized) {
pub fn queue(&mut self, new: QueuedSemanticallyVerified) {
let new_hash = new.0.hash;
let new_height = new.0.height;
let parent_hash = new.0.block.header.previous_block_hash;
Expand Down Expand Up @@ -86,7 +86,10 @@ impl QueuedBlocks {
/// Dequeue and return all blocks that were waiting for the arrival of
/// `parent`.
#[instrument(skip(self), fields(%parent_hash))]
pub fn dequeue_children(&mut self, parent_hash: block::Hash) -> Vec<QueuedNonFinalized> {
pub fn dequeue_children(
&mut self,
parent_hash: block::Hash,
) -> Vec<QueuedSemanticallyVerified> {
let queued_children = self
.by_parent
.remove(&parent_hash)
Expand Down Expand Up @@ -176,7 +179,7 @@ impl QueuedBlocks {
}

/// Return the queued block if it has already been registered
pub fn get_mut(&mut self, hash: &block::Hash) -> Option<&mut QueuedNonFinalized> {
pub fn get_mut(&mut self, hash: &block::Hash) -> Option<&mut QueuedSemanticallyVerified> {
self.blocks.get_mut(hash)
}

Expand Down Expand Up @@ -208,7 +211,7 @@ impl QueuedBlocks {
/// Returns all key-value pairs of blocks as an iterator.
///
/// Doesn't update the metrics, because it is only used when the state is being dropped.
pub fn drain(&mut self) -> Drain<'_, block::Hash, QueuedNonFinalized> {
pub fn drain(&mut self) -> Drain<'_, block::Hash, QueuedSemanticallyVerified> {
self.known_utxos.clear();
self.known_utxos.shrink_to_fit();
self.by_parent.clear();
Expand Down
6 changes: 3 additions & 3 deletions zebra-state/src/service/queued_blocks/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ use zebra_test::prelude::*;

use crate::{
arbitrary::Prepare,
service::queued_blocks::{QueuedBlocks, QueuedNonFinalized},
service::queued_blocks::{QueuedBlocks, QueuedSemanticallyVerified},
tests::FakeChainHelper,
};

// Quick helper trait for making queued blocks with throw away channels
trait IntoQueued {
fn into_queued(self) -> QueuedNonFinalized;
fn into_queued(self) -> QueuedSemanticallyVerified;
}

impl IntoQueued for Arc<Block> {
fn into_queued(self) -> QueuedNonFinalized {
fn into_queued(self) -> QueuedSemanticallyVerified {
let (rsp_tx, _) = oneshot::channel();
(self.prepare(), rsp_tx)
}
Expand Down
8 changes: 4 additions & 4 deletions zebra-state/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ proptest! {
expected_finalized_value_pool += *block_value_pool;
}

let result_receiver = state_service.queue_and_commit_finalized(block.clone());
let result_receiver = state_service.queue_and_commit_to_finalized_state(block.clone());
let result = result_receiver.blocking_recv();

prop_assert!(result.is_ok(), "unexpected failed finalized block commit: {:?}", result);
Expand All @@ -450,7 +450,7 @@ proptest! {
let block_value_pool = &block.block.chain_value_pool_change(&transparent::utxos_from_ordered_utxos(utxos))?;
expected_non_finalized_value_pool += *block_value_pool;

let result_receiver = state_service.queue_and_commit_non_finalized(block.clone());
let result_receiver = state_service.queue_and_commit_to_non_finalized_state(block.clone());
let result = result_receiver.blocking_recv();

prop_assert!(result.is_ok(), "unexpected failed non-finalized block commit: {:?}", result);
Expand Down Expand Up @@ -509,7 +509,7 @@ proptest! {
TipAction::grow_with(expected_block.clone().into())
};

let result_receiver = state_service.queue_and_commit_finalized(block);
let result_receiver = state_service.queue_and_commit_to_finalized_state(block);
let result = result_receiver.blocking_recv();

prop_assert!(result.is_ok(), "unexpected failed finalized block commit: {:?}", result);
Expand All @@ -532,7 +532,7 @@ proptest! {
TipAction::grow_with(expected_block.clone().into())
};

let result_receiver = state_service.queue_and_commit_non_finalized(block);
let result_receiver = state_service.queue_and_commit_to_non_finalized_state(block);
let result = result_receiver.blocking_recv();

prop_assert!(result.is_ok(), "unexpected failed non-finalized block commit: {:?}", result);
Expand Down
6 changes: 3 additions & 3 deletions zebra-state/src/service/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
check,
finalized_state::{FinalizedState, ZebraDb},
non_finalized_state::NonFinalizedState,
queued_blocks::{QueuedFinalized, QueuedNonFinalized},
queued_blocks::{QueuedCheckpointVerified, QueuedSemanticallyVerified},
BoxError, ChainTipBlock, ChainTipSender, CloneError,
},
CommitSemanticallyVerifiedError, SemanticallyVerifiedBlock,
Expand Down Expand Up @@ -131,8 +131,8 @@ fn update_latest_chain_channels(
)
)]
pub fn write_blocks_from_channels(
mut finalized_block_write_receiver: UnboundedReceiver<QueuedFinalized>,
mut non_finalized_block_write_receiver: UnboundedReceiver<QueuedNonFinalized>,
mut finalized_block_write_receiver: UnboundedReceiver<QueuedCheckpointVerified>,
mut non_finalized_block_write_receiver: UnboundedReceiver<QueuedSemanticallyVerified>,
mut finalized_state: FinalizedState,
mut non_finalized_state: NonFinalizedState,
invalid_block_reset_sender: UnboundedSender<block::Hash>,
Expand Down

0 comments on commit 8a7c871

Please sign in to comment.