Skip to content

Commit

Permalink
v1.18: Support json parsing of epoch-rewards partition data sysvar ac…
Browse files Browse the repository at this point in the history
…counts (backport of solana-labs#34914) (solana-labs#34926)

Support json parsing of epoch-rewards partition data sysvar accounts (solana-labs#34914)

(cherry picked from commit b9947bd)

Co-authored-by: Tyera <tyera@solana.com>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Jan 24, 2024
1 parent 4d9fa8b commit 60bb090
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion account-decoder/src/parse_sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use {
bv::BitVec,
solana_sdk::{
clock::{Clock, Epoch, Slot, UnixTimestamp},
epoch_rewards_partition_data::EpochRewardsPartitionDataVersion,
epoch_schedule::EpochSchedule,
pubkey::Pubkey,
rent::Rent,
Expand Down Expand Up @@ -96,7 +97,24 @@ pub fn parse_sysvar(data: &[u8], pubkey: &Pubkey) -> Result<SysvarAccountType, P
.ok()
.map(SysvarAccountType::EpochRewards)
} else {
None
// EpochRewards PartitionData accounts are owned by the sysvar
// program, but have dynamically generated addresses. Test on
// whether account content deserializes properly.
if let Ok(epoch_rewards_partition_data) =
deserialize::<EpochRewardsPartitionDataVersion>(data)
{
let EpochRewardsPartitionDataVersion::V0(partition_data) =
epoch_rewards_partition_data;
Some(SysvarAccountType::EpochRewardsPartitionData(
UiEpochRewardsPartitionData {
version: 0,
num_partitions: partition_data.num_partitions as u64,
parent_blockhash: partition_data.parent_blockhash.to_string(),
},
))
} else {
None
}
}
};
parsed_account.ok_or(ParseAccountError::AccountNotParsable(
Expand All @@ -120,6 +138,7 @@ pub enum SysvarAccountType {
StakeHistory(Vec<UiStakeHistoryEntry>),
LastRestartSlot(UiLastRestartSlot),
EpochRewards(EpochRewards),
EpochRewardsPartitionData(UiEpochRewardsPartitionData),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -239,6 +258,14 @@ pub struct UiLastRestartSlot {
pub last_restart_slot: Slot,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct UiEpochRewardsPartitionData {
pub version: u32,
pub num_partitions: u64,
pub parent_blockhash: String,
}

#[cfg(test)]
mod test {
#[allow(deprecated)]
Expand Down

0 comments on commit 60bb090

Please sign in to comment.