Consolidate validation in Block and Transaction (#1354)

* Consolidate validation in Block and Transaction

Introduce TransactionBody which is included into block and tx.
Fixes #1333
This commit is contained in:
hashmap
2018-08-15 23:14:48 +02:00
committed by GitHub
parent 37fa413329
commit 99a66c1960
20 changed files with 570 additions and 476 deletions
+1 -1
View File
@@ -421,7 +421,7 @@ impl Chain {
let height = self.next_block_height()?;
let mut txhashset = self.txhashset.write().unwrap();
txhashset::extending_readonly(&mut txhashset, |extension| {
extension.verify_coinbase_maturity(&tx.inputs, height)?;
extension.verify_coinbase_maturity(&tx.inputs(), height)?;
Ok(())
})
}
+4 -4
View File
@@ -66,9 +66,9 @@ pub fn process_block(b: &Block, ctx: &mut BlockContext) -> Result<Option<Tip>, E
"pipe: process_block {} at {} with {} inputs, {} outputs, {} kernels",
b.hash(),
b.header.height,
b.inputs.len(),
b.outputs.len(),
b.kernels.len(),
b.inputs().len(),
b.outputs().len(),
b.kernels().len(),
);
check_known(b.hash(), ctx)?;
@@ -328,7 +328,7 @@ fn validate_block(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> {
fn validate_block_via_txhashset(b: &Block, ext: &mut txhashset::Extension) -> Result<(), Error> {
// First check we are not attempting to spend any coinbase outputs
// before they have matured sufficiently.
ext.verify_coinbase_maturity(&b.inputs, b.header.height)?;
ext.verify_coinbase_maturity(&b.inputs(), b.header.height)?;
// apply the new block to the MMR trees and check the new root hashes
ext.apply_block(&b)?;
+1 -1
View File
@@ -157,7 +157,7 @@ impl ChainStore {
pub fn build_block_input_bitmap(&self, block: &Block) -> Result<Bitmap, Error> {
let bitmap = block
.inputs
.inputs()
.iter()
.filter_map(|x| self.get_output_pos(&x.commitment()).ok())
.map(|x| x as u32)
+7 -7
View File
@@ -474,27 +474,27 @@ impl<'a> Extension<'a> {
// Build bitmap of output pos spent (as inputs) by this tx for rewind.
let rewind_rm_pos = tx
.inputs
.inputs()
.iter()
.filter_map(|x| self.get_output_pos(&x.commitment()).ok())
.map(|x| x as u32)
.collect();
for ref output in &tx.outputs {
for ref output in tx.outputs() {
if let Err(e) = self.apply_output(output) {
self.rewind_raw_tx(output_pos, kernel_pos, &rewind_rm_pos)?;
return Err(e);
}
}
for ref input in &tx.inputs {
for ref input in tx.inputs() {
if let Err(e) = self.apply_input(input) {
self.rewind_raw_tx(output_pos, kernel_pos, &rewind_rm_pos)?;
return Err(e);
}
}
for ref kernel in &tx.kernels {
for ref kernel in tx.kernels() {
if let Err(e) = self.apply_kernel(kernel) {
self.rewind_raw_tx(output_pos, kernel_pos, &rewind_rm_pos)?;
return Err(e);
@@ -591,15 +591,15 @@ impl<'a> Extension<'a> {
// 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 {
for out in b.outputs() {
self.apply_output(out)?;
}
for input in &b.inputs {
for input in b.inputs() {
self.apply_input(input)?;
}
for kernel in &b.kernels {
for kernel in b.kernels() {
self.apply_kernel(kernel)?;
}