hotfix: make sub ids unique in eth provider

This commit is contained in:
dr-frmr 2024-01-25 22:51:59 -03:00
parent 23ed84de4a
commit 7d01dcfcae
No known key found for this signature in database
2 changed files with 4 additions and 1 deletions

View File

@ -118,6 +118,7 @@ async fn handle_request(
) -> Result<(), EthError> { ) -> Result<(), EthError> {
match action { match action {
EthAction::SubscribeLogs { sub_id, filter } => { EthAction::SubscribeLogs { sub_id, filter } => {
let sub_id = (target.process.clone(), sub_id);
if connections.ws_provider_subscriptions.contains_key(&sub_id) { if connections.ws_provider_subscriptions.contains_key(&sub_id) {
return Err(EthError::SubscriptionIdCollision); return Err(EthError::SubscriptionIdCollision);
} }
@ -133,6 +134,7 @@ async fn handle_request(
Ok(()) Ok(())
} }
EthAction::UnsubscribeLogs(sub_id) => { EthAction::UnsubscribeLogs(sub_id) => {
let sub_id = (target.process.clone(), sub_id);
let handle = connections let handle = connections
.ws_provider_subscriptions .ws_provider_subscriptions
.remove(&sub_id) .remove(&sub_id)

View File

@ -1,3 +1,4 @@
use crate::types::ProcessId;
use ethers::prelude::Provider; use ethers::prelude::Provider;
use ethers::types::{Filter, Log}; use ethers::types::{Filter, Log};
use ethers_providers::Ws; use ethers_providers::Ws;
@ -48,5 +49,5 @@ pub enum EthSubEvent {
/// Primary state object of the `eth` module /// Primary state object of the `eth` module
pub struct RpcConnections { pub struct RpcConnections {
pub provider: Provider<Ws>, pub provider: Provider<Ws>,
pub ws_provider_subscriptions: HashMap<u64, JoinHandle<Result<(), EthError>>>, pub ws_provider_subscriptions: HashMap<(ProcessId, u64), JoinHandle<Result<(), EthError>>>,
} }