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

Mandatory checkpoint on Canopy - breaking cached state test change #1898

Merged
merged 6 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jobs:
cd zebra/;
docker build --build-arg SHORT_SHA=$SHORT_SHA -f docker/Dockerfile.test -t zebrad-test .;
docker run -i zebrad-test cargo test --workspace --no-fail-fast -- -Zunstable-options --include-ignored;
docker run -i --mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/zebrad-cache-$SHORT_SHA-mainnet-419200,target=/zebrad-cache zebrad-test:latest cargo test --verbose --features test_sync_past_sapling_mainnet --manifest-path zebrad/Cargo.toml sync_past_sapling_mainnet;
docker run -i --mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/zebrad-cache-$SHORT_SHA-testnet-280000,target=/zebrad-cache zebrad-test:latest cargo test --verbose --features test_sync_past_sapling_testnet --manifest-path zebrad/Cargo.toml sync_past_sapling_testnet;
docker run -i --mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/zebrad-cache-$SHORT_SHA-mainnet-419200,target=/zebrad-cache zebrad-test:latest cargo test --verbose --features test_sync_past_canopy_mainnet --manifest-path zebrad/Cargo.toml sync_past_canopy_mainnet;
docker run -i --mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/zebrad-cache-$SHORT_SHA-testnet-280000,target=/zebrad-cache zebrad-test:latest cargo test --verbose --features test_sync_past_canopy_testnet --manifest-path zebrad/Cargo.toml sync_past_canopy_testnet;
"
# Clean up
- name: Delete test instance
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ This release also implements some other Zcash consensus rules, to check that
Zebra's [validation architecture](#architecture) supports future work on a
full validating node:
- block and transaction structure
- checkpoint-based verification up to Sapling
- checkpoint-based verification up to Canopy
- transaction validation (incomplete)
- transaction cryptography (incomplete)
- transaction scripts (incomplete)
Expand Down
6 changes: 3 additions & 3 deletions book/src/dev/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ The following are general desiderata for Zebra:
perform Zcash-related tasks. Implementation details of each
component should not leak into all other components.

* Zebra should checkpoint on Sapling activation and drop all
Sprout-related functionality not required post-Sapling.
* Zebra should checkpoint on Canopy activation and drop all
Sprout-related functionality not required post-Canopy.

### Non-Goals

Expand Down Expand Up @@ -189,7 +189,7 @@ for Zcash script inspection, debugging, etc.
transaction is accepted in a particular chain state context.
- verifying mempool (unconfirmed) transactions
- block checkpoints
- mandatory checkpoints (genesis block, sapling activation)
- mandatory checkpoints (genesis block, canopy activation)
- optional regular checkpoints (every Nth block)
- modifying the chain state
- adding new blocks to `ZebraState`, including chain reorganisation
Expand Down
4 changes: 2 additions & 2 deletions book/src/dev/rfcs/0005-state-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ new chains for `push` when new blocks arrive whose parent isn't a tip of an
existing chain.

**Note:** The `Chain` type's API is only designed to handle non-finalized
data. The genesis block and all pre sapling blocks are always considered to
data. The genesis block and all pre canopy blocks are always considered to
be finalized blocks and should not be handled via the `Chain` type through
`CommitBlock`. They should instead be committed directly to the finalized
state with `CommitFinalizedBlock`. This is particularly important with the
Expand Down Expand Up @@ -419,7 +419,7 @@ chain and updates all side chains to match.

Commit `block` to the non-finalized state.

1. If the block is a pre-Sapling block, panic.
1. If the block is a pre-Canopy block, panic.
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

2. If any chains tip hash equal `block.header.previous_block_hash` remove that chain from `self.chain_set`

Expand Down
10 changes: 5 additions & 5 deletions book/src/dev/rfcs/0006-contextual-difficulty.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Contextual validation is implemented in
`StateService::check_contextual_validity`, which calls a separate function for
each contextual validity check.

In Zebra, contextual validation starts after Sapling activation, so we can assume
In Zebra, contextual validation starts after Canopy activation, so we can assume
that the relevant chain contains at least 28 blocks on Mainnet and Testnet. (And
panic if this assumption does not hold at runtime.)

Expand Down Expand Up @@ -423,7 +423,7 @@ the sum of these difficulty thresholds will be less than or equal to
`(2^251 − 1)*17 = 2^255 + 2^251 - 17`. Therefore, this calculation can not
overflow a `u256` value. So the function is infalliable.

In Zebra, contextual validation starts after Sapling activation, so we can assume
In Zebra, contextual validation starts after Canopy activation, so we can assume
that the relevant chain contains at least 17 blocks. Therefore, the `PoWLimit`
case of `MeanTarget()` in the Zcash specification is unreachable.

Expand Down Expand Up @@ -492,7 +492,7 @@ impl NetworkUpgrade {

#### Implementation notes

In Zebra, contextual validation starts after Sapling activation, so we can assume
In Zebra, contextual validation starts after Canopy activation, so we can assume
that the relevant chain contains at least 28 blocks. Therefore:
* `max(0, height − PoWMedianBlockSpan)` in the `MedianTime()` calculation
simplifies to `height − PoWMedianBlockSpan`, and
Expand Down Expand Up @@ -577,7 +577,7 @@ pub fn is_testnet_min_difficulty_block(
#### Implementation notes

In Zcash, the Testnet minimum difficulty rule starts at block 299188, and in
Zebra, contextual validation starts after Sapling activation. So we can assume
Zebra, contextual validation starts after Canopy activation. So we can assume
that there is always a previous block.

Therefore, this function is infalliable.
Expand All @@ -596,7 +596,7 @@ minimum difficulty gap. We use the existing
`ExpandedDifficulty::target_difficulty_limit` function to calculate the value of
`ToCompact(PoWLimit(network))`.

In Zebra, contextual validation starts after Sapling activation, so the genesis
In Zebra, contextual validation starts after Canopy activation, so the genesis
case of `Threshold()` in the Zcash specification is unreachable.

#### Block difficulty threshold implementation
Expand Down
2 changes: 1 addition & 1 deletion book/src/dev/zebra-checkpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
`zebra-checkpoints` uses a local `zcashd` instance to generate a list of checkpoints for Zebra's checkpoint verifier.

Developers should run this tool every few months to add new checkpoints for the `checkpoint_sync = true` mode.
(By default, Zebra syncs up to Sapling using checkpoints. These checkpoints don't need to be updated.)
(By default, Zebra syncs up to Canopy using checkpoints. These checkpoints don't need to be updated.)

For more information on how to run this program visit [Zebra checkpoints document](https://github.com/ZcashFoundation/zebra/tree/main/zebra-consensus/src/checkpoint/README.md)
2 changes: 1 addition & 1 deletion zebra-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl LedgerState {
impl Default for LedgerState {
fn default() -> Self {
let network = parameters::Network::Mainnet;
let tip_height = parameters::NetworkUpgrade::Sapling
let tip_height = parameters::NetworkUpgrade::Canopy
.activation_height(network)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::{
/// blockchain).
///
/// Zcash has a number of different transaction formats. They are represented
/// internally by different enum variants. Because we checkpoint on Sapling
/// internally by different enum variants. Because we checkpoint on Canopy
/// activation, we do not validate any pre-Sapling transaction types.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
// XXX consider boxing the Optional fields of V4 and V5 txs
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ZcashSerialize for Transaction {
// we start parsing mempool transactions, or generating our own
// transactions (see #483).
//
// Since we checkpoint on Sapling activation, we won't ever need
// Since we checkpoint on Canopy activation, we won't ever need
// to check the smaller pre-Sapling transaction size limit.
match self {
Transaction::V1 {
Expand Down
6 changes: 3 additions & 3 deletions zebra-consensus/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing::instrument;

use zebra_chain::{
block::{self, Block},
parameters::{Network, NetworkUpgrade::Sapling},
parameters::{Network, NetworkUpgrade::Canopy},
};

use zebra_state as zs;
Expand Down Expand Up @@ -135,8 +135,8 @@ where
let max_checkpoint_height = if config.checkpoint_sync {
list.max_height()
} else {
list.min_height_in_range(Sapling.activation_height(network).unwrap()..)
.expect("hardcoded checkpoint list extends past sapling activation")
list.min_height_in_range(Canopy.activation_height(network).unwrap()..)
.expect("hardcoded checkpoint list extends past canopy activation")
};

let tip = match state_service
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/checkpoint/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Zebra checkpoints

Zebra validates pre-Sapling blocks using a list of `Mainnet` and `Testnet` block hash checkpoints:
Zebra validates pre-Canopy blocks using a list of `Mainnet` and `Testnet` block hash checkpoints:

- [Mainnet checkpoints](https://github.com/ZcashFoundation/zebra/blob/main/zebra-consensus/src/checkpoint/main-checkpoints.txt)
- [Testnet checkpoints](https://github.com/ZcashFoundation/zebra/blob/main/zebra-consensus/src/checkpoint/test-checkpoints.txt)

Zebra can also be configured to use these checkpoints after Sapling:
Zebra can also be configured to use these checkpoints after Canopy:
```
[consensus]
checkpoint_sync = true
Expand Down
21 changes: 21 additions & 0 deletions zebra-consensus/src/checkpoint/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,28 @@ use std::{
use zebra_chain::block;
use zebra_chain::parameters::{genesis_hash, Network};

/// The hard-coded checkpoints for mainnet, generated using the
/// `zebra-checkpoints` tool.
///
/// To regenerate the latest checkpoints, use the following commands:
/// ```sh
/// LAST_CHECKPOINT=$(tail -1 main-checkpoints.txt | cut -d' ' -f1)
/// echo "$LAST_CHECKPOINT"
/// zebra-checkpoints --cli /path/to/zcash-cli --last-checkpoint "$LAST_CHECKPOINT" >> main-checkpoints.txt &
/// tail -f main-checkpoints.txt
/// ```
///
/// See the checkpoints [./README.md] for more details.
const MAINNET_CHECKPOINTS: &str = include_str!("main-checkpoints.txt");

/// The hard-coded checkpoints for testnet, generated using the
/// `zebra-checkpoints` tool.
///
/// To use testnet, use the testnet checkpoints file, and run
/// `zebra-checkpoints [other args] -- -testnet`.
///
/// See [`MAINNET_CHECKPOINTS`] for detailed `zebra-checkpoints` usage
/// information.
const TESTNET_CHECKPOINTS: &str = include_str!("test-checkpoints.txt");

/// A list of block height and hash checkpoints.
Expand Down
20 changes: 10 additions & 10 deletions zebra-consensus/src/checkpoint/list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,28 +241,28 @@ fn checkpoint_list_load_hard_coded() -> Result<(), BoxError> {
}

#[test]
fn checkpoint_list_hard_coded_sapling_mainnet() -> Result<(), BoxError> {
checkpoint_list_hard_coded_sapling(Mainnet)
fn checkpoint_list_hard_coded_canopy_mainnet() -> Result<(), BoxError> {
checkpoint_list_hard_coded_canopy(Mainnet)
}

#[test]
fn checkpoint_list_hard_coded_sapling_testnet() -> Result<(), BoxError> {
checkpoint_list_hard_coded_sapling(Testnet)
fn checkpoint_list_hard_coded_canopy_testnet() -> Result<(), BoxError> {
checkpoint_list_hard_coded_canopy(Testnet)
}

/// Check that the hard-coded lists cover the Sapling network upgrade
fn checkpoint_list_hard_coded_sapling(network: Network) -> Result<(), BoxError> {
/// Check that the hard-coded lists cover the Canopy network upgrade
fn checkpoint_list_hard_coded_canopy(network: Network) -> Result<(), BoxError> {
zebra_test::init();

let sapling_activation = Sapling
let canopy_activation = Canopy
.activation_height(network)
.expect("Unexpected network upgrade info: Sapling must have an activation height");
.expect("Unexpected network upgrade info: Canopy must have an activation height");

let list = CheckpointList::new(network);

assert!(
list.max_height() >= sapling_activation,
"Pre-Sapling blocks must be verified by checkpoints"
list.max_height() >= canopy_activation,
"Pre-Canopy blocks must be verified by checkpoints"
);

Ok(())
Expand Down
Loading