Skip to content

Commit

Permalink
redis app storage removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Volovyk committed Nov 7, 2024
1 parent f82cb38 commit d7314e3
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 116 deletions.
1 change: 0 additions & 1 deletion chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
&mpc_contract_id,
&account_id,
&sign_queue,
&gcp_service,
&rt,
)?;

Expand Down
22 changes: 0 additions & 22 deletions chain-signatures/node/src/gcp/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,3 @@ pub enum SecretStorageError {
#[error("(de)serialization error: {0}")]
SerdeError(#[from] serde_json::Error),
}

#[derive(thiserror::Error, Debug)]
pub enum DatastoreStorageError {
#[error("GCP error: {0}")]
GcpError(#[from] google_datastore1::Error),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("(de)serialization error: {0}")]
SerdeError(#[from] serde_json::Error),
#[error("datastore value conversion error: {0}")]
ConvertError(ConvertError),
#[error("fetch_entities error: `{0}`")]
FetchEntitiesError(String),
#[error("could not find entity: {0}")]
EntityNotFound(String),
}

impl From<ConvertError> for DatastoreStorageError {
fn from(err: ConvertError) -> Self {
DatastoreStorageError::ConvertError(err)
}
}
11 changes: 2 additions & 9 deletions chain-signatures/node/src/gcp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
pub mod error;
pub mod value;

use self::value::{FromValue, IntoValue};
use crate::gcp::error::DatastoreStorageError;
use crate::storage;

use google_datastore1::api::Filter;
use google_datastore1::api::{
CommitRequest, Entity, EntityResult, Key, KindExpression, LookupRequest, Mutation, PathElement,
Query, RunQueryRequest,
};
use google_datastore1::api::Key;
use google_datastore1::oauth2::AccessTokenAuthenticator;
use google_datastore1::Datastore;
use google_secretmanager1::api::{AddSecretVersionRequest, SecretPayload};
use google_secretmanager1::oauth2::authenticator::ApplicationDefaultCredentialsTypes;
use google_secretmanager1::oauth2::{
Expand Down Expand Up @@ -101,8 +94,8 @@ impl GcpService {
) -> anyhow::Result<Self> {
let project_id = storage_options.gcp_project_id.clone();
let secret_manager;
// TODO: check string
if storage_options.env == "local-test" {
// TODO: check string
let client = hyper::Client::builder().build(
hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
Expand Down
38 changes: 9 additions & 29 deletions chain-signatures/node/src/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::gcp::GcpService;
use crate::protocol::{SignQueue, SignRequest};
use crate::storage::app_data_storage::AppDataRedisStorage;
use crypto_shared::{derive_epsilon, ScalarExt};
use k256::Scalar;
use near_account_id::AccountId;
Expand Down Expand Up @@ -99,19 +97,18 @@ pub struct ContractSignRequest {
pub key_version: u32,
}

#[derive(Debug, Clone)]
pub struct Indexer {
storage: AppDataRedisStorage,
last_updated_timestamp: Arc<RwLock<Instant>>,
latest_block_timestamp_nanosec: Arc<RwLock<Option<u64>>>,
running_threshold: Duration,
behind_threshold: Duration,
}

impl Indexer {
async fn new(storage: AppDataRedisStorage, options: &Options) -> Self {
fn new(options: &Options) -> Self {
// TODO: log latest block height
Self {
storage,
last_updated_timestamp: Arc::new(RwLock::new(Instant::now())),
latest_block_timestamp_nanosec: Arc::new(RwLock::new(None)),
running_threshold: Duration::from_secs(options.running_threshold),
Expand All @@ -121,20 +118,8 @@ impl Indexer {

/// Get the latest processed block height
pub async fn latest_block_height(&self) -> BlockHeight {
let height = match self.storage.get_last_processed_block().await {
Ok(Some(height)) => height,
Ok(None) => {
tracing::warn!("block height was not set");
return 0;
}
Err(e) => {
// TODO: make it error in triples and presignatures
tracing::error!(?e, "failed to get block height");
return 0;
}
};
tracing::debug!(height, "latest block height");
height
// TODO: fetch latest block using RPC
0 as BlockHeight
}

/// Check whether the indexer is on track with the latest block height from the chain.
Expand Down Expand Up @@ -168,12 +153,7 @@ impl Indexer {
tracing::debug!(block_height, "update_block_height_and_timestamp");
*self.last_updated_timestamp.write().await = Instant::now();
*self.latest_block_timestamp_nanosec.write().await = Some(block_timestamp_nanosec);
self.storage
.set_last_processed_block(block_height)
.await
.map_err(|e| {
tracing::error!(?e, "failed to set last processed block");
});
// TODO: update the block height in the indexer (add in memoru variable?)
}
}

Expand Down Expand Up @@ -275,7 +255,7 @@ async fn handle_block(
.await;

crate::metrics::LATEST_BLOCK_HEIGHT
.with_label_values(&[ctx.gcp_service.account_id.as_str()])
.with_label_values(&[ctx.node_account_id.as_str()])
.set(block.block_height() as i64);

// Add the requests after going through the whole block to avoid partial processing if indexer fails somewhere.
Expand All @@ -284,7 +264,7 @@ async fn handle_block(
for request in pending_requests {
queue.add(request);
crate::metrics::NUM_SIGN_REQUESTS
.with_label_values(&[ctx.gcp_service.account_id.as_str()])
.with_label_values(&[ctx.node_account_id.as_str()])
.inc();
}
drop(queue);
Expand All @@ -306,7 +286,7 @@ pub fn run(
mpc_contract_id: &AccountId,
node_account_id: &AccountId,
queue: &Arc<RwLock<SignQueue>>,
rt: &tokio::runtime::Runtime,
_rt: &tokio::runtime::Runtime,
) -> anyhow::Result<(JoinHandle<anyhow::Result<()>>, Indexer)> {
tracing::info!(
s3_bucket = options.s3_bucket,
Expand All @@ -317,7 +297,7 @@ pub fn run(
"starting indexer"
);

let indexer = Indexer::new(options).await;
let indexer = Indexer::new(options);
let context = Context {
mpc_contract_id: mpc_contract_id.clone(),
node_account_id: node_account_id.clone(),
Expand Down
9 changes: 0 additions & 9 deletions chain-signatures/node/src/protocol/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::state::{
WaitingForConsensusState,
};
use super::{Config, SignQueue};
use crate::gcp::error::DatastoreStorageError;
use crate::gcp::error::SecretStorageError;
use crate::http_client::MessageQueue;
use crate::protocol::contract::primitives::Participants;
Expand Down Expand Up @@ -68,8 +67,6 @@ pub enum ConsensusError {
CaitSithInitializationError(#[from] InitializationError),
#[error("secret storage error: {0}")]
SecretStorageError(SecretStorageError),
#[error("datastore storage error: {0}")]
DatastoreStorageError(DatastoreStorageError),
}

impl From<SecretStorageError> for ConsensusError {
Expand All @@ -78,12 +75,6 @@ impl From<SecretStorageError> for ConsensusError {
}
}

impl From<DatastoreStorageError> for ConsensusError {
fn from(err: DatastoreStorageError) -> Self {
ConsensusError::DatastoreStorageError(err)
}
}

#[async_trait]
pub trait ConsensusProtocol {
async fn advance<C: ConsensusCtx + Send + Sync>(
Expand Down
45 changes: 0 additions & 45 deletions chain-signatures/node/src/storage/app_data_storage.rs

This file was deleted.

1 change: 0 additions & 1 deletion chain-signatures/node/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod app_data_storage;
pub mod presignature_storage;
pub mod secret_storage;
pub mod triple_storage;
Expand Down

0 comments on commit d7314e3

Please sign in to comment.