decouple kernels from the kernel MMR (#2043)

This commit is contained in:
Antioch Peverell 2018-11-29 10:01:59 +00:00 committed by GitHub
parent 8e3a3e1a40
commit 8e62130a7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 16 deletions

View file

@ -15,7 +15,7 @@
//! Lightweight readonly view into kernel MMR for convenience. //! Lightweight readonly view into kernel MMR for convenience.
use core::core::pmmr::RewindablePMMR; use core::core::pmmr::RewindablePMMR;
use core::core::{BlockHeader, TxKernelEntry}; use core::core::{BlockHeader, TxKernel};
use error::{Error, ErrorKind}; use error::{Error, ErrorKind};
use grin_store::pmmr::PMMRBackend; use grin_store::pmmr::PMMRBackend;
@ -23,7 +23,7 @@ use store::Batch;
/// Rewindable (but readonly) view of the kernel set (based on kernel MMR). /// Rewindable (but readonly) view of the kernel set (based on kernel MMR).
pub struct RewindableKernelView<'a> { pub struct RewindableKernelView<'a> {
pmmr: RewindablePMMR<'a, TxKernelEntry, PMMRBackend<TxKernelEntry>>, pmmr: RewindablePMMR<'a, TxKernel, PMMRBackend<TxKernel>>,
batch: &'a Batch<'a>, batch: &'a Batch<'a>,
header: BlockHeader, header: BlockHeader,
} }
@ -31,7 +31,7 @@ pub struct RewindableKernelView<'a> {
impl<'a> RewindableKernelView<'a> { impl<'a> RewindableKernelView<'a> {
/// Build a new readonly kernel view. /// Build a new readonly kernel view.
pub fn new( pub fn new(
pmmr: RewindablePMMR<'a, TxKernelEntry, PMMRBackend<TxKernelEntry>>, pmmr: RewindablePMMR<'a, TxKernel, PMMRBackend<TxKernel>>,
batch: &'a Batch, batch: &'a Batch,
header: BlockHeader, header: BlockHeader,
) -> RewindableKernelView<'a> { ) -> RewindableKernelView<'a> {

View file

@ -104,7 +104,7 @@ pub struct TxHashSet {
output_pmmr_h: PMMRHandle<OutputIdentifier>, output_pmmr_h: PMMRHandle<OutputIdentifier>,
rproof_pmmr_h: PMMRHandle<RangeProof>, rproof_pmmr_h: PMMRHandle<RangeProof>,
kernel_pmmr_h: PMMRHandle<TxKernelEntry>, kernel_pmmr_h: PMMRHandle<TxKernel>,
// chain store used as index of commitments to MMR positions // chain store used as index of commitments to MMR positions
commit_index: Arc<ChainStore>, commit_index: Arc<ChainStore>,
@ -199,7 +199,7 @@ impl TxHashSet {
/// as above, for kernels /// as above, for kernels
pub fn last_n_kernel(&mut self, distance: u64) -> Vec<(Hash, TxKernelEntry)> { pub fn last_n_kernel(&mut self, distance: u64) -> Vec<(Hash, TxKernelEntry)> {
let kernel_pmmr: PMMR<TxKernelEntry, _> = let kernel_pmmr: PMMR<TxKernel, _> =
PMMR::at(&mut self.kernel_pmmr_h.backend, self.kernel_pmmr_h.last_pos); PMMR::at(&mut self.kernel_pmmr_h.backend, self.kernel_pmmr_h.last_pos);
kernel_pmmr.get_last_n_insertions(distance) kernel_pmmr.get_last_n_insertions(distance)
} }
@ -256,7 +256,7 @@ impl TxHashSet {
PMMR::at(&mut self.output_pmmr_h.backend, self.output_pmmr_h.last_pos); PMMR::at(&mut self.output_pmmr_h.backend, self.output_pmmr_h.last_pos);
let rproof_pmmr: PMMR<RangeProof, _> = let rproof_pmmr: PMMR<RangeProof, _> =
PMMR::at(&mut self.rproof_pmmr_h.backend, self.rproof_pmmr_h.last_pos); PMMR::at(&mut self.rproof_pmmr_h.backend, self.rproof_pmmr_h.last_pos);
let kernel_pmmr: PMMR<TxKernelEntry, _> = let kernel_pmmr: PMMR<TxKernel, _> =
PMMR::at(&mut self.kernel_pmmr_h.backend, self.kernel_pmmr_h.last_pos); PMMR::at(&mut self.kernel_pmmr_h.backend, self.kernel_pmmr_h.last_pos);
TxHashSetRoots { TxHashSetRoots {
@ -775,7 +775,7 @@ pub struct Extension<'a> {
header_pmmr: PMMR<'a, BlockHeader, PMMRBackend<BlockHeader>>, header_pmmr: PMMR<'a, BlockHeader, PMMRBackend<BlockHeader>>,
output_pmmr: PMMR<'a, OutputIdentifier, PMMRBackend<OutputIdentifier>>, output_pmmr: PMMR<'a, OutputIdentifier, PMMRBackend<OutputIdentifier>>,
rproof_pmmr: PMMR<'a, RangeProof, PMMRBackend<RangeProof>>, rproof_pmmr: PMMR<'a, RangeProof, PMMRBackend<RangeProof>>,
kernel_pmmr: PMMR<'a, TxKernelEntry, PMMRBackend<TxKernelEntry>>, kernel_pmmr: PMMR<'a, TxKernel, PMMRBackend<TxKernel>>,
/// Rollback flag. /// Rollback flag.
rollback: bool, rollback: bool,
@ -996,7 +996,7 @@ impl<'a> Extension<'a> {
/// Push kernel onto MMR (hash and data files). /// Push kernel onto MMR (hash and data files).
fn apply_kernel(&mut self, kernel: &TxKernel) -> Result<(), Error> { fn apply_kernel(&mut self, kernel: &TxKernel) -> Result<(), Error> {
self.kernel_pmmr self.kernel_pmmr
.push(TxKernelEntry::from(kernel.clone())) .push(kernel.clone())
.map_err(&ErrorKind::TxHashSetErr)?; .map_err(&ErrorKind::TxHashSetErr)?;
Ok(()) Ok(())
} }

View file

@ -188,6 +188,15 @@ impl Readable for TxKernel {
} }
} }
/// We store TxKernelEntry in the kernel MMR.
impl PMMRable for TxKernel {
type E = TxKernelEntry;
fn as_elmt(self) -> Self::E {
self.into()
}
}
impl TxKernel { impl TxKernel {
/// Return the excess commitment for this tx_kernel. /// Return the excess commitment for this tx_kernel.
pub fn excess(&self) -> Commitment { pub fn excess(&self) -> Commitment {
@ -310,14 +319,6 @@ impl FixedLength for TxKernelEntry {
+ secp::constants::AGG_SIGNATURE_SIZE; + secp::constants::AGG_SIGNATURE_SIZE;
} }
impl PMMRable for TxKernelEntry {
type E = Self;
fn as_elmt(self) -> Self::E {
self
}
}
/// TransactionBody is a common abstraction for transaction and block /// TransactionBody is a common abstraction for transaction and block
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TransactionBody { pub struct TransactionBody {