mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
cleanup verify_coinbase on block (#1326)
This commit is contained in:
parent
f0bdb2c8fa
commit
328d832bd6
1 changed files with 16 additions and 15 deletions
|
@ -776,12 +776,9 @@ impl Block {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Validate the coinbase outputs generated by miners. Entails 2 main
|
||||
/// checks:
|
||||
///
|
||||
/// * That the sum of all coinbase-marked outputs equal the supply.
|
||||
/// * That the sum of blinding factors for all coinbase-marked outputs match
|
||||
/// the coinbase-marked kernels.
|
||||
/// Validate the coinbase outputs generated by miners.
|
||||
/// Check the sum of coinbase-marked outputs match
|
||||
/// the sum of coinbase-marked kernels accounting for fees.
|
||||
pub fn verify_coinbase(&self) -> Result<(), Error> {
|
||||
let cb_outs = self.outputs
|
||||
.iter()
|
||||
|
@ -793,23 +790,27 @@ impl Block {
|
|||
.filter(|kernel| kernel.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.collect::<Vec<&TxKernel>>();
|
||||
|
||||
let over_commit;
|
||||
let out_adjust_sum;
|
||||
let kerns_sum;
|
||||
{
|
||||
let secp = static_secp_instance();
|
||||
let secp = secp.lock().unwrap();
|
||||
over_commit = secp.commit_value(reward(self.total_fees()))?;
|
||||
out_adjust_sum = secp.commit_sum(
|
||||
let over_commit = secp.commit_value(reward(self.total_fees()))?;
|
||||
|
||||
let out_adjust_sum = secp.commit_sum(
|
||||
cb_outs.iter().map(|x| x.commitment()).collect(),
|
||||
vec![over_commit],
|
||||
)?;
|
||||
kerns_sum = secp.commit_sum(cb_kerns.iter().map(|x| x.excess).collect(), vec![])?;
|
||||
|
||||
let kerns_sum = secp.commit_sum(
|
||||
cb_kerns.iter().map(|x| x.excess).collect(),
|
||||
vec![],
|
||||
)?;
|
||||
|
||||
// Verify the kernel sum equals the output sum accounting for block fees.
|
||||
if kerns_sum != out_adjust_sum {
|
||||
return Err(Error::CoinbaseSumMismatch);
|
||||
}
|
||||
}
|
||||
|
||||
if kerns_sum != out_adjust_sum {
|
||||
return Err(Error::CoinbaseSumMismatch);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue