Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Atomic transaction annotation for dispatchable calls #6587

@shaunxw

Description

@shaunxw

This issue is a syntax proposal to support atomic transaction annotation for dispatchable calls definition in decl_module.

The boilerplate

With nested storage supported #6269 , now transaction rollback on error is possible. A typical atomic dispatch call implementation would be:

use frame_support::storage::{with_transaction, TransactionOutcome};

pub fn my_call(origin) {
        with_transaction(|| {
                // `my_call` implementation
                // -- snip --
                // Finally we have a `Result` of execution as `r`
		if r.is_ok() {
			TransactionOutcome::Commit(res)
		} else {
			TransactionOutcome::Rollback(res)
		}
	})?;
}

This pattern would be repeated every time defining an atomic dispatchable call.

The syntax

To avoid repeating the boilerplate, I propose to add an atomic (or other names if preferred) annotation syntax, which will wrap the implementation in a with_transaction commit/rollback pattern as above. The syntax is like:

#[atomic]
pub fn my_call(origin) {
        // `my_call` implementation
        // -- snip --
}

And expanded as:

use frame_support::storage::{with_transaction, TransactionOutcome};

pub fn my_call(origin) {
        with_transaction(|| {
                let r = {
                        // `my_call` implementation
                        // -- snip --
                };
		if r.is_ok() {
			TransactionOutcome::Commit(res)
		} else {
			TransactionOutcome::Rollback(res)
		}
	})?;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    J0-enhancementAn additional feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions