Skip to content

Commit

Permalink
[GASP-1099] Prometheus metrics for gasp-node (#421)
Browse files Browse the repository at this point in the history
[GASP-1099] Provide metrics per chain
  • Loading branch information
mateuszaaa authored Jan 27, 2025
1 parent 3431e2e commit 680a369
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gasp-node/pallets/rolldown/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<C, Block, L1Update, Chain> RolldownApiServer<<Block as BlockT>::Hash, L1Upd
where
Block: BlockT,
L1Update: Decode,
Chain: Encode,
Chain: Encode + Decode,
C: Send + Sync + 'static,
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block>,
Expand Down
3 changes: 2 additions & 1 deletion gasp-node/pallets/rolldown/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use sp_std::vec::Vec;
sp_api::decl_runtime_apis! {
pub trait RolldownRuntimeApi<L1Update, Chain> where
L1Update: Decode,
Chain: Encode
Chain: Encode + Decode,
{
fn get_all_chains() -> Vec<Chain>;
fn get_abi_encoded_l2_request(chain: Chain, requestId: u128) -> Vec<u8>;
fn get_native_sequencer_update(hex_payload: Vec<u8>) -> Option<L1Update>;
fn verify_sequencer_update(chain: Chain, hash: H256, request_id: u128) -> Option<bool>;
Expand Down
6 changes: 6 additions & 0 deletions gasp-node/pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,12 @@ impl<T: Config> Pallet<T> {

Ok(().into())
}

pub fn get_all_chains() -> Vec<ChainIdOf<T>> {
let keys1: BTreeSet<_> = LastProcessedRequestOnL2::<T>::iter_keys().collect();
let keys2: BTreeSet<_> = L2OriginRequestId::<T>::get().keys().cloned().collect();
keys1.union(&keys2).cloned().collect()
}
}

impl<T: Config> RolldownProviderTrait<ChainIdOf<T>, AccountIdOf<T>> for Pallet<T> {
Expand Down
12 changes: 12 additions & 0 deletions gasp-node/pallets/rolldown/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pub mod eth_abi;

use core::fmt::Display;

use self::eth_abi::to_eth_u256;
use crate::L2Request;
use alloy_sol_types::SolValue;
Expand Down Expand Up @@ -105,6 +107,16 @@ pub enum Chain {
Base,
}

impl AsRef<str> for Chain {
fn as_ref(&self) -> &'static str {
match self {
Chain::Ethereum => "Ethereum",
Chain::Arbitrum => "Arbitrum",
Chain::Base => "Base",
}
}
}

#[repr(u8)]
#[derive(
Default, Eq, PartialEq, RuntimeDebug, Clone, Encode, Decode, TypeInfo, Serialize, Copy,
Expand Down
44 changes: 26 additions & 18 deletions gasp-node/rollup/node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ where

fn collect(&self, mut set: impl FnMut(&[&str], Self::N)) {
let at = self.0.info().best_hash;
set(
&["Ethereum"],
self.0
.runtime_api()
.get_last_processed_request_on_l2(at, pallet_rolldown::messages::Chain::Ethereum)
.unwrap_or(None)
.unwrap_or_default()
.saturated_into::<u64>(),
);
let chains = self.0.runtime_api().get_all_chains(at).unwrap_or_default();

for c in chains {
set(
&[c.as_ref()],
self.0
.runtime_api()
.get_last_processed_request_on_l2(at, c)
.unwrap_or(None)
.unwrap_or_default()
.saturated_into::<u64>(),
);
}
}
}

Expand Down Expand Up @@ -151,15 +155,19 @@ where

fn collect(&self, mut set: impl FnMut(&[&str], Self::N)) {
let at = self.0.info().best_hash;
set(
&["Ethereum"],
self.0
.runtime_api()
.get_number_of_pending_requests(at, pallet_rolldown::messages::Chain::Ethereum)
.unwrap_or(None)
.unwrap_or_default()
.saturated_into::<u64>(),
);
let chains = self.0.runtime_api().get_all_chains(at).unwrap_or_default();

for c in chains {
set(
&[c.as_ref()],
self.0
.runtime_api()
.get_number_of_pending_requests(at, c)
.unwrap_or(None)
.unwrap_or_default()
.saturated_into::<u64>(),
);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions gasp-node/rollup/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@ impl_runtime_apis! {
) -> Vec<u8>{
Rolldown::get_abi_encoded_l2_request(chain, request_id)
}

fn get_all_chains() -> Vec<pallet_rolldown::messages::Chain>{
Rolldown::get_all_chains()
}
}

impl proof_of_stake_runtime_api::ProofOfStakeApi<Block, Balance , TokenId, AccountId> for Runtime{
Expand Down

0 comments on commit 680a369

Please sign in to comment.