-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set stake_vote optional and integrate leader schedule and vote in sen…
…d Tx
- Loading branch information
Showing
11 changed files
with
219 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use anyhow::{bail, Error}; | ||
use async_trait::async_trait; | ||
use solana_lite_rpc_core::structures::epoch::EpochCache; | ||
use solana_lite_rpc_core::structures::leaderschedule::CalculatedSchedule; | ||
use solana_lite_rpc_core::{ | ||
structures::leader_data::LeaderData, traits::leaders_fetcher_interface::LeaderFetcherInterface, | ||
}; | ||
use std::sync::Arc; | ||
use tokio::sync::RwLock; | ||
|
||
// Stores leaders for slots from older to newer in leader schedule | ||
// regularly removed old leaders and adds new ones | ||
pub struct GrpcLeaderGetter { | ||
epoch_data: EpochCache, | ||
leader_schedule: Arc<RwLock<CalculatedSchedule>>, | ||
} | ||
|
||
impl GrpcLeaderGetter { | ||
pub fn new(leader_schedule: Arc<RwLock<CalculatedSchedule>>, epoch_data: EpochCache) -> Self { | ||
Self { | ||
leader_schedule, | ||
epoch_data, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl LeaderFetcherInterface for GrpcLeaderGetter { | ||
async fn get_slot_leaders( | ||
&self, | ||
from: solana_sdk::slot_history::Slot, | ||
to: solana_sdk::slot_history::Slot, | ||
) -> anyhow::Result<Vec<LeaderData>> { | ||
//get epoch of from/to slot to see if they're in the current stored epoch. | ||
let from_epoch = self.epoch_data.get_epoch_at_slot(from).epoch; | ||
let to_epoch = self.epoch_data.get_epoch_at_slot(to).epoch; | ||
let leader_schedule_data = self.leader_schedule.read().await; | ||
let current_epoch = leader_schedule_data | ||
.current | ||
.as_ref() | ||
.map(|e| e.epoch) | ||
.unwrap_or(from_epoch); | ||
let next_epoch = leader_schedule_data | ||
.current | ||
.as_ref() | ||
.map(|e| e.epoch) | ||
.unwrap_or(to_epoch); | ||
if from > to { | ||
bail!("invalid arguments for get_slot_leaders"); | ||
} | ||
if from_epoch < current_epoch || from_epoch > next_epoch { | ||
bail!("invalid arguments for get_slot_leaders"); | ||
} | ||
if to_epoch < current_epoch || to_epoch > next_epoch { | ||
bail!("invalid arguments for get_slot_leaders"); | ||
} | ||
|
||
let limit = to - from; | ||
|
||
let schedule = leader_schedule_data | ||
.get_slot_leaders(from, limit, self.epoch_data.get_epoch_schedule()) | ||
.await | ||
.map_err(Error::msg)?; | ||
|
||
Ok(schedule | ||
.into_iter() | ||
.enumerate() | ||
.map(|(index, pubkey)| LeaderData { | ||
leader_slot: from + index as u64, | ||
pubkey, | ||
}) | ||
.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"rpc_addr": "http://localhost:8899", | ||
"ws_addr": "ws://localhost:8900", | ||
"lite_rpc_http_addr": "[::]:8890", | ||
"lite_rpc_ws_addr": "[::]:8891", | ||
"fanout_size": 18, | ||
"identity_keypair": null, | ||
"prometheus_addr": "[::]:9091", | ||
"maximum_retries_per_tx": 40, | ||
"transaction_retry_after_secs": 3, | ||
"quic_proxy_addr": null, | ||
"use_grpc": false, | ||
"activate_leader_schedule": false, | ||
"grpc_addr": "http://127.0.0.0:10000", | ||
"grpc_x_token": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.