Skip to content

Commit

Permalink
Merge branch 'feature/rpc-cli'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jul 4, 2024
2 parents 57a31c3 + 9aade0b commit ddef2a6
Show file tree
Hide file tree
Showing 22 changed files with 940 additions and 187 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ rustc_version = "0.4"
rustls = "0.23"
rustls-webpki = "0.102"
scc = "2.1"
scopeguard = "1.2"
serde = "1.0"
serde_json = "1.0.114"
serde_path_to_error = "0.1"
Expand Down
46 changes: 39 additions & 7 deletions block-util/src/archive/entry_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use smallvec::SmallVec;

/// Package entry id.
#[derive(Debug, Hash, Eq, PartialEq)]
pub enum ArchiveEntryId<I> {
pub enum ArchiveEntryId<I = BlockId> {
/// Block data entry.
Block(I),
/// Block proof entry.
Expand Down Expand Up @@ -37,6 +37,37 @@ impl ArchiveEntryId<BlockId> {
}
}

impl<T> ArchiveEntryId<T> {
pub fn extract_kind(data: &[u8]) -> Option<ArchiveEntryIdKind> {
if data.len() < SERIALIZED_LEN {
return None;
}

Some(match data[SERIALIZED_LEN - 1] {
0 => ArchiveEntryIdKind::Block,
1 => ArchiveEntryIdKind::Proof,
2 => ArchiveEntryIdKind::ProofLink,
_ => return None,
})
}

pub fn kind(&self) -> ArchiveEntryIdKind {
match self {
Self::Block(_) => ArchiveEntryIdKind::Block,
Self::Proof(_) => ArchiveEntryIdKind::Proof,
Self::ProofLink(_) => ArchiveEntryIdKind::ProofLink,
}
}
}

#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
#[repr(u8)]
pub enum ArchiveEntryIdKind {
Block = 0,
Proof = 1,
ProofLink = 2,
}

impl<I> ArchiveEntryId<I>
where
I: Borrow<BlockId>,
Expand All @@ -51,13 +82,12 @@ where
}

/// Constructs on-stack buffer with the serialized object
pub fn to_vec(&self) -> SmallVec<[u8; 4 + 8 + 4 + 32 + 1]> {
// TODO:
let mut result = SmallVec::with_capacity(4 + 8 + 4 + 32 + 1); // TODO:
pub fn to_vec(&self) -> SmallVec<[u8; SERIALIZED_LEN]> {
let mut result = SmallVec::with_capacity(SERIALIZED_LEN);
let (block_id, ty) = match self {
Self::Block(id) => (id, 0),
Self::Proof(id) => (id, 1),
Self::ProofLink(id) => (id, 2),
Self::Block(id) => (id, ArchiveEntryIdKind::Block as u8),
Self::Proof(id) => (id, ArchiveEntryIdKind::Proof as u8),
Self::ProofLink(id) => (id, ArchiveEntryIdKind::ProofLink as u8),
};
let block_id = block_id.borrow();

Expand All @@ -71,6 +101,8 @@ where
}
}

const SERIALIZED_LEN: usize = 4 + 8 + 4 + 32 + 1;

pub trait GetFileName {
fn filename(&self) -> String;
}
Expand Down
2 changes: 1 addition & 1 deletion block-util/src/archive/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytes::Bytes;

pub use self::entry_id::{ArchiveEntryId, GetFileName};
pub use self::entry_id::{ArchiveEntryId, ArchiveEntryIdKind, GetFileName};
pub use self::reader::{ArchiveEntry, ArchiveReader, ArchiveReaderError, ArchiveVerifier};

mod entry_id;
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use std::sync::OnceLock;
use anyhow::Result;
use clap::{Parser, Subcommand};

use crate::tools::storage_cli::StorageCmd;

mod tools {
pub mod gen_account;
pub mod gen_dht;
pub mod gen_key;
pub mod gen_zerostate;
pub mod storage_cli;
}

mod node;
Expand Down Expand Up @@ -56,13 +59,16 @@ enum Cmd {

#[clap(subcommand)]
Tool(ToolCmd),
#[clap(subcommand)]
Storage(StorageCmd),
}

impl Cmd {
fn run(self) -> Result<()> {
match self {
Cmd::Node(cmd) => cmd.run(),
Cmd::Tool(cmd) => cmd.run(),
Cmd::Storage(cmd) => cmd.run(),
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions cli/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use tycho_collator::validator::client::retry::BackoffConfig;
use tycho_collator::validator::config::ValidatorConfig;
use tycho_collator::validator::validator::ValidatorStdImplFactory;
use tycho_core::block_strider::{
BlockProvider, BlockStrider, BlockchainBlockProvider, BlockchainBlockProviderConfig,
MetricsSubscriber, OptionalBlockStuff, PersistentBlockStriderState, ShardStateApplier,
StateSubscriber, StateSubscriberContext, StorageBlockProvider,
BlockProvider, BlockStrider, BlockSubscriberExt, BlockchainBlockProvider,
BlockchainBlockProviderConfig, GcSubscriber, MetricsSubscriber, OptionalBlockStuff,
PersistentBlockStriderState, ShardStateApplier, StateSubscriber, StateSubscriberContext,
StorageBlockProvider,
};
use tycho_core::blockchain_rpc::{
BlockchainRpcClient, BlockchainRpcService, BlockchainRpcServiceConfig, BroadcastListener,
Expand Down Expand Up @@ -671,14 +672,17 @@ impl Node {
collator_block_provider,
))
.with_state(strider_state)
.with_block_subscriber((
ShardStateApplier::new(
self.state_tracker.clone(),
self.storage.clone(),
(collator_state_subscriber, rpc_state),
),
MetricsSubscriber,
))
.with_block_subscriber(
(
ShardStateApplier::new(
self.state_tracker.clone(),
self.storage.clone(),
(collator_state_subscriber, rpc_state),
),
MetricsSubscriber,
)
.chain(GcSubscriber::new(self.storage.clone())),
)
.build();

// Run block strider
Expand Down
Loading

0 comments on commit ddef2a6

Please sign in to comment.