Skip to content
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

merge queue: embarking main (97460cf), #9167 and #9208 together #9220

Closed
wants to merge 8 commits into from
8 changes: 4 additions & 4 deletions .github/workflows/cd-deploy-nodes-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

- name: Create instance template for ${{ matrix.network }}
run: |
Expand Down Expand Up @@ -384,13 +384,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Create instance template from container image
- name: Manual deploy of a single ${{ inputs.network }} instance running zebrad
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/chore-delete-gcp-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Deletes all mainnet and testnet instances older than $DELETE_INSTANCE_DAYS days.
#
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Rust files
id: changed-files-rust
uses: tj-actions/[email protected].6
uses: tj-actions/[email protected].7
with:
files: |
**/*.rs
Expand All @@ -56,7 +56,7 @@ jobs:

- name: Workflow files
id: changed-files-workflows
uses: tj-actions/[email protected].6
uses: tj-actions/[email protected].7
with:
files: |
.github/workflows/*.yml
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs-deploy-firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- uses: r7kamura/[email protected]

- name: Setup mdBook
uses: jontze/action-mdbook@v3.0.1
uses: jontze/action-mdbook@v4.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
mdbook-version: '~0.4'
Expand All @@ -106,7 +106,7 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_FIREBASE_SA }}'
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_FIREBASE_SA }}'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/manual-zcashd-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Create instance template from container image
- name: Create instance template
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes
- uses: release-drafter/release-drafter@v6.0.0
- uses: release-drafter/release-drafter@v6.1.0
with:
config-name: release-drafter.yml
commitish: main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sub-build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_ARTIFACTS_SA }}'
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/sub-deploy-integration-tests-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Create a Compute Engine virtual machine and attach a cached state disk using the
# $CACHED_DISK_NAME env as the source image to populate the disk cached state
Expand Down Expand Up @@ -429,13 +429,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Sets the $UPDATE_SUFFIX env var to "-u" if updating a previous cached state,
# and the empty string otherwise.
Expand Down Expand Up @@ -695,13 +695,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Deletes the instances that has been recently deployed in the actual commit after all
# previous jobs have run, no matter the outcome of the job.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sub-find-cached-disks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ jobs:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected].7
uses: google-github-actions/[email protected].8
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/[email protected].2
uses: google-github-actions/[email protected].4

# Performs formatting on disk name components.
#
Expand Down
44 changes: 43 additions & 1 deletion zebra-state/src/service/non_finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
};

use zebra_chain::{
block::{self, Block},
block::{self, Block, Hash},
parameters::Network,
sprout, transparent,
};
Expand Down Expand Up @@ -45,6 +45,10 @@ pub struct NonFinalizedState {
/// callers should migrate to `chain_iter().next()`.
chain_set: BTreeSet<Arc<Chain>>,

/// Blocks that have been invalidated in, and removed from, the non finalized
/// state.
invalidated_blocks: HashMap<Hash, Arc<Vec<ContextuallyVerifiedBlock>>>,

// Configuration
//
/// The configured Zcash network.
Expand Down Expand Up @@ -92,6 +96,7 @@ impl Clone for NonFinalizedState {
Self {
chain_set: self.chain_set.clone(),
network: self.network.clone(),
invalidated_blocks: self.invalidated_blocks.clone(),

#[cfg(feature = "getblocktemplate-rpcs")]
should_count_metrics: self.should_count_metrics,
Expand All @@ -112,6 +117,7 @@ impl NonFinalizedState {
NonFinalizedState {
chain_set: Default::default(),
network: network.clone(),
invalidated_blocks: Default::default(),
#[cfg(feature = "getblocktemplate-rpcs")]
should_count_metrics: true,
#[cfg(feature = "progress-bar")]
Expand Down Expand Up @@ -264,6 +270,37 @@ impl NonFinalizedState {
Ok(())
}

/// Invalidate block with hash `block_hash` and all descendants from the non-finalized state. Insert
/// the new chain into the chain_set and discard the previous.
pub fn invalidate_block(&mut self, block_hash: Hash) {
let Some(chain) = self.find_chain(|chain| chain.contains_block_hash(block_hash)) else {
return;
};

let invalidated_blocks = if chain.non_finalized_root_hash() == block_hash {
self.chain_set.remove(&chain);
chain.blocks.values().cloned().collect()
} else {
let (new_chain, invalidated_blocks) = chain
.invalidate_block(block_hash)
.expect("already checked that chain contains hash");

// Add the new chain fork or updated chain to the set of recent chains, and
// remove the chain containing the hash of the block from chain set
self.insert_with(Arc::new(new_chain.clone()), |chain_set| {
chain_set.retain(|c| !c.contains_block_hash(block_hash))
});

invalidated_blocks
};

self.invalidated_blocks
.insert(block_hash, Arc::new(invalidated_blocks));

self.update_metrics_for_chains();
self.update_metrics_bars();
}

/// Commit block to the non-finalized state as a new chain where its parent
/// is the finalized tip.
#[tracing::instrument(level = "debug", skip(self, finalized_state, prepared))]
Expand Down Expand Up @@ -586,6 +623,11 @@ impl NonFinalizedState {
self.chain_set.len()
}

/// Return the invalidated blocks.
pub fn invalidated_blocks(&self) -> HashMap<block::Hash, Arc<Vec<ContextuallyVerifiedBlock>>> {
self.invalidated_blocks.clone()
}

/// Return the chain whose tip block hash is `parent_hash`.
///
/// The chain can be an existing chain in the non-finalized state, or a freshly
Expand Down
24 changes: 22 additions & 2 deletions zebra-state/src/service/non_finalized_state/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,26 @@ impl Chain {
(block, treestate)
}

// Returns the block at the provided height and all of its descendant blocks.
pub fn child_blocks(&self, block_height: &block::Height) -> Vec<ContextuallyVerifiedBlock> {
self.blocks
.range(block_height..)
.map(|(_h, b)| b.clone())
.collect()
}

// Returns a new chain without the invalidated block or its descendants.
pub fn invalidate_block(
&self,
block_hash: block::Hash,
) -> Option<(Self, Vec<ContextuallyVerifiedBlock>)> {
let block_height = self.height_by_hash(block_hash)?;
let mut new_chain = self.fork(block_hash)?;
new_chain.pop_tip();
new_chain.last_fork_height = None;
Some((new_chain, self.child_blocks(&block_height)))
}

/// Returns the height of the chain root.
pub fn non_finalized_root_height(&self) -> block::Height {
self.blocks
Expand Down Expand Up @@ -1600,7 +1620,7 @@ impl DerefMut for Chain {

/// The revert position being performed on a chain.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum RevertPosition {
pub(crate) enum RevertPosition {
/// The chain root is being reverted via [`Chain::pop_root`], when a block
/// is finalized.
Root,
Expand All @@ -1619,7 +1639,7 @@ enum RevertPosition {
/// and [`Chain::pop_tip`] functions, and fear that it would be easy to
/// introduce bugs when updating them, unless the code was reorganized to keep
/// related operations adjacent to each other.
trait UpdateWith<T> {
pub(crate) trait UpdateWith<T> {
/// When `T` is added to the chain tip,
/// update [`Chain`] cumulative data members to add data that are derived from `T`.
fn update_chain_tip_with(&mut self, _: &T) -> Result<(), ValidateContextError>;
Expand Down
Loading
Loading