diff --git a/Cargo.lock b/Cargo.lock index da0c8b8..e9cb80e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -992,6 +992,7 @@ dependencies = [ "ckb-jsonrpc-types", "ckb-types", "jsonrpc-core", + "log", "reqwest", "serde", "serde_json", diff --git a/emitter-core/Cargo.toml b/emitter-core/Cargo.toml index 5296b00..684728f 100644 --- a/emitter-core/Cargo.toml +++ b/emitter-core/Cargo.toml @@ -15,6 +15,7 @@ reqwest = { version = "0.11", features = ["json"], optional = true } jsonrpc-core = "18.0" async-trait = "0.1" tokio = { version = "1", features = ["time"] } +log = "0.4" [features] default = ["client"] diff --git a/emitter-core/src/lib.rs b/emitter-core/src/lib.rs index 3228022..51cbe84 100644 --- a/emitter-core/src/lib.rs +++ b/emitter-core/src/lib.rs @@ -6,9 +6,9 @@ macro_rules! rpc_get { Ok(r) => break r, Err(e) => match e.kind() { ConnectionRefused | ConnectionReset | ConnectionAborted | BrokenPipe => { - panic!("{e}") + log::error!("rpc get with serious error: {e}") } - _ => (), + _ => log::warn!("rpc get with error: {e}"), }, } } diff --git a/emitter/src/emit_data/eth_tx.rs b/emitter/src/emit_data/eth_tx.rs index f1aff3d..25ecd14 100644 --- a/emitter/src/emit_data/eth_tx.rs +++ b/emitter/src/emit_data/eth_tx.rs @@ -30,11 +30,10 @@ pub async fn send_eth_tx(axon_url: &str, data: Vec, to: Address) -> Result<( let tx = Legacy(transaction_request); let signature: Signature = wallet.sign_transaction(&tx).await?; - provider - .send_raw_transaction(tx.rlp_signed(&signature)) - .await? - .await? - .expect("failed to send eth tx"); + let tx_raw = tx.rlp_signed(&signature); + while let None = provider.send_raw_transaction(tx_raw.clone()).await?.await? { + log::warn!("can't get axon tx receipt, send tx fails, retry...") + } Ok(()) } diff --git a/emitter/src/main.rs b/emitter/src/main.rs index 63324b0..ed3657b 100644 --- a/emitter/src/main.rs +++ b/emitter/src/main.rs @@ -129,16 +129,19 @@ async fn main() { } async fn submit_cells(axon_url: &str, submits: Vec) { - if let Err(e) = send_eth_tx(axon_url, convert_blocks(submits), IMAGE_CELL_ADDRESS).await { - println!("emitter submit cells tx error: {e}") - }; + let data = convert_blocks(submits); + + while let Err(e) = send_eth_tx(axon_url, data.clone(), IMAGE_CELL_ADDRESS).await { + log::warn!("emitter submit cells tx error: {e}") + } } async fn submit_headers(axon_url: &str, headers: Vec) { - if let Err(e) = send_eth_tx(axon_url, convert_headers(headers), CKB_LIGHT_CLIENT_ADDRESS).await - { - println!("emitter submit headers tx error: {e}") - }; + let data = convert_headers(headers); + + while let Err(e) = send_eth_tx(axon_url, data.clone(), CKB_LIGHT_CLIENT_ADDRESS).await { + log::warn!("emitter submit headers tx error: {e}") + } } struct ScanTipInner(AtomicPtr);