Skip to content

Commit 1f112cc

Browse files
authored
Designdoc/batching (#90)
1 parent d2e2ef3 commit 1f112cc

File tree

2 files changed

+118
-10
lines changed

2 files changed

+118
-10
lines changed

designdocs/batched_messages.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Batched Messages
2+
3+
## Table of Contents
4+
* [Context and Scope](#context-and-scope)
5+
* [Problem Statement](#problem-statement)
6+
* [Goals and Non-Goals](#goals-and-non-goals)
7+
* [Proposal](#proposal)
8+
* [Benefits and Risks](#benefits-and-risks)
9+
* [Alternatives and Rationale](#alternatives-and-rationale)
10+
* [Glossary](#glossary)
11+
12+
## Context and Scope
13+
This design document describes batched messages and APIs for sending and retrieving them.
14+
15+
## Problem Statement
16+
In order to reduce costs for announcers of messages on-chain as well as reduce network congestion, announcers collate messages into batches of the same type of message and announce the batch location on-chain, instead of announcing each individual message.
17+
18+
## Goals and Non-Goals
19+
This specifies how batches are to be announced on chain; what is required and how a batch may be partially verified based on on-chain information.
20+
21+
This document does not describe the types of DSNP messages that would be in batch announcements. Batch announcements must reference a schema through its ID number. A schema may or may not describe a DSNP message.
22+
23+
This document does not discuss validation of batch file format located at the URI in the announcement, since
24+
the file format cannot be verified on-chain. For details about batch files themselves, see [DSNP Spec: Batch Publications](https://spec.dsnp.org/DSNP/BatchPublications).
25+
26+
## Proposal
27+
* All names are placeholders and may be changed.
28+
* Types may change as needed during implementation phase
29+
* Errors in the extrinsic(s) must have different, reasonably-named error enums for each type of error for ease of debugging.
30+
31+
### Constants
32+
* `BatchPageSizeMax` - the maximum number of batch announcements that will be returned by the `get_batches` query
33+
* `BatchSizeMinBytes` - the minimum possible size of a valid batch file with 1 row
34+
35+
### Enums
36+
* `BatchFormat` - a list of supported formats for batch files. Currently only Parquet file format is supported, however,
37+
other formats are being considered.
38+
39+
### Types
40+
* `BatchAnnouncementParams<T:Config>`: generic
41+
* `batch_uri`:`Vec<u8>` the URI of the batch file. Must be an IPFS [CIDv1](https://github.com/multiformats/cid/) URI. Accepted codec, algorithm, and base are to be determined.
42+
* `message_schema_id`: `SchemaId` the schema id for the messages in this batch. The `schema_id` must refer to schemas used for batching only.
43+
* `file_size`: `usize`, the size of the batch file, used to determine message fee as well as to let consumers know what size files to expect. Must be &gt;= the minimum possible DSNP batch file size.
44+
* `file_format`: `BatchFormat`, indicator of the file format of the batch file.
45+
46+
The file hash is not included separately. Since the `batch_uri` uses CIDv1 specification, the file hash is already included.
47+
48+
* `BatchAnnouncement`: implements `BatchAnnouncementParams`, returned by `get_batches`
49+
50+
See the [implementation of paging in the messages pallet](https://github.com/LibertyDSNP/mrc/blob/main/common/primitives/src/messages.rs#L26-L58) for comparison.
51+
52+
* `BatchAnnouncementOptions<T:Config>`
53+
* `msa_id`: `Option<MsaId>`, the announcer's MSA id. Pass None() to get all announcements.
54+
* `from_block`: `<T::BlockNumber>`, retrieve messages starting at the given block number (inclusive)
55+
* `to_block`: `<T::BlockNumber>`, retrieve messages ending at the given block number (inclusive)
56+
* `from_index`: `u32`, starting message index
57+
* `page_size`: `usize`, retrieve `page_size` messages at a time, up to configured `T::BatchPageSizeMax`. If 0, return `T::BatchPageSizeMax` results
58+
59+
* `BatchAnnouncementResult`
60+
* `has_next`: `uint32`, current page number
61+
* `next_block`: `<T::BlockNumber>` starting block number of next page of results
62+
* `next_index`: `u32` starting index of next results in `next_block`
63+
* `results`: `Vec<BatchAnnouncement>`
64+
65+
### Extrinsics
66+
#### announce_batch(origin, batch_announcement_params)
67+
Creates and posts a new batch announcement message on chain, using the batch message Schema Id. This Schema Id must already be registered and will need to be fetched by the extrinsic. The transaction fee is determined in part by the file size.
68+
69+
* **Parameters**
70+
* origin: required for all extrinsics, the caller/sender.
71+
* `batch_announcement_params`: `BatchAnnouncementParams`, the parameters to use in the batch announcement.
72+
73+
* **Event**: `Event::<T>::BatchAnnounced(schema_id, msa_id, file_size, batch_uri)`
74+
* **Restrictions**:
75+
* origin's `msa_id` must have capacity to post the transaction during the current epoch
76+
77+
### Custom RPCs
78+
79+
#### get_batches(options)
80+
Retrieves paged batch announcements that have not been garbage-collected which meet `options` criteria. The `msa_id` does not need to be active.
81+
82+
* **Parameters**
83+
* `options`: `BatchAnnouncementOptions` containing batch announcement criteria
84+
85+
* **Returns**
86+
* `None()` if no messages meet the criteria.
87+
* `Some(Vec<BatchAnnouncement>)`, in descending block-transaction order
88+
89+
90+
### Benefits and Risks
91+
Please see [Batching Source Dependent Messages With Delegation](https://forums.projectliberty.io/t/04-batching-source-dependent-messages-with-delegation/216), for discussion about the benefits of announcing batch files on chain rather than all types of user-created messages.
92+
93+
One risk is that providers on MRC could simply register a new schema and announce batches "unofficially". We have not decided whether to let everyone with enough token to register a schema. Other MRC participants would need to first learn about and evaluate new schemas, then update their software to consume a new message type.
94+
95+
Another risk, mentioned in the Alternatives and Rationale section, is that providers would announce smaller batches than the actual batch file sizes. Earnest MRC participants, such as indexers, will quickly learn this announcer is not reliable and ignore batches marked with that announcer's MsaId.
96+
97+
### Alternatives and Rationale
98+
We discussed whether a batch message itself can be delegated, but this would have complicated things and we cannot come up with a use case for delegating batches. It also violates the idea of users delegating explicitly to every provider that performs a service for them, which is a fundamental value we want to apply to the network.
99+
100+
We discussed whether to allow URLs such as HTTP/HTTPS or other URLs and instead opted for content-addressable URIs (CIDv1) which can be resolved by some other service. This allows us to put the file hash directly into a URI. It reduces message storage because we don't have to include both a URL and a file hash. A file hash is necessary as a check against file tampering.
101+
102+
We revisited the idea of whether it really is necessary to include a file size. We will be charging a premium for larger files, however, there will be per-byte discount for larger files in order to create an incentive for posting batches while reducing the incentive for announcers to allow spam. Although the processing and downloading time for enormous files also serves as a disincentive for spam, we feel it would not be sufficient.
103+
104+
Despite the fact that announcers can lie abut the file size, the file_size parameter also serves as an on-chain declaration that not only allows consumers of batches to quickly discover if a batch announcer was honest, but the file requestor can know in advance when to stop requesting data.
105+
106+
### Glossary
107+
* *IPFS* [InterPlanetary File System](https://docs.ipfs.io/), a decentralized file system for building the next generation of the internet
108+
* *CID* [Content IDentifier](https://github.com/multiformats/cid/), Self-describing content-addressed identifiers for distributed systems
109+
* *MsaId* [Message Source Account ID](https://github.com/LibertyDSNP/mrc/blob/main/designdocs/ACCOUNTS.md) an identifier for a MSA.

designdocs/delegation.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
This document describes the permissioned delegation of actions, largely, but not limited to, account creation and announcing messages by the owner of an `MsaId` on chain on behalf of the owner of another `MsaId`.
33

44
## Table of Contents
5-
* [Context and Scope](https://github.com/LibertyDSNP/meta#installation)
6-
* [Problem Statement](https://github.com/LibertyDSNP/meta#dependenciesrequirements)
7-
* [Goals and Non-Goals](https://github.com/LibertyDSNP/meta#configuration)
8-
* [Proposal](https://github.com/LibertyDSNP/meta#examples)
9-
* [Benefits and Risks](https://github.com/LibertyDSNP/meta#roadmap)
10-
* [Alternatives and Rationale](https://github.com/LibertyDSNP/meta#support)
11-
* [Additional Resources](https://github.com/LibertyDSNP/meta#contributing)
12-
* [Glossary](https://github.com/LibertyDSNP/meta#overview)
5+
* [Context and Scope](#context-and-scope)
6+
* [Problem Statement](#problem-statement)
7+
* [Goals and Non-Goals](#goals-and-non-goals)
8+
* [Proposal](#proposal)
9+
* [Benefits and Risks](#benefits-and-risks)
10+
* [Alternatives and Rationale](#alternatives-and-rationale)
11+
* [Glossary](#glossary)
1312

1413

1514
## Context and Scope
@@ -62,8 +61,8 @@ Creates a new `MsaId` on behalf of an MSA and adds the origin as the MSA's deleg
6261
* `permission` a value indicating the permission to be given to the delegate
6362
2. `public_key` - The authorizing key used to create `signature`
6463
3. `signature` - The signature of the hash of `data`
65-
* Event: `IdentityCreated`, with the `public_key`, the newly created `MsaId`, and `msa_id`
66-
* Restrictions: origin must own `msa_id` in the payload.
64+
* Event: `IdentityCreated`, with the `public_key`, the newly created `MsaId`, and `msa_id`
65+
* Restrictions: origin must own `msa_id` in the payload.
6766

6867
#### add_self_as_delegate(payload)
6968
Adds the `MsaId` in the payload as a delegate, to an MSA owning `delegator_msa_id`

0 commit comments

Comments
 (0)