Pool tx weight verification (#2466)
This commit is contained in:
committed by
Ignotus Peverell
parent
a97ab376cb
commit
c8fd0575ed
+83
-50
@@ -20,7 +20,7 @@ use self::core::core::block::BlockHeader;
|
||||
use self::core::core::block::Error::KernelLockHeight;
|
||||
use self::core::core::hash::{Hashed, ZERO_HASH};
|
||||
use self::core::core::verifier_cache::{LruVerifierCache, VerifierCache};
|
||||
use self::core::core::{aggregate, deaggregate, KernelFeatures, Output, Transaction};
|
||||
use self::core::core::{aggregate, deaggregate, KernelFeatures, Output, Transaction, Weighting};
|
||||
use self::core::libtx::build::{
|
||||
self, initial_tx, input, output, with_excess, with_fee, with_lock_height,
|
||||
};
|
||||
@@ -115,7 +115,8 @@ fn build_tx_kernel() {
|
||||
.unwrap();
|
||||
|
||||
// check the tx is valid
|
||||
tx.validate(verifier_cache()).unwrap();
|
||||
tx.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.unwrap();
|
||||
|
||||
// check the kernel is also itself valid
|
||||
assert_eq!(tx.kernels().len(), 1);
|
||||
@@ -133,15 +134,19 @@ fn transaction_cut_through() {
|
||||
let tx1 = tx1i2o();
|
||||
let tx2 = tx2i1o();
|
||||
|
||||
assert!(tx1.validate(verifier_cache()).is_ok());
|
||||
assert!(tx2.validate(verifier_cache()).is_ok());
|
||||
assert!(tx1
|
||||
.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.is_ok());
|
||||
assert!(tx2
|
||||
.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.is_ok());
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
// now build a "cut_through" tx from tx1 and tx2
|
||||
let tx3 = aggregate(vec![tx1, tx2]).unwrap();
|
||||
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
}
|
||||
|
||||
// Attempt to deaggregate a multi-kernel transaction in a different way
|
||||
@@ -154,26 +159,32 @@ fn multi_kernel_transaction_deaggregation() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx4.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx4.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let tx1234 = aggregate(vec![tx1.clone(), tx2.clone(), tx3.clone(), tx4.clone()]).unwrap();
|
||||
let tx12 = aggregate(vec![tx1.clone(), tx2.clone()]).unwrap();
|
||||
let tx34 = aggregate(vec![tx3.clone(), tx4.clone()]).unwrap();
|
||||
|
||||
assert!(tx1234.validate(vc.clone()).is_ok());
|
||||
assert!(tx12.validate(vc.clone()).is_ok());
|
||||
assert!(tx34.validate(vc.clone()).is_ok());
|
||||
assert!(tx1234
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert!(tx12.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx34.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let deaggregated_tx34 = deaggregate(tx1234.clone(), vec![tx12.clone()]).unwrap();
|
||||
assert!(deaggregated_tx34.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx34
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx34, deaggregated_tx34);
|
||||
|
||||
let deaggregated_tx12 = deaggregate(tx1234.clone(), vec![tx34.clone()]).unwrap();
|
||||
|
||||
assert!(deaggregated_tx12.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx12
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx12, deaggregated_tx12);
|
||||
}
|
||||
|
||||
@@ -185,18 +196,20 @@ fn multi_kernel_transaction_deaggregation_2() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let tx123 = aggregate(vec![tx1.clone(), tx2.clone(), tx3.clone()]).unwrap();
|
||||
let tx12 = aggregate(vec![tx1.clone(), tx2.clone()]).unwrap();
|
||||
|
||||
assert!(tx123.validate(vc.clone()).is_ok());
|
||||
assert!(tx12.validate(vc.clone()).is_ok());
|
||||
assert!(tx123.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx12.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let deaggregated_tx3 = deaggregate(tx123.clone(), vec![tx12.clone()]).unwrap();
|
||||
assert!(deaggregated_tx3.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx3
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx3, deaggregated_tx3);
|
||||
}
|
||||
|
||||
@@ -208,19 +221,21 @@ fn multi_kernel_transaction_deaggregation_3() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let tx123 = aggregate(vec![tx1.clone(), tx2.clone(), tx3.clone()]).unwrap();
|
||||
let tx13 = aggregate(vec![tx1.clone(), tx3.clone()]).unwrap();
|
||||
let tx2 = aggregate(vec![tx2.clone()]).unwrap();
|
||||
|
||||
assert!(tx123.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx123.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let deaggregated_tx13 = deaggregate(tx123.clone(), vec![tx2.clone()]).unwrap();
|
||||
assert!(deaggregated_tx13.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx13
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx13, deaggregated_tx13);
|
||||
}
|
||||
|
||||
@@ -234,11 +249,11 @@ fn multi_kernel_transaction_deaggregation_4() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx4.validate(vc.clone()).is_ok());
|
||||
assert!(tx5.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx4.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx5.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let tx12345 = aggregate(vec![
|
||||
tx1.clone(),
|
||||
@@ -248,14 +263,18 @@ fn multi_kernel_transaction_deaggregation_4() {
|
||||
tx5.clone(),
|
||||
])
|
||||
.unwrap();
|
||||
assert!(tx12345.validate(vc.clone()).is_ok());
|
||||
assert!(tx12345
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
|
||||
let deaggregated_tx5 = deaggregate(
|
||||
tx12345.clone(),
|
||||
vec![tx1.clone(), tx2.clone(), tx3.clone(), tx4.clone()],
|
||||
)
|
||||
.unwrap();
|
||||
assert!(deaggregated_tx5.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx5
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx5, deaggregated_tx5);
|
||||
}
|
||||
|
||||
@@ -269,11 +288,11 @@ fn multi_kernel_transaction_deaggregation_5() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx4.validate(vc.clone()).is_ok());
|
||||
assert!(tx5.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx4.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx5.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let tx12345 = aggregate(vec![
|
||||
tx1.clone(),
|
||||
@@ -286,10 +305,14 @@ fn multi_kernel_transaction_deaggregation_5() {
|
||||
let tx12 = aggregate(vec![tx1.clone(), tx2.clone()]).unwrap();
|
||||
let tx34 = aggregate(vec![tx3.clone(), tx4.clone()]).unwrap();
|
||||
|
||||
assert!(tx12345.validate(vc.clone()).is_ok());
|
||||
assert!(tx12345
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
|
||||
let deaggregated_tx5 = deaggregate(tx12345.clone(), vec![tx12.clone(), tx34.clone()]).unwrap();
|
||||
assert!(deaggregated_tx5.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx5
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx5, deaggregated_tx5);
|
||||
}
|
||||
|
||||
@@ -301,22 +324,26 @@ fn basic_transaction_deaggregation() {
|
||||
|
||||
let vc = verifier_cache();
|
||||
|
||||
assert!(tx1.validate(vc.clone()).is_ok());
|
||||
assert!(tx2.validate(vc.clone()).is_ok());
|
||||
assert!(tx1.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
assert!(tx2.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
// now build a "cut_through" tx from tx1 and tx2
|
||||
let tx3 = aggregate(vec![tx1.clone(), tx2.clone()]).unwrap();
|
||||
|
||||
assert!(tx3.validate(vc.clone()).is_ok());
|
||||
assert!(tx3.validate(Weighting::AsTransaction, vc.clone()).is_ok());
|
||||
|
||||
let deaggregated_tx1 = deaggregate(tx3.clone(), vec![tx2.clone()]).unwrap();
|
||||
|
||||
assert!(deaggregated_tx1.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx1
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx1, deaggregated_tx1);
|
||||
|
||||
let deaggregated_tx2 = deaggregate(tx3.clone(), vec![tx1.clone()]).unwrap();
|
||||
|
||||
assert!(deaggregated_tx2.validate(vc.clone()).is_ok());
|
||||
assert!(deaggregated_tx2
|
||||
.validate(Weighting::AsTransaction, vc.clone())
|
||||
.is_ok());
|
||||
assert_eq!(tx2, deaggregated_tx2);
|
||||
}
|
||||
|
||||
@@ -347,7 +374,9 @@ fn hash_output() {
|
||||
#[test]
|
||||
fn blind_tx() {
|
||||
let btx = tx2i1o();
|
||||
assert!(btx.validate(verifier_cache()).is_ok());
|
||||
assert!(btx
|
||||
.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.is_ok());
|
||||
|
||||
// Ignored for bullet proofs, because calling range_proof_info
|
||||
// with a bullet proof causes painful errors
|
||||
@@ -410,7 +439,9 @@ fn tx_build_exchange() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
tx_final.validate(verifier_cache()).unwrap();
|
||||
tx_final
|
||||
.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -436,7 +467,7 @@ fn reward_with_tx_block() {
|
||||
let vc = verifier_cache();
|
||||
|
||||
let mut tx1 = tx2i1o();
|
||||
tx1.validate(vc.clone()).unwrap();
|
||||
tx1.validate(Weighting::AsTransaction, vc.clone()).unwrap();
|
||||
|
||||
let previous_header = BlockHeader::default();
|
||||
|
||||
@@ -524,11 +555,13 @@ fn test_block_with_timelocked_tx() {
|
||||
#[test]
|
||||
pub fn test_verify_1i1o_sig() {
|
||||
let tx = tx1i1o();
|
||||
tx.validate(verifier_cache()).unwrap();
|
||||
tx.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_verify_2i1o_sig() {
|
||||
let tx = tx2i1o();
|
||||
tx.validate(verifier_cache()).unwrap();
|
||||
tx.validate(Weighting::AsTransaction, verifier_cache())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user