Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send_extrinsic(xt, XtStatus::Finalized) does not report error upon xt failure #288

Closed
haerdib opened this issue Oct 7, 2022 · 2 comments · Fixed by #398
Closed

send_extrinsic(xt, XtStatus::Finalized) does not report error upon xt failure #288

haerdib opened this issue Oct 7, 2022 · 2 comments · Fixed by #398
Assignees
Labels
F7-enhancement Enhances an already existing functionality Q5-involved Will take some time to fix this

Comments

@haerdib
Copy link
Contributor

haerdib commented Oct 7, 2022

.send_extrinsic(xt.hex_encode(), XtStatus::Finalized)

Gives back the hash even though the extrinsic has failed. Is there a way to prevent that?

@haerdib haerdib added F2-bug Something isn't working Q5-involved Will take some time to fix this labels Nov 2, 2022
@haerdib haerdib added F7-enhancement Enhances an already existing functionality and removed F2-bug Something isn't working labels Nov 10, 2022
@haerdib
Copy link
Contributor Author

haerdib commented Nov 10, 2022

This is not a bug actually, because the extrinsic, even when failed, gets finalized. However, just like in subxt, we could provide a functionality check_success or similar. This function would then check the associated events of this call and check if there's been an ExtrinsicFailed event or ExtrinsicSuccess.

Example from subxt:

    /// Fetch the events associated with this transaction. If the transaction
    /// was successful (ie no `ExtrinsicFailed`) events were found, then we return
    /// the events associated with it. If the transaction was not successful, or
    /// something else went wrong, we return an error.
    ///
    /// **Note:** If multiple `ExtrinsicFailed` errors are returned (for instance
    /// because a pallet chooses to emit one as an event, which is considered
    /// abnormal behaviour), it is not specified which of the errors is returned here.
    /// You can use [`TxInBlock::fetch_events`] instead if you'd like to
    /// work with multiple "error" events.
    ///
    /// **Note:** This has to download block details from the node and decode events
    /// from them.
pub async fn wait_for_success(
        &self,
    ) -> Result<crate::blocks::ExtrinsicEvents<T>, Error> {
        let events = self.fetch_events().await?;

        // Try to find any errors; return the first one we encounter.
        for ev in events.iter() {
            let ev = ev?;
            if ev.pallet_name() == "System" && ev.variant_name() == "ExtrinsicFailed" {
                let dispatch_error =
                    DispatchError::decode_from(ev.field_bytes(), &self.client.metadata());
                return Err(dispatch_error.into())
            }
        }

        Ok(events)
    }

@haerdib haerdib self-assigned this Dec 12, 2022
@haerdib
Copy link
Contributor Author

haerdib commented Dec 12, 2022

Also take a look at the function wait_for_event. The current implementation is not very satisfactory because the parameter subscription needs to be passed around too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F7-enhancement Enhances an already existing functionality Q5-involved Will take some time to fix this
Projects
None yet
1 participant