Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix substrate rpc reconnection issue #584

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/development/evm-blanknet/athena.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enabled = true
# - SignatureBridge
contract = "VAnchor"
# The address of the contract
address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
# The deployed block number of the contract. When a relayer does not have information for
# this contract in its store, it will start to sync and query for relevant historical data
# starting at this block number
Expand All @@ -54,8 +54,8 @@ events-watcher = { enabled = true, polling-interval = 1000, print-progress-inter
# Entries for this anchor contract's connected edges.
# These fields are used to determine the generation of AnchorUpdate proposals
linked-anchors = [
{ type = "Evm", chain = "hermes", chain-id = 5001, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "demeter", chain-id = 5003, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "hermes", chain-id = 5001, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
{ type = "Evm", chain = "demeter", chain-id = 5003, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
]

# Proposal signing backend can have a value of "Mocked" or the name of the DKG configuration.
Expand All @@ -66,6 +66,6 @@ proposal-signing-backend = { type = "Mocked", private-key = "$GOVERNOR_PRIVATE_K

[[evm.athena.contracts]]
contract = "SignatureBridge"
address = "0xf2e246bb76df876cef8b38ae84130f4f55de395b"
address = "0x2946259E0334f33A064106302415aD3391BeD384"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 1000, print-progress-interval = 60000 }
8 changes: 4 additions & 4 deletions config/development/evm-blanknet/demeter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enabled = true
# - SignatureBridge
contract = "VAnchor"
# The address of the contract
address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
# The deployed block number of the contract. When a relayer does not have information for
# this contract in its store, it will start to sync and query for relevant historical data
# starting at this block number
Expand All @@ -53,8 +53,8 @@ events-watcher = { enabled = true, polling-interval = 10000, print-progress-inte
# Entries for this anchor contract's connected edges.
# These fields are used to determine the generation of AnchorUpdate proposals
linked-anchors = [
{ type = "Evm", chain = "hermes", chain-id = 5001, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "athena", chain-id = 5002, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "hermes", chain-id = 5001, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
{ type = "Evm", chain = "athena", chain-id = 5002, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
]
# Proposal signing backend can have a value of "Mocked" or the name of the DKG configuration.
# When the type is "Mocked", the supplied private-key will sign any proposed updates and submit
Expand All @@ -64,6 +64,6 @@ proposal-signing-backend = { type = "Mocked", private-key = "$GOVERNOR_PRIVATE_K

[[evm.demeter.contracts]]
contract = "SignatureBridge"
address = "0xf2e246bb76df876cef8b38ae84130f4f55de395b"
address = "0x2946259E0334f33A064106302415aD3391BeD384"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 10000, print-progress-interval = 0 }
8 changes: 4 additions & 4 deletions config/development/evm-blanknet/hermes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enabled = true
# - SignatureBridge
contract = "VAnchor"
# The address of the contract
address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
# The deployed block number of the contract. When a relayer does not have information for
# this contract in its store, it will start to sync and query for relevant historical data
# starting at this block number
Expand All @@ -53,8 +53,8 @@ events-watcher = { enabled = true, polling-interval = 1000, print-progress-inter
# Entries for this anchor contract's connected edges.
# These fields are used to determine the generation of AnchorUpdate proposals
linked-anchors = [
{ type = "Evm", chain = "athena", chain-id = 5002, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "demeter", chain-id = 5003, address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e" },
{ type = "Evm", chain = "athena", chain-id = 5002, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
{ type = "Evm", chain = "demeter", chain-id = 5003, address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3" },
]
# Proposal signing backend can have a value of "Mocked" or the name of the DKG configuration.
# When the type is "Mocked", the supplied private-key will sign any proposed updates and submit
Expand All @@ -64,6 +64,6 @@ proposal-signing-backend = { type = "Mocked", private-key = "$GOVERNOR_PRIVATE_K

[[evm.hermes.contracts]]
contract = "SignatureBridge"
address = "0xf2e246bb76df876cef8b38ae84130f4f55de395b"
address = "0x2946259E0334f33A064106302415aD3391BeD384"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 1000, print-progress-interval = 60000 }
8 changes: 4 additions & 4 deletions config/development/evm-local-tangle/athena.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contracts": [
{
"contract": "VAnchor",
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e",
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand All @@ -30,13 +30,13 @@
"type": "Evm",
"chain": "hermes",
"chain-id": 5001,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
},
{
"type": "Evm",
"chain": "demeter",
"chain-id": 5003,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
}
],
"proposal-signing-backend": {
Expand All @@ -46,7 +46,7 @@
},
{
"contract": "SignatureBridge",
"address": "0xf2e246bb76df876cef8b38ae84130f4f55de395b",
"address": "0x2946259E0334f33A064106302415aD3391BeD384",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand Down
8 changes: 4 additions & 4 deletions config/development/evm-local-tangle/demeter.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contracts": [
{
"contract": "VAnchor",
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e",
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand All @@ -30,13 +30,13 @@
"type": "Evm",
"chain": "hermes",
"chain-id": 5001,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
},
{
"type": "Evm",
"chain": "athena",
"chain-id": 5002,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
}
],
"proposal-signing-backend": {
Expand All @@ -46,7 +46,7 @@
},
{
"contract": "SignatureBridge",
"address": "0xf2e246bb76df876cef8b38ae84130f4f55de395b",
"address": "0x2946259E0334f33A064106302415aD3391BeD384",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand Down
8 changes: 4 additions & 4 deletions config/development/evm-local-tangle/hermes.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contracts": [
{
"contract": "VAnchor",
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e",
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand All @@ -30,13 +30,13 @@
"type": "Evm",
"chain": "athena",
"chain-id": 5002,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
},
{
"type": "Evm",
"chain": "demeter",
"chain-id": 5003,
"address": "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
"address": "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
}
],
"proposal-signing-backend": {
Expand All @@ -46,7 +46,7 @@
},
{
"contract": "SignatureBridge",
"address": "0xf2e246bb76df876cef8b38ae84130f4f55de395b",
"address": "0x2946259E0334f33A064106302415aD3391BeD384",
"deployed-at": 1,
"events-watcher": {
"enabled": true,
Expand Down
31 changes: 31 additions & 0 deletions config/development/local-evm/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@
"price": 10
}
},
"substrate": {
"tangle": {
"name": "tangle",
"enabled": false,
"http-endpoint": "$TANGLE_HTTP_URL",
"ws-endpoint": "$TANGLE_WSS_URL",
"runtime": "DKG",
"suri": "$TANGLE_WEBB_RELAYER_SURI",
"chain-id": "1080",
"pallets": [
{
"pallet": "DKG",
"events-watcher": {
"enabled": false,
"polling-interval": 12000,
"print-progress-interval": 60000,
"sync-blocks-from": 59500
}
},
{
"pallet": "DKGProposalHandler",
"events-watcher": {
"enabled": false,
"polling-interval": 12000,
"print-progress-interval": 60000,
"sync-blocks-from": 59500
}
}
]
}
},
"evm": {
"athena": {
"name": "athena",
Expand Down
32 changes: 25 additions & 7 deletions crates/relayer-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct RelayerContext {
/// Evm Providers Cache.
evm_providers: Arc<HashMap<types::U256, Arc<EthersClient>>>,
/// Substrate providers cache.
substrate_providers: Arc<HashMap<types::U256, Arc<WebbRpcClient>>>,
substrate_providers: Arc<Mutex<HashMap<types::U256, Arc<WebbRpcClient>>>>,
}

impl RelayerContext {
Expand Down Expand Up @@ -161,6 +161,7 @@ impl RelayerContext {
Arc::new(webb_rpc_client),
);
}
let substrate_providers = Arc::new(Mutex::new(substrate_providers));

Ok(Self {
config,
Expand All @@ -170,7 +171,7 @@ impl RelayerContext {
price_oracle,
etherscan_clients: Arc::new(etherscan_clients),
evm_providers: Arc::new(evm_providers),
substrate_providers: substrate_providers.into(),
substrate_providers,
})
}
/// Returns a broadcast receiver handle for the shutdown signal.
Expand Down Expand Up @@ -239,11 +240,28 @@ impl RelayerContext {
chain_id: I,
) -> webb_relayer_utils::Result<subxt::OnlineClient<C>> {
let chain_id: types::U256 = chain_id.into();
if let Some(webb_rpc_client) = self.substrate_providers.get(&chain_id) {
let substrate_client = subxt::OnlineClient::<C>::from_rpc_client(
webb_rpc_client.clone(),
)
.await?;
let chain_name = chain_id.to_string();
let node_config =
self.config.substrate.get(&chain_name).ok_or_else(|| {
webb_relayer_utils::Error::NodeNotFound {
chain_id: chain_id.to_string(),
}
})?;
let mut substrate_providers = self.substrate_providers.lock().await;
if let Some(webb_rpc_client) = substrate_providers.get(&chain_id) {
// check if rpc is connected if not create a new connection and cache it
let substrate_client = if webb_rpc_client.0.is_connected() {
subxt::OnlineClient::<C>::from_rpc_client(
webb_rpc_client.clone(),
)
.await?
} else {
let url = node_config.ws_endpoint.to_string();
let webb_rpc_client = Arc::new(WebbRpcClient::new(url).await?);
substrate_providers.insert(chain_id, webb_rpc_client.clone());
subxt::OnlineClient::<C>::from_rpc_client(webb_rpc_client)
.await?
};
Ok(substrate_client)
} else {
let chain_id_string = chain_id.clone().to_string();
Expand Down
Loading