[testnet2] Store output sum (#1043)
* block sums and reworked block validation read and write block_sums refactor validate on both block and txhashset write block_sum on fast sync we store the kernel_sum (need to account for the offset) * block_sums * rustfmt * cleanup
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
use std::{error, fmt, io};
|
||||
|
||||
use util::secp;
|
||||
use util::secp_static;
|
||||
use util::secp::pedersen::Commitment;
|
||||
|
||||
use core::core::hash::{Hash, Hashed};
|
||||
@@ -328,6 +329,15 @@ pub trait ChainStore: Send + Sync {
|
||||
/// Deletes a block marker associated with the provided hash
|
||||
fn delete_block_marker(&self, bh: &Hash) -> Result<(), store::Error>;
|
||||
|
||||
/// Save block sums for the given block hash.
|
||||
fn save_block_sums(&self, bh: &Hash, marker: &BlockSums) -> Result<(), store::Error>;
|
||||
|
||||
/// Get block sums for the given block hash.
|
||||
fn get_block_sums(&self, bh: &Hash) -> Result<BlockSums, store::Error>;
|
||||
|
||||
/// Delete block sums for the given block hash.
|
||||
fn delete_block_sums(&self, bh: &Hash) -> Result<(), store::Error>;
|
||||
|
||||
/// Saves the provided block header at the corresponding height. Also check
|
||||
/// the consistency of the height chain in store by assuring previous
|
||||
/// headers are also at their respective heights.
|
||||
@@ -389,3 +399,42 @@ impl Default for BlockMarker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The output_sum and kernel_sum for a given block.
|
||||
/// This is used to validate the next block being processed by applying
|
||||
/// the inputs, outputs, kernels and kernel_offset from the new block
|
||||
/// and checking everything sums correctly.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BlockSums {
|
||||
/// The total output sum so far.
|
||||
pub output_sum: Commitment,
|
||||
/// The total kernel sum so far.
|
||||
pub kernel_sum: Commitment,
|
||||
}
|
||||
|
||||
impl Writeable for BlockSums {
|
||||
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ser::Error> {
|
||||
writer.write_fixed_bytes(&self.output_sum)?;
|
||||
writer.write_fixed_bytes(&self.kernel_sum)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Readable for BlockSums {
|
||||
fn read(reader: &mut Reader) -> Result<BlockSums, ser::Error> {
|
||||
Ok(BlockSums {
|
||||
output_sum: Commitment::read(reader)?,
|
||||
kernel_sum: Commitment::read(reader)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BlockSums {
|
||||
fn default() -> BlockSums {
|
||||
let zero_commit = secp_static::commit_to_zero_value();
|
||||
BlockSums {
|
||||
output_sum: zero_commit.clone(),
|
||||
kernel_sum: zero_commit.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user