Skip to content

Commit

Permalink
refactor(blockchain-server): unify models
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Apr 29, 2024
1 parent 568b295 commit 6eac0ee
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 707 deletions.
6 changes: 3 additions & 3 deletions core/src/block_strider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use futures_util::future::BoxFuture;
use tycho_block_util::block::{BlockStuff, BlockStuffAug};
use tycho_storage::Storage;

use crate::blockchain_client::BlockchainClient;
use crate::proto::overlay::BlockFull;
use crate::blockchain_rpc::BlockchainRpcClient;
use crate::proto::blockchain::BlockFull;

pub type OptionalBlockStuff = Option<anyhow::Result<BlockStuffAug>>;

Expand Down Expand Up @@ -82,7 +82,7 @@ impl<T1: BlockProvider, T2: BlockProvider> BlockProvider for ChainBlockProvider<
}
}

impl BlockProvider for BlockchainClient {
impl BlockProvider for BlockchainRpcClient {
type GetNextBlockFut<'a> = BoxFuture<'a, OptionalBlockStuff>;
type GetBlockFut<'a> = BoxFuture<'a, OptionalBlockStuff>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use anyhow::Result;
use everscale_types::models::BlockId;

use crate::overlay_client::{PublicOverlayClient, QueryResponse};
use crate::proto::overlay::rpc::*;
use crate::proto::overlay::*;
use crate::proto::blockchain::*;

pub struct BlockchainClientConfig {
pub struct BlockchainRpcClientConfig {
pub get_next_block_polling_interval: Duration,
pub get_block_polling_interval: Duration,
}

impl Default for BlockchainClientConfig {
impl Default for BlockchainRpcClientConfig {
fn default() -> Self {
Self {
get_block_polling_interval: Duration::from_millis(50),
Expand All @@ -24,17 +23,17 @@ impl Default for BlockchainClientConfig {

#[derive(Clone)]
#[repr(transparent)]
pub struct BlockchainClient {
pub struct BlockchainRpcClient {
inner: Arc<Inner>,
}

struct Inner {
overlay_client: PublicOverlayClient,
config: BlockchainClientConfig,
config: BlockchainRpcClientConfig,
}

impl BlockchainClient {
pub fn new(overlay_client: PublicOverlayClient, config: BlockchainClientConfig) -> Self {
impl BlockchainRpcClient {
pub fn new(overlay_client: PublicOverlayClient, config: BlockchainRpcClientConfig) -> Self {
Self {
inner: Arc::new(Inner {
overlay_client,
Expand All @@ -47,7 +46,7 @@ impl BlockchainClient {
&self.inner.overlay_client
}

pub fn config(&self) -> &BlockchainClientConfig {
pub fn config(&self) -> &BlockchainRpcClientConfig {
&self.inner.config
}

Expand All @@ -58,8 +57,8 @@ impl BlockchainClient {
) -> Result<QueryResponse<KeyBlockIds>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, KeyBlockIds>(&GetNextKeyBlockIds {
block: *block,
.query::<_, KeyBlockIds>(&rpc::GetNextKeyBlockIds {
block_id: *block,
max_size,
})
.await?;
Expand All @@ -69,7 +68,7 @@ impl BlockchainClient {
pub async fn get_block_full(&self, block: &BlockId) -> Result<QueryResponse<BlockFull>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, BlockFull>(GetBlockFull { block: *block })
.query::<_, BlockFull>(&rpc::GetBlockFull { block_id: *block })
.await?;
Ok(data)
}
Expand All @@ -80,8 +79,8 @@ impl BlockchainClient {
) -> Result<QueryResponse<BlockFull>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, BlockFull>(GetNextBlockFull {
prev_block: *prev_block,
.query::<_, BlockFull>(&rpc::GetNextBlockFull {
prev_block_id: *prev_block,
})
.await?;
Ok(data)
Expand All @@ -90,7 +89,7 @@ impl BlockchainClient {
pub async fn get_archive_info(&self, mc_seqno: u32) -> Result<QueryResponse<ArchiveInfo>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, ArchiveInfo>(GetArchiveInfo { mc_seqno })
.query::<_, ArchiveInfo>(&rpc::GetArchiveInfo { mc_seqno })
.await?;
Ok(data)
}
Expand All @@ -103,7 +102,7 @@ impl BlockchainClient {
) -> Result<QueryResponse<Data>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, Data>(GetArchiveSlice {
.query::<_, Data>(&rpc::GetArchiveSlice {
archive_id,
offset,
max_size,
Expand All @@ -121,9 +120,9 @@ impl BlockchainClient {
) -> Result<QueryResponse<PersistentStatePart>> {
let client = &self.inner.overlay_client;
let data = client
.query::<_, PersistentStatePart>(GetPersistentStatePart {
block: *block,
mc_block: *mc_block,
.query::<_, PersistentStatePart>(&rpc::GetPersistentStatePart {
block_id: *block,
mc_block_id: *mc_block,
offset,
max_size,
})
Expand Down
7 changes: 7 additions & 0 deletions core/src/blockchain_rpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub use self::client::{BlockchainRpcClient, BlockchainRpcClientConfig};
pub use self::service::{BlockchainRpcService, BlockchainRpcServiceConfig};

mod client;
mod service;

pub const INTERNAL_ERROR_CODE: u32 = 1;
Loading

0 comments on commit 6eac0ee

Please sign in to comment.