Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Update getLeaderSchedule options (#16749) (#16752)
Browse files Browse the repository at this point in the history
(cherry picked from commit 636b598)

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Apr 22, 2021
1 parent 0269fff commit fadf1ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 16 additions & 0 deletions client/src/rpc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ pub struct RpcLeaderScheduleConfig {
pub commitment: Option<CommitmentConfig>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RpcLeaderScheduleConfigWrapper {
SlotOnly(Option<Slot>),
ConfigOnly(Option<RpcLeaderScheduleConfig>),
}

impl RpcLeaderScheduleConfigWrapper {
pub fn unzip(&self) -> (Option<Slot>, Option<RpcLeaderScheduleConfig>) {
match &self {
RpcLeaderScheduleConfigWrapper::SlotOnly(slot) => (*slot, None),
RpcLeaderScheduleConfigWrapper::ConfigOnly(config) => (None, config.clone()),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum RpcLargestAccountsFilter {
Expand Down
13 changes: 9 additions & 4 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ pub mod rpc_minimal {
fn get_leader_schedule(
&self,
meta: Self::Metadata,
slot: Option<Slot>,
options: Option<RpcLeaderScheduleConfigWrapper>,
config: Option<RpcLeaderScheduleConfig>,
) -> Result<Option<RpcLeaderSchedule>>;
}
Expand Down Expand Up @@ -2213,10 +2213,11 @@ pub mod rpc_minimal {
fn get_leader_schedule(
&self,
meta: Self::Metadata,
slot: Option<Slot>,
options: Option<RpcLeaderScheduleConfigWrapper>,
config: Option<RpcLeaderScheduleConfig>,
) -> Result<Option<RpcLeaderSchedule>> {
let config = config.unwrap_or_default();
let (slot, maybe_config) = options.map(|options| options.unzip()).unwrap_or_default();
let config = maybe_config.or(config).unwrap_or_default();

if let Some(ref identity) = config.identity {
let _ = verify_pubkey(identity)?;
Expand Down Expand Up @@ -4122,6 +4123,10 @@ pub mod tests {
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}" }}]}}"#,
bank.collector_id().to_string()
),
&format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [{{ "identity": "{}" }}]}}"#,
bank.collector_id().to_string()
),
]
.iter()
{
Expand Down Expand Up @@ -4171,7 +4176,7 @@ pub mod tests {

// `bob` is not in the leader schedule, look for an empty response
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [null, {{ "identity": "{}"}}]}}"#,
r#"{{"jsonrpc":"2.0","id":1,"method":"getLeaderSchedule", "params": [{{ "identity": "{}"}}]}}"#,
bob_pubkey
);

Expand Down

0 comments on commit fadf1ef

Please sign in to comment.