Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dubbelosix committed Nov 24, 2023
1 parent c1e4dc7 commit 9df60cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn transfer_initial_token() {
&mut working_set,
);
assert_eq!((sender_balance, receiver_balance), (100, 100));
println!("Starting commit for genesis, i.e. slot 1");
commit(working_set, prover_storage.clone());
println!("Genesis commit complete");

let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(prover_storage.clone());

Expand All @@ -55,9 +53,7 @@ fn transfer_initial_token() {
);
assert_eq!((sender_balance, receiver_balance), (90, 110));

println!("Starting commit for slot 2");
commit(working_set, prover_storage.clone());
println!("Commit complete for slot 2");

let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(prover_storage.clone());

Expand All @@ -76,12 +72,9 @@ fn transfer_initial_token() {
&mut working_set,
);
assert_eq!((sender_balance, receiver_balance), (80, 120));
println!("Starting commit for slot 3");
commit(working_set, prover_storage.clone());
println!("Commit complete for slot 3");

let archival_slot: u64 = 2;
println!("Archival reads at slot {}", archival_slot);
let archival_storage = prover_storage.get_archival_storage(archival_slot).unwrap();
let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(archival_storage);
let (sender_balance, receiver_balance) = query_sender_receiver_balances(
Expand All @@ -94,7 +87,6 @@ fn transfer_initial_token() {
assert_eq!((sender_balance, receiver_balance), (90, 110));

let archival_slot: u64 = 1;
println!("Archival archival reads at slot {}", archival_slot);
let archival_storage = prover_storage.get_archival_storage(archival_slot).unwrap();
let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(archival_storage);
let (sender_balance, receiver_balance) = query_sender_receiver_balances(
Expand All @@ -105,15 +97,13 @@ fn transfer_initial_token() {
&mut working_set,
);
assert_eq!((sender_balance, receiver_balance), (100, 100));
println!("Transfer on archival");
transfer(
&bank,
token_address,
sender_address,
receiver_address,
&mut working_set,
);
println!("Archival query for modified working set");
let (sender_balance, receiver_balance) = query_sender_receiver_balances(
&bank,
token_address,
Expand All @@ -123,7 +113,6 @@ fn transfer_initial_token() {
);
assert_eq!((sender_balance, receiver_balance), (90, 110));

println!(" Move back from archival to current once again");
let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(prover_storage.clone());
let (sender_balance, receiver_balance) = query_sender_receiver_balances(
&bank,
Expand Down Expand Up @@ -190,11 +179,8 @@ fn transfer_initial_token() {
let mut working_set: WorkingSet<DefaultContext> = WorkingSet::new(archival_storage);
let mut accessory_state = working_set.accessory_state();
let val = accessory_state.get(&StorageKey::from("k")).unwrap();

assert_eq!("v1", String::from_utf8(val.value().to_vec()).unwrap());

commit(working_set, prover_storage.clone());
println!("{:?}", val);
}

fn query_sender_receiver_balances(
Expand Down
18 changes: 5 additions & 13 deletions module-system/sov-state/src/prover_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl<S: MerkleProofSpec> Storages<S> {
)),
}
}

/// placeholder
pub fn with_path(path: impl AsRef<Path>) -> Result<Storages<S>, anyhow::Error> {
ProverStorage::with_path(path)
}
}

impl<S: MerkleProofSpec> Storage for Storages<S> {
Expand Down Expand Up @@ -159,19 +164,6 @@ impl<S: MerkleProofSpec> ProverStorage<S> {
}))
}

/// Creates a new [`ProverStorage`] instance at the specified path, opening
/// or creating the necessary RocksDB database(s) at the specified path.
pub fn with_path_prover(path: impl AsRef<Path>) -> Result<Self, anyhow::Error> {
let state_db = StateDB::with_path(&path)?;
let native_db = NativeDB::with_path(&path)?;

Ok(Self {
db: state_db,
native_db,
_phantom_hasher: Default::default(),
})
}

pub(crate) fn with_db_handles(db: StateDB, native_db: NativeDB) -> Self {
Self {
db,
Expand Down

0 comments on commit 9df60cd

Please sign in to comment.