Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fvs-pla-626-use-traci…
Browse files Browse the repository at this point in the history
…ng-instead-of-vlog-macros
  • Loading branch information
montekki committed Oct 16, 2023
2 parents a5aadb3 + 768fdf3 commit a0a5955
Show file tree
Hide file tree
Showing 26 changed files with 435 additions and 154 deletions.
2 changes: 2 additions & 0 deletions .github/spellcheck/finalizer.dic
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ RPC
tx
txs
unfinalizable
meterer
Timedout
100 changes: 93 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ members = [

[workspace.dependencies]
tracing = "0.1"
vise = { git = "https://github.com/matter-labs/vise.git" }
2 changes: 1 addition & 1 deletion chain-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ edition = "2021"
client = { path = "../client" }
ethers = { version = "2.0.10", features = ["ws"] }
futures = "0.3.28"
metrics = "0.21.1"
thiserror = "1.0.49"
tokio = { version = "1.33.0", features = ["time"] }
tracing = { workspace = true }
vise = { workspace = true }

ethers-log-decode = { path = "../ethers-log-decode" }
16 changes: 6 additions & 10 deletions chain-events/src/block_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use client::{
};
use ethers_log_decode::EthLogDecode;

use crate::{Error, Result, RECONNECT_BACKOFF};
use crate::{metrics::CHAIN_EVENTS_METRICS, Error, Result, RECONNECT_BACKOFF};

// Total timecap for tx querying retry 10 minutes
const PENDING_TX_RETRY: usize = 12 * 10;
Expand Down Expand Up @@ -59,16 +59,12 @@ impl BlockEvents {
async fn connect(&self) -> Option<Provider<Ws>> {
match Provider::<Ws>::connect_with_reconnects(&self.url, 0).await {
Ok(p) => {
metrics::increment_counter!(
"watcher.chain_events.block_events.successful_reconnects"
);
CHAIN_EVENTS_METRICS.successful_l1_reconnects.inc();
Some(p)
}
Err(e) => {
tracing::warn!("Block events stream reconnect attempt failed: {e}");
metrics::increment_counter!(
"watcher.chain_events.block_events.reconnects_on_error"
);
CHAIN_EVENTS_METRICS.l1_reconnects_on_error.inc();
None
}
}
Expand Down Expand Up @@ -303,7 +299,7 @@ where
.await
.map_err(|_| Error::ChannelClosing)?;

metrics::increment_counter!("watcher.chain_events.block_commit_events");
CHAIN_EVENTS_METRICS.block_commit_events.inc();
sender
.send(BlockEvent::BlockCommit {
block_number,
Expand All @@ -313,7 +309,7 @@ where
.map_err(|_| Error::ChannelClosing)?;
}
L1Events::BlocksVerification(event) => {
metrics::increment_counter!("watcher.chain_events.block_verification_events");
CHAIN_EVENTS_METRICS.block_verification_events.inc();
sender
.send(BlockEvent::BlocksVerification {
block_number,
Expand All @@ -328,7 +324,7 @@ where
log.transaction_hash
);

metrics::increment_counter!("watcher.chain_events.block_execution_events");
CHAIN_EVENTS_METRICS.block_execution_events.inc();
sender
.send(BlockEvent::BlockExecution {
block_number,
Expand Down
28 changes: 11 additions & 17 deletions chain-events/src/l2_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use ethers::{
types::{BlockNumber, Filter, Log},
};

use crate::{rpc_query_too_large, Error, L2Event, L2TokenInitEvent, Result, RECONNECT_BACKOFF};
use crate::{
metrics::CHAIN_EVENTS_METRICS, rpc_query_too_large, Error, L2Event, L2TokenInitEvent, Result,
RECONNECT_BACKOFF,
};
use ethers_log_decode::EthLogDecode;

struct NewTokenAdded;
Expand Down Expand Up @@ -71,16 +74,12 @@ impl L2EventsListener {
async fn connect(&self) -> Option<Provider<Ws>> {
match Provider::<Ws>::connect_with_reconnects(&self.url, 0).await {
Ok(p) => {
metrics::increment_counter!(
"watcher.chain_events.withdrawal_events.successful_reconnects"
);
CHAIN_EVENTS_METRICS.successful_l2_reconnects.inc();
Some(p)
}
Err(e) => {
tracing::warn!("Withdrawal events stream reconnect attempt failed: {e}");
metrics::increment_counter!(
"watcher.chain_events.withdrawal_events.reconnects_on_error"
);
CHAIN_EVENTS_METRICS.reconnects_on_error.inc();
None
}
}
Expand Down Expand Up @@ -236,10 +235,7 @@ impl L2EventsListener {
};

let middleware = Arc::new(provider_l1);
metrics::gauge!(
"watcher.chain_events.l2_events.query_pagination",
pagination as f64
);
CHAIN_EVENTS_METRICS.query_pagination.set(pagination as i64);

match self
.run(
Expand Down Expand Up @@ -396,7 +392,7 @@ impl L2EventsListener {
Ok(log) => log,
};
let raw_log: RawLog = log.clone().into();
metrics::increment_counter!("watcher.chain_events.l2_logs_received");
CHAIN_EVENTS_METRICS.l2_logs_received.inc();
successful_logs += 1;

if should_attempt_pagination_increase(pagination_step, successful_logs) {
Expand All @@ -413,7 +409,7 @@ impl L2EventsListener {
continue;
};
}
metrics::increment_counter!("watcher.chain_events.l2_logs_decoded");
CHAIN_EVENTS_METRICS.l2_logs_decoded.inc();

match self
.process_l2_event(&log, &l2_event, &mut sender, &middleware)
Expand Down Expand Up @@ -453,7 +449,7 @@ impl L2EventsListener {
match l2_event {
L2Events::BridgeBurn(BridgeBurnFilter { amount, .. })
| L2Events::Withdrawal(WithdrawalFilter { amount, .. }) => {
metrics::increment_counter!("watcher.chain_events.withdrawal_events");
CHAIN_EVENTS_METRICS.withdrawal_events.inc();

let we = WithdrawalEvent {
tx_hash,
Expand Down Expand Up @@ -487,9 +483,7 @@ impl L2EventsListener {
self.bridge_initialize_event(bridge_init_log)?
{
if self.tokens.insert(address) {
metrics::increment_counter!(
"watcher.chain_events.new_token_added_events"
);
CHAIN_EVENTS_METRICS.new_token_added.inc();

let event = l2_event.into();
tracing::info!("sending new token event {event:?}");
Expand Down
1 change: 1 addition & 0 deletions chain-events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
mod block_events;
mod error;
mod l2_events;
mod metrics;

use std::time::Duration;

Expand Down
Loading

0 comments on commit a0a5955

Please sign in to comment.