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

feat(stats): Active bundlers/paymasters charts #1193

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions stats/config/charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
"title": "Number of user operations",
"description": "Cumulative user operation (ERC-4337) growth over time"
},
"active_bundlers": {
"title": "Active bundlers",
"description": "Active user ops bundlers number per period"
},
"active_paymasters": {
"title": "Active paymasters",
"description": "Active user ops paymasters number per period"
},
"new_block_rewards": {
"enabled": false,
"title": "New block rewards",
Expand Down
4 changes: 3 additions & 1 deletion stats/config/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
"title": "User operations",
"charts_order": [
"user_ops_growth",
"new_user_ops"
"new_user_ops",
"active_bundlers",
"active_paymasters"
]
}
]
Expand Down
2 changes: 2 additions & 0 deletions stats/config/update_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"new_contracts_group": "0 20 */3 * * * *",
"new_txns_group": "0 10 */3 * * * *",
"new_user_ops_group": "0 5 7 * * * *",
"active_bundlers_group": "0 7 7 * * * *",
"active_paymasters_group": "0 8 7 * * * *",
"new_verified_contracts_group": "0 30 */3 * * * *",
"native_coin_holders_growth_group": "0 0 7,17,22 * * * *",
"new_native_coin_transfers_group": "0 0 3,13 * * * *",
Expand Down
2 changes: 2 additions & 0 deletions stats/stats-server/src/runtime_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ impl RuntimeSetup {
vec![
// actual singletons
Arc::new(ActiveAccountsGroup),
Arc::new(ActiveBundlersGroup),
Arc::new(ActivePaymastersGroup),
Arc::new(AverageBlockTimeGroup),
Arc::new(CompletedTxnsGroup),
Arc::new(PendingTxns30mGroup),
Expand Down
2 changes: 2 additions & 0 deletions stats/stats-server/tests/it/chart_endpoints/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub async fn test_lines_ok(base: Url) {
"txnsSuccessRate",
"newUserOps",
"userOpsGrowth",
"activeBundlers",
"activePaymasters",
"newVerifiedContracts",
"newContracts",
"verifiedContractsGrowth",
Expand Down
4 changes: 4 additions & 0 deletions stats/stats/src/charts/lines/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod accounts_growth;
pub mod active_accounts;
pub mod active_recurring_accounts;
pub mod new_accounts;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
types::BlockscoutMigrations,
},
define_and_impl_resolution_properties,
lines::{NewBlockRewardsInt, NewBlockRewardsMonthlyInt},
types::timespans::{Month, Week, Year},
utils::sql_with_range_filter_opt,
ChartProperties, Named,
Expand All @@ -28,8 +29,6 @@ use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use sea_orm::{DbBackend, Statement};

use super::{NewBlockRewardsInt, NewBlockRewardsMonthlyInt};

const ETH: i64 = 1_000_000_000_000_000_000;

pub struct AverageBlockRewardsQuery;
Expand Down
4 changes: 4 additions & 0 deletions stats/stats/src/charts/lines/blocks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod average_block_rewards;
pub mod average_block_size;
pub mod new_block_rewards;
pub mod new_blocks;
4 changes: 4 additions & 0 deletions stats/stats/src/charts/lines/contracts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod contracts_growth;
pub mod new_contracts;
pub mod new_verified_contracts;
pub mod verified_contracts_growth;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
types::BlockscoutMigrations,
},
define_and_impl_resolution_properties,
lines::new_blocks::{NewBlocksInt, NewBlocksMonthlyInt},
types::timespans::{Month, Week, Year},
utils::sql_with_range_filter_opt,
ChartProperties, Named,
Expand All @@ -28,8 +29,6 @@ use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use sea_orm::{DbBackend, Statement};

use super::new_blocks::{NewBlocksInt, NewBlocksMonthlyInt};

pub struct AverageGasLimitStatement;

impl StatementFromRange for AverageGasLimitStatement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
types::BlockscoutMigrations,
},
define_and_impl_resolution_properties,
lines::{new_txns::NewTxnsMonthlyInt, NewTxnsInt},
types::timespans::{Month, Week, Year},
utils::{produce_filter_and_values, sql_with_range_filter_opt},
ChartProperties, Named,
Expand All @@ -28,8 +29,6 @@ use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use sea_orm::{DbBackend, Statement};

use super::new_txns::{NewTxnsInt, NewTxnsMonthlyInt};

const GWEI: i64 = 1_000_000_000;

pub struct AverageGasPriceStatement;
Expand Down
3 changes: 3 additions & 0 deletions stats/stats/src/charts/lines/gas/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod average_gas_limit;
pub mod average_gas_price;
pub mod gas_used_growth;
46 changes: 17 additions & 29 deletions stats/stats/src/charts/lines/mod.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
mod accounts_growth;
mod active_accounts;
mod active_recurring_accounts;
mod average_block_rewards;
mod average_block_size;
mod average_gas_limit;
mod average_gas_price;
mod average_txn_fee;
mod contracts_growth;
mod gas_used_growth;
mod native_coin_holders_growth;
mod native_coin_supply;
mod new_accounts;
mod new_block_rewards;
mod new_blocks;
mod new_contracts;
mod new_native_coin_holders;
mod new_native_coin_transfers;
mod new_operational_txns;
mod new_txns;
mod new_txns_window;
mod new_user_ops;
mod new_verified_contracts;
mod operational_txns_growth;
mod txns_fee;
mod txns_growth;
mod txns_success_rate;
mod user_ops_growth;
mod verified_contracts_growth;
mod accounts;
mod blocks;
mod contracts;
mod gas;
mod tokens;
mod transactions;
mod user_ops;

use accounts::*;
use blocks::*;
use contracts::*;
use gas::*;
use tokens::*;
use transactions::*;
use user_ops::*;

#[cfg(test)]
mod mock;
Expand All @@ -37,6 +23,8 @@ pub use accounts_growth::{
AccountsGrowth, AccountsGrowthMonthly, AccountsGrowthWeekly, AccountsGrowthYearly,
};
pub use active_accounts::ActiveAccounts;
pub use active_bundlers::ActiveBundlers;
pub use active_paymasters::ActivePaymasters;
#[rustfmt::skip]
pub use active_recurring_accounts::{
ActiveRecurringAccountsDailyRecurrence120Days, ActiveRecurringAccountsMonthlyRecurrence120Days,
Expand Down
4 changes: 4 additions & 0 deletions stats/stats/src/charts/lines/tokens/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod native_coin_holders_growth;
pub mod native_coin_supply;
pub mod new_native_coin_holders;
pub mod new_native_coin_transfers;
8 changes: 8 additions & 0 deletions stats/stats/src/charts/lines/transactions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod average_txn_fee;
pub mod new_operational_txns;
pub mod new_txns;
pub mod new_txns_window;
pub mod operational_txns_growth;
pub mod txns_fee;
pub mod txns_growth;
pub mod txns_success_rate;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
},
},
define_and_impl_resolution_properties,
lines::{new_blocks::NewBlocksInt, NewTxnsInt},
types::{
timespans::{Month, Week, Year},
Timespan, TimespanValue,
Expand All @@ -24,8 +25,6 @@ use chrono::NaiveDate;
use entity::sea_orm_active_enums::ChartType;
use itertools::Itertools;

use super::{new_blocks::NewBlocksInt, NewTxnsInt};

pub struct Properties;

impl Named for Properties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
types::BlockscoutMigrations,
UpdateContext,
},
lines::NewTxnsStatement,
range::UniversalRange,
types::{Timespan, TimespanDuration, TimespanValue},
utils::day_start,
Expand All @@ -33,8 +34,6 @@ use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use sea_orm::{FromQueryResult, Statement};

use super::NewTxnsStatement;

pub const WINDOW: u64 = 30;

fn new_txns_window_statement(
Expand Down
83 changes: 83 additions & 0 deletions stats/stats/src/charts/lines/user_ops/active_bundlers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Active bundlers on each day.

use std::ops::Range;

use crate::{
charts::db_interaction::read::QueryAllBlockTimestampRange,
data_source::{
kinds::{
local_db::{
parameters::update::batching::parameters::Batch30Days, DirectVecLocalDbChartSource,
},
remote_db::{PullAllWithAndSort, RemoteDatabaseSource, StatementFromRange},
},
types::BlockscoutMigrations,
},
ChartProperties, Named,
};

use blockscout_db::entity::user_operations;
use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use migration::IntoColumnRef;
use sea_orm::Statement;

use super::count_distinct_in_user_ops;

pub struct ActiveBundlersStatement;

impl StatementFromRange for ActiveBundlersStatement {
fn get_statement(
range: Option<Range<DateTime<Utc>>>,
_completed_migrations: &BlockscoutMigrations,
) -> Statement {
count_distinct_in_user_ops(user_operations::Column::Bundler.into_column_ref(), range)
}
}

pub type ActiveBundlersRemote = RemoteDatabaseSource<
PullAllWithAndSort<ActiveBundlersStatement, NaiveDate, String, QueryAllBlockTimestampRange>,
>;

pub struct Properties;

impl Named for Properties {
fn name() -> String {
"activeBundlers".into()
}
}

impl ChartProperties for Properties {
type Resolution = NaiveDate;

fn chart_type() -> ChartType {
ChartType::Line
}
}

pub type ActiveBundlers =
DirectVecLocalDbChartSource<ActiveBundlersRemote, Batch30Days, Properties>;

#[cfg(test)]
mod tests {
use crate::tests::simple_test::simple_test_chart;

use super::ActiveBundlers;

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_active_bundlers() {
simple_test_chart::<ActiveBundlers>(
"update_active_bundlers",
vec![
("2022-11-09", "1"),
("2022-11-10", "2"),
("2022-11-11", "2"),
("2022-11-12", "1"),
("2022-12-01", "1"),
("2023-02-01", "1"),
],
)
.await;
}
}
83 changes: 83 additions & 0 deletions stats/stats/src/charts/lines/user_ops/active_paymasters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Active paymasters on each day.

use std::ops::Range;

use crate::{
charts::db_interaction::read::QueryAllBlockTimestampRange,
data_source::{
kinds::{
local_db::{
parameters::update::batching::parameters::Batch30Days, DirectVecLocalDbChartSource,
},
remote_db::{PullAllWithAndSort, RemoteDatabaseSource, StatementFromRange},
},
types::BlockscoutMigrations,
},
ChartProperties, Named,
};

use blockscout_db::entity::user_operations;
use chrono::{DateTime, NaiveDate, Utc};
use entity::sea_orm_active_enums::ChartType;
use migration::IntoColumnRef;
use sea_orm::Statement;

use super::count_distinct_in_user_ops;

pub struct ActivePaymastersStatement;

impl StatementFromRange for ActivePaymastersStatement {
fn get_statement(
range: Option<Range<DateTime<Utc>>>,
_completed_migrations: &BlockscoutMigrations,
) -> Statement {
count_distinct_in_user_ops(user_operations::Column::Paymaster.into_column_ref(), range)
}
}

pub type ActivePaymastersRemote = RemoteDatabaseSource<
PullAllWithAndSort<ActivePaymastersStatement, NaiveDate, String, QueryAllBlockTimestampRange>,
>;

pub struct Properties;

impl Named for Properties {
fn name() -> String {
"activePaymasters".into()
}
}

impl ChartProperties for Properties {
type Resolution = NaiveDate;

fn chart_type() -> ChartType {
ChartType::Line
}
}

pub type ActivePaymasters =
DirectVecLocalDbChartSource<ActivePaymastersRemote, Batch30Days, Properties>;

#[cfg(test)]
mod tests {
use crate::tests::simple_test::simple_test_chart;

use super::ActivePaymasters;

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_active_paymasters() {
simple_test_chart::<ActivePaymasters>(
"update_active_paymasters",
vec![
("2022-11-09", "1"),
("2022-11-10", "1"),
("2022-11-11", "1"),
("2022-11-12", "1"),
("2022-12-01", "1"),
("2023-02-01", "1"),
],
)
.await;
}
}
Loading
Loading