Skip to content

Commit

Permalink
Merge pull request #2493 from ProvableHQ/feat/log-credits-mappings
Browse files Browse the repository at this point in the history
[Feature] Support historical logging for `delegated`, `bonded, and `unbonding` mappings.
  • Loading branch information
apruden2008 authored Jun 14, 2024
2 parents 454d555 + 057573f commit 6d64025
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 30 deletions.
53 changes: 27 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ cli = [
aleo-cli = [ "snarkvm-synthesizer/aleo-cli" ]
async = [ "snarkvm-ledger/async", "snarkvm-synthesizer/async" ]
cuda = [ "snarkvm-algorithms/cuda" ]
history = [ "snarkvm-synthesizer/history" ]
parameters_no_std_out = [ "snarkvm-parameters/no_std_out" ]
noconfig = [ ]
rocks = [ "snarkvm-ledger/rocks", "snarkvm-synthesizer/rocks" ]
Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/r1cs/test_constraint_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<F: Field> TestConstraintSystem<F> {
ns_idx
}
Entry::Occupied(e) => {
let interned_segments = e.remove_entry().0;
let interned_segments = e.swap_remove_entry().0;
panic!("tried to create object at existing path: {}", self.unintern_path(interned_segments));
}
}
Expand Down
5 changes: 5 additions & 0 deletions synthesizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ snark = [ "synthesizer-snark" ]
aleo-cli = [ ]
async = [ "ledger-query/async", "synthesizer-process/async" ]
cuda = [ "algorithms/cuda" ]
history = [ "serde" ]
rocks = [ "ledger-store/rocks" ]
serial = [
"console/serial",
Expand Down Expand Up @@ -162,6 +163,10 @@ version = "0.8"
version = "1"
optional = true

[dependencies.serde]
version = "1.0"
optional = true

[dependencies.serde_json]
version = "1.0"
features = [ "preserve_order" ]
Expand Down
37 changes: 34 additions & 3 deletions synthesizer/src/vm/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
let post_ratifications = reward_ratifications.iter().chain(post_ratifications);

// Process the post-ratifications.
match Self::atomic_post_ratify(&self.puzzle, store, state, post_ratifications, solutions) {
match Self::atomic_post_ratify::<false>(&self.puzzle, store, state, post_ratifications, solutions) {
// Store the finalize operations from the post-ratify.
Ok(operations) => ratified_finalize_operations.extend(operations),
// Note: This will abort the entire atomic batch.
Expand Down Expand Up @@ -739,7 +739,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {

/* Perform the ratifications after finalize. */

match Self::atomic_post_ratify(&self.puzzle, store, state, post_ratifications, solutions) {
match Self::atomic_post_ratify::<true>(&self.puzzle, store, state, post_ratifications, solutions) {
// Store the finalize operations from the post-ratify.
Ok(operations) => ratified_finalize_operations.extend(operations),
// Note: This will abort the entire atomic batch.
Expand Down Expand Up @@ -1191,7 +1191,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {

/// Performs the post-ratifications after finalizing transactions.
#[inline]
fn atomic_post_ratify<'a>(
fn atomic_post_ratify<'a, const IS_FINALIZE: bool>(
puzzle: &Puzzle<N>,
store: &FinalizeStore<N, C::FinalizeStorage>,
state: FinalizeGlobalState,
Expand Down Expand Up @@ -1258,6 +1258,37 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {

// Insert the next committee into storage.
store.committee_store().insert(state.block_height(), next_committee)?;

#[cfg(all(feature = "history", feature = "rocks"))]
{
// When finalizing in `FinalizeMode::RealRun`, store the delegated and bonded mappings in history.
if IS_FINALIZE {
// Load a `History` object.
let history = History::new(N::ID, store.storage_mode());

// Write the delegated mapping as JSON.
history.store_mapping(state.block_height(), MappingName::Delegated, &next_delegated_map)?;

// Write the bonded mapping as JSON.
history.store_mapping(state.block_height(), MappingName::Bonded, &next_bonded_map)?;

// Write the metadata mapping as JSON.
let metadata_mapping = Identifier::from_str("metadata")?;
let metadata_map = store.get_mapping_speculative(program_id, metadata_mapping)?;
history.store_mapping(state.block_height(), MappingName::Metadata, &metadata_map)?;

// Write the unbonding mapping as JSON.
let unbonding_mapping = Identifier::from_str("unbonding")?;
let unbonding_map = store.get_mapping_speculative(program_id, unbonding_mapping)?;
history.store_mapping(state.block_height(), MappingName::Unbonding, &unbonding_map)?;

// Write the withdraw mapping as JSON.
let withdraw_mapping = Identifier::from_str("withdraw")?;
let withdraw_map = store.get_mapping_speculative(program_id, withdraw_mapping)?;
history.store_mapping(state.block_height(), MappingName::Withdraw, &withdraw_map)?;
}
}

// Store the finalize operations for updating the committee and bonded mapping.
finalize_operations.extend(&[
// Replace the committee mapping in storage.
Expand Down
Loading

0 comments on commit 6d64025

Please sign in to comment.