mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-25 11:43:06 +00:00
fix(wallet): await on-chain confirmation before returning from deploy-program
The DeployProgram command previously submitted the transaction and immediately returned success, even if the sequencer rejected it. Now it polls get_transaction_by_hash until the transaction appears in a block, exiting non-zero with a clear error message after a 30s timeout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
226ebe3e0e
commit
30c78cbfbd
@ -97,6 +97,32 @@ pub enum SubcommandReturnValue {
|
|||||||
SyncedToBlock(u64),
|
SyncedToBlock(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Poll the sequencer until a transaction appears in a block.
|
||||||
|
/// Returns `Ok(true)` if confirmed, `Ok(false)` if timed out.
|
||||||
|
async fn wait_for_tx_confirmation(
|
||||||
|
client: &common::sequencer_client::SequencerClient,
|
||||||
|
tx_hash: HashType,
|
||||||
|
max_attempts: u32,
|
||||||
|
poll_interval_ms: u64,
|
||||||
|
) -> Result<bool> {
|
||||||
|
for attempt in 1..=max_attempts {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(poll_interval_ms)).await;
|
||||||
|
|
||||||
|
match client.get_transaction_by_hash(tx_hash).await {
|
||||||
|
Ok(resp) if resp.transaction.is_some() => {
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
Ok(_) => {
|
||||||
|
println!(" Attempt {}/{}: pending...", attempt, max_attempts);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!(" Attempt {}/{}: error querying tx: {}", attempt, max_attempts, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn execute_subcommand(
|
pub async fn execute_subcommand(
|
||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
command: Command,
|
command: Command,
|
||||||
@ -169,12 +195,35 @@ pub async fn execute_subcommand(
|
|||||||
))?;
|
))?;
|
||||||
let message = nssa::program_deployment_transaction::Message::new(bytecode);
|
let message = nssa::program_deployment_transaction::Message::new(bytecode);
|
||||||
let transaction = ProgramDeploymentTransaction::new(message);
|
let transaction = ProgramDeploymentTransaction::new(message);
|
||||||
let _response = wallet_core
|
|
||||||
|
println!("Submitting program deployment transaction...");
|
||||||
|
let response = wallet_core
|
||||||
.sequencer_client
|
.sequencer_client
|
||||||
.send_tx_program(transaction)
|
.send_tx_program(transaction)
|
||||||
.await
|
.await
|
||||||
.context("Transaction submission error")?;
|
.context("Transaction submission error")?;
|
||||||
|
|
||||||
|
let tx_hash = response.tx_hash;
|
||||||
|
println!("Transaction submitted: {}", tx_hash);
|
||||||
|
println!("Waiting for confirmation...");
|
||||||
|
|
||||||
|
// Poll until the transaction is included in a block
|
||||||
|
let confirmed = wait_for_tx_confirmation(
|
||||||
|
&wallet_core.sequencer_client,
|
||||||
|
tx_hash,
|
||||||
|
30, // max attempts
|
||||||
|
1000, // ms between polls
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !confirmed {
|
||||||
|
anyhow::bail!(
|
||||||
|
"Transaction was not confirmed after timeout. \
|
||||||
|
The program may not have been deployed. Check sequencer logs."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Program deployed successfully! Program ID: {}", tx_hash);
|
||||||
SubcommandReturnValue::Empty
|
SubcommandReturnValue::Empty
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user