db: migrate from lmdb-zero to heed
This commit is contained in:
@@ -189,7 +189,7 @@ impl Desegmenter {
|
||||
|
||||
// TODO: Unwraps
|
||||
let tip = Tip::from_header(&h);
|
||||
let batch = self.store.batch()?;
|
||||
let mut batch = self.store.batch()?;
|
||||
batch.save_pibd_head(&tip)?;
|
||||
batch.commit()?;
|
||||
|
||||
@@ -283,11 +283,11 @@ impl Desegmenter {
|
||||
{
|
||||
let header_pmmr = self.header_pmmr.read();
|
||||
let txhashset = self.txhashset.read();
|
||||
let batch = self.store.batch()?;
|
||||
let mut batch = self.store.batch()?;
|
||||
txhashset.verify_kernel_pos_index(
|
||||
&self.genesis,
|
||||
&header_pmmr,
|
||||
&batch,
|
||||
&mut batch,
|
||||
Some(status.clone()),
|
||||
Some(stop_state.clone()),
|
||||
)?;
|
||||
@@ -308,9 +308,9 @@ impl Desegmenter {
|
||||
&mut header_pmmr,
|
||||
&mut txhashset,
|
||||
&mut batch,
|
||||
|ext, batch| {
|
||||
|ext, mut batch| {
|
||||
let extension = &mut ext.extension;
|
||||
extension.rewind(&self.archive_header, batch)?;
|
||||
extension.rewind(&self.archive_header, &mut batch)?;
|
||||
|
||||
// Validate the extension, generating the utxo_sum and kernel_sum.
|
||||
// Full validation, including rangeproofs and kernel signature verification.
|
||||
@@ -359,10 +359,10 @@ impl Desegmenter {
|
||||
}
|
||||
|
||||
// Rebuild our output_pos index in the db based on fresh UTXO set.
|
||||
txhashset.init_output_pos_index(&header_pmmr, &batch)?;
|
||||
txhashset.init_output_pos_index(&header_pmmr, &mut batch)?;
|
||||
|
||||
// Rebuild our NRD kernel_pos index based on recent kernel history.
|
||||
txhashset.init_recent_kernel_pos_index(&header_pmmr, &batch)?;
|
||||
txhashset.init_recent_kernel_pos_index(&header_pmmr, &mut batch)?;
|
||||
|
||||
// Commit all the changes to the db.
|
||||
batch.commit()?;
|
||||
|
||||
@@ -538,7 +538,7 @@ impl TxHashSet {
|
||||
pub fn init_recent_kernel_pos_index(
|
||||
&self,
|
||||
header_pmmr: &PMMRHandle<BlockHeader>,
|
||||
batch: &Batch<'_>,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<(), Error> {
|
||||
let head = batch.head()?;
|
||||
let cutoff = head.height.saturating_sub(WEEK_HEIGHT * 2);
|
||||
@@ -552,7 +552,7 @@ impl TxHashSet {
|
||||
&self,
|
||||
from_header: &BlockHeader,
|
||||
header_pmmr: &PMMRHandle<BlockHeader>,
|
||||
batch: &Batch<'_>,
|
||||
batch: &mut Batch<'_>,
|
||||
status: Option<Arc<SyncState>>,
|
||||
stop_state: Option<Arc<StopState>>,
|
||||
) -> Result<(), Error> {
|
||||
@@ -635,7 +635,7 @@ impl TxHashSet {
|
||||
pub fn init_output_pos_index(
|
||||
&self,
|
||||
header_pmmr: &PMMRHandle<BlockHeader>,
|
||||
batch: &Batch<'_>,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<(), Error> {
|
||||
let now = Instant::now();
|
||||
|
||||
@@ -733,10 +733,10 @@ pub fn extending_readonly<F, T>(
|
||||
inner: F,
|
||||
) -> Result<T, Error>
|
||||
where
|
||||
F: FnOnce(&mut ExtensionPair<'_>, &Batch<'_>) -> Result<T, Error>,
|
||||
F: FnOnce(&mut ExtensionPair<'_>, &mut Batch<'_>) -> Result<T, Error>,
|
||||
{
|
||||
let commit_index = trees.commit_index.clone();
|
||||
let batch = commit_index.batch()?;
|
||||
let mut batch = commit_index.batch()?;
|
||||
|
||||
trace!("Starting new txhashset (readonly) extension.");
|
||||
|
||||
@@ -751,7 +751,7 @@ where
|
||||
header_extension: &mut header_extension,
|
||||
extension: &mut extension,
|
||||
};
|
||||
inner(&mut extension_pair, &batch)
|
||||
inner(&mut extension_pair, &mut batch)
|
||||
};
|
||||
|
||||
trace!("Rollbacking txhashset (readonly) extension.");
|
||||
@@ -830,7 +830,7 @@ pub fn extending<'a, F, T>(
|
||||
inner: F,
|
||||
) -> Result<T, Error>
|
||||
where
|
||||
F: FnOnce(&mut ExtensionPair<'_>, &Batch<'_>) -> Result<T, Error>,
|
||||
F: FnOnce(&mut ExtensionPair<'_>, &mut Batch<'_>) -> Result<T, Error>,
|
||||
{
|
||||
let sizes: (u64, u64, u64);
|
||||
let res: Result<T, Error>;
|
||||
@@ -842,7 +842,7 @@ where
|
||||
|
||||
// create a child transaction so if the state is rolled back by itself, all
|
||||
// index saving can be undone
|
||||
let child_batch = batch.child()?;
|
||||
let mut child_batch = batch.child()?;
|
||||
{
|
||||
trace!("Starting new txhashset extension.");
|
||||
|
||||
@@ -853,7 +853,7 @@ where
|
||||
header_extension: &mut header_extension,
|
||||
extension: &mut extension,
|
||||
};
|
||||
res = inner(&mut extension_pair, &child_batch);
|
||||
res = inner(&mut extension_pair, &mut child_batch);
|
||||
|
||||
rollback = extension_pair.extension.rollback;
|
||||
sizes = extension_pair.extension.sizes();
|
||||
@@ -901,15 +901,15 @@ where
|
||||
/// Start a new readonly header MMR extension.
|
||||
/// This MMR can be extended individually beyond the other (output, rangeproof and kernel) MMRs
|
||||
/// to allow headers to be validated before we receive the full block data.
|
||||
pub fn header_extending_readonly<'a, F, T>(
|
||||
handle: &'a mut PMMRHandle<BlockHeader>,
|
||||
pub fn header_extending_readonly<F, T>(
|
||||
handle: &mut PMMRHandle<BlockHeader>,
|
||||
store: &ChainStore,
|
||||
inner: F,
|
||||
) -> Result<T, Error>
|
||||
where
|
||||
F: FnOnce(&mut HeaderExtension<'_>, &Batch<'_>) -> Result<T, Error>,
|
||||
F: FnOnce(&mut HeaderExtension<'_>, &mut Batch<'_>) -> Result<T, Error>,
|
||||
{
|
||||
let batch = store.batch()?;
|
||||
let mut batch = store.batch()?;
|
||||
|
||||
let head = match handle.head_hash() {
|
||||
Ok(hash) => {
|
||||
@@ -921,7 +921,7 @@ where
|
||||
|
||||
let pmmr = PMMR::at(&mut handle.backend, handle.size);
|
||||
let mut extension = HeaderExtension::new(pmmr, head);
|
||||
let res = inner(&mut extension, &batch);
|
||||
let res = inner(&mut extension, &mut batch);
|
||||
|
||||
handle.backend.discard();
|
||||
|
||||
@@ -937,7 +937,7 @@ pub fn header_extending<'a, F, T>(
|
||||
inner: F,
|
||||
) -> Result<T, Error>
|
||||
where
|
||||
F: FnOnce(&mut HeaderExtension<'_>, &Batch<'_>) -> Result<T, Error>,
|
||||
F: FnOnce(&mut HeaderExtension<'_>, &mut Batch<'_>) -> Result<T, Error>,
|
||||
{
|
||||
let size: u64;
|
||||
let res: Result<T, Error>;
|
||||
@@ -945,7 +945,7 @@ where
|
||||
|
||||
// create a child transaction so if the state is rolled back by itself, all
|
||||
// index saving can be undone
|
||||
let child_batch = batch.child()?;
|
||||
let mut child_batch = batch.child()?;
|
||||
|
||||
let head = match handle.head_hash() {
|
||||
Ok(hash) => {
|
||||
@@ -958,7 +958,7 @@ where
|
||||
{
|
||||
let pmmr = PMMR::at(&mut handle.backend, handle.size);
|
||||
let mut extension = HeaderExtension::new(pmmr, head);
|
||||
res = inner(&mut extension, &child_batch);
|
||||
res = inner(&mut extension, &mut child_batch);
|
||||
|
||||
rollback = extension.rollback;
|
||||
size = extension.size();
|
||||
@@ -1233,7 +1233,7 @@ impl<'a> Extension<'a> {
|
||||
&mut self,
|
||||
b: &Block,
|
||||
header_ext: &HeaderExtension<'_>,
|
||||
batch: &Batch<'_>,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<(), Error> {
|
||||
let mut affected_pos = vec![];
|
||||
|
||||
@@ -1499,7 +1499,7 @@ impl<'a> Extension<'a> {
|
||||
&mut self,
|
||||
kernels: &[TxKernel],
|
||||
height: u64,
|
||||
batch: &Batch<'_>,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<(), Error> {
|
||||
for kernel in kernels {
|
||||
let pos = self.apply_kernel(kernel)?;
|
||||
@@ -1579,7 +1579,7 @@ impl<'a> Extension<'a> {
|
||||
/// Rewinds the MMRs to the provided block, rewinding to the last output pos
|
||||
/// and last kernel pos of that block. If `updated_bitmap` is supplied, the
|
||||
/// bitmap accumulator will be replaced with its contents
|
||||
pub fn rewind(&mut self, header: &BlockHeader, batch: &Batch<'_>) -> Result<(), Error> {
|
||||
pub fn rewind(&mut self, header: &BlockHeader, batch: &mut Batch) -> Result<(), Error> {
|
||||
debug!(
|
||||
"Rewind extension to {} at {} from {} at {}",
|
||||
header.hash(),
|
||||
@@ -1622,7 +1622,11 @@ impl<'a> Extension<'a> {
|
||||
// Rewind the MMRs and the output_pos index.
|
||||
// Returns a vec of "affected_pos" so we can apply the necessary updates to the bitmap
|
||||
// accumulator in a single pass for all rewound blocks.
|
||||
fn rewind_single_block(&mut self, block: &Block, batch: &Batch<'_>) -> Result<Vec<u64>, Error> {
|
||||
fn rewind_single_block(
|
||||
&mut self,
|
||||
block: &Block,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<Vec<u64>, Error> {
|
||||
let header = &block.header;
|
||||
let prev_header = batch.get_previous_header(&header)?;
|
||||
|
||||
@@ -2206,7 +2210,11 @@ fn input_pos_to_rewind(
|
||||
}
|
||||
|
||||
/// If NRD enabled then enforce NRD relative height rules.
|
||||
fn apply_kernel_rules(kernel: &TxKernel, pos: CommitPos, batch: &Batch<'_>) -> Result<(), Error> {
|
||||
fn apply_kernel_rules(
|
||||
kernel: &TxKernel,
|
||||
pos: CommitPos,
|
||||
batch: &mut Batch<'_>,
|
||||
) -> Result<(), Error> {
|
||||
if !global::is_nrd_enabled() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user