From c9229fa97be34ef32df2e195a8bd4f50ce4f9fab Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Wed, 20 Jun 2018 15:47:32 -0400 Subject: [PATCH] [consensus breaking] apply block outputs first (simplification) and add verify_cut_through() (#1112) * CONSENSUS BREAKING - simplification apply_block just does outputs first * rustfmt * add verify_cut_through to both block and transaction --- chain/src/txhashset.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/chain/src/txhashset.rs b/chain/src/txhashset.rs index 46004156..4969c9cf 100644 --- a/chain/src/txhashset.rs +++ b/chain/src/txhashset.rs @@ -575,30 +575,17 @@ impl<'a> Extension<'a> { /// applied in order of the provided Vec. If pruning is enabled, inputs also /// prune MMR data. pub fn apply_block(&mut self, b: &Block) -> Result<(), Error> { - // first applying coinbase outputs. due to the construction of PMMRs the - // last element, when its a leaf, can never be pruned as it has no parent - // yet and it will be needed to calculate that hash. to work around this, - // we insert coinbase outputs first to add at least one output of padding + // A block is not valid if it has not been fully cut-through. + // So we can safely apply outputs first (we will not spend these in the same + // block). for out in &b.outputs { - if out.features.contains(OutputFeatures::COINBASE_OUTPUT) { - self.apply_output(out)?; - } + self.apply_output(out)?; } - // then doing inputs guarantees an input can't spend an output in the - // same block, enforcing block cut-through for input in &b.inputs { self.apply_input(input)?; } - // now all regular, non coinbase outputs - for out in &b.outputs { - if !out.features.contains(OutputFeatures::COINBASE_OUTPUT) { - self.apply_output(out)?; - } - } - - // then applying all kernels for kernel in &b.kernels { self.apply_kernel(kernel)?; }