cleanup verify_coinbase on block
@@ -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);
}
+ }
+
Ok(())
}
}
