Skip to content

Commit

Permalink
feat: complete sync of cells and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Nov 6, 2023
1 parent 1a7b60c commit c71f6e4
Show file tree
Hide file tree
Showing 14 changed files with 1,328 additions and 113 deletions.
26 changes: 3 additions & 23 deletions crates/relayer/src/chain/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ use ibc_proto::{
use ibc_relayer_types::{
applications::ics31_icq::response::CrossChainQueryResponse,
clients::ics07_axon::{
client_state::AxonClientState,
consensus_state::AxonConsensusState,
header::{AxonHeader, AXON_HEADER_TYPE_URL},
client_state::AxonClientState, consensus_state::AxonConsensusState, header::AxonHeader,
light_block::AxonLightBlock,
},
core::{
Expand Down Expand Up @@ -1169,15 +1167,15 @@ impl AxonChain {
let cell_process_manager = CellProcessManager::new(
self.rt.clone(),
&self.config.emitter_ckb_url.to_string(),
self.client.clone(),
self.chain_id,
self.contract_provider()?,
self.config.emitter_scan_start_block_number,
);

let (mut event_monitor, monitor_tx) = AxonEventMonitor::new(
self.config.id.clone(),
self.config.websocket_addr.clone(),
self.config.contract_address,
// header_receiver,
self.rt.clone(),
ibc_cache.clone(),
cell_process_manager,
Expand Down Expand Up @@ -1367,24 +1365,6 @@ impl AxonChain {
create_client::TYPE_URL => {
convert!(self, msg, MsgCreateClient, create_client)
}
// TODO: this update_client uses Hermes internal message to handle the Axon-specific function,
// so maybe there is possibility to create a new one to do so
update_client::TYPE_URL => {
let msg = update_client::MsgUpdateClient::from_any(msg)
.map_err(|e| Error::protobuf_decode(update_client::TYPE_URL.to_string(), e))?;
let bytes = msg.header.value.as_slice();
let type_url = msg.header.type_url;
let to = match type_url.as_str() {
AXON_HEADER_TYPE_URL => self.config.ckb_light_client_contract_address,
"CELL_TYPE_URL" => self.config.image_cell_contract_address,
type_url => {
return Err(Error::other_error(format!("unknown type_url {type_url}")))
}
};
let tx = TransactionRequest::new().to(to).data(bytes.to_vec());
self.rt
.block_on(async { Ok(self.client.send_transaction(tx, None).await?.await?) })
}
// connection
conn_open_init::TYPE_URL => {
convert!(self, msg, MsgConnectionOpenInit, connection_open_init)
Expand Down
189 changes: 189 additions & 0 deletions crates/relayer/src/chain/axon/contract/abi/ImageCellContract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"contractName": "image_cell_contract",
"abi": [
{
"inputs": [
{
"components": [
{
"components": [
{
"internalType": "bytes32",
"name": "txHash",
"type": "bytes32"
},
{
"internalType": "uint32",
"name": "index",
"type": "uint32"
}
],
"internalType": "struct CkbType.OutPoint[]",
"name": "txInputs",
"type": "tuple[]"
},
{
"components": [
{
"internalType": "bytes32",
"name": "txHash",
"type": "bytes32"
},
{
"internalType": "uint32",
"name": "index",
"type": "uint32"
}
],
"internalType": "struct CkbType.OutPoint[]",
"name": "txOutputs",
"type": "tuple[]"
}
],
"internalType": "struct ImageCell.BlockRollBlack[]",
"name": "blocks",
"type": "tuple[]"
}
],
"name": "rollback",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "allowRead",
"type": "bool"
}
],
"name": "setState",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"components": [
{
"internalType": "bytes32",
"name": "txHash",
"type": "bytes32"
},
{
"internalType": "uint32",
"name": "index",
"type": "uint32"
}
],
"internalType": "struct CkbType.OutPoint[]",
"name": "txInputs",
"type": "tuple[]"
},
{
"components": [
{
"components": [
{
"internalType": "bytes32",
"name": "txHash",
"type": "bytes32"
},
{
"internalType": "uint32",
"name": "index",
"type": "uint32"
}
],
"internalType": "struct CkbType.OutPoint",
"name": "outPoint",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint64",
"name": "capacity",
"type": "uint64"
},
{
"components": [
{
"internalType": "bytes32",
"name": "codeHash",
"type": "bytes32"
},
{
"internalType": "enum CkbType.ScriptHashType",
"name": "hashType",
"type": "uint8"
},
{
"internalType": "bytes",
"name": "args",
"type": "bytes"
}
],
"internalType": "struct CkbType.Script",
"name": "lock",
"type": "tuple"
},
{
"components": [
{
"internalType": "bytes32",
"name": "codeHash",
"type": "bytes32"
},
{
"internalType": "enum CkbType.ScriptHashType",
"name": "hashType",
"type": "uint8"
},
{
"internalType": "bytes",
"name": "args",
"type": "bytes"
}
],
"internalType": "struct CkbType.Script[]",
"name": "type_",
"type": "tuple[]"
}
],
"internalType": "struct CkbType.CellOutput",
"name": "output",
"type": "tuple"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"internalType": "struct CkbType.CellInfo[]",
"name": "txOutputs",
"type": "tuple[]"
}
],
"internalType": "struct ImageCell.BlockUpdate[]",
"name": "blocks",
"type": "tuple[]"
}
],
"name": "update",
"outputs": [],
"stateMutability": "view",
"type": "function"
}
]
}
106 changes: 106 additions & 0 deletions crates/relayer/src/chain/axon/contract/abi/LightClientContract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"contractName": "ckb_light_client_contract",
"abi": [
{
"inputs": [
{
"internalType": "bytes32[]",
"name": "blockHashs",
"type": "bytes32[]"
}
],
"name": "rollback",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "allowRead",
"type": "bool"
}
],
"name": "setState",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint32",
"name": "version",
"type": "uint32"
},
{
"internalType": "uint32",
"name": "compactTarget",
"type": "uint32"
},
{
"internalType": "uint64",
"name": "timestamp",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "number",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "epoch",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "parentHash",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "transactionsRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "proposalsHash",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "unclesHash",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "dao",
"type": "bytes32"
},
{
"internalType": "uint128",
"name": "nonce",
"type": "uint128"
},
{
"internalType": "bytes32",
"name": "blockHash",
"type": "bytes32"
}
],
"internalType": "struct CkbType.Header[]",
"name": "headers",
"type": "tuple[]"
}
],
"name": "update",
"outputs": [],
"stateMutability": "view",
"type": "function"
}
]
}
Loading

0 comments on commit c71f6e4

Please sign in to comment.