From 82696b150b4e55bfbbe98f2430870a16489e7c41 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 13 Jul 2021 06:11:33 +1000 Subject: [PATCH] Document some consensus-critical finalized state behaviour (#2476) * Document the new genesis transaction consensus rule Zebra previously implemented this rule, but we documented it as a bug in `zcashd`. * Document the actual behaviour of zs_insert --- zebra-state/src/service/finalized_state.rs | 8 ++++---- zebra-state/src/service/finalized_state/disk_format.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zebra-state/src/service/finalized_state.rs b/zebra-state/src/service/finalized_state.rs index 85d99491..b78a2ec5 100644 --- a/zebra-state/src/service/finalized_state.rs +++ b/zebra-state/src/service/finalized_state.rs @@ -246,9 +246,10 @@ impl FinalizedState { // TODO: sprout and sapling anchors (per block) - // Consensus-critical bug in zcashd: transactions in the - // genesis block are ignored. - if block.header.previous_block_hash == block::Hash([0; 32]) { + // "A transaction MUST NOT spend an output of the genesis block coinbase transaction. + // (There is one such zero-valued output, on each of Testnet and Mainnet .)" + // https://zips.z.cash/protocol/protocol.pdf#txnconsensus + if block.header.previous_block_hash == GENESIS_PREVIOUS_BLOCK_HASH { return batch; } @@ -258,7 +259,6 @@ impl FinalizedState { } // Index each transaction, spent inputs, nullifiers - // TODO: move computation into FinalizedBlock as with transparent outputs for (transaction_index, (transaction, transaction_hash)) in block .transactions .iter() diff --git a/zebra-state/src/service/finalized_state/disk_format.rs b/zebra-state/src/service/finalized_state/disk_format.rs index 4da8886d..fce669e9 100644 --- a/zebra-state/src/service/finalized_state/disk_format.rs +++ b/zebra-state/src/service/finalized_state/disk_format.rs @@ -235,7 +235,8 @@ impl IntoDisk for transparent::OutPoint { /// Helper trait for inserting (Key, Value) pairs into rocksdb with a consistently /// defined format pub trait DiskSerialize { - /// Serialize and insert the given key and value into a rocksdb column family. + /// Serialize and insert the given key and value into a rocksdb column family, + /// overwriting any existing `value` for `key`. fn zs_insert(&mut self, cf: &rocksdb::ColumnFamily, key: K, value: V) where K: IntoDisk + Debug,