Skip to content

Commit

Permalink
use broadcast sender
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Jan 17, 2024
1 parent 359f68c commit c80ed8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions lite-rpc/src/block_priofees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use jsonrpsee::tracing::field::debug;
use log::{debug, error, info, trace, warn};

Check warning on line 7 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `debug`

Check warning on line 7 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `debug`

Check warning on line 7 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / Test lite-rpc against running Validator

unused import: `debug`
use solana_rpc_client_api::response::Fees;

Check warning on line 8 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `solana_rpc_client_api::response::Fees`

Check warning on line 8 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `solana_rpc_client_api::response::Fees`

Check warning on line 8 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / Test lite-rpc against running Validator

unused import: `solana_rpc_client_api::response::Fees`

Check warning on line 8 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

Diff in /home/runner/work/lite-rpc/lite-rpc/lite-rpc/src/block_priofees.rs
use solana_sdk::clock::Slot;
use tokio::sync::broadcast::Sender;
use tokio::sync::broadcast::error::RecvError::{Closed, Lagged};
use tokio::sync::broadcast::error::SendError;

Check warning on line 12 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `tokio::sync::broadcast::error::SendError`

Check warning on line 12 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `tokio::sync::broadcast::error::SendError`

Check warning on line 12 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / Test lite-rpc against running Validator

unused import: `tokio::sync::broadcast::error::SendError`
use tokio::sync::broadcast::Receiver;

Check warning on line 13 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `tokio::sync::broadcast::Receiver`

Check warning on line 13 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

unused import: `tokio::sync::broadcast::Receiver`

Check warning on line 13 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / Test lite-rpc against running Validator

unused import: `tokio::sync::broadcast::Receiver`
use tokio::task::JoinHandle;

Check warning on line 14 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

Diff in /home/runner/work/lite-rpc/lite-rpc/lite-rpc/src/block_priofees.rs
use solana_lite_rpc_cluster_endpoints::CommitmentLevel;
Expand All @@ -25,7 +27,8 @@ pub struct PrioFeeStore {

pub struct PrioFeesService {
pub block_fees_store: PrioFeeStore,
pub block_fees_stream: Receiver<PrioFeesUpdateMessage>,
// use .subscribe() to get a receiver
pub block_fees_stream: Sender<PrioFeesUpdateMessage>,
}

impl PrioFeesService {
Expand All @@ -50,10 +53,11 @@ pub async fn start_priofees_task(data_cache: DataCache, mut block_stream: BlockS
recent: recent_data.clone(),
slot_cache: data_cache.slot_cache,
};
let (priofees_update_sender, priofees_update_receiver) = tokio::sync::broadcast::channel(100);
drop(priofees_update_receiver);
let (priofees_update_sender, _priofees_update_receiver) = tokio::sync::broadcast::channel(100);
let senderfoooo = priofees_update_sender.clone();

let jh_priofees_task = tokio::spawn(async move {
let sender = priofees_update_sender.clone();
'recv_loop: loop {
let block = block_stream.recv().await;
match block {
Expand All @@ -80,7 +84,15 @@ pub async fn start_priofees_task(data_cache: DataCache, mut block_stream: BlockS
slot,
fees_info: prioritization_fees_info,
};
priofees_update_sender.send(msg).unwrap();
let send_result = sender.send(msg);

Check warning on line 87 in lite-rpc/src/block_priofees.rs

View workflow job for this annotation

GitHub Actions / lite-rpc full build

Diff in /home/runner/work/lite-rpc/lite-rpc/lite-rpc/src/block_priofees.rs
match send_result {
Ok(n_subscribers) => {
trace!("sent priofees update message to {} subscribers", n_subscribers);
}
Err(_) => {
trace!("no subscribers for priofees update message");
}
}
}
Err(Lagged(_lagged)) => {
warn!("channel error receiving block for priofees calculation - continue");
Expand All @@ -99,7 +111,7 @@ pub async fn start_priofees_task(data_cache: DataCache, mut block_stream: BlockS
jh_priofees_task,
PrioFeesService {
block_fees_store: store,
block_fees_stream: priofees_update_receiver,
block_fees_stream: senderfoooo,
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion lite-rpc/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl LiteRpcServer for LiteBridge {
) -> SubscriptionResult {
let sink = pending.accept().await?;

let mut block_fees_stream = self.prio_fees_service.block_fees_stream.resubscribe();
let mut block_fees_stream = self.prio_fees_service.block_fees_stream.subscribe();
tokio::spawn(async move {
RPC_BLOCK_PRIOFEES_SUBSCRIBE.inc();
while let Ok(PrioFeesUpdateMessage { slot: confirmation_slot, fees_info}) = block_fees_stream.recv().await {
Expand Down

0 comments on commit c80ed8c

Please sign in to comment.