Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: read-write separation and merge rocksdb instance #1338

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 66 additions & 18 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 @@ -34,6 +34,7 @@ members = [
"core/api",
"core/cli",
"core/consensus",
"core/db",
"core/executor",
"core/mempool",
"core/network",
Expand Down
17 changes: 1 addition & 16 deletions common/config-parser/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,9 @@ pub struct Config {
}

impl Config {
pub fn data_path_for_system_contract(&self) -> PathBuf {
pub fn data_path_for_rocksdb(&self) -> PathBuf {
let mut path_state = self.data_path.clone();
path_state.push("rocksdb");
path_state.push("system_contract");
path_state
}

pub fn data_path_for_state(&self) -> PathBuf {
let mut path_state = self.data_path.clone();
path_state.push("rocksdb");
path_state.push("state_data");
path_state
}

pub fn data_path_for_block(&self) -> PathBuf {
let mut path_state = self.data_path.clone();
path_state.push("rocksdb");
path_state.push("block_data");
path_state
}

Expand Down
24 changes: 13 additions & 11 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::Arc;

use protocol::traits::{APIAdapter, Context, Executor, ExecutorAdapter, MemPool, Network, Storage};
use protocol::traits::{
APIAdapter, Context, Executor, ExecutorReadOnlyAdapter, MemPool, Network, ReadOnlyStorage,
};
use protocol::types::{
Account, BigEndianHash, Block, BlockNumber, Bytes, CkbRelatedInfo, ExecutorContext, Hash,
Header, Metadata, Proposal, Receipt, SignedTransaction, TxResp, H160, H256,
Expand All @@ -9,7 +11,7 @@ use protocol::types::{
use protocol::{async_trait, codec::ProtocolCodec, trie, ProtocolResult};

use core_executor::{
system_contract::metadata::MetadataHandle, AxonExecutor, AxonExecutorAdapter, MPTTrie,
system_contract::metadata::MetadataHandle, AxonExecutor, AxonExecutorReadOnlyAdapter, MPTTrie,
};

use crate::APIError;
Expand All @@ -25,8 +27,8 @@ pub struct DefaultAPIAdapter<M, S, DB, Net> {
impl<M, S, DB, Net> DefaultAPIAdapter<M, S, DB, Net>
where
M: MemPool + 'static,
S: Storage + 'static,
DB: trie::DB + 'static,
S: ReadOnlyStorage + 'static,
DB: trie::DB + Send + Sync + 'static,
Net: Network + 'static,
{
pub fn new(mempool: Arc<M>, storage: Arc<S>, trie_db: Arc<DB>, net: Arc<Net>) -> Self {
Expand All @@ -41,13 +43,13 @@ where
pub async fn evm_backend(
&self,
number: Option<BlockNumber>,
) -> ProtocolResult<AxonExecutorAdapter<S, DB>> {
) -> ProtocolResult<AxonExecutorReadOnlyAdapter<S, DB>> {
let block = self
.get_block_by_number(Context::new(), number)
.await?
.ok_or_else(|| APIError::Adapter(format!("Cannot get {:?} block", number)))?;

AxonExecutorAdapter::from_root(
AxonExecutorReadOnlyAdapter::from_root(
block.header.state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
Expand All @@ -60,8 +62,8 @@ where
impl<M, S, DB, Net> APIAdapter for DefaultAPIAdapter<M, S, DB, Net>
where
M: MemPool + 'static,
S: Storage + 'static,
DB: trie::DB + 'static,
S: ReadOnlyStorage + 'static,
DB: trie::DB + Send + Sync + 'static,
Net: Network + 'static,
{
async fn insert_signed_txs(
Expand Down Expand Up @@ -188,7 +190,7 @@ where
exec_ctx.origin = from.unwrap_or_default();
exec_ctx.gas_price = gas_price.unwrap_or_else(U256::one);

let backend = AxonExecutorAdapter::from_root(
let backend = AxonExecutorReadOnlyAdapter::from_root(
state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
Expand Down Expand Up @@ -257,7 +259,7 @@ where
async fn get_image_cell_root(&self, ctx: Context) -> ProtocolResult<H256> {
let state_root = self.storage.get_latest_block_header(ctx).await?.state_root;

Ok(AxonExecutorAdapter::from_root(
Ok(AxonExecutorReadOnlyAdapter::from_root(
state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
Expand All @@ -269,7 +271,7 @@ where
async fn get_metadata_root(&self, ctx: Context) -> ProtocolResult<H256> {
let state_root = self.storage.get_latest_block_header(ctx).await?.state_root;

Ok(AxonExecutorAdapter::from_root(
Ok(AxonExecutorReadOnlyAdapter::from_root(
state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
Expand Down
2 changes: 2 additions & 0 deletions core/cli/src/args/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ impl RunArgs {
) -> Result<()> {
let Self { config, spec } = self;
let genesis = spec.genesis.build_rich_block();

utils::check_version(
&config.data_path_for_version(),
&kernel_version,
utils::latest_compatible_version(),
)?;
utils::register_log(&config);

Axon::new(application_version.to_string(), config, spec, genesis)
.run(key_provider)
.map_err(Error::Running)
Expand Down
10 changes: 5 additions & 5 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use clap::{CommandFactory as _, FromArgMatches as _, Parser, Subcommand};

use common_version::Version;
use core_run::{KeyProvider, SecioKeyPair};

mod args;
mod error;
pub(crate) mod utils;

pub use args::run::RunArgs;
pub use error::{CheckingVersionError, Error, Result};

use clap::{CommandFactory as _, FromArgMatches as _, Parser, Subcommand};

use common_version::Version;
use core_run::{KeyProvider, SecioKeyPair};

#[derive(Parser, Debug)]
#[command(name = "axon")]
struct Cli {
Expand Down
Loading