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
+6 -5
View File
@@ -53,7 +53,7 @@ where
let mut txs = vec![];
for x in &self.entries {
for kernel in &x.tx.kernels {
for kernel in x.tx.kernels() {
// rehash each kernel to calculate the block specific short_id
let short_id = kernel.short_id(&cb.hash(), cb.nonce);
@@ -97,7 +97,8 @@ where
to_state: PoolEntryState,
extra_tx: Option<Transaction>,
) -> Result<Vec<Transaction>, PoolError> {
let entries = &mut self.entries
let entries = &mut self
.entries
.iter_mut()
.filter(|x| x.state == from_state)
.collect::<Vec<_>>();
@@ -189,8 +190,8 @@ where
fn remaining_transactions(&self, block: &Block) -> Vec<Transaction> {
self.entries
.iter()
.filter(|x| !x.tx.kernels.iter().any(|y| block.kernels.contains(y)))
.filter(|x| !x.tx.inputs.iter().any(|y| block.inputs.contains(y)))
.filter(|x| !x.tx.kernels().iter().any(|y| block.kernels().contains(y)))
.filter(|x| !x.tx.inputs().iter().any(|y| block.inputs().contains(y)))
.map(|x| x.tx.clone())
.collect()
}
@@ -205,7 +206,7 @@ where
// Check each transaction in the pool
for entry in &self.entries {
let entry_kernel_set = entry.tx.kernels.iter().cloned().collect::<HashSet<_>>();
let entry_kernel_set = entry.tx.kernels().iter().cloned().collect::<HashSet<_>>();
if entry_kernel_set.is_subset(&kernel_set) {
found_txs.push(entry.tx.clone());
}
+6 -5
View File
@@ -17,8 +17,8 @@
//! resulting tx pool can be added to the current chain state to produce a
//! valid chain state.
use chrono::prelude::Utc;
use std::sync::Arc;
use chrono::prelude::{Utc};
use core::core::hash::Hashed;
use core::core::{transaction, Block, CompactBlock, Transaction};
@@ -69,9 +69,10 @@ where
fn add_to_txpool(&mut self, mut entry: PoolEntry) -> Result<(), PoolError> {
// First deaggregate the tx based on current txpool txs.
if entry.tx.kernels.len() > 1 {
let txs = self.txpool
.find_matching_transactions(entry.tx.kernels.clone());
if entry.tx.kernels().len() > 1 {
let txs = self
.txpool
.find_matching_transactions(entry.tx.kernels().clone());
if !txs.is_empty() {
entry.tx = transaction::deaggregate(entry.tx, txs)?;
entry.src.debug_name = "deagg".to_string();
@@ -100,7 +101,7 @@ where
LOGGER,
"pool: add_to_pool: {:?}, kernels - {}, stem? {}",
tx.hash(),
tx.kernels.len(),
tx.kernels().len(),
stem,
);