mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Update kvdb-* and trie (#4483)
This commit is contained in:
@@ -77,7 +77,7 @@ impl<H, N> LeafSet<H, N> where
|
||||
}
|
||||
|
||||
/// Read the leaf list from the DB, using given prefix for keys.
|
||||
pub fn read_from_db(db: &dyn KeyValueDB, column: Option<u32>, prefix: &[u8]) -> Result<Self> {
|
||||
pub fn read_from_db(db: &dyn KeyValueDB, column: u32, prefix: &[u8]) -> Result<Self> {
|
||||
let mut storage = BTreeMap::new();
|
||||
|
||||
for (key, value) in db.iter_from_prefix(column, prefix) {
|
||||
@@ -173,7 +173,7 @@ impl<H, N> LeafSet<H, N> where
|
||||
}
|
||||
|
||||
/// Write the leaf list to the database transaction.
|
||||
pub fn prepare_transaction(&mut self, tx: &mut DBTransaction, column: Option<u32>, prefix: &[u8]) {
|
||||
pub fn prepare_transaction(&mut self, tx: &mut DBTransaction, column: u32, prefix: &[u8]) {
|
||||
let mut buf = prefix.to_vec();
|
||||
for LeafSetItem { hash, number } in self.pending_added.drain(..) {
|
||||
hash.using_encoded(|s| buf.extend(s));
|
||||
@@ -277,7 +277,7 @@ mod tests {
|
||||
#[test]
|
||||
fn flush_to_disk() {
|
||||
const PREFIX: &[u8] = b"abcdefg";
|
||||
let db = ::kvdb_memorydb::create(0);
|
||||
let db = ::kvdb_memorydb::create(1);
|
||||
|
||||
let mut set = LeafSet::new();
|
||||
set.import(0u32, 0u32, 0u32);
|
||||
@@ -288,10 +288,10 @@ mod tests {
|
||||
|
||||
let mut tx = DBTransaction::new();
|
||||
|
||||
set.prepare_transaction(&mut tx, None, PREFIX);
|
||||
set.prepare_transaction(&mut tx, 0, PREFIX);
|
||||
db.write(tx).unwrap();
|
||||
|
||||
let set2 = LeafSet::read_from_db(&db, None, PREFIX).unwrap();
|
||||
let set2 = LeafSet::read_from_db(&db, 0, PREFIX).unwrap();
|
||||
assert_eq!(set, set2);
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ mod tests {
|
||||
#[test]
|
||||
fn finalization_consistent_with_disk() {
|
||||
const PREFIX: &[u8] = b"prefix";
|
||||
let db = ::kvdb_memorydb::create(0);
|
||||
let db = ::kvdb_memorydb::create(1);
|
||||
|
||||
let mut set = LeafSet::new();
|
||||
set.import(10_1u32, 10u32, 0u32);
|
||||
@@ -322,12 +322,12 @@ mod tests {
|
||||
assert!(set.contains(10, 10_1));
|
||||
|
||||
let mut tx = DBTransaction::new();
|
||||
set.prepare_transaction(&mut tx, None, PREFIX);
|
||||
set.prepare_transaction(&mut tx, 0, PREFIX);
|
||||
db.write(tx).unwrap();
|
||||
|
||||
let _ = set.finalize_height(11);
|
||||
let mut tx = DBTransaction::new();
|
||||
set.prepare_transaction(&mut tx, None, PREFIX);
|
||||
set.prepare_transaction(&mut tx, 0, PREFIX);
|
||||
db.write(tx).unwrap();
|
||||
|
||||
assert!(set.contains(11, 11_1));
|
||||
@@ -335,7 +335,7 @@ mod tests {
|
||||
assert!(set.contains(12, 12_1));
|
||||
assert!(!set.contains(10, 10_1));
|
||||
|
||||
let set2 = LeafSet::read_from_db(&db, None, PREFIX).unwrap();
|
||||
let set2 = LeafSet::read_from_db(&db, 0, PREFIX).unwrap();
|
||||
assert_eq!(set, set2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user