crate-crypto / rust-verkle

Apache License 2.0
118 stars 41 forks source link

Error when loading trie from existing rocksdb #95

Open hiasr opened 6 months ago

hiasr commented 6 months ago

When creating a tree from an existing db, the following error occurs:

thread 'main' panicked at .../rust_verkle/verkle-trie/src/database/generic.rs:145:72:
called `Result::unwrap()` on an `Err` value: InvalidData

If you run the following example twice, you will see the error on the second run.

fn test_rocksdb() {
    let keys = (0..1000).map(|_| generate_rand_address()); 
    let kvs = keys.clone().map(|key| (key, key));
    let db: VerkleDb<RocksDb> = VerkleDb::from_path("dbs/test_rocksdb");
    let mut trie = Trie::new(DefaultConfig::new(db));
    trie.insert(kvs.clone());
    trie.flush_database();
}

fn generate_rand_address() -> [u8; 32] {
    let mut rng = rand::thread_rng();
    let mut address = [0u8; 32];
    rng.fill_bytes(&mut address);
    address
}