Skip to content

Commit

Permalink
refactor: sync with axon new start commands & axon-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyuanhust committed Oct 23, 2023
1 parent abcfe1b commit 7d2047f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ibc-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
timeout-minutes: 60
env:
SRC_DIR: ${{ github.workspace }}/ibc-test-src
AXON_COMMIT: d03d2bb7cb3dcdc03319c3a74beeee6715e7f448
IBC_CONTRACT_COMMIT: 35290d79c9fa45583b00f228dd3ed7e8468ccc67
AXON_COMMIT: a088cf83d29b8658a7d2ae96a74a53bffb743f03
IBC_CONTRACT_COMMIT: c5417573ec15c8aaab048caa1ec5f3bd50c2170e
strategy:
fail-fast: false
matrix:
Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $ yarn migrate > migrate.log | tail -f migrate.log
After running `yarn migrate`, the `OwnableIBCHandler` address is listing in console, we record it and mark as **`YOUR_IBC_AXON_ADDRESS`** to use later.

### Contract Deployment on CKB
Detailed deployment steps can be found in [ibc-ckb-contracts](https://github.com/synapseweb3/ibc-ckb-contracts). Alternatively, you can find pre-deployed contracts TYPE_ARGS on both testnet and mainnet:
Detailed deployment steps can be found in [forcerelay-ckb-contracts](https://github.com/synapseweb3/forcerelay-ckb-contracts). Alternatively, you can find pre-deployed contracts TYPE_ARGS on both testnet and mainnet:
||Mainnet|Testnet|
|-|-|-|
|connection|WIP|WIP|
Expand All @@ -58,7 +58,7 @@ Unlike Axon, business modules cannot be registered directly with a contract on C
It's important to note that the IBC port on CKB corresponds to the `LOCK_HASH` of your wallet cell on CKB, which we will refer to as `WALLET_LOCK_HASH` for future use.

### Installation and Setting
We recommand you to download the pre-compiled binary, or you can compile mannully from the source code, which requires `Rust ^v1.72.0` installed:
We recommend you to download the pre-compiled binary, or you can compile mannully from the source code, which requires `Rust ^v1.72.0` installed:

```
$ git clone https://github.com/synapseweb3/forcerelay
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tree_hash_derive = { git = "https://github.com/synapseweb3/lighthouse", rev = "2
thiserror = "1.0"
ethereum-types = "0.14.1"
hex = "0.4"
axon-tools = { version = "0.1.1", features = ["impl-serde", "proof"] }
axon-tools = { git = "https://github.com/axonweb3/axon-tools.git", branch = "main", version = "0.1.1", features = ["impl-serde", "proof"] }
strum = { version = "0.24.1", features = ["derive"] }

[dependencies.tendermint]
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tree_hash = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6"

eth_light_client_in_ckb-verification = { version = "0.2.1", git = "https://github.com/synapseweb3/eth-light-client-in-ckb", tag = "v0.2.1" }
eth_light_client_in_ckb-prover = { version = "0.2.1", git = "https://github.com/synapseweb3/eth-light-client-in-ckb", tag = "v0.2.1" }
axon-tools = { version = "0.1.1", features = ["proof", "impl-serde"] }
axon-tools = { git = "https://github.com/axonweb3/axon-tools.git", branch = "main", version = "0.1.1", features = ["impl-serde", "proof"] }

subtle-encoding = "0.5"
humantime-serde = "1.1.1"
Expand Down
32 changes: 21 additions & 11 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, str::FromStr, sync::Arc, thread, time::Duration};

use axon_tools::types::{AxonBlock, Proof as AxonProof, Validator};
use axon_tools::types::{AxonBlock, Proof as AxonProof, ValidatorExtend};
use eth2_types::Hash256;
use k256::ecdsa::SigningKey;
use rlp::Encodable;
Expand Down Expand Up @@ -1176,12 +1176,17 @@ impl AxonChain {
.rt
.block_on(self.get_proofs_ingredients(block_number))?;

// FIXME: keep it commentted until Axon team fixed this verify issue
//
// check the validation of receipts mpt proof
// let key = rlp::encode(&receipt.transaction_index.as_u64());
// axon_tools::verify_trie_proof(block.header.receipts_root, &key, receipt_proof.clone())
// .map_err(|e| Error::rpc_response(format!("unverified receipts mpt: {e:?}")))?;
let key = rlp::encode(&receipt.transaction_index.as_u64());
let result =
axon_tools::verify_trie_proof(block.header.receipts_root, &key, receipt_proof.clone())
.map_err(|e| Error::rpc_response(format!("unverified receipts mpt: {e:?}")))?;
if result.is_none() {
return Err(Error::rpc_response(format!(
"trie key: {} doesn't exist",
receipt.transaction_index
)));
}

let object_proof =
to_ckb_like_object_proof(&receipt, &receipt_proof, &block, &state_root, &block_proof)
Expand All @@ -1201,16 +1206,20 @@ impl AxonChain {
.unwrap();

// check the validation of Axon block
axon_tools::verify_proof(block, state_root, &mut validators, block_proof)
.map_err(|_| Error::rpc_response("unverified axon block".to_owned()))?;
axon_tools::verify_proof(block, state_root, &mut validators, block_proof).map_err(
|err| {
let err_msg = format!("unverified axon block, err: {:?}", err);
Error::rpc_response(err_msg)
},
)?;

Ok(proofs)
}

async fn get_proofs_ingredients(
&self,
block_number: U64,
) -> Result<(AxonBlock, Hash256, AxonProof, Vec<Validator>), Error> {
) -> Result<(AxonBlock, Hash256, AxonProof, Vec<ValidatorExtend>), Error> {
let previous_number = block_number
.checked_sub(1u64.into())
.expect("bad block_number");
Expand Down Expand Up @@ -1246,8 +1255,9 @@ impl AxonChain {
.await?
.verifier_list
.into_iter()
.map(|v| Validator {
bls_pub_key: v.bls_pub_key,
.map(|v| ValidatorExtend {
bls_pub_key: v.bls_pub_key.clone(),
pub_key: v.pub_key.clone(),
address: v.address,
propose_weight: v.propose_weight,
vote_weight: v.vote_weight,
Expand Down
2 changes: 1 addition & 1 deletion tools/ibc-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Environment variables:

``` bash
# IBC contracts
export IBC_CONTRACTS_SRC_PATH = <ibc solidity contract source path>
export IBC_CONTRACTS_SRC_PATH=<ibc solidity contract source path>
cd $IBC_CONTRACTS_SRC_PATH && yarn install && yarn compile

# Axon
Expand Down
31 changes: 23 additions & 8 deletions tools/ibc-test/src/framework/utils/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,30 @@ pub(crate) fn prepare_axon_chain(
working_dir.push(dir_path);
let _ = std::fs::remove_dir_all(dir_path);
std::fs::create_dir_all(dir_path).with_context(|| format!("create_dir {:?}", dir_path))?;
let binding = working_dir.join("devtools/chain/specs/single_node");
let chain_spec_dir_path = binding.to_str().unwrap();
std::fs::create_dir_all(chain_spec_dir_path)
.with_context(|| format!("create_chain_spec_dir {:?}", chain_spec_dir_path))?;

// copy configs to working dir
for file in [
"config.toml",
"genesis_single_node.json",
"specs/single_node/chain-spec.toml",
"default.db-options",
"bls.key",
"net.key",
] {
let src_path = axon_src_path.join("devtools/chain").join(file);
std::fs::copy(&src_path, working_dir.join(file))
std::fs::copy(&src_path, working_dir.join("devtools/chain").join(file))
.with_context(|| format!("cp {:?} -> {:?}", &src_path, working_dir.join(file)))?;
}

let chain_config_path = working_dir.join("config.toml");
let genesis_config_path = working_dir.join("genesis_single_node.json");
let chain_config_path = working_dir.join("devtools/chain").join("config.toml");
let chain_spec_path = working_dir
.join("devtools/chain")
.join("specs/single_node/chain-spec.toml");

// Modify configs

let mut config_doc = fs::read_to_string(&chain_config_path)
.with_context(|| format!("read chain config from {:?}", &chain_config_path))?
.parse::<Document>()
Expand All @@ -80,14 +87,22 @@ pub(crate) fn prepare_axon_chain(
fs::write(&chain_config_path, config_doc.to_string())
.with_context(|| format!("write config to {:?}", &chain_config_path))?;

// init axon
let _init_command = Command::new("axon")
.arg("init")
.arg("--config")
.arg(&chain_config_path)
.arg("--chain-spec")
.arg(&chain_spec_path)
.current_dir(&working_dir)
.output()?;

// start process
let chain_process = ChildProcess::new(
Command::new("axon")
.arg("run")
.arg("-c")
.arg("--config")
.arg(&chain_config_path)
.arg("-g")
.arg(&genesis_config_path)
.current_dir(&working_dir)
.stdout(Stdio::null())
.stderr(Stdio::null())
Expand Down

0 comments on commit 7d2047f

Please sign in to comment.