Skip to content

Commit 6d64025

Browse files
authored
Merge pull request ProvableHQ#2493 from ProvableHQ/feat/log-credits-mappings
[Feature] Support historical logging for `delegated`, `bonded, and `unbonding` mappings.
2 parents 454d555 + 057573f commit 6d64025

File tree

7 files changed

+202
-30
lines changed

7 files changed

+202
-30
lines changed

Cargo.lock

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ cli = [
131131
aleo-cli = [ "snarkvm-synthesizer/aleo-cli" ]
132132
async = [ "snarkvm-ledger/async", "snarkvm-synthesizer/async" ]
133133
cuda = [ "snarkvm-algorithms/cuda" ]
134+
history = [ "snarkvm-synthesizer/history" ]
134135
parameters_no_std_out = [ "snarkvm-parameters/no_std_out" ]
135136
noconfig = [ ]
136137
rocks = [ "snarkvm-ledger/rocks", "snarkvm-synthesizer/rocks" ]

algorithms/src/r1cs/test_constraint_system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<F: Field> TestConstraintSystem<F> {
306306
ns_idx
307307
}
308308
Entry::Occupied(e) => {
309-
let interned_segments = e.remove_entry().0;
309+
let interned_segments = e.swap_remove_entry().0;
310310
panic!("tried to create object at existing path: {}", self.unintern_path(interned_segments));
311311
}
312312
}

synthesizer/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ snark = [ "synthesizer-snark" ]
3131
aleo-cli = [ ]
3232
async = [ "ledger-query/async", "synthesizer-process/async" ]
3333
cuda = [ "algorithms/cuda" ]
34+
history = [ "serde" ]
3435
rocks = [ "ledger-store/rocks" ]
3536
serial = [
3637
"console/serial",
@@ -162,6 +163,10 @@ version = "0.8"
162163
version = "1"
163164
optional = true
164165

166+
[dependencies.serde]
167+
version = "1.0"
168+
optional = true
169+
165170
[dependencies.serde_json]
166171
version = "1.0"
167172
features = [ "preserve_order" ]

synthesizer/src/vm/finalize.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
495495
let post_ratifications = reward_ratifications.iter().chain(post_ratifications);
496496

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

740740
/* Perform the ratifications after finalize. */
741741

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

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

12591259
// Insert the next committee into storage.
12601260
store.committee_store().insert(state.block_height(), next_committee)?;
1261+
1262+
#[cfg(all(feature = "history", feature = "rocks"))]
1263+
{
1264+
// When finalizing in `FinalizeMode::RealRun`, store the delegated and bonded mappings in history.
1265+
if IS_FINALIZE {
1266+
// Load a `History` object.
1267+
let history = History::new(N::ID, store.storage_mode());
1268+
1269+
// Write the delegated mapping as JSON.
1270+
history.store_mapping(state.block_height(), MappingName::Delegated, &next_delegated_map)?;
1271+
1272+
// Write the bonded mapping as JSON.
1273+
history.store_mapping(state.block_height(), MappingName::Bonded, &next_bonded_map)?;
1274+
1275+
// Write the metadata mapping as JSON.
1276+
let metadata_mapping = Identifier::from_str("metadata")?;
1277+
let metadata_map = store.get_mapping_speculative(program_id, metadata_mapping)?;
1278+
history.store_mapping(state.block_height(), MappingName::Metadata, &metadata_map)?;
1279+
1280+
// Write the unbonding mapping as JSON.
1281+
let unbonding_mapping = Identifier::from_str("unbonding")?;
1282+
let unbonding_map = store.get_mapping_speculative(program_id, unbonding_mapping)?;
1283+
history.store_mapping(state.block_height(), MappingName::Unbonding, &unbonding_map)?;
1284+
1285+
// Write the withdraw mapping as JSON.
1286+
let withdraw_mapping = Identifier::from_str("withdraw")?;
1287+
let withdraw_map = store.get_mapping_speculative(program_id, withdraw_mapping)?;
1288+
history.store_mapping(state.block_height(), MappingName::Withdraw, &withdraw_map)?;
1289+
}
1290+
}
1291+
12611292
// Store the finalize operations for updating the committee and bonded mapping.
12621293
finalize_operations.extend(&[
12631294
// Replace the committee mapping in storage.

0 commit comments

Comments
 (0)