Skip to content

Reversible Transfer Events

Nikolaus Heger edited this page Jul 29, 2025 · 4 revisions

Tracking Reversible Transfer Events

This document outlines how to track the lifecycle of a reversible transfer by correlating events from the reversible-transfers, scheduler, and balances pallets.

The Challenge

When a reversible transfer is executed by the scheduler pallet, the final balances::Transfer event does not have a direct identifier linking it back to the initial transaction. This makes it challenging to trace, especially if multiple identical transfers are processed in the same block.

The Solution: Event Correlation

The key to tracking the entire lifecycle is to use the tx_id from the reversible-transfers pallet and the deterministic order of events emitted during execution.

The Connection: tx_id and schedule_id

When a reversible transfer is scheduled, the reversible-transfers pallet generates a unique tx_id. This tx_id is then used as the schedule_id (specifically, a TaskName) when the task is registered with the scheduler pallet.

The Execution Flow

When the scheduler executes the transfer, a specific sequence of events is guaranteed to be emitted in the following order:

  1. scheduler::Dispatched: This event marks the beginning of the execution. It contains an id field which is the TaskName corresponding to the reversible transfer's tx_id.

  2. balances::Transfer: This event is emitted immediately after the scheduler::Dispatched event. It represents the actual transfer of funds but lacks a direct ID. You can reliably link it to the dispatched task because it will be the very next event in the block.

  3. reversible-transfers::TransactionExecuted: This event is emitted last in the sequence, confirming that the reversible transfer logic has been successfully executed. It also contains the original tx_id, which provides a final confirmation that you are tracking the correct transaction.

By relying on this guaranteed order, you can confidently correlate all three events, even in complex scenarios with multiple identical transfers.

Diagram of the Event Flow

The following diagram illustrates the complete, ordered flow of events:

image

Clone this wiki locally