Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
5 changes: 3 additions & 2 deletions common/config-parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ pub struct Config {
pub prometheus: Option<ConfigPrometheus>,
pub cross_client: ConfigCrossChain,
pub epoch_len: u64,
pub metadata_contract_address: H256,
pub crosschain_contract_address: H256,
pub metadata_contract_address: H160,
pub crosschain_contract_address: H160,
pub wckb_contract_address: H160,
pub ibc: Option<ConfigIbc>,
pub interoperability_extension: ConfigInteroperabilityExtension,
}
Expand Down
19 changes: 13 additions & 6 deletions core/cross-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ use protocol::types::{
};
use protocol::{async_trait, lazy::CHAIN_ID, tokio, ProtocolResult};

use core_executor::{CROSSCHAIN_CONTRACT_ADDRESS, WCKB_CONTRACT_ADDRESS};

use crate::error::CrossChainError;
use crate::task::{message::CrossChainMessage, RequestCkbTask};
use crate::{adapter::fixed_array, monitor::CrossChainMonitor, sidechain::SidechainTask};
Expand All @@ -58,6 +56,9 @@ pub struct CrossChainImpl<Adapter> {
reqs_tx: UnboundedSender<Requests>,

adapter: Arc<Adapter>,

cross_chain_address: H160,
wckb_address: H160,
}

impl<Adapter: CrossAdapter + 'static> CrossChainImpl<Adapter> {
Expand All @@ -66,6 +67,8 @@ impl<Adapter: CrossAdapter + 'static> CrossChainImpl<Adapter> {
config: ConfigCrossChain,
ckb_client: Arc<C>,
adapter: Arc<Adapter>,
cross_chain_address: H160,
wckb_address: H160,
) -> (
Self,
CrossChainHandler<C>,
Expand Down Expand Up @@ -114,6 +117,8 @@ impl<Adapter: CrossAdapter + 'static> CrossChainImpl<Adapter> {
req_rx,
reqs_tx,
adapter,
cross_chain_address,
wckb_address,
};

crosschain
Expand All @@ -133,7 +138,7 @@ impl<Adapter: CrossAdapter + 'static> CrossChainImpl<Adapter> {
if !to_ckbs.is_empty() {
let tx_clone = self.reqs_tx.clone();
tokio::spawn(async move {
build_ckb_tx_process(to_ckbs, tx_clone).await;
build_ckb_tx_process(to_ckbs, tx_clone, &self.wckb_address).await;
});
}

Expand All @@ -145,7 +150,7 @@ impl<Adapter: CrossAdapter + 'static> CrossChainImpl<Adapter> {
Some(reqs) = self.req_rx.recv() => {
log::info!("[cross-chain]: receive requests {:?} from CKB", reqs);
let nonce = self.nonce(self.address).await;
let (reqs, stx) = build_axon_txs(reqs, nonce, &self.priv_key);
let (reqs, stx) = build_axon_txs(reqs, nonce, &self.priv_key, self.cross_chain_address);
self.adapter.insert_in_process(
Context::new(),
&rlp::encode(&reqs).freeze(),
Expand Down Expand Up @@ -320,12 +325,13 @@ pub fn decode_resp_nonce(data: &[u8]) -> U256 {
async fn build_ckb_tx_process(
to_ckbs: Vec<crosschain_abi::CrossToCKBFilter>,
request_tx: UnboundedSender<Requests>,
wckb_address: &H160,
) {
let _ = request_tx.send(Requests(
to_ckbs
.iter()
.map(|log| {
let (s_amount, c_amount) = if log.token == WCKB_CONTRACT_ADDRESS {
let (s_amount, c_amount) = if &log.token == wckb_address {
(0, log.amount.as_u64() + BASE_CROSSCHAIN_CELL_CAPACITY)
} else {
(log.amount.as_u128(), BASE_CROSSCHAIN_CELL_CAPACITY)
Expand All @@ -349,6 +355,7 @@ pub fn build_axon_txs(
txs: Vec<TransactionView>,
addr_nonce: U256,
priv_key: &Secp256k1RecoverablePrivateKey,
cross_chain_address: H160,
) -> (Requests, SignedTransaction) {
let reqs = txs
.iter()
Expand Down Expand Up @@ -391,7 +398,7 @@ pub fn build_axon_txs(
max_priority_fee_per_gas: MAX_PRIORITY_FEE_PER_GAS.into(),
gas_price: U256::zero(),
gas_limit: MAX_BLOCK_GAS_LIMIT.into(),
action: TransactionAction::Call(CROSSCHAIN_CONTRACT_ADDRESS),
action: TransactionAction::Call(cross_chain_address),
value: U256::zero(),
data: AbiEncode::encode(call_data).into(),
access_list: vec![],
Expand Down
10 changes: 7 additions & 3 deletions core/executor/src/debugger/crosschain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use protocol::{codec::hex_decode, tokio};
use core_cross_client::crosschain_abi as abi;
use core_cross_client::{build_axon_txs, monitor::search_tx};

use crate::debugger::{clear_data, mock_signed_tx, EvmDebugger};
use crate::CROSSCHAIN_CONTRACT_ADDRESS;
use crate::debugger::{clear_data, mock_signed_tx, EvmDebugger, CROSSCHAIN_CONTRACT_ADDRESS};

const CKB_BLOCK_5910757: &str = "./src/debugger/block_5910757.json";
const ACS_CODE_HASH: ckb_types::H256 =
Expand Down Expand Up @@ -60,7 +59,12 @@ async fn test_cross_from_ckb() {
let mut ckb_tx_hash = [0u8; 32];
ckb_tx_hash.copy_from_slice(&ckb_txs[0].hash().raw_data()[..32]);

let (_, stx) = build_axon_txs(ckb_txs, debugger.nonce(address), &priv_key);
let (_, stx) = build_axon_txs(
ckb_txs,
debugger.nonce(address),
&priv_key,
CROSSCHAIN_CONTRACT_ADDRESS,
);
let resp = debugger.exec(1, vec![stx]);

println!("{:?}", resp);
Expand Down
3 changes: 3 additions & 0 deletions core/executor/src/debugger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use crate::adapter::{AxonExecutorAdapter, MPTTrie};
use crate::{AxonExecutor, RocksTrieDB};

const GENESIS_PATH: &str = "../../devtools/chain/genesis_single_node.json";
pub const CROSSCHAIN_CONTRACT_ADDRESS: H160 = H160([
180, 132, 253, 72, 14, 89, 134, 33, 99, 143, 56, 15, 64, 70, 151, 205, 159, 88, 176, 248,
]);

pub struct EvmDebugger {
state_root: H256,
Expand Down
10 changes: 2 additions & 8 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ mod vm;
pub use crate::adapter::{AxonExecutorAdapter, MPTTrie, RocksTrieDB};
pub use crate::system::NATIVE_TOKEN_ISSUE_ADDRESS;
pub use crate::utils::{code_address, decode_revert_msg, logs_bloom};
pub use crate::vm::{
CROSSCHAIN_CONTRACT_ADDRESS, METADATA_CONTRACT_ADDRESS, WCKB_CONTRACT_ADDRESS,
};

use std::collections::BTreeMap;

Expand Down Expand Up @@ -253,9 +250,6 @@ pub fn is_call_system_script(action: &TransactionAction) -> bool {
}
}

pub fn is_crosschain_transaction(action: &TransactionAction) -> bool {
match action {
TransactionAction::Call(addr) => addr == &CROSSCHAIN_CONTRACT_ADDRESS,
TransactionAction::Create => false,
}
pub fn is_transaction_call(action: &TransactionAction, addr: &H160) -> bool {
action == &TransactionAction::Call(*addr)
}
10 changes: 0 additions & 10 deletions core/executor/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ use evm::executor::stack::{MemoryStackState, PrecompileFn, StackExecutor, StackS
use protocol::traits::{ApplyBackend, Backend};
use protocol::types::{Config, SignedTransaction, TransactionAction, TxResp, H160};

pub const METADATA_CONTRACT_ADDRESS: H160 = H160([
176, 13, 97, 107, 130, 12, 57, 97, 158, 226, 158, 81, 68, 208, 34, 108, 248, 181, 193, 90,
]);
pub const WCKB_CONTRACT_ADDRESS: H160 = H160([
74, 245, 236, 94, 61, 41, 217, 221, 215, 244, 191, 145, 160, 34, 19, 28, 65, 183, 35, 82,
]);
pub const CROSSCHAIN_CONTRACT_ADDRESS: H160 = H160([
180, 132, 253, 72, 14, 89, 134, 33, 99, 143, 56, 15, 64, 70, 151, 205, 159, 88, 176, 248,
]);

// deprecated
#[allow(dead_code)]
#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion core/mempool/benches/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub async fn new_mempool(
_max_tx_size: u64,
) -> MemPoolImpl<HashMemPoolAdapter> {
let adapter = HashMemPoolAdapter::new();
MemPoolImpl::new(pool_size, 20, adapter, vec![]).await
MemPoolImpl::new(pool_size, 20, adapter, vec![], Default::default()).await
}

pub async fn default_mempool() -> MemPoolImpl<HashMemPoolAdapter> {
Expand Down
13 changes: 8 additions & 5 deletions core/mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use futures::future::try_join_all;

use common_apm::Instant;
use core_executor::{is_call_system_script, is_crosschain_transaction};
use core_executor::{is_call_system_script, is_transaction_call};
use core_network::NetworkContext;
use protocol::traits::{Context, MemPool, MemPoolAdapter};
use protocol::types::{BlockNumber, Hash, PackedTxHashes, SignedTransaction, H160, H256, U256};
Expand All @@ -30,8 +30,9 @@ use crate::context::TxContext;
use crate::pool::PriorityPool;

pub struct MemPoolImpl<Adapter> {
pool: PriorityPool,
adapter: Arc<Adapter>,
pool: PriorityPool,
adapter: Arc<Adapter>,
cross_chain_address: H160,
}

impl<Adapter> MemPoolImpl<Adapter>
Expand All @@ -43,10 +44,12 @@ where
timeout_gap: u64,
adapter: Adapter,
initial_txs: Vec<SignedTransaction>,
cross_chain_address: H160,
) -> Self {
let mempool = MemPoolImpl {
pool: PriorityPool::new(pool_size, timeout_gap).await,
pool: PriorityPool::new(pool_size, timeout_gap).await,
adapter: Arc::new(adapter),
cross_chain_address,
};

for tx in initial_txs.into_iter() {
Expand Down Expand Up @@ -188,7 +191,7 @@ where
{
async fn insert(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()> {
let is_call_system_script = is_call_system_script(tx.transaction.unsigned.action())
|| is_crosschain_transaction(tx.transaction.unsigned.action());
|| is_transaction_call(tx.transaction.unsigned.action(), &self.cross_chain_address);

log::debug!(
"[mempool]: is call system script {:?}",
Expand Down
2 changes: 1 addition & 1 deletion core/mempool/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async fn new_mempool(
_max_tx_size: u64,
) -> MemPoolImpl<HashMemPoolAdapter> {
let adapter = HashMemPoolAdapter::new();
MemPoolImpl::new(pool_size, 20, adapter, vec![]).await
MemPoolImpl::new(pool_size, 20, adapter, vec![], Default::default()).await
}

fn check_hash(tx: &SignedTransaction) -> ProtocolResult<()> {
Expand Down
16 changes: 9 additions & 7 deletions core/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ use ethers_core::abi::{
use parking_lot::RwLock;

use protocol::traits::{Context, MetadataControl, MetadataControlAdapter};
use protocol::types::{ExitReason, Hash, Header, Hex, Metadata, MetadataVersion, ValidatorExtend};
use protocol::types::{
ExitReason, Hash, Header, Hex, Metadata, MetadataVersion, ValidatorExtend, H160,
};
use protocol::{Display, ProtocolError, ProtocolErrorKind, ProtocolResult};

use core_executor::METADATA_CONTRACT_ADDRESS;

type Epoch = u64;

lazy_static::lazy_static! {
pub static ref EPOCH_LEN: ArcSwap<u64> = ArcSwap::from_pointee(u64::MAX);
}

pub struct MetadataController<Adapter> {
adapter: Arc<Adapter>,
metadata_cache: RwLock<BTreeMap<Epoch, Metadata>>,
adapter: Arc<Adapter>,
metadata_cache: RwLock<BTreeMap<Epoch, Metadata>>,
metadata_address: H160,
}

impl<Adapter> MetadataControl for MetadataController<Adapter>
Expand Down Expand Up @@ -82,11 +83,12 @@ where
}

impl<Adapter: MetadataControlAdapter> MetadataController<Adapter> {
pub fn new(adapter: Arc<Adapter>, epoch_len: u64) -> Self {
pub fn new(adapter: Arc<Adapter>, epoch_len: u64, metadata_address: H160) -> Self {
EPOCH_LEN.swap(Arc::new(epoch_len));
MetadataController {
adapter,
metadata_cache: RwLock::new(BTreeMap::new()),
metadata_address,
}
}

Expand All @@ -99,7 +101,7 @@ impl<Adapter: MetadataControlAdapter> MetadataController<Adapter> {
let res = self.adapter.call_evm(
Context::new(),
header,
METADATA_CONTRACT_ADDRESS,
self.metadata_address,
payload.encode(),
)?;

Expand Down
9 changes: 6 additions & 3 deletions core/metadata/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ use std::sync::Arc;
use ethers_core::abi::AbiEncode;

use core_executor::adapter::{MPTTrie, RocksTrieDB};
use core_executor::{AxonExecutor, AxonExecutorAdapter, METADATA_CONTRACT_ADDRESS};
use core_executor::{AxonExecutor, AxonExecutorAdapter};
use core_storage::{adapter::rocks::RocksAdapter, ImplStorage};
use protocol::codec::ProtocolCodec;
use protocol::traits::{CommonStorage, Context, Executor, Storage};
use protocol::types::{
Account, Address, Bytes, Eip1559Transaction, Header, Metadata, Proposal, Public, RichBlock,
SignatureComponents, SignedTransaction, TransactionAction, UnsignedTransaction,
UnverifiedTransaction, H256, NIL_DATA, RLP_NULL, U256,
UnverifiedTransaction, H160, H256, NIL_DATA, RLP_NULL, U256,
};

use crate::{calc_epoch, metadata_abi as abi, MetadataAdapterImpl, MetadataController, EPOCH_LEN};

const GENESIS_PATH: &str = "../../devtools/chain/genesis_single_node.json";
pub const METADATA_CONTRACT_ADDRESS: H160 = H160([
176, 13, 97, 107, 130, 12, 57, 97, 158, 226, 158, 81, 68, 208, 34, 108, 248, 181, 193, 90,
]);

struct TestHandle {
storage: Arc<ImplStorage<RocksAdapter>>,
Expand Down Expand Up @@ -105,7 +108,7 @@ impl TestHandle {
) -> MetadataController<MetadataAdapterImpl<ImplStorage<RocksAdapter>, RocksTrieDB>> {
let adapter =
MetadataAdapterImpl::new(Arc::clone(&self.storage), Arc::clone(&self.trie_db));
MetadataController::new(Arc::new(adapter), epoch_len)
MetadataController::new(Arc::new(adapter), epoch_len, METADATA_CONTRACT_ADDRESS)
}

pub fn exec(&mut self, txs: Vec<SignedTransaction>) {
Expand Down
6 changes: 5 additions & 1 deletion core/run/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ impl Axon {
let metadata_controller = Arc::new(MetadataController::new(
Arc::new(metadata_adapter),
self.config.epoch_len,
self.config.metadata_contract_address,
));

let metadata = metadata_controller.get_metadata(Context::new(), &current_block.header)?;
Expand Down Expand Up @@ -351,6 +352,7 @@ impl Axon {
config.mempool.timeout_gap,
mempool_adapter,
current_stxs.clone(),
config.crosschain_contract_address,
)
.await,
);
Expand Down Expand Up @@ -468,6 +470,8 @@ impl Axon {
config.cross_client.clone(),
Arc::clone(&ckb_client),
Arc::new(crosschain_adapter),
config.crosschain_contract_address,
config.wckb_contract_address,
)
.await;

Expand Down Expand Up @@ -512,7 +516,7 @@ impl Axon {

let overlord_consensus = Arc::new(OverlordConsensus::new(
status_agent.clone(),
self.config.metadata_contract_address.into(),
self.config.metadata_contract_address,
node_info,
Arc::clone(&crypto),
Arc::clone(&txs_wal),
Expand Down
5 changes: 3 additions & 2 deletions devtools/chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ data_path = "./devtools/chain/data"

epoch_len = 100_000_000

metadata_contract_address = "0xc2fd48d60ae16b3fe6e333a9a13763691970d9373d4fab7cc323d7ba06fa9986"
crosschain_contract_address = "0x2c3a9349df5b162519b17621f67bc4e50d1df92b0e4c61794a4517af6a995cb2"
metadata_contract_address = "0xb00d616b820c39619ee29e5144d0226cf8b5c15a"
crosschain_contract_address = "0xb484fd480e598621638f380f404697cd9f58b0f8"
wckb_contract_address = "0x4af5ec5e3d29d9ddd7f4bf91a022131c41b72352"

[accounts]
mnemonic = "test test test test test test test test test test test junk"
Expand Down
5 changes: 3 additions & 2 deletions devtools/chain/k8s/node_1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ data_path = "./devtools/chain/data1"

epoch_len = 100_000_000

metadata_contract_address = "0xc2fd48d60ae16b3fe6e333a9a13763691970d9373d4fab7cc323d7ba06fa9986"
crosschain_contract_address = "0x2c3a9349df5b162519b17621f67bc4e50d1df92b0e4c61794a4517af6a995cb2"
metadata_contract_address = "0xb00d616b820c39619ee29e5144d0226cf8b5c15a"
crosschain_contract_address = "0xb484fd480e598621638f380f404697cd9f58b0f8"
wckb_contract_address = "0x4af5ec5e3d29d9ddd7f4bf91a022131c41b72352"

[accounts]
mnemonic = "test test test test test test test test test test test junk"
Expand Down
5 changes: 3 additions & 2 deletions devtools/chain/k8s/node_2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ data_path = "./devtools/chain/data2"

epoch_len = 100_000_000

metadata_contract_address = "0xc2fd48d60ae16b3fe6e333a9a13763691970d9373d4fab7cc323d7ba06fa9986"
crosschain_contract_address = "0x2c3a9349df5b162519b17621f67bc4e50d1df92b0e4c61794a4517af6a995cb2"
metadata_contract_address = "0xb00d616b820c39619ee29e5144d0226cf8b5c15a"
crosschain_contract_address = "0xb484fd480e598621638f380f404697cd9f58b0f8"
wckb_contract_address = "0x4af5ec5e3d29d9ddd7f4bf91a022131c41b72352"

[accounts]
mnemonic = "test test test test test test test test test test test junk"
Expand Down
5 changes: 3 additions & 2 deletions devtools/chain/k8s/node_3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ data_path = "./devtools/chain/data3"

epoch_len = 100_000_000

metadata_contract_address = "0xc2fd48d60ae16b3fe6e333a9a13763691970d9373d4fab7cc323d7ba06fa9986"
crosschain_contract_address = "0x2c3a9349df5b162519b17621f67bc4e50d1df92b0e4c61794a4517af6a995cb2"
metadata_contract_address = "0xb00d616b820c39619ee29e5144d0226cf8b5c15a"
crosschain_contract_address = "0xb484fd480e598621638f380f404697cd9f58b0f8"
wckb_contract_address = "0x4af5ec5e3d29d9ddd7f4bf91a022131c41b72352"

[accounts]
mnemonic = "test test test test test test test test test test test junk"
Expand Down
Loading