diff --git a/chain-signatures/node/src/cli.rs b/chain-signatures/node/src/cli.rs index 83131e2d..3d7710f7 100644 --- a/chain-signatures/node/src/cli.rs +++ b/chain-signatures/node/src/cli.rs @@ -200,7 +200,6 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> { &mpc_contract_id, &account_id, &sign_queue, - &gcp_service, &rt, )?; diff --git a/chain-signatures/node/src/gcp/error.rs b/chain-signatures/node/src/gcp/error.rs index 8818a07f..42463611 100644 --- a/chain-signatures/node/src/gcp/error.rs +++ b/chain-signatures/node/src/gcp/error.rs @@ -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 for DatastoreStorageError { - fn from(err: ConvertError) -> Self { - DatastoreStorageError::ConvertError(err) - } -} diff --git a/chain-signatures/node/src/gcp/mod.rs b/chain-signatures/node/src/gcp/mod.rs index d011c4ad..17d791f4 100644 --- a/chain-signatures/node/src/gcp/mod.rs +++ b/chain-signatures/node/src/gcp/mod.rs @@ -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::{ @@ -101,8 +94,8 @@ impl GcpService { ) -> anyhow::Result { 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() diff --git a/chain-signatures/node/src/indexer.rs b/chain-signatures/node/src/indexer.rs index 1618a12b..826a07f4 100644 --- a/chain-signatures/node/src/indexer.rs +++ b/chain-signatures/node/src/indexer.rs @@ -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; @@ -99,8 +97,8 @@ pub struct ContractSignRequest { pub key_version: u32, } +#[derive(Debug, Clone)] pub struct Indexer { - storage: AppDataRedisStorage, last_updated_timestamp: Arc>, latest_block_timestamp_nanosec: Arc>>, running_threshold: Duration, @@ -108,10 +106,9 @@ pub struct Indexer { } 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), @@ -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. @@ -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?) } } @@ -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. @@ -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); @@ -306,7 +286,7 @@ pub fn run( mpc_contract_id: &AccountId, node_account_id: &AccountId, queue: &Arc>, - rt: &tokio::runtime::Runtime, + _rt: &tokio::runtime::Runtime, ) -> anyhow::Result<(JoinHandle>, Indexer)> { tracing::info!( s3_bucket = options.s3_bucket, @@ -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(), diff --git a/chain-signatures/node/src/protocol/consensus.rs b/chain-signatures/node/src/protocol/consensus.rs index d50fd031..40f30e4a 100644 --- a/chain-signatures/node/src/protocol/consensus.rs +++ b/chain-signatures/node/src/protocol/consensus.rs @@ -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; @@ -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 for ConsensusError { @@ -78,12 +75,6 @@ impl From for ConsensusError { } } -impl From for ConsensusError { - fn from(err: DatastoreStorageError) -> Self { - ConsensusError::DatastoreStorageError(err) - } -} - #[async_trait] pub trait ConsensusProtocol { async fn advance( diff --git a/chain-signatures/node/src/storage/app_data_storage.rs b/chain-signatures/node/src/storage/app_data_storage.rs deleted file mode 100644 index a0d340a7..00000000 --- a/chain-signatures/node/src/storage/app_data_storage.rs +++ /dev/null @@ -1,45 +0,0 @@ -use anyhow::Ok; -use deadpool_redis::Pool; -use near_primitives::types::BlockHeight; -use near_sdk::AccountId; -use redis::AsyncCommands; - -type AppDataResult = std::result::Result; - -const APP_DATA_PREFIX: &str = "app_data"; -const APP_DATA_STORAGE_VERSION: &str = "v1"; - -pub fn init(pool: &Pool, node_account_id: &AccountId) -> AppDataRedisStorage { - AppDataRedisStorage { - redis_pool: pool.clone(), - node_account_id: node_account_id.clone(), - } -} - -#[derive(Clone)] -pub struct AppDataRedisStorage { - redis_pool: Pool, - node_account_id: AccountId, -} - -impl AppDataRedisStorage { - pub async fn set_last_processed_block(&self, height: BlockHeight) -> AppDataResult<()> { - let mut conn = self.redis_pool.get().await?; - conn.set::<&str, BlockHeight, ()>(&self.last_block_key(), height) - .await?; - Ok(()) - } - - pub async fn get_last_processed_block(&self) -> AppDataResult> { - let mut conn = self.redis_pool.get().await?; - let result: Option = conn.get(self.last_block_key()).await?; - Ok(result) - } - - fn last_block_key(&self) -> String { - format!( - "{}:{}:{}:last_block", - APP_DATA_PREFIX, APP_DATA_STORAGE_VERSION, self.node_account_id - ) - } -} diff --git a/chain-signatures/node/src/storage/mod.rs b/chain-signatures/node/src/storage/mod.rs index c5230121..d4bb21ba 100644 --- a/chain-signatures/node/src/storage/mod.rs +++ b/chain-signatures/node/src/storage/mod.rs @@ -1,4 +1,3 @@ -pub mod app_data_storage; pub mod presignature_storage; pub mod secret_storage; pub mod triple_storage;