Module pallet_gear::manager

source ·
Expand description

Manager which handles results of message processing.

Should be mentioned, that if message contains value we have a guarantee that it will be sent further in case of successful execution, or sent back in case execution ends up with an error. This guarantee is reached by the following conditions:

  1. Reserve/unreserve model for transferring values. Ownership over message value is moved not by simple transfer operation, which decreases free balance of sender. That is done by reserving value before message is executed and repatriating reserved in favor of beneficiary in case of successful execution, or unreserving in case of execution resulting in a trap. So, it gives us a guarantee that regardless of the result of message execution, there is always some value to perform asset management, i.e move tokens further to the recipient or give back to sender. The guarantee is implemented by using corresponding pallet_balances functions (reserve, repatriate_reserved, unreserve along with transfer) in pallet_gear extrinsics, JournalHandler::send_dispatch and JournalHandler::send_value procedures.

  2. Balance sufficiency before adding message with value to the queue. Before message is added to the queue, sender’s balance is checked for having adequate amount of assets to send desired value. For actors, who can sign transactions, these checks are done in extrinsic calls. For programs these checks are done on core backend level during execution. In details, when a message is executed, it has some context, which is set from the pallet level, and a part of the context data is program’s actual balance (current balance + value sent within the executing message). So if during execution of the original message some other messages were sent, message send call is followed by program’s balance checks. The check gives guarantee that value reservation call in

JournalHandler::send_dispatch for program’s messages won’t fail, because there is always a sufficient balance for the call.

  1. Messages’s value management considers existential deposit rule. It means that before message with value is added to the queue, value is checked to be in the valid range - {0} ∪ [existential_deposit; +inf). This is crucial for programs. The check gives guarantee that if funds were moved to the program, the program will definitely have an account in pallet_balances registry and will be able then to manage these funds. Without this check, program could receive funds, but won’t be able to use them.

Due to these 3 conditions implemented in pallet_gear, we have a guarantee that value management calls, performed by user or program, won’t fail.

Structs§

Enums§

Functions§