Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporting claim fix #128

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/validator-bonds-cli/src/commands/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { setProgramIdOrDefault } from '../context'
import {
MARINADE_CONFIG_ADDRESS,
bondAddress,
withdrawRequestAddress,
} from '@marinade.finance/validator-bonds-sdk'
import { ProgramAccount } from '@coral-xyz/anchor'

Expand Down Expand Up @@ -65,8 +66,16 @@ async function showBondAddress({
'Deriving bond account address from vote account: ' +
`${address.toBase58()}, config: ${config.toBase58()}, programId: ${program.programId.toBase58()}`
)
const [withdrawRequestAddr, withdrawRequestBump] = withdrawRequestAddress(
bondAddr,
program.programId
)
logger.debug(
'Deriving withdraw request account address from bond account: ' +
`${bondAddr.toBase58()}, programId: ${program.programId.toBase58()}`
)
console.log(
`Bond account address: ${bondAddr.toBase58()} [bump: ${bondBump}]`
`Bond account address: ${bondAddr.toBase58()} [bump: ${bondBump}], withdraw request address: ${withdrawRequestAddr.toBase58()} [bump: ${withdrawRequestBump}]`
)
} catch (err) {
throw new CliCommandError({
Expand Down
4 changes: 3 additions & 1 deletion protected-event-distribution/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use protected_event_distribution::{
protected_events::generate_protected_event_collection,
utils::{read_from_json_file, write_to_json_file},
};
use snapshot_parser_types::{stake_meta::StakeMetaCollection, validator_meta::ValidatorMetaCollection};
use snapshot_parser_types::{
stake_meta::StakeMetaCollection, validator_meta::ValidatorMetaCollection,
};
use solana_sdk::pubkey::Pubkey;
use std::collections::HashSet;
use {clap::Parser, log::info};
Expand Down
39 changes: 21 additions & 18 deletions settlement-pipelines/src/bin/claim_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async fn real_main(reporting: &mut ReportHandler<ClaimSettlementsReport>) -> any
let minimal_stake_lamports = config.minimum_stake_lamports + STAKE_ACCOUNT_RENT_EXEMPTION;

let mut json_data = load_json(&args.json_files)?;
let settlement_records_per_epoch =
let json_loaded_settlements_per_epoch =
parse_settlements_from_json(&mut json_data, &config_address, args.epoch)
.map_err(CliError::processing)?;

Expand All @@ -120,7 +120,7 @@ async fn real_main(reporting: &mut ReportHandler<ClaimSettlementsReport>) -> any

reporting.reportable.init(
rpc_client.clone(),
&settlement_records_per_epoch,
&json_loaded_settlements_per_epoch,
&claimable_settlements,
);

Expand Down Expand Up @@ -152,14 +152,16 @@ async fn real_main(reporting: &mut ReportHandler<ClaimSettlementsReport>) -> any
let mut stake_accounts_to_cache = StakeAccountsCache::default();

for claimable_settlement in claimable_settlements {
let json_matching_settlement =
match get_settlement_from_json(&settlement_records_per_epoch, &claimable_settlement) {
Ok(json_record) => json_record,
Err(e) => {
reporting.add_cli_error(e);
continue;
}
};
let json_matching_settlement = match get_settlement_from_json(
&json_loaded_settlements_per_epoch,
&claimable_settlement,
) {
Ok(json_record) => json_record,
Err(e) => {
reporting.add_cli_error(e);
continue;
}
};

info!(
"Claiming settlement {}, vote account {}, claim amount {}, for epoch {}, number of FROM stake accounts {}, already claimed merkle tree nodes {}",
Expand Down Expand Up @@ -451,16 +453,17 @@ fn get_settlement_from_json<'a>(
on_chain_settlement: &ClaimableSettlementsReturn,
) -> Result<&'a SettlementRecord, CliError> {
let settlement_epoch = on_chain_settlement.settlement.epoch_created_for;
let settlement_merkle_tree =
if let Some(settlement_merkle_tree) = per_epoch_settlement_records.get(&settlement_epoch) {
settlement_merkle_tree
} else {
return Err(CliError::Processing(anyhow!(
"No JSON merkle tree data found for settlement {} epoch {}",
let settlement_merkle_tree = if let Some(settlement_merkle_tree) =
per_epoch_settlement_records.get(&settlement_epoch)
{
settlement_merkle_tree
} else {
return Err(CliError::Processing(anyhow!(
"No JSON merkle tree data found for settlement {} epoch {}, probably missing JSON input data for epoch (e.g., bidding or protected-events data)",
on_chain_settlement.settlement_address,
settlement_epoch
)));
};
};

// find on-chain data match with json data
let matching_settlement = settlement_merkle_tree.iter().find(|settlement_from_json| {
Expand Down Expand Up @@ -741,7 +744,7 @@ impl ClaimSettlementReport {
.map_or_else(|| (0, 0, 0), |(nodes, lamports)| (1, *nodes, *lamports))
})
.fold((0, 0, 0), |acc, (settlements, nodes, lamports)| {
(acc.0 + settlements, acc.1 + nodes, acc.0 + lamports)
(acc.0 + settlements, acc.1 + nodes, acc.2 + lamports)
});
(reason, (settlements_count, claimed_nodes, claimed_lamports))
})
Expand Down
5 changes: 4 additions & 1 deletion settlement-pipelines/src/reporting_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ impl SettlementsReportData {
};
result.get_mut(&reason_type).unwrap().insert(*pubkey);
} else {
debug!("Unknown settlement record for pubkey: {}", pubkey);
debug!(
"group by reason: unknown settlement record for pubkey: {}",
pubkey
);
};
}
result
Expand Down