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

Even more metrics #595

Merged
merged 7 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 0 additions & 2 deletions rust/abacus-base/src/contract_sync/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ where
let indexed_height = self
.metrics
.indexed_height
.clone()
.with_label_values(&[GAS_PAYMENTS_LABEL, &self.chain_name]);

let stored_messages = self
.metrics
.stored_events
.clone()
.with_label_values(&[GAS_PAYMENTS_LABEL, &self.chain_name]);

let config_from = self.index_settings.from();
Expand Down
41 changes: 19 additions & 22 deletions rust/abacus-base/src/contract_sync/outbox.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use abacus_core::{ListValidity, OutboxIndexer};
use std::cmp::min;
use std::time::Duration;

use tokio::time::sleep;
use tracing::{info, info_span, warn};
use tracing::{instrument::Instrumented, Instrument};

use std::cmp::min;
use std::time::Duration;
use abacus_core::{chain_from_domain, CommittedMessage, ListValidity, OutboxIndexer};

use crate::{
contract_sync::{last_message::OptLatestLeafIndex, schema::OutboxContractSyncDB},
Expand All @@ -27,26 +27,20 @@ where
let indexed_height = self
.metrics
.indexed_height
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.chain_name]);

let stored_messages = self
.metrics
.stored_events
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.chain_name]);

let missed_messages = self
.metrics
.missed_events
.clone()
.with_label_values(&[MESSAGES_LABEL, &self.chain_name]);

let message_leaf_index = self.metrics.message_leaf_index.clone().with_label_values(&[
"dispatch",
&self.chain_name,
"unknown",
]);
let message_leaf_index = self.metrics.message_leaf_index.clone();
let chain_name = self.chain_name.clone();

let config_from = self.index_settings.from();
let chunk_size = self.index_settings.chunk_size();
Expand All @@ -63,11 +57,6 @@ where

info!(from = from, "[Messages]: resuming indexer from {from}");

// Set the metrics with the latest known leaf index
if let Ok(Some(idx)) = db.retrieve_latest_leaf_index() {
message_leaf_index.set(idx as i64);
}

loop {
indexed_height.set(from as i64);

Expand Down Expand Up @@ -128,8 +117,16 @@ where
// Report amount of messages stored into db
stored_messages.add(sorted_messages.len().try_into()?);

// Report latest leaf index to gauge
message_leaf_index.set(max_leaf_index_of_batch as i64);
// Report latest leaf index to gauge by dst
for raw_msg in sorted_messages.iter() {
let dst = CommittedMessage::try_from(raw_msg)
.ok()
.and_then(|msg| chain_from_domain(msg.message.destination))
.unwrap_or("unknown");
message_leaf_index
.with_label_values(&["dispatch", &chain_name, dst])
.set(max_leaf_index_of_batch as i64);
}

// Move forward next height
db.store_message_latest_block_end(to)?;
Expand Down Expand Up @@ -166,20 +163,20 @@ where

#[cfg(test)]
mod test {
use abacus_test::mocks::indexer::MockAbacusIndexer;
use mockall::*;

use std::sync::Arc;

use ethers::core::types::H256;
use mockall::*;

use abacus_core::{db::AbacusDB, AbacusMessage, Encode, RawCommittedMessage};
use abacus_test::mocks::indexer::MockAbacusIndexer;
use abacus_test::test_utils;

use super::*;
use crate::ContractSync;
use crate::{settings::IndexSettings, ContractSyncMetrics, CoreMetrics};

use super::*;

#[tokio::test]
async fn handles_missing_rpc_messages() {
test_utils::run_test_db(|db| async move {
Expand Down
42 changes: 42 additions & 0 deletions rust/abacus-core/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,45 @@ impl From<&'_ Address> for ethers::types::H160 {
ethers::types::H160::from_slice(addr.0.as_ref())
}
}

/// Quick single-use macro to prevent typing domain and chain twice and risking inconsistencies.
macro_rules! domain_and_chain {
{$($domain:literal <=> $chain:literal,)*} => {
/// Get the chain name from a domain id. Returns `None` if the `domain` is unknown.
pub fn chain_from_domain(domain: u32) -> Option<&'static str> {
match domain {
$( $domain => Some($chain), )*
_ => None
}
}

/// Get the domain id from a chain name. Expects `chain` to be a lowercase str.
/// Returns `None` if the `chain` is unknown.
pub fn domain_from_chain(chain: &str) -> Option<u32> {
match chain {
$( $chain => Some($domain), )*
_ => None
}
}
}
}

// Copied from https://github.com/abacus-network/abacus-monorepo/blob/54a41d5a4bbb86a3b08d02d7ff6662478c41e221/typescript/sdk/src/chain-metadata.ts
domain_and_chain! {
0x63656c6f <=> "celo",
0x657468 <=> "ethereum",
0x61766178 <=> "avalanche",
0x706f6c79 <=> "polygon",
1000 <=> "alfajores",
43113 <=> "fuji",
5 <=> "goerli",
3000 <=> "kovan",
80001 <=> "mumbai",
13371 <=> "test1",
13372 <=> "test2",
13373 <=> "test3",
0x62732d74 <=> "bsctestnet",
0x61722d72 <=> "arbitrumrinkeby",
0x6f702d6b <=> "optimismkovan",
0x61752d74 <=> "auroratestnet",
}
2 changes: 1 addition & 1 deletion rust/abacus-core/src/db/abacus_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl AbacusDB {
for message in messages {
self.store_latest_message(message)?;

let committed_message: CommittedMessage = message.clone().try_into()?;
let committed_message: CommittedMessage = message.try_into()?;
info!(
leaf_index = &committed_message.leaf_index,
origin = &committed_message.message.origin,
Expand Down
10 changes: 9 additions & 1 deletion rust/abacus-core/src/traits/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ impl TryFrom<RawCommittedMessage> for CommittedMessage {
type Error = AbacusError;

fn try_from(raw: RawCommittedMessage) -> Result<Self, Self::Error> {
(&raw).try_into()
}
}

impl TryFrom<&RawCommittedMessage> for CommittedMessage {
type Error = AbacusError;

fn try_from(raw: &RawCommittedMessage) -> Result<Self, Self::Error> {
Ok(Self {
leaf_index: raw.leaf_index,
message: AbacusMessage::read_from(&mut &raw.message[..])?,
message: AbacusMessage::read_from(&mut raw.message.as_slice())?,
})
}
}