-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bolt-sidecar): AccountStateCache with metrics
- Loading branch information
1 parent
6a2cdc9
commit 7ecafa1
Showing
4 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
use alloy::primitives::Address; | ||
|
||
use crate::{common::score_cache::ScoreCache, primitives::AccountState, telemetry::ApiMetrics}; | ||
|
||
const GET_SCORE: isize = 4; | ||
const INSERT_SCORE: isize = 4; | ||
const UPDATE_SCORE: isize = -1; | ||
|
||
/// A scored cache for account states. | ||
#[derive(Debug, Default)] | ||
pub struct AccountStateCache( | ||
pub ScoreCache<GET_SCORE, INSERT_SCORE, UPDATE_SCORE, Address, AccountState>, | ||
); | ||
|
||
impl Deref for AccountStateCache { | ||
type Target = ScoreCache<GET_SCORE, INSERT_SCORE, UPDATE_SCORE, Address, AccountState>; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for AccountStateCache { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
impl AccountStateCache { | ||
/// Insert an account state into the cache, and update the metrics. | ||
pub fn insert(&mut self, address: Address, account_state: AccountState) { | ||
ApiMetrics::set_account_states(self.len()); | ||
self.0.insert(address, account_state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters