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

feat: prepare ckb4ibc packet test #280

Merged
merged 10 commits into from
Aug 22, 2023
Merged
13 changes: 6 additions & 7 deletions .github/workflows/ckb4ibc-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Ckb4ibc
on:
pull_request:
path:
paths:
- .github/workflows/ckb4ibc-test.yaml
- Cargo.toml
- Cargo.lock
Expand All @@ -21,9 +21,8 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:
integration-test:
ckb4ibc-test:
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
Expand All @@ -48,10 +47,10 @@ jobs:
with:
python-version: '3.10'
- uses: actions-rs/cargo@v1
- env:
CHAIN_COMMAND_PATHS=ckb
ACCOUNT_PREFIXES=ckb
RUST_LOG=info
env:
CHAIN_COMMAND_PATHS: ckb
ACCOUNT_PREFIXES: ckb
RUST_LOG: info
with:
command: test
args: -p ckb4ibc-test --all-features -- --nocapture
2 changes: 1 addition & 1 deletion .github/workflows/forcrerelay-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Forcerelay
on:
pull_request:
path:
paths:
- .github/workflows/forcerelay-test.yaml
- Cargo.toml
- Cargo.lock
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

59 changes: 37 additions & 22 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
[package]
name = "ibc-relayer"
version = "0.23.0"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
keywords = ["blockchain", "consensus", "cosmos", "ibc", "tendermint"]
repository = "https://github.com/informalsystems/hermes"
authors = ["Informal Systems <[email protected]>"]
name = "ibc-relayer"
version = "0.23.0"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
keywords = ["blockchain", "consensus", "cosmos", "ibc", "tendermint"]
repository = "https://github.com/informalsystems/hermes"
authors = ["Informal Systems <[email protected]>"]
rust-version = "1.65"
description = """
description = """
Implementation of an IBC Relayer in Rust, as a library
"""

[package.metadata.docs.rs]
all-features = true

[features]
default = ["flex-error/std", "flex-error/eyre_tracer"]
default = ["flex-error/std", "flex-error/eyre_tracer"]
profiling = []
telemetry = ["ibc-telemetry"]

[dependencies]
ibc-proto = { version = "0.28.0" }
ibc-telemetry = { version = "0.23.0", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.23.0", path = "../relayer-types", features = ["mocks"] }
ibc-relayer-storage = { version = "0.1.0", path = "../relayer-storage" }
ibc-proto = { version = "0.28.0" }
ibc-telemetry = { version = "0.23.0", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.23.0", path = "../relayer-types", features = [
"mocks",
] }
ibc-relayer-storage = { version = "0.1.0", path = "../relayer-storage" }

eth2_types = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6", package = "types" }
eth2_types = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6", package = "types" }
tree_hash_derive = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6" }
tree_hash = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6" }
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" }
Expand All @@ -41,7 +43,12 @@ serde_derive = "1.0"
thiserror = "1.0.40"
toml = "0.5"
tracing = "0.1.36"
tokio = { version = "1.0", features = ["rt-multi-thread", "time", "sync", "parking_lot"] }
tokio = { version = "1.0", features = [
"rt-multi-thread",
"time",
"sync",
"parking_lot",
] }
serde_json = { version = "1" }
bytes = "1.4.0"
prost = { version = "0.11" }
Expand All @@ -53,7 +60,9 @@ bitcoin = { version = "0.29.1", features = ["serde"] }
tiny-bip39 = "1.0.0"
hdpath = "0.6.1"
sha2 = "0.10.6"
tiny-keccak = { version = "2.0.2", features = ["keccak"], default-features = false }
tiny-keccak = { version = "2.0.2", features = [
"keccak",
], default-features = false }
ripemd = "0.1.3"
bech32 = "0.9.1"
itertools = "0.10.5"
Expand All @@ -77,7 +86,7 @@ ed25519-dalek-bip32 = "0.2.0"
generic-array = "0.14.6"
secp256k1 = { version = "0.24.2", features = ["rand-std"] }
async-trait = "0.1"
reqwest = { version = "0.11", features = ["json"]}
reqwest = { version = "0.11", features = ["json"] }
reqwest-middleware = "0.1"
reqwest-retry = "0.1"
eyre = "0.6"
Expand All @@ -90,7 +99,7 @@ jsonrpc-core = "18.0"
strum = { version = "0.24.1", features = ["derive"] }
lazy_static = "1.4.0"

ckb-ics-axon = {git = "https://github.com/synapseweb3/ckb-ics.git", rev = "fe67bd3"}
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "1dc597c" }
cstr_core = "0.2.6"
rlp = "0.5.2"

Expand Down Expand Up @@ -120,10 +129,16 @@ version = "0.30.0"
default-features = false

[dev-dependencies]
ibc-relayer-types = { version = "0.23.0", path = "../relayer-types", features = ["mocks"] }
ibc-relayer-types = { version = "0.23.0", path = "../relayer-types", features = [
"mocks",
] }
serial_test = "1.0.0"
env_logger = "0.10.0"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"] }
tracing-subscriber = { version = "0.3.14", features = [
"fmt",
"env-filter",
"json",
] }
test-log = { version = "0.2.10", features = ["trace"] }
tempfile = "3.3.0"
rand = "0.8.5"
Expand Down
2 changes: 2 additions & 0 deletions crates/relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub mod requests;
pub mod runtime;
pub mod tracking;

pub const SEC_TO_NANO: u64 = 1_000_000_000;

use serde::{de::Error, Deserialize, Serialize};

// NOTE(new): When adding a variant to `ChainType`, make sure to update
Expand Down
85 changes: 59 additions & 26 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use ethers::{
types::{BlockNumber, TransactionRequest, TxHash, U64},
utils::rlp,
};
use ibc_proto::google::protobuf::Any;
use ibc_proto::{
google::protobuf::Any,
ibc::apps::fee::v1::{QueryIncentivizedPacketRequest, QueryIncentivizedPacketResponse},
};
use ibc_relayer_types::{
applications::ics31_icq::response::CrossChainQueryResponse,
clients::ics07_axon::{
Expand All @@ -47,7 +50,7 @@ use ibc_relayer_types::{
msgs::{conn_open_ack, conn_open_confirm, conn_open_init, conn_open_try},
},
ics04_channel::{
channel::{ChannelEnd, IdentifiedChannelEnd},
channel::{ChannelEnd, IdentifiedChannelEnd, Order},
msgs::{
acknowledgement, chan_close_confirm, chan_close_init, chan_open_ack,
chan_open_confirm, chan_open_init, chan_open_try, recv_packet, timeout,
Expand Down Expand Up @@ -610,29 +613,57 @@ impl ChainEndpoint for AxonChain {
.call(),
)
.map_err(convert_err)?;
Ok((vec![has_receipt as u8], None))
if has_receipt {
Ok((vec![1u8], None))
} else {
Ok((vec![], None))
}
}

fn query_unreceived_packets(
&self,
request: QueryUnreceivedPacketsRequest,
) -> Result<Vec<Sequence>, Error> {
let (channel, _) = self.query_channel(
QueryChannelRequest {
port_id: request.port_id.clone(),
channel_id: request.channel_id.clone(),
height: QueryHeight::Latest,
},
IncludeProof::No,
)?;
let mut sequences: Vec<Sequence> = vec![];
for seq in request.packet_commitment_sequences {
let has_receipt = self
.rt
.block_on(
self.contract
.has_packet_receipt(
request.port_id.to_string(),
request.channel_id.to_string(),
seq.into(),
)
.call(),
)
.map_err(convert_err)?;
if !has_receipt {
sequences.push(seq);
if channel.ordering == Order::Ordered {
let (max_recv_seq, _) = self.query_next_sequence_receive(
QueryNextSequenceReceiveRequest {
port_id: request.port_id,
channel_id: request.channel_id,
height: QueryHeight::Latest,
},
IncludeProof::No,
)?;
sequences = request
.packet_commitment_sequences
.into_iter()
.filter(|seq| *seq >= max_recv_seq)
.collect();
} else if channel.ordering == Order::Unordered {
for seq in request.packet_commitment_sequences {
let has_receipt = self
.rt
.block_on(
self.contract
.has_packet_receipt(
request.port_id.to_string(),
request.channel_id.to_string(),
seq.into(),
)
.call(),
)
.map_err(convert_err)?;
if !has_receipt {
sequences.push(seq);
}
}
}
Ok(sequences)
Expand All @@ -643,10 +674,6 @@ impl ChainEndpoint for AxonChain {
request: QueryPacketAcknowledgementRequest,
_include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
if matches!(request.height, QueryHeight::Specific(_)) {
// TODO: no implemention for specific acknowledgement query
warn!("search packet acknoledgement at specific height will fallback to latest");
}
let (commitment, _) = self
.rt
.block_on(
Expand Down Expand Up @@ -750,14 +777,20 @@ impl ChainEndpoint for AxonChain {
&self,
_request: QueryHostConsensusStateRequest,
) -> Result<Self::ConsensusState, Error> {
todo!()
// TODO
warn!("axon query_host_consensus_state() not support");
Ok(AxonConsensusState {})
}

fn query_incentivized_packet(
&self,
_request: ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketRequest,
) -> Result<ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketResponse, Error> {
todo!()
_request: QueryIncentivizedPacketRequest,
) -> Result<QueryIncentivizedPacketResponse, Error> {
// TODO
warn!("axon query_incentivized_packet() not support");
Ok(QueryIncentivizedPacketResponse {
incentivized_packet: None,
})
}

fn build_client_state(
Expand Down
7 changes: 2 additions & 5 deletions crates/relayer/src/chain/axon/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ use ibc_relayer_types::{
Height,
};

use super::{
contract,
utils::{to_timestamp, SEC_TO_NANO},
};
use crate::error::Error;
use super::{contract, utils::to_timestamp};
use crate::{chain::SEC_TO_NANO, error::Error};

fn into_ethers_client_id(value: Option<ClientId>) -> String {
match value {
Expand Down
3 changes: 1 addition & 2 deletions crates/relayer/src/chain/axon/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ckb_ics_axon::proof::{
use rlp::Encodable;

use crate::{
chain::SEC_TO_NANO,
client_state::{AnyClientState, IdentifiedAnyClientState},
consensus_state::AnyConsensusState,
error::Error,
Expand All @@ -21,8 +22,6 @@ use ibc_relayer_types::{
timestamp::Timestamp,
};

pub const SEC_TO_NANO: u64 = 1_000_000_000;

pub fn to_timestamp(seconds: u64) -> Result<Timestamp, Error> {
Timestamp::from_nanoseconds(seconds * SEC_TO_NANO).map_err(convert_err)
}
Expand Down
Loading
Loading