Skip to content

Commit

Permalink
chore: enable contracts that remove a-instructions (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuralyk authored Dec 14, 2023
2 parents 5a20e78 + ffcfd49 commit 1e0a1d8
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 119 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ibc-packet-trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ jobs:
# for forcerelay-ckb-sdk
FORCERELAY_CKB_SDK_COMMIT: ${{ vars.FORCERELAY_CKB_SDK_COMMIT || 'main' }}
AXON_RECEIVER: ${{ vars.AXON_RECEIVER || 'f39fd6e51aad88f6f4ce6ab8827279cfffb92266' }}
SUDT_AMOUNT: 1000
SUDT_AMOUNT: ${{ vars.SUDT_TRANSFER_AMOUNT || 1000 }}
SDK_WORKSPACE: ${{ github.workspace }}/forcerelay-ckb-sdk
SDK_CONFIG: ${{ github.workspace }}/e2e/schedule/sdk.config.toml
# for ibc-solidity-contract
AXON_HTTP_RPC_URL: https://rpc-alphanet-axon.ckbapp.dev
IBC_SOLIDITY_CONTRACT_COMMIT: ${{ vars.IBC_SOLIDITY_CONTRACT_COMMIT || 'e0d1f4bf20c40aad721bff5838d8a3fa80c94585' }}
IBC_SOLIDITY_CONTRACT_COMMIT: ${{ vars.IBC_SOLIDITY_CONTRACT_COMMIT || 'master' }}
CONTRACT_WORKSPACE: ${{ github.workspace }}/ibc-solidity-contract
TRANSFER_CONTRACT_ADDRESS: ${{ vars.TRANSFER_CONTRACT_ADDRESS || '0x9E545E3C0baAB3E08CdfD552C960A1050f373042' }}
CHANNEL: channel-8
DENOM: f2a14f50a56b9aab8e960cb1b2c7f1152d7523e6cacb45b1ab2a94acb83e0233
AMOUNT: 990
TRANSFER_CONTRACT_ADDRESS: ${{ vars.TRANSFER_CONTRACT_ADDRESS || '0x5FeaeBfB4439F3516c74939A9D04e95AFE82C4ae' }}
CHANNEL: ${{ vars.AXON_CHANNEL || 'channel-0' }}
DENOM: ${{ vars.AXON_DENOM || 'f2a14f50a56b9aab8e960cb1b2c7f1152d7523e6cacb45b1ab2a94acb83e0233' }}
AMOUNT: ${{ vars.AXON_TRANSFER_AMOUNT || 990 }}
# 1. firstly, run ibc-solidity-contract script to send SendPacket to Axon and then, trigger RecvPacket process via forcerleay-ckb-sdk
# 2. secondly, directly run forcerelay-ckb-sdk to send SendPacket to CKB, and then, it'll automatically listen AckPacket
steps:
Expand Down
67 changes: 23 additions & 44 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 = "a3c3c3a2" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "adb8bcfb033d111174f06b88609aded5b9f2a181" }
cstr_core = "0.2.6"
rlp = "0.5.2"

Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub mod contract;
mod eth_err;
mod monitor;
mod msg;
mod rpc;
pub mod rpc;
pub mod utils;

pub use rpc::AxonRpc;
Expand Down Expand Up @@ -1232,7 +1232,7 @@ impl AxonChain {
self.config.id.clone(),
self.config.websocket_addr.clone(),
self.config.contract_address,
// header_receiver,
self.config.restore_block_count,
self.rt.clone(),
)
.map_err(Error::event_monitor)?;
Expand Down
46 changes: 44 additions & 2 deletions crates/relayer/src/chain/axon/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl AxonEventMonitor {
chain_id: ChainId,
websocket_addr: WebSocketClientUrl,
contract_address: Address,
reprocess_block_count: u64,
rt: Arc<TokioRuntime>,
) -> Result<(Self, TxMonitorCmd)> {
let (tx_cmd, rx_cmd) = channel::unbounded();
Expand All @@ -57,7 +58,9 @@ impl AxonEventMonitor {
let start_block_number = rt
.block_on(client.get_block_number())
.map_err(|e| Error::others(e.to_string()))?
.as_u64();
.as_u64()
.checked_sub(reprocess_block_count)
.expect("check-sub axon block number");

let event_bus = EventBus::new();
let monitor = Self {
Expand Down Expand Up @@ -87,6 +90,41 @@ impl AxonEventMonitor {
Ok(client)
}

pub fn reprocess_previous_events(&mut self) -> Result<()> {
let contract = Arc::new(Contract::new(
self.contract_address,
Arc::clone(&self.client),
));
let latest_block_number = self
.rt
.block_on(self.client.get_block_number())
.map_err(|e| Error::others(e.to_string()))?
.as_u64();
let mut reprocessed = 0;
self.rt
.block_on(
contract
.events()
.from_block(self.start_block_number)
.to_block(latest_block_number)
.query_with_meta(),
)
.map_err(|e| Error::others(e.to_string()))?
.into_iter()
.for_each(|(event, meta)| {
if matches!(
event,
OwnableIBCHandlerEvents::SendPacketFilter(_)
| OwnableIBCHandlerEvents::WriteAcknowledgementFilter(_)
) {
self.process_event(event, meta);
reprocessed += 1;
}
});
debug!("Axon reprocessed {} events", reprocessed);
Ok(())
}

#[allow(clippy::while_let_loop)]
#[instrument(
name = "axon_event_monitor",
Expand All @@ -96,7 +134,11 @@ impl AxonEventMonitor {
)]
pub fn run(mut self) {
if let Next::Continue = self.update_subscribe(false) {
info!("start Axon event monitor for {}", self.chain_id,);
info!("start Axon event monitor for {}", self.chain_id);
// reprocess messages from Axon to CKB that have failed in accident
if let Err(e) = self.reprocess_previous_events() {
error!("Axon reprocess failed: {e}");
}
let mut contract = Contract::new(self.contract_address, Arc::clone(&self.client));
info!(
"start to fetch IBC events from block {}",
Expand Down
22 changes: 18 additions & 4 deletions crates/relayer/src/chain/ckb4ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ impl Ckb4IbcChain {
) -> Result<Vec<(IbcPacket, CellInput, u64, H256)>, Error> {
// packets with particular sequence are only 4: Send, WriteAck, Recv and AckPacket
let limit = if sequence.is_some() { 4 } else { 20 };
let search_key = get_packet_search_key(&self.config, channel_id, port_id, sequence)?;
let search_key = get_packet_search_key(
&self.config,
self.counterparty_client_type(),
channel_id,
port_id,
sequence,
)?;
let mut result = vec![];
let mut cursor = None;
loop {
Expand Down Expand Up @@ -732,7 +738,10 @@ impl ChainEndpoint for Ckb4IbcChain {
result_events.push(ibc_event_with_height);
}
Err(err) => {
warn!("wait transaction failed: {err}");
let json_tx = serde_json::to_string_pretty(&tx).unwrap();
let error =
format!("wait transaction failed: {err}\n\n======== transaction info ========\n\n{json_tx}\n");
warn!("{error}");
continue;
}
}
Expand Down Expand Up @@ -1642,8 +1651,13 @@ impl ChainEndpoint for Ckb4IbcChain {

// search frist packet cell on-chain if cache is missing
if tx_hash.is_none() {
let packet_key =
get_packet_search_key(&self.config, &channel_id, &port_id, Some(sequence))?;
let packet_key = get_packet_search_key(
&self.config,
self.counterparty_client_type(),
&channel_id,
&port_id,
Some(sequence),
)?;
let result = self
.rt
.block_on(self.rpc_client.fetch_live_cells(packet_key, 1, None))?;
Expand Down
25 changes: 15 additions & 10 deletions crates/relayer/src/chain/ckb4ibc/message/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ pub fn convert_recv_packet_to_tx<C: MsgToTxConverter>(

let port_id = convert_port_id_to_array(&msg.packet.destination_port)?;
let channel_number = get_channel_number(&channel_id)?;
let packet_args = PacketArgs {
channel_id: channel_number,
port_id,
sequence: packet.sequence,
};

let connection_id = new_channel_end.connection_hops[0].parse().unwrap();
let connection_args = converter
Expand All @@ -91,6 +86,13 @@ pub fn convert_recv_packet_to_tx<C: MsgToTxConverter>(
port_id,
};

let packet_args = PacketArgs {
ibc_handler_address: connection_args.ibc_handler_address,
channel_id: channel_number,
port_id,
sequence: packet.sequence,
};

let packet = IbcPacket {
packet,
status: PacketStatus::Recv,
Expand Down Expand Up @@ -195,11 +197,7 @@ pub fn convert_ack_packet_to_tx<C: MsgToTxConverter>(
let channel_number = get_channel_number(&channel_id)?;
let packet = convert_ibc_packet(&msg.packet);
let port_id = convert_port_id_to_array(&msg.packet.source_port)?;
let packet_args = PacketArgs {
sequence: packet.sequence,
channel_id: channel_number,
port_id,
};
let sequence = packet.sequence;

let new_packet_object = IbcPacket {
packet,
Expand Down Expand Up @@ -231,6 +229,13 @@ pub fn convert_ack_packet_to_tx<C: MsgToTxConverter>(
port_id,
};

let packet_args = PacketArgs {
ibc_handler_address: connection_args.ibc_handler_address,
sequence,
channel_id: channel_number,
port_id,
};

let channel_lock = get_channel_lock_script(converter, new_channel_args.to_args());
let packet_lock = get_packet_lock_script(converter, packet_args.to_args());

Expand Down
Loading

0 comments on commit 1e0a1d8

Please sign in to comment.