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: remove outdated cross chain code #1085

Merged
merged 6 commits into from
Mar 16, 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
408 changes: 220 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ members = [
"core/api",
"core/cli",
"core/consensus",
"core/cross-client",
"core/executor",
"core/mempool",
"core/metadata",
Expand All @@ -39,7 +38,7 @@ members = [
"core/run",
"core/storage",

"core/tx-assembler",
"devtools/abi-generator",
"devtools/genesis-generator",
"devtools/keypair",

Expand Down
1 change: 0 additions & 1 deletion core/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ core-executor = { path = "../../core/executor" }
protocol = { path = "../../protocol", package = "axon-protocol" }

[dev-dependencies]
fastrand = "1.8"
json = "0.12"
13 changes: 2 additions & 11 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::sync::Arc;
use core_executor::{AxonExecutor, AxonExecutorAdapter, MPTTrie};
use protocol::traits::{APIAdapter, Context, Executor, ExecutorAdapter, MemPool, Network, Storage};
use protocol::types::{
Account, BigEndianHash, Block, BlockNumber, Bytes, ExecutorContext, Hash, HashWithDirection,
Header, Proposal, Receipt, SignedTransaction, TxResp, H160, MAX_BLOCK_GAS_LIMIT, NIL_DATA,
RLP_NULL, U256,
Account, BigEndianHash, Block, BlockNumber, Bytes, ExecutorContext, Hash, Header, Proposal,
Receipt, SignedTransaction, TxResp, H160, MAX_BLOCK_GAS_LIMIT, NIL_DATA, RLP_NULL, U256,
};
use protocol::{async_trait, codec::ProtocolCodec, trie, ProtocolResult};

Expand Down Expand Up @@ -196,14 +195,6 @@ where
self.storage.get_code_by_hash(ctx, hash).await
}

async fn get_crosschain_record_by_hash(
&self,
ctx: Context,
hash: &Hash,
) -> ProtocolResult<Option<HashWithDirection>> {
self.storage.get_crosschain_record(ctx, hash).await
}

async fn peer_count(&self, ctx: Context) -> ProtocolResult<U256> {
self.net.peer_count(ctx).map(Into::into)
}
Expand Down
16 changes: 0 additions & 16 deletions core/api/src/jsonrpc/crosschain_types.rs

This file was deleted.

71 changes: 0 additions & 71 deletions core/api/src/jsonrpc/impl/crosschain.rs

This file was deleted.

2 changes: 0 additions & 2 deletions core/api/src/jsonrpc/impl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod crosschain;
mod filter;
mod node;
mod web3;

pub use crosschain::CrossChainRpcImpl;
pub use filter::filter_module;
pub use node::NodeRpcImpl;
pub use web3::{from_receipt_to_web3_log, Web3RpcImpl};
14 changes: 1 addition & 13 deletions core/api/src/jsonrpc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod crosschain_types;
mod error;
mod r#impl;
mod web3_types;
Expand All @@ -19,7 +18,7 @@ use crate::jsonrpc::web3_types::{
Web3Filter, Web3Log, Web3Receipt, Web3SyncStatus, Web3Transaction,
};
use crate::jsonrpc::ws_subscription::{ws_subscription_module, HexIdProvider};
use crate::{jsonrpc::crosschain_types::CrossChainTransaction, APIError};
use crate::APIError;

type RpcResult<T> = Result<T, Error>;

Expand Down Expand Up @@ -201,15 +200,6 @@ pub trait AxonNodeRpc {
fn pprof(&self, enable: bool) -> RpcResult<bool>;
}

#[rpc(server)]
pub trait AxonCrossChainRpc {
#[method(name = "getCrosschainResult")]
async fn get_crosschain_result(
&self,
tx_hash: H256,
) -> RpcResult<Option<CrossChainTransaction>>;
}

pub async fn run_jsonrpc_server<Adapter: APIAdapter + 'static>(
config: Config,
adapter: Arc<Adapter>,
Expand All @@ -219,11 +209,9 @@ pub async fn run_jsonrpc_server<Adapter: APIAdapter + 'static>(
let mut rpc = r#impl::Web3RpcImpl::new(Arc::clone(&adapter), config.rpc.gas_cap).into_rpc();
let node_rpc =
r#impl::NodeRpcImpl::new(&config.rpc.client_version, config.data_path).into_rpc();
let crosschain_rpc = r#impl::CrossChainRpcImpl::new(Arc::clone(&adapter)).into_rpc();
let filter = r#impl::filter_module(Arc::clone(&adapter)).into_rpc();

rpc.merge(node_rpc).unwrap();
rpc.merge(crosschain_rpc).unwrap();
rpc.merge(filter).unwrap();

if let Some(addr) = config.rpc.http_listening_address {
Expand Down
7 changes: 4 additions & 3 deletions core/api/src/jsonrpc/web3_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ pub struct RawLoggerFilter {
#[cfg(test)]
mod tests {
use super::*;
use protocol::rand::random;

#[test]
fn test_sync_status_json() {
Expand All @@ -763,9 +764,9 @@ mod tests {
assert!(json.is_boolean());

let status = Web3SyncStatus::Doing(SyncStatus {
starting_block: fastrand::u64(..).into(),
current_block: fastrand::u64(..).into(),
highest_block: fastrand::u64(..).into(),
starting_block: random::<u64>().into(),
current_block: random::<u64>().into(),
highest_block: random::<u64>().into(),
known_states: U256::default(),
pulled_states: U256::default(),
});
Expand Down
2 changes: 0 additions & 2 deletions core/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
[dependencies]
arc-swap = "1.6"

creep = "0.2"
futures = { version = "0.3", features = ["async-await"] }
json = "0.12"
lazy_static = "1.4"
Expand Down Expand Up @@ -35,7 +34,6 @@ protocol = { path = "../../protocol", package = "axon-protocol" }
bit-vec = "0.6"
criterion = "0.4"
num-traits = "0.2"
rand = "0.7"

[features]
default = []
Expand Down
3 changes: 1 addition & 2 deletions core/consensus/benches/bench_wal.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rand::random;
use rand::rngs::OsRng;

use common_crypto::{
Crypto, PrivateKey, Secp256k1Recoverable, Secp256k1RecoverablePrivateKey, Signature,
};
use core_consensus::SignedTxsWAL;
use protocol::rand::{random, rngs::OsRng};
use protocol::types::{
Bytes, Eip1559Transaction, Hash, Hasher, SignatureComponents, SignedTransaction,
TransactionAction, UnsignedTransaction, UnverifiedTransaction,
Expand Down
41 changes: 8 additions & 33 deletions core/consensus/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use common_apm_derive::trace_span;
use core_executor::{AxonExecutor, AxonExecutorAdapter};
use core_network::{PeerId, PeerIdExt};
use protocol::traits::{
CommonConsensusAdapter, ConsensusAdapter, Context, CrossChain, Executor, Gossip, MemPool,
MessageTarget, MetadataControl, Network, PeerTrust, Priority, Rpc, Storage,
SynchronizationAdapter,
CommonConsensusAdapter, ConsensusAdapter, Context, Executor, Gossip, MemPool, MessageTarget,
MetadataControl, Network, PeerTrust, Priority, Rpc, Storage, SynchronizationAdapter,
};
use protocol::types::{
BatchSignedTxs, Block, BlockNumber, Bytes, ExecResp, Hash, Header, Hex, Log, MerkleRoot,
Metadata, PackedTxHashes, Proof, Proposal, Receipt, SignedTransaction, Validator, U256,
BatchSignedTxs, Block, BlockNumber, Bytes, ExecResp, Hash, Header, Hex, MerkleRoot, Metadata,
PackedTxHashes, Proof, Proposal, Receipt, SignedTransaction, Validator, U256,
};
use protocol::{async_trait, tokio::task, trie, ProtocolResult};

Expand All @@ -34,7 +33,6 @@ pub struct OverlordConsensusAdapter<
M: MemPool,
N: Rpc + PeerTrust + Gossip + 'static,
S: Storage,
CS: CrossChain,
MT: MetadataControl,
DB: trie::DB,
> {
Expand All @@ -43,19 +41,17 @@ pub struct OverlordConsensusAdapter<

storage: Arc<S>,
trie_db: Arc<DB>,
cross_client: Arc<CS>,
metadata: Arc<MT>,
overlord_handler: RwLock<Option<OverlordHandler<Proposal>>>,
crypto: Arc<OverlordCrypto>,
}

#[async_trait]
impl<M, N, S, CS, MT, DB> ConsensusAdapter for OverlordConsensusAdapter<M, N, S, CS, MT, DB>
impl<M, N, S, MT, DB> ConsensusAdapter for OverlordConsensusAdapter<M, N, S, MT, DB>
where
M: MemPool + 'static,
N: Network + Rpc + PeerTrust + Gossip + 'static,
S: Storage + 'static,
CS: CrossChain + 'static,
MT: MetadataControl + 'static,
DB: trie::DB + 'static,
{
Expand Down Expand Up @@ -129,12 +125,11 @@ where
}

#[async_trait]
impl<M, N, S, CS, MT, DB> SynchronizationAdapter for OverlordConsensusAdapter<M, N, S, CS, MT, DB>
impl<M, N, S, MT, DB> SynchronizationAdapter for OverlordConsensusAdapter<M, N, S, MT, DB>
where
M: MemPool + 'static,
N: Network + Rpc + PeerTrust + Gossip + 'static,
S: Storage + 'static,
CS: CrossChain + 'static,
MT: MetadataControl + 'static,
DB: trie::DB + 'static,
{
Expand Down Expand Up @@ -232,12 +227,11 @@ where
}

#[async_trait]
impl<M, N, S, CS, MT, DB> CommonConsensusAdapter for OverlordConsensusAdapter<M, N, S, CS, MT, DB>
impl<M, N, S, MT, DB> CommonConsensusAdapter for OverlordConsensusAdapter<M, N, S, MT, DB>
where
M: MemPool + 'static,
N: Network + Rpc + PeerTrust + Gossip + 'static,
S: Storage + 'static,
CS: CrossChain + 'static,
MT: MetadataControl + 'static,
DB: trie::DB + 'static,
{
Expand Down Expand Up @@ -542,22 +536,6 @@ where
Ok(())
}

async fn notify_block_logs(
&self,
ctx: Context,
block_number: u64,
block_hash: Hash,
logs: &[Vec<Log>],
) {
self.cross_client
.set_evm_log(ctx, block_number, block_hash, logs)
.await
}

async fn notify_checkpoint(&self, ctx: Context, block: Block, proof: Proof) {
self.cross_client.set_checkpoint(ctx, block, proof).await
}

#[trace_span(kind = "consensus.adapter")]
fn verify_proof_signature(
&self,
Expand Down Expand Up @@ -628,12 +606,11 @@ where
}
}

impl<M, N, S, CS, MT, DB> OverlordConsensusAdapter<M, N, S, CS, MT, DB>
impl<M, N, S, MT, DB> OverlordConsensusAdapter<M, N, S, MT, DB>
where
M: MemPool + 'static,
N: Rpc + PeerTrust + Gossip + 'static,
S: Storage + 'static,
CS: CrossChain + 'static,
MT: MetadataControl + 'static,
DB: trie::DB + 'static,
{
Expand All @@ -642,7 +619,6 @@ where
mempool: Arc<M>,
storage: Arc<S>,
trie_db: Arc<DB>,
cross_client: Arc<CS>,
metadata: Arc<MT>,
crypto: Arc<OverlordCrypto>,
) -> ProtocolResult<Self> {
Expand All @@ -652,7 +628,6 @@ where
storage,
metadata,
trie_db,
cross_client,
overlord_handler: RwLock::new(None),
crypto,
})
Expand Down
5 changes: 1 addition & 4 deletions core/consensus/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::sync::Arc;

use creep::Context;
use overlord::types::{
AggregatedVote, Node, OverlordMsg, SignedChoke, SignedProposal, SignedVote, Status,
};
use overlord::{DurationConfig, Overlord, OverlordHandler};

use protocol::traits::{Consensus, ConsensusAdapter, NodeInfo};
use protocol::traits::{Consensus, ConsensusAdapter, Context, NodeInfo};
use protocol::types::{Proposal, Validator, H160};
use protocol::{
async_trait, codec::ProtocolCodec, tokio::sync::Mutex as AsyncMutex, ProtocolResult,
Expand Down Expand Up @@ -110,7 +109,6 @@ impl<Adapter: ConsensusAdapter + 'static> OverlordConsensus<Adapter> {
adapter: Arc<Adapter>,
lock: Arc<AsyncMutex<()>>,
consensus_wal: Arc<ConsensusWal>,
cross_period_interval: u64,
) -> Self {
let engine = Arc::new(ConsensusEngine::new(
status,
Expand All @@ -121,7 +119,6 @@ impl<Adapter: ConsensusAdapter + 'static> OverlordConsensus<Adapter> {
Arc::clone(&crypto),
lock,
consensus_wal,
cross_period_interval,
));
let status = engine.status();
let metadata = adapter.get_metadata_unchecked(Context::new(), status.last_number + 1);
Expand Down
Loading