Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Cargo.lock

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

33 changes: 29 additions & 4 deletions src/faucet/server_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxHash, ServerFnError> {
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,
Expand Down
7 changes: 5 additions & 2 deletions src/utils/rpc_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ impl Provider {
.await
}

pub async fn eth_get_transaction_hash_by_cid(&self, cid: Cid) -> anyhow::Result<TxHash> {
invoke_rpc_method(
pub async fn eth_get_transaction_hash_by_cid(
&self,
cid: Cid,
) -> anyhow::Result<Option<TxHash>> {
invoke_rpc_method::<Option<TxHash>>(
&self.url,
"Filecoin.EthGetTransactionHashByCid",
&[serde_json::to_value(LotusJson(cid))?],
Expand Down
Loading