diff --git a/Cargo.lock b/Cargo.lock index fb1670f..4b98235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1268,6 +1268,15 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + [[package]] name = "bumpalo" version = "3.20.2" @@ -1802,7 +1811,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccc2776f0c61eca1ca32528f85548abd1a4be8fb53d1b21c013e4f18da1e7090" dependencies = [ "data-encoding", - "syn 2.0.117", + "syn 1.0.109", ] [[package]] @@ -4999,11 +5008,12 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.19.0" +version = "3.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05839ce67618e14a09b286535c0d9c94e85ef25469b0e13cb4f844e5593eb19" +checksum = "76a5c54c7310e7b8b9577c286d7e399ddd876c3e12b3ed917a8aabc4b96e9e8c" dependencies = [ "base64", + "bs58", "chrono", "hex", "indexmap 1.9.3", @@ -5018,9 +5028,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.19.0" +version = "3.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2ebbe86054f9b45bc3881e865683ccfaccce97b9b4cb53f3039d67f355a334" +checksum = "84d57bc0c8b9a17920c178daa6bb924850d54a9c97ab45194bb8c17ad66bb660" dependencies = [ "darling 0.23.0", "proc-macro2", diff --git a/src/faucet/server_api.rs b/src/faucet/server_api.rs index c27197d..06015f5 100644 --- a/src/faucet/server_api.rs +++ b/src/faucet/server_api.rs @@ -441,16 +441,41 @@ async fn handle_native_claim( { Ok(LotusJson(smsg)) => { let cid = rpc.mpool_push(smsg).await.map_err(ServerFnError::new)?; - let tx_hash = rpc - .eth_get_transaction_hash_by_cid(cid) - .await - .map_err(ServerFnError::new)?; + let tx_hash = poll_eth_tx_hash(&rpc, cid).await?; Ok(tx_hash) } Err(err) => Err(handle_faucet_error(err)), } } +#[cfg(feature = "ssr")] +async fn poll_eth_tx_hash( + rpc: &crate::utils::rpc_context::Provider, + cid: cid::Cid, +) -> Result { + use std::time::Duration; + + const MAX_ATTEMPTS: usize = 3; + const DELAY: Duration = Duration::from_millis(500); + + for attempt in 1..=MAX_ATTEMPTS { + match rpc + .eth_get_transaction_hash_by_cid(cid) + .await + .map_err(ServerFnError::new)? + { + Some(tx_hash) => return Ok(tx_hash), + None => { + log::debug!("polling tx hash ({attempt}/{MAX_ATTEMPTS})"); + worker::Delay::from(DELAY).await; + } + } + } + Err(ServerFnError::ServerError(format!( + "Failed to get tx hash for submitted transaction {cid}" + ))) +} + #[cfg(feature = "ssr")] async fn handle_erc20_claim( faucet_info: FaucetInfo, diff --git a/src/utils/rpc_context.rs b/src/utils/rpc_context.rs index 71de4ab..d559516 100644 --- a/src/utils/rpc_context.rs +++ b/src/utils/rpc_context.rs @@ -326,8 +326,11 @@ impl Provider { .await } - pub async fn eth_get_transaction_hash_by_cid(&self, cid: Cid) -> anyhow::Result { - invoke_rpc_method( + pub async fn eth_get_transaction_hash_by_cid( + &self, + cid: Cid, + ) -> anyhow::Result> { + invoke_rpc_method::>( &self.url, "Filecoin.EthGetTransactionHashByCid", &[serde_json::to_value(LotusJson(cid))?],