diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index f61004f3..da892a48 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -94,6 +94,12 @@ pub struct RpcQueryKey { rpc_key_user_id: Option, } +impl RpcQueryKey { + pub fn is_registered(&self) -> bool { + self.rpc_key_user_id.is_some() + } +} + /// round the unix epoch time to the start of a period fn round_timestamp(timestamp: i64, period_seconds: i64) -> i64 { timestamp / period_seconds * period_seconds diff --git a/web3_proxy/src/stats/stat_buffer.rs b/web3_proxy/src/stats/stat_buffer.rs index da30ca87..a2a88f6d 100644 --- a/web3_proxy/src/stats/stat_buffer.rs +++ b/web3_proxy/src/stats/stat_buffer.rs @@ -178,7 +178,10 @@ impl StatBuffer { approximate_balance_remaining = user_balance.remaining(); } - self.accounting_db_buffer.entry(stat.accounting_key(self.billing_period_seconds)).or_default().add(stat.clone(), approximate_balance_remaining).await; + let accounting_key = stat.accounting_key(self.billing_period_seconds); + if accounting_key.is_registered() { + self.accounting_db_buffer.entry(accounting_key).or_default().add(stat.clone(), approximate_balance_remaining).await; + } } if self.influxdb_client.is_some() {