cleanup verify_coinbase on block (#1326)

This commit is contained in:
Antioch Peverell 2018-08-08 09:47:30 +01:00 committed by GitHub
parent f0bdb2c8fa
commit 328d832bd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -776,12 +776,9 @@ impl Block {
Ok(()) Ok(())
} }
/// Validate the coinbase outputs generated by miners. Entails 2 main /// Validate the coinbase outputs generated by miners.
/// checks: /// Check the sum of coinbase-marked outputs match
/// /// the sum of coinbase-marked kernels accounting for fees.
/// * 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.
pub fn verify_coinbase(&self) -> Result<(), Error> { pub fn verify_coinbase(&self) -> Result<(), Error> {
let cb_outs = self.outputs let cb_outs = self.outputs
.iter() .iter()
@ -793,23 +790,27 @@ impl Block {
.filter(|kernel| kernel.features.contains(KernelFeatures::COINBASE_KERNEL)) .filter(|kernel| kernel.features.contains(KernelFeatures::COINBASE_KERNEL))
.collect::<Vec<&TxKernel>>(); .collect::<Vec<&TxKernel>>();
let over_commit;
let out_adjust_sum;
let kerns_sum;
{ {
let secp = static_secp_instance(); let secp = static_secp_instance();
let secp = secp.lock().unwrap(); let secp = secp.lock().unwrap();
over_commit = secp.commit_value(reward(self.total_fees()))?; let over_commit = secp.commit_value(reward(self.total_fees()))?;
out_adjust_sum = secp.commit_sum(
let out_adjust_sum = secp.commit_sum(
cb_outs.iter().map(|x| x.commitment()).collect(), cb_outs.iter().map(|x| x.commitment()).collect(),
vec![over_commit], 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 { if kerns_sum != out_adjust_sum {
return Err(Error::CoinbaseSumMismatch); return Err(Error::CoinbaseSumMismatch);
} }
}
Ok(()) Ok(())
} }
} }