Skip to content

Commit 0c3e18a

Browse files
committed
Merge branch 'refs/heads/lmdb_update' into grim
2 parents 42b928a + 02cce56 commit 0c3e18a

16 files changed

Lines changed: 615 additions & 529 deletions

File tree

Cargo.lock

Lines changed: 179 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/src/chain.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ pub struct Chain {
150150
store: Arc<store::ChainStore>,
151151
adapter: Arc<dyn ChainAdapter + Send + Sync>,
152152
orphans: Arc<OrphanBlockPool>,
153-
txhashset: Arc<RwLock<txhashset::TxHashSet>>,
154-
header_pmmr: Arc<RwLock<txhashset::PMMRHandle<BlockHeader>>>,
153+
txhashset: Arc<RwLock<TxHashSet>>,
154+
header_pmmr: Arc<RwLock<PMMRHandle<BlockHeader>>>,
155155
pibd_segmenter: Arc<RwLock<Option<Segmenter>>>,
156156
pibd_desegmenter: Arc<RwLock<Option<Desegmenter>>>,
157157
// POW verification function
@@ -189,9 +189,9 @@ impl Chain {
189189
// Initialize the output_pos index based on UTXO set
190190
// and NRD kernel_pos index based recent kernel history.
191191
{
192-
let batch = store.batch()?;
193-
txhashset.init_output_pos_index(&header_pmmr, &batch)?;
194-
txhashset.init_recent_kernel_pos_index(&header_pmmr, &batch)?;
192+
let mut batch = store.batch()?;
193+
txhashset.init_output_pos_index(&header_pmmr, &mut batch)?;
194+
txhashset.init_recent_kernel_pos_index(&header_pmmr, &mut batch)?;
195195
batch.commit()?;
196196
}
197197

@@ -275,7 +275,7 @@ impl Chain {
275275
pub fn reset_chain_head_to_genesis(&self) -> Result<(), Error> {
276276
let mut header_pmmr = self.header_pmmr.write();
277277
let mut txhashset = self.txhashset.write();
278-
let batch = self.store.batch()?;
278+
let mut batch = self.store.batch()?;
279279

280280
// Change head back to genesis
281281
{
@@ -314,7 +314,7 @@ impl Chain {
314314

315315
/// Reset PIBD head
316316
pub fn reset_pibd_head(&self) -> Result<(), Error> {
317-
let batch = self.store.batch()?;
317+
let mut batch = self.store.batch()?;
318318
batch.save_pibd_head(&self.genesis().into())?;
319319
Ok(())
320320
}
@@ -530,9 +530,9 @@ impl Chain {
530530
pub fn new_ctx<'a>(
531531
&self,
532532
opts: Options,
533-
batch: store::Batch<'a>,
534-
header_pmmr: &'a mut txhashset::PMMRHandle<BlockHeader>,
535-
txhashset: &'a mut txhashset::TxHashSet,
533+
batch: Batch<'a>,
534+
header_pmmr: &'a mut PMMRHandle<BlockHeader>,
535+
txhashset: &'a mut TxHashSet,
536536
) -> Result<pipe::BlockContext<'a>, Error> {
537537
let denylist = self.denylist.read().clone();
538538
Ok(pipe::BlockContext {
@@ -832,7 +832,7 @@ impl Chain {
832832
&self,
833833
header: &BlockHeader,
834834
ext: &mut ExtensionPair,
835-
batch: &Batch,
835+
batch: &mut Batch,
836836
) -> Result<BlockHeader, Error> {
837837
let denylist = self.denylist.read().clone();
838838
pipe::rewind_and_apply_fork(header, ext, batch, &|header| {
@@ -846,7 +846,7 @@ impl Chain {
846846
&self,
847847
header: &BlockHeader,
848848
ext: &mut HeaderExtension,
849-
batch: &Batch,
849+
batch: &mut Batch,
850850
) -> Result<(), Error> {
851851
let denylist = self.denylist.read().clone();
852852
pipe::rewind_and_apply_header_fork(header, ext, batch, &|header| {
@@ -1015,7 +1015,7 @@ impl Chain {
10151015
fn validate_kernel_history(
10161016
&self,
10171017
header: &BlockHeader,
1018-
txhashset: &txhashset::TxHashSet,
1018+
txhashset: &TxHashSet,
10191019
) -> Result<(), Error> {
10201020
debug!("validate_kernel_history: rewinding and validating kernel history (readonly)");
10211021

@@ -1151,11 +1151,11 @@ impl Chain {
11511151
self.validate_kernel_history(&header, &txhashset)?;
11521152

11531153
let header_pmmr = self.header_pmmr.read();
1154-
let batch = self.store.batch()?;
1154+
let mut batch = self.store.batch()?;
11551155
txhashset.verify_kernel_pos_index(
11561156
&self.genesis.header,
11571157
&header_pmmr,
1158-
&batch,
1158+
&mut batch,
11591159
None,
11601160
None,
11611161
)?;
@@ -1213,10 +1213,10 @@ impl Chain {
12131213
}
12141214

12151215
// Rebuild our output_pos index in the db based on fresh UTXO set.
1216-
txhashset.init_output_pos_index(&header_pmmr, &batch)?;
1216+
txhashset.init_output_pos_index(&header_pmmr, &mut batch)?;
12171217

12181218
// Rebuild our NRD kernel_pos index based on recent kernel history.
1219-
txhashset.init_recent_kernel_pos_index(&header_pmmr, &batch)?;
1219+
txhashset.init_recent_kernel_pos_index(&header_pmmr, &mut batch)?;
12201220

12211221
// Commit all the changes to the db.
12221222
batch.commit()?;
@@ -1257,9 +1257,9 @@ impl Chain {
12571257
/// *Only* runs if we are not in archive mode.
12581258
fn remove_historical_blocks(
12591259
&self,
1260-
header_pmmr: &txhashset::PMMRHandle<BlockHeader>,
1260+
header_pmmr: &PMMRHandle<BlockHeader>,
12611261
archive_header: BlockHeader,
1262-
batch: &store::Batch<'_>,
1262+
batch: &mut Batch<'_>,
12631263
) -> Result<(), Error> {
12641264
if self.archive_mode() {
12651265
return Ok(());
@@ -1345,7 +1345,7 @@ impl Chain {
13451345
// Take a write lock on the txhashet and start a new writeable db batch.
13461346
let header_pmmr = self.header_pmmr.read();
13471347
let mut txhashset = self.txhashset.write();
1348-
let batch = self.store.batch()?;
1348+
let mut batch = self.store.batch()?;
13491349

13501350
// Compact the txhashset itself (rewriting the pruned backend files).
13511351
{
@@ -1361,15 +1361,15 @@ impl Chain {
13611361

13621362
// If we are not in archival mode remove historical blocks from the db.
13631363
if !self.archive_mode() {
1364-
self.remove_historical_blocks(&header_pmmr, archive_header, &batch)?;
1364+
self.remove_historical_blocks(&header_pmmr, archive_header, &mut batch)?;
13651365
}
13661366

13671367
// Make sure our output_pos index is consistent with the UTXO set.
1368-
txhashset.init_output_pos_index(&header_pmmr, &batch)?;
1368+
txhashset.init_output_pos_index(&header_pmmr, &mut batch)?;
13691369

13701370
// TODO - Why is this part of chain compaction?
13711371
// Rebuild our NRD kernel_pos index based on recent kernel history.
1372-
txhashset.init_recent_kernel_pos_index(&header_pmmr, &batch)?;
1372+
txhashset.init_recent_kernel_pos_index(&header_pmmr, &mut batch)?;
13731373

13741374
// Commit all the above db changes.
13751375
batch.commit()?;
@@ -1439,7 +1439,8 @@ impl Chain {
14391439
0
14401440
} else {
14411441
self.get_header_by_height(start_block_height - 1)?
1442-
.output_mmr_size + 1
1442+
.output_mmr_size
1443+
+ 1
14431444
};
14441445
let end_mmr_size = self.get_header_by_height(end_block_height)?.output_mmr_size;
14451446
Ok((start_mmr_size, end_mmr_size))

chain/src/linked_list.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,28 @@ pub trait ListIndex {
108108
/// Push a pos onto the list for the specified commitment.
109109
fn push_pos(
110110
&self,
111-
batch: &Batch<'_>,
111+
batch: &mut Batch<'_>,
112112
commit: Commitment,
113113
new_pos: <Self::Entry as ListIndexEntry>::Pos,
114114
) -> Result<(), Error>;
115115

116116
/// Pop a pos off the list for the specified commitment.
117117
fn pop_pos(
118118
&self,
119-
batch: &Batch<'_>,
119+
batch: &mut Batch<'_>,
120120
commit: Commitment,
121121
) -> Result<Option<<Self::Entry as ListIndexEntry>::Pos>, Error>;
122122
}
123123

124124
/// Supports "rewind" given the provided commit and a pos to rewind back to.
125125
pub trait RewindableListIndex {
126126
/// Rewind the index for the given commitment to the specified position.
127-
fn rewind(&self, batch: &Batch<'_>, commit: Commitment, rewind_pos: u64) -> Result<(), Error>;
127+
fn rewind(
128+
&self,
129+
batch: &mut Batch<'_>,
130+
commit: Commitment,
131+
rewind_pos: u64,
132+
) -> Result<(), Error>;
128133
}
129134

130135
/// A pruneable list index supports pruning of old data from the index lists.
@@ -133,15 +138,20 @@ pub trait RewindableListIndex {
133138
pub trait PruneableListIndex: ListIndex {
134139
/// Clear all data from the index.
135140
/// Used when rebuilding the index.
136-
fn clear(&self, batch: &Batch<'_>) -> Result<(), Error>;
141+
fn clear(&self, batch: &mut Batch<'_>) -> Result<(), Error>;
137142

138143
/// Prune old data.
139-
fn prune(&self, batch: &Batch<'_>, commit: Commitment, cutoff_pos: u64) -> Result<(), Error>;
144+
fn prune(
145+
&self,
146+
batch: &mut Batch<'_>,
147+
commit: Commitment,
148+
cutoff_pos: u64,
149+
) -> Result<(), Error>;
140150

141151
/// Pop a pos off the back of the list (used for pruning old data).
142152
fn pop_pos_back(
143153
&self,
144-
batch: &Batch<'_>,
154+
batch: &mut Batch<'_>,
145155
commit: Commitment,
146156
) -> Result<Option<<Self::Entry as ListIndexEntry>::Pos>, Error>;
147157
}
@@ -255,7 +265,7 @@ where
255265
}
256266
}
257267

258-
fn push_pos(&self, batch: &Batch<'_>, commit: Commitment, new_pos: T) -> Result<(), Error> {
268+
fn push_pos(&self, batch: &mut Batch<'_>, commit: Commitment, new_pos: T) -> Result<(), Error> {
259269
match self.get_list(batch, commit)? {
260270
None => {
261271
let list = ListWrapper::Single { pos: new_pos };
@@ -327,7 +337,7 @@ where
327337
/// Pop the head of the list.
328338
/// Returns the output_pos.
329339
/// Returns None if list was empty.
330-
fn pop_pos(&self, batch: &Batch<'_>, commit: Commitment) -> Result<Option<T>, Error> {
340+
fn pop_pos(&self, batch: &mut Batch<'_>, commit: Commitment) -> Result<Option<T>, Error> {
331341
match self.get_list(batch, commit)? {
332342
None => Ok(None),
333343
Some(ListWrapper::Single { pos }) => {
@@ -373,7 +383,12 @@ where
373383

374384
/// List index that supports rewind.
375385
impl<T: PosEntry> RewindableListIndex for MultiIndex<T> {
376-
fn rewind(&self, batch: &Batch<'_>, commit: Commitment, rewind_pos: u64) -> Result<(), Error> {
386+
fn rewind(
387+
&self,
388+
batch: &mut Batch<'_>,
389+
commit: Commitment,
390+
rewind_pos: u64,
391+
) -> Result<(), Error> {
377392
while self
378393
.peek_pos(batch, commit)?
379394
.map(|x| x.pos() > rewind_pos)
@@ -386,7 +401,7 @@ impl<T: PosEntry> RewindableListIndex for MultiIndex<T> {
386401
}
387402

388403
impl<T: PosEntry> PruneableListIndex for MultiIndex<T> {
389-
fn clear(&self, batch: &Batch<'_>) -> Result<(), Error> {
404+
fn clear(&self, batch: &mut Batch<'_>) -> Result<(), Error> {
390405
let mut list_count = 0;
391406
let mut entry_count = 0;
392407
let prefix = to_key(self.list_prefix, "");
@@ -409,7 +424,7 @@ impl<T: PosEntry> PruneableListIndex for MultiIndex<T> {
409424
/// Pruning will be more performant than full rebuild but not yet necessary.
410425
fn prune(
411426
&self,
412-
_batch: &Batch<'_>,
427+
_batch: &mut Batch<'_>,
413428
_commit: Commitment,
414429
_cutoff_pos: u64,
415430
) -> Result<(), Error> {
@@ -420,7 +435,7 @@ impl<T: PosEntry> PruneableListIndex for MultiIndex<T> {
420435

421436
/// Pop off the back/tail of the linked list.
422437
/// Used when pruning old data.
423-
fn pop_pos_back(&self, batch: &Batch<'_>, commit: Commitment) -> Result<Option<T>, Error> {
438+
fn pop_pos_back(&self, batch: &mut Batch<'_>, commit: Commitment) -> Result<Option<T>, Error> {
424439
match self.get_list(batch, commit)? {
425440
None => Ok(None),
426441
Some(ListWrapper::Single { pos }) => {

0 commit comments

Comments
 (0)