Skip to content

Commit

Permalink
doc: add tutorial for multi-signer script execution
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoks committed Mar 26, 2024
1 parent deb9d80 commit 4fd8228
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/assets/polkadot.js_multisign_events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions doc/final-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This article discusses the pallet-move functionality.
- [Extrinsics](#extrinsics)
- [RPC](#rpc)
- [Design architecture](#design-architecture)
- [Multi Signer Script Execution](#multi-signer-script-execution)


# Pallet API
Expand Down Expand Up @@ -119,12 +120,8 @@ Estimate gas for executing a Move script.

**Parameters**

`account: AccountId` - Account ID which is publishing the module.

`transaction: Vec<u8>` - Script transaction bytecode.

`cheque_limit: u128` - The amount the account is willing to possibly spend.

`at: Option<BlockHash>` - Optional block.

----------------------------------------------------------------
Expand Down Expand Up @@ -186,3 +183,17 @@ How it works under the hood is shown in a simple UML diagram below:

[smove]: https://github.com/eigerco/smove
[substrate-move]: https://github.com/eigerco/substrate-move

# Multi Signer Script Execution

Executing Move scripts with multiple signers works basically the same as for a single signer.
When the first signer executes a script transaction with multiple signers, the Move pallet will create a multi-signer execution request in the storage.
Each following signer will execute the same script transaction with its individual cheque limit for the planned script execution.
Pallet move will store the state of each signature and each cheque limit and keep track if all users have signed or not.
After each signer has signed by calling the exact same extrinsic call with the same script transaction, the Move pallet will execute the script.

**Differences to single signer:**
- The cheque limit (tokens) of each signer will be locked on their accounts until the request gets finally executed or deleted.
- Except for the final signer, the event `SignedMultisigScript` will be emitted instead of `ExecuteCalled`.
- When all signers have signed, the script will be executed, the tokens be unlocked, and balances applied according to the Move script.
- In case not every signer signes the execution request, the request gets removed automatically after a certain amount of time (defined by the blockchain developer).
18 changes: 17 additions & 1 deletion doc/tech_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,27 @@ Read detailed info about test concepts (what tests cover and how) in the [old te

## Pallet Configuration in a Substrate-Node

The pallet's configuration is concise. Besides the regular `RuntimeEvent` and a predefined `WeightInfo`, you only have to tell the pallet about your `Currency` handler:
The pallet's configuration is concise. Besides the regular `RuntimeEvent` and a predefined `WeightInfo`, you have to tell the pallet about your `Currency` handler, the used balance data type in your blockchain (`CurrencyBalance`), the maximum lifetime (`MaxLifetimeRequests`) and maximum number of signers (`MaxScriptSigners`) in case of a multi signer script execution request:
```rust
parameter_types! {
// Number of blocks after that a multi signer request gets removed.
pub const MaxLifetimeRequests: BlockNumberFor<Test> = 5;
// Maximum number of signers in a multi signer script execution.
pub const MaxScriptSigners: u32 = 8;
}

impl pallet_move::Config for Test {
// The currency handler of this blockchain.
type Currency = Balances; // here pallet-balances is used
// The used balance type. For example: `type Balance = u128;`.
type CurrencyBalance = Balance;
// Max lifetime of a multi signer execution request, see constant above.
type MaxLifetimeRequests = MaxLifetimeRequests;
// Max number of signers in a multi signer execution request.
type MaxScriptSigners = MaxScriptSigners;
// Runtime event of this blockchain.
type RuntimeEvent = RuntimeEvent;
// Weight info for this pallet.
type WeightInfo = (); // or use pallet_move::weights::SubstrateWeight<Test>;
}
```
Expand Down
36 changes: 36 additions & 0 deletions doc/tutorial-multi-signer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Multiple Signer Script Execution

### Prerequisites

You have already done the [tutorial](tutorial.md) and you are familiar with publishing modules and executing scripts with the Move pallet.

### Differences to a Single User Script Execution

Again, the story starts with the developer, Bob, who publishes a module.
This time, it is the `Dorm.mv` module from our example move project [`multi-signer`](../pallet/srv/tests/assets/move-projects/multi-signer), which allows to rent apartments for groups of three students each.
We assumed that dorms with exactly three rooms are available and can only be rented with three students together.
| ![polkadot.js_multisign_bob_publishes_module.png](assets/polkadot.js_multisign_bob_publishes_module.png) |
|:--:|
| _Bob publishes a module using [polkadot.js][polkadotjs]_ |

Again, developer Bob initialises his module by executing the script transaction `init_module.mvt`.
| ![polkadot.js_multisign_bob_inits_module.png](assets/polkadot.js_multisign_bob_inits_module.png) |
|:--:|
| _Bob initialises his module using [polkadot.js][polkadotjs]_ |

The student Alice is the first one and executes the script transaction `rent_apartment.mvt`, which is already prepared for the student group Alice, Dave and Eve and with two months of rental.
| ![polkadot.js_multisign_alice_initiates.png](assets/polkadot.js_multisign_alice_initiates.png) |
|:--:|
| _Alice initiates the multi signer execution request using [polkadot.js][polkadotjs]_ |

Now same script transaction must be executed by Dave and Eve as well.
After all three students have executed that script transaction you should see, that the amounts of tokens have be withdrawn from their accounts.

Because every student has to sign the extrinsic call and execute the script execution, the execution request will be stored in the pallet's storage until every student has signed.
> Note: After the initiation of a multi signer execution requests, the specified cheque limits will be locked until it the request gets executed or deleted.
From the first signer to the one before the last one, they will see the event `SignedMultisigScript`.
After the final signer has signed and executed the same extrinsic call, the script transaction will be executed, tokens with amount of the cheque limit will be unlocked and withdrawn, and the event `ExecuteCalled` will be emitted.
Here, the second was Dave, and the last one was Eve, who signed the extrinsic call. As a result you can see the events in that order.
| ![polkadot.js_multisign_events.png](assets/polkadot.js_multisign_events.png) |
|:--:|
| _Events in a multi signer execution requests in [polkadot.js][polkadotjs]_ |
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
cd $(dirname $0)
# Our students who want to rent a dorm together.
BOB=5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
# Estimate needed gas for a single script execution.
smove node rpc estimate-gas-execute-script -a $BOB -s build/multiple-signers/script_transactions/init_module.mvt --cheque-limit 100000000000000

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
cd $(dirname $0)
# Our students who want to rent a dorm together.
BOB=5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
# Estimate needed gas for a single script execution.
smove node rpc estimate-gas-publish-module -a $BOB -m build/multiple-signers/bytecode_modules/Dorm.mv

0 comments on commit 4fd8228

Please sign in to comment.