Merge pull request #250 from blockworks-foundation/fixing_network_issues

Resubscribing grpc block subsciption on failure, get vote accounts ev…
This commit is contained in:
galactus 2023-12-01 11:22:45 +01:00 committed by GitHub
commit 8760021e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 104 deletions

View File

@ -253,6 +253,8 @@ pub fn create_block_processing_task(
block_sx: Sender<ProducedBlock>,
commitment_level: CommitmentLevel,
) -> AnyhowJoinHandle {
tokio::spawn(async move {
loop {
let mut blocks_subs = HashMap::new();
blocks_subs.insert(
"client".to_string(),
@ -270,9 +272,9 @@ pub fn create_block_processing_task(
CommitmentLevel::Processed => CommitmentConfig::processed(),
};
tokio::spawn(async move {
// connect to grpc
let mut client = GeyserGrpcClient::connect(grpc_addr, grpc_x_token, None)?;
let mut client =
GeyserGrpcClient::connect(grpc_addr.clone(), grpc_x_token.clone(), None)?;
let mut stream = client
.subscribe_once(
HashMap::new(),
@ -304,12 +306,14 @@ pub fn create_block_processing_task(
UpdateOneof::Ping(_) => {
log::trace!("GRPC Ping");
}
u => {
bail!("Unexpected update: {u:?}");
_ => {
log::trace!("unknown GRPC notification");
}
};
}
bail!("geyser slot stream ended");
log::error!("Grpc block subscription broken (resubscribing)");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
})
}
@ -324,6 +328,11 @@ pub fn create_grpc_subscription(
let (cluster_info_sx, cluster_info_notifier) = tokio::sync::broadcast::channel(10);
let (va_sx, vote_account_notifier) = tokio::sync::broadcast::channel(10);
let slot_task: AnyhowJoinHandle = {
let grpc_x_token = grpc_x_token.clone();
let grpc_addr = grpc_addr.clone();
tokio::spawn(async move {
loop {
let mut slots = HashMap::new();
slots.insert(
"client".to_string(),
@ -331,13 +340,9 @@ pub fn create_grpc_subscription(
filter_by_commitment: Some(true),
},
);
let slot_task: AnyhowJoinHandle = {
let grpc_x_token = grpc_x_token.clone();
let grpc_addr = grpc_addr.clone();
tokio::spawn(async move {
// connect to grpc
let mut client = GeyserGrpcClient::connect(grpc_addr, grpc_x_token.clone(), None)?;
let mut client =
GeyserGrpcClient::connect(grpc_addr.clone(), grpc_x_token.clone(), None)?;
let version = client.get_version().await?.version;
if version != expected_grpc_version {
@ -385,7 +390,9 @@ pub fn create_grpc_subscription(
}
};
}
bail!("geyser slot stream ended");
log::error!("Grpc slot subscription broken (resubscribing)");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
})
};

View File

@ -22,7 +22,7 @@ pub fn poll_vote_accounts_and_cluster_info(
.send(vote_accounts)
.context("Should be able to send vote accounts")?;
}
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_secs(600)).await;
}
})
}