Skip to content

Commit

Permalink
feat: include fee, reserves and treasury delta when importing snapshots.
Browse files Browse the repository at this point in the history
  Still, unregistered rewards are missing and needs to be added
  eventually.
  • Loading branch information
KtorZ committed Dec 20, 2024
1 parent e9012de commit a2b7e9d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions crates/amaru/src/bin/amaru/cmd/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ fn decode_new_epoch_state(
import_block_issuers(db, d.decode().into_diagnostic()?)?;

let accounts: HashMap<StakeCredential, Account>;
let fees: i64;
let treasury: i64;
let reserves: i64;

// Epoch State
{
d.array().into_diagnostic()?;

// Epoch State / Account State
d.array().into_diagnostic()?;
let treasury: u64 = d.decode().into_diagnostic()?;
let reserves: u64 = d.decode().into_diagnostic()?;
treasury = d.decode().into_diagnostic()?;
reserves = d.decode().into_diagnostic()?;

// Epoch State / Ledger State
d.array().into_diagnostic()?;
Expand Down Expand Up @@ -175,7 +178,7 @@ fn decode_new_epoch_state(

let _deposited: u64 = d.decode().into_diagnostic()?;

import_pots(db, treasury, reserves, d.decode().into_diagnostic()?)?;
fees = d.decode().into_diagnostic()?;

// Epoch State / Ledger State / UTxO State / utxosGovState
d.skip().into_diagnostic()?;
Expand Down Expand Up @@ -205,11 +208,26 @@ fn decode_new_epoch_state(
);
d.array().into_diagnostic()?;

// ΔT
d.skip().into_diagnostic()?;
// ΔR
let delta_treasury: i64 = d.decode().into_diagnostic()?;

let delta_reserves: i64 = d.decode().into_diagnostic()?;

let rewards: HashMap<StakeCredential, Set<Reward>> = d.decode().into_diagnostic()?;
let delta_fees: i64 = d.decode().into_diagnostic()?;

// NonMyopic
d.skip().into_diagnostic()?;
import_accounts(db, accounts, d.decode().into_diagnostic()?)?;

import_accounts(db, accounts, rewards)?;

// TODO: Also add the total of unregistered rewards, that is, rewards supposed to go to stake
// credentials that are no longer registered going to the treasury instead.
import_pots(
db,
(treasury + delta_treasury) as u64,
(reserves - delta_reserves) as u64,
(fees - delta_fees) as u64,
)?;
}

Ok(epoch)
Expand Down

0 comments on commit a2b7e9d

Please sign in to comment.