[consensus breaking] apply block outputs first (simplification) and add verify_cut_through() ()

* CONSENSUS BREAKING - simplification apply_block just does outputs first

* rustfmt

* add verify_cut_through to both block and transaction
This commit is contained in:
Antioch Peverell 2018-06-20 15:47:32 -04:00 committed by GitHub
parent 0ff6763ee6
commit c9229fa97b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)?;
}