db: migrate from lmdb-zero to heed
This commit is contained in:
@@ -50,7 +50,7 @@ fn test_store_indices() {
|
||||
{
|
||||
// Start a new batch and delete the block.
|
||||
let store = chain.store();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
assert!(batch.delete_block(&block_hash).is_ok());
|
||||
|
||||
// Block is deleted within this batch.
|
||||
|
||||
@@ -39,14 +39,14 @@ fn test_store_kernel_idx() {
|
||||
let commit = Commitment::from_vec(vec![]);
|
||||
|
||||
let store = ChainStore::new(chain_dir).unwrap();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
let index = store::nrd_recent_kernel_index();
|
||||
|
||||
assert_eq!(index.peek_pos(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -63,7 +63,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -79,17 +79,17 @@ fn test_store_kernel_idx() {
|
||||
|
||||
// Pos must always increase.
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Err(Error::OtherErr("pos must be increasing".into())),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Err(Error::OtherErr("pos must be increasing".into())),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -104,7 +104,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos(&batch, commit),
|
||||
index.pop_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 3, height: 3 })),
|
||||
);
|
||||
|
||||
@@ -119,7 +119,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -134,7 +134,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos(&batch, commit),
|
||||
index.pop_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 3, height: 3 })),
|
||||
);
|
||||
|
||||
@@ -149,7 +149,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos(&batch, commit),
|
||||
index.pop_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 2, height: 2 })),
|
||||
);
|
||||
|
||||
@@ -166,7 +166,7 @@ fn test_store_kernel_idx() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos(&batch, commit),
|
||||
index.pop_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 1, height: 1 })),
|
||||
);
|
||||
|
||||
@@ -186,14 +186,14 @@ fn test_store_kernel_idx_pop_back() {
|
||||
let commit = Commitment::from_vec(vec![]);
|
||||
|
||||
let store = ChainStore::new(chain_dir).unwrap();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
let index = store::nrd_recent_kernel_index();
|
||||
|
||||
assert_eq!(index.peek_pos(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -210,7 +210,7 @@ fn test_store_kernel_idx_pop_back() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos_back(&batch, commit),
|
||||
index.pop_pos_back(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 1, height: 1 })),
|
||||
);
|
||||
|
||||
@@ -218,32 +218,32 @@ fn test_store_kernel_idx_pop_back() {
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.peek_pos(&batch, commit),
|
||||
index.peek_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 3, height: 3 })),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.get_list(&batch, commit),
|
||||
index.get_list(&mut batch, commit),
|
||||
Ok(Some(ListWrapper::Multi { head: 3, tail: 1 })),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos_back(&batch, commit),
|
||||
index.pop_pos_back(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 1, height: 1 })),
|
||||
);
|
||||
|
||||
@@ -258,7 +258,7 @@ fn test_store_kernel_idx_pop_back() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos_back(&batch, commit),
|
||||
index.pop_pos_back(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 2, height: 2 })),
|
||||
);
|
||||
|
||||
@@ -275,7 +275,7 @@ fn test_store_kernel_idx_pop_back() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos_back(&batch, commit),
|
||||
index.pop_pos_back(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 3, height: 3 })),
|
||||
);
|
||||
|
||||
@@ -294,21 +294,21 @@ fn test_store_kernel_idx_rewind() {
|
||||
let commit = Commitment::from_vec(vec![]);
|
||||
|
||||
let store = ChainStore::new(chain_dir).unwrap();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
let index = store::nrd_recent_kernel_index();
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -317,7 +317,7 @@ fn test_store_kernel_idx_rewind() {
|
||||
Ok(Some(ListWrapper::Multi { head: 3, tail: 1 })),
|
||||
);
|
||||
|
||||
assert_eq!(index.rewind(&batch, commit, 1), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 1), Ok(()),);
|
||||
|
||||
assert_eq!(
|
||||
index.get_list(&batch, commit),
|
||||
@@ -327,7 +327,7 @@ fn test_store_kernel_idx_rewind() {
|
||||
);
|
||||
|
||||
// Check we can safely noop rewind.
|
||||
assert_eq!(index.rewind(&batch, commit, 2), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 2), Ok(()),);
|
||||
|
||||
assert_eq!(
|
||||
index.get_list(&batch, commit),
|
||||
@@ -336,7 +336,7 @@ fn test_store_kernel_idx_rewind() {
|
||||
})),
|
||||
);
|
||||
|
||||
assert_eq!(index.rewind(&batch, commit, 1), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 1), Ok(()),);
|
||||
|
||||
assert_eq!(
|
||||
index.get_list(&batch, commit),
|
||||
@@ -346,42 +346,42 @@ fn test_store_kernel_idx_rewind() {
|
||||
);
|
||||
|
||||
// Check we can rewind back to 0.
|
||||
assert_eq!(index.rewind(&batch, commit, 0), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 0), Ok(()),);
|
||||
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None),);
|
||||
|
||||
assert_eq!(index.rewind(&batch, commit, 0), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 0), Ok(()),);
|
||||
|
||||
// Now check we can rewind past the end of a list safely.
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos_back(&batch, commit),
|
||||
index.pop_pos_back(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 1, height: 1 })),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.get_list(&batch, commit),
|
||||
index.get_list(&mut batch, commit),
|
||||
Ok(Some(ListWrapper::Multi { head: 3, tail: 2 })),
|
||||
);
|
||||
|
||||
assert_eq!(index.rewind(&batch, commit, 1), Ok(()),);
|
||||
assert_eq!(index.rewind(&mut batch, commit, 1), Ok(()),);
|
||||
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None),);
|
||||
assert_eq!(index.get_list(&mut batch, commit), Ok(None),);
|
||||
|
||||
clean_output_dir(chain_dir);
|
||||
}
|
||||
@@ -396,14 +396,14 @@ fn test_store_kernel_idx_multiple_commits() {
|
||||
let commit2 = Commitment::from_vec(vec![1]);
|
||||
|
||||
let store = ChainStore::new(chain_dir).unwrap();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
let index = store::nrd_recent_kernel_index();
|
||||
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit2), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -417,7 +417,7 @@ fn test_store_kernel_idx_multiple_commits() {
|
||||
assert_eq!(index.get_list(&batch, commit2), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit2, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit2, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -436,7 +436,7 @@ fn test_store_kernel_idx_multiple_commits() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 3, height: 3 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
@@ -453,7 +453,7 @@ fn test_store_kernel_idx_multiple_commits() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.pop_pos(&batch, commit),
|
||||
index.pop_pos(&mut batch, commit),
|
||||
Ok(Some(CommitPos { pos: 3, height: 3 })),
|
||||
);
|
||||
|
||||
@@ -488,18 +488,18 @@ fn test_store_kernel_idx_clear() -> Result<(), Error> {
|
||||
|
||||
// Add a couple of single entries to the index and commit the batch.
|
||||
{
|
||||
let batch = store.batch()?;
|
||||
let mut batch = store.batch()?;
|
||||
assert_eq!(index.peek_pos(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
index.push_pos(
|
||||
&batch,
|
||||
&mut batch,
|
||||
commit2,
|
||||
CommitPos {
|
||||
pos: 10,
|
||||
@@ -544,8 +544,8 @@ fn test_store_kernel_idx_clear() -> Result<(), Error> {
|
||||
|
||||
// Clear the index and confirm everything was deleted as expected.
|
||||
{
|
||||
let batch = store.batch()?;
|
||||
assert_eq!(index.clear(&batch), Ok(()));
|
||||
let mut batch = store.batch()?;
|
||||
assert_eq!(index.clear(&mut batch), Ok(()));
|
||||
assert_eq!(index.peek_pos(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
assert_eq!(index.peek_pos(&batch, commit2), Ok(None));
|
||||
@@ -555,13 +555,13 @@ fn test_store_kernel_idx_clear() -> Result<(), Error> {
|
||||
|
||||
// Add multiple entries to the index, commit the batch.
|
||||
{
|
||||
let batch = store.batch()?;
|
||||
let mut batch = store.batch()?;
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 1, height: 1 }),
|
||||
Ok(()),
|
||||
);
|
||||
assert_eq!(
|
||||
index.push_pos(&batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
index.push_pos(&mut batch, commit, CommitPos { pos: 2, height: 2 }),
|
||||
Ok(()),
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -577,8 +577,8 @@ fn test_store_kernel_idx_clear() -> Result<(), Error> {
|
||||
|
||||
// Clear the index and confirm everything was deleted as expected.
|
||||
{
|
||||
let batch = store.batch()?;
|
||||
assert_eq!(index.clear(&batch), Ok(()));
|
||||
let mut batch = store.batch()?;
|
||||
assert_eq!(index.clear(&mut batch), Ok(()));
|
||||
assert_eq!(index.peek_pos(&batch, commit), Ok(None));
|
||||
assert_eq!(index.get_list(&batch, commit), Ok(None));
|
||||
batch.commit()?;
|
||||
|
||||
@@ -61,7 +61,7 @@ fn check_known() {
|
||||
{
|
||||
let chain = init_chain(chain_dir, genesis.clone());
|
||||
let store = chain.store();
|
||||
let batch = store.batch().unwrap();
|
||||
let mut batch = store.batch().unwrap();
|
||||
let head_header = chain.head_header().unwrap();
|
||||
let prev = batch.get_previous_header(&head_header).unwrap();
|
||||
batch.save_body_head(&Tip::from_header(&prev)).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user