Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvious committed Jun 17, 2024
2 parents 6ff55cb + a606e80 commit dbc164d
Show file tree
Hide file tree
Showing 20 changed files with 1,287 additions and 149 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ jobs:
crate: taplo-cli
- name: Run taplo linter
run: taplo format --check --verbose

cargo-test-workspace:
name: test workspace crates
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: dsherret/rust-toolchain-file@v1
- name: Test Workspace
run: cargo test --workspace --features mock_storage
118 changes: 107 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/actors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
default = ["local"]
local = []
remote = []
mock_storage = []

[dependencies]
async-recursion = "1.0.5"
Expand Down Expand Up @@ -69,3 +70,4 @@ web3 = { version = "0.19.0" }

[dev-dependencies]
anyhow = "1"
serial_test = "3.1.1"
29 changes: 19 additions & 10 deletions crates/actors/src/account_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use lasr_messages::{
AccountCacheMessage, ActorName, ActorType, RpcMessage, RpcResponseError, SupervisorType,
TransactionResponse,
};
use lasr_types::{Account, AccountType, Address};
#[cfg(feature = "mock_storage")]
use lasr_types::MockPersistenceStore;
use lasr_types::{Account, AccountType, Address, PersistenceStore};
use ractor::{
concurrency::OneshotReceiver, Actor, ActorCell, ActorProcessingErr, ActorRef, SupervisionEvent,
};
Expand All @@ -14,12 +16,15 @@ use std::{
time::{Duration, Instant},
};
use thiserror::Error;
#[cfg(not(feature = "mock_storage"))]
use tikv_client::RawClient as TikvClient;
use tokio::sync::mpsc::Sender;

#[derive(Debug, Clone, Default)]
pub struct AccountCacheActor;

pub type StorageRef = <AccountCacheActor as Actor>::Arguments;

impl ActorName for AccountCacheActor {
fn name(&self) -> ractor::ActorName {
ActorType::AccountCache.to_string()
Expand All @@ -44,15 +49,15 @@ impl Default for AccountCacheError {
}
}

pub struct AccountCache {
pub struct AccountCache<S: PersistenceStore> {
inner: AccountCacheInner,
tikv_client: TikvClient,
storage: S,
}
impl AccountCache {
pub fn new(tikv_client: TikvClient) -> Self {
impl<S: PersistenceStore> AccountCache<S> {
pub fn new(storage: S) -> Self {
Self {
inner: AccountCacheInner::new(),
tikv_client,
storage,
}
}
}
Expand Down Expand Up @@ -192,8 +197,11 @@ impl AccountCacheActor {
#[async_trait]
impl Actor for AccountCacheActor {
type Msg = AccountCacheMessage;
type State = AccountCache;
type State = AccountCache<Self::Arguments>;
#[cfg(not(feature = "mock_storage"))]
type Arguments = TikvClient;
#[cfg(feature = "mock_storage")]
type Arguments = MockPersistenceStore<String, Vec<u8>>;

async fn pre_start(
&self,
Expand Down Expand Up @@ -243,9 +251,10 @@ impl Actor for AccountCacheActor {
let acc_key = address.to_full_string();

// Pull `Account` data from persistence store
state
.tikv_client
.get(acc_key.to_owned())
PersistenceStore::get(
&state.storage,
acc_key.to_owned().into()
)
.await
.typecast()
.log_err(|e| AccountCacheError::Custom(format!("failed to find Account with address: {hex_address} in persistence store: {e:?}")))
Expand Down
Loading

0 comments on commit dbc164d

Please sign in to comment.