mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Validate resulting tx after aggregation (and deaggregation) (#1331)
This commit is contained in:
parent
ae3b1da18b
commit
9c05471979
1 changed files with 15 additions and 5 deletions
|
@ -573,11 +573,18 @@ pub fn aggregate(transactions: Vec<Transaction>) -> Result<Transaction, Error> {
|
||||||
new_outputs.sort();
|
new_outputs.sort();
|
||||||
kernels.sort();
|
kernels.sort();
|
||||||
|
|
||||||
|
// build a new aggregate tx from the following -
|
||||||
|
// * cut-through inputs
|
||||||
|
// * cut-through outputs
|
||||||
|
// * full set of tx kernels
|
||||||
|
// * sum of all kernel offsets
|
||||||
let tx = Transaction::new(new_inputs, new_outputs, kernels).with_offset(total_kernel_offset);
|
let tx = Transaction::new(new_inputs, new_outputs, kernels).with_offset(total_kernel_offset);
|
||||||
|
|
||||||
// We need to check sums here as aggregation/cut-through
|
// Now validate the aggregate tx to ensure we have not built something invalid.
|
||||||
// may have created an invalid tx.
|
// The resulting tx could be invalid for a variety of reasons -
|
||||||
tx.verify_kernel_sums(tx.overage(), tx.offset)?;
|
// * tx too large (too many inputs|outputs|kernels)
|
||||||
|
// * cut-through may have invalidated the sums
|
||||||
|
tx.validate()?;
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
@ -641,8 +648,11 @@ pub fn deaggregate(mk_tx: Transaction, txs: Vec<Transaction>) -> Result<Transact
|
||||||
outputs.sort();
|
outputs.sort();
|
||||||
kernels.sort();
|
kernels.sort();
|
||||||
|
|
||||||
let mut tx = Transaction::new(inputs, outputs, kernels);
|
// Build a new tx from the above data.
|
||||||
tx.offset = total_kernel_offset;
|
let tx = Transaction::new(inputs, outputs, kernels).with_offset(total_kernel_offset);
|
||||||
|
|
||||||
|
// Now validate the resulting tx to ensure we have not built something invalid.
|
||||||
|
tx.validate()?;
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue