Repository navigation
FIP: Cast Format and Chained Casts #278
alexpaden
started this conversation in
FIP Stage 2: Draft
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
FIP: Cast Format and Chained Casts
Abstract
This proposal adds two optional fields to
CastAddBody:format_versionsays how to read the text of a cast. 0 is plain text, as today.chainputs a cast in an ordered chain of casts by one author, for example an article. It gives the first cast of the chain, the position of the cast, and the number of casts.The protocol delta is small:
ChainCast) and two new fields (CastAddBody.format_versionandCastAddBody.chain).chain, and none onformat_version.CastTypeor to cast size limits.The keywords MUST, MUST NOT, SHOULD and MAY are used as described in RFC 2119.
Cast format
A cast cannot say how to read its text. A client that writes Markdown cannot tell other clients, so they show the symbols or guess.
format_versionhas the value 0, which is plain text. All casts from before this change are plain text. Their encoding does not change.format_version. Any value is valid. Clients SHOULD show the text of an unknownformat_versionas plain text.chainalso activatesformat_version. The rules before activation (section 3) apply to it too.Chained casts
Problem
Long-form content, for example articles, does not fit in one cast. The largest cast holds 10,000 bytes (Pro; 1,024 bytes otherwise). An article is therefore a sequence of casts by one author.
Today the protocol cannot say which casts belong to that sequence. Clients use conventions:
embeds) uses an embed slot, and every client must decode it permanently.A larger cast type is not a solution. It increases the cost of storage and bandwidth for all casts, and it still has a limit.
Why not existing primitives
parent_url). A channel URL can mark an article, but then the article cannot be posted into a channel.MessageType. A new message type needs a new store, new APIs and new indexer code, and it does not use the existing cast features: mentions, embeds, reactions, replies and pruning.Specification
1) New message and field
optional. A cast withoutchainis not a chain cast, and its encoding does not change.CastTypedoes not change. Each chain cast uses theCastTypethat its text needs (CAST,LONG_CASTorTEN_K_CAST). The current text limits and the current rules forTEN_K_CASTapply.2) Validation (consensus)
The
ChainedCastsprotocol feature in the next free engine version activateschainandformat_version. A node validates aCastAddmessage with these rules:ChainedCastsis not active for the block, the node MUST NOT apply rules 3 to 6. Section 3 gives the rules before activation.chainis absent, the current rules apply. Nothing changes.countMUST be 100 or less (MAX_CHAIN_PARTS).indexMUST be less than 100.countis more than 0,indexMUST be less thancount.indexis 0,rootMUST be absent.indexis more than 0,rootMUST be present.rootMUST be a validCastId: itsfidis more than 0, and itshashis 20 bytes.root.fidMUST be equal to thefidof the message.CastAddrules apply: signature, signer, text length for theCastType, embeds, mentions and storage.The node rejects a message that fails a rule with one of these errors:
CastIderrors ("fid is missing" or "hash is missing") for arootthat is not validValidation does not do these things:
count.3) Messages before activation (consensus)
Before
ChainedCastsis active, nodes MUST accept and reject the same messages as nodes without this change:data_bytesbecause it haschainorformat_version. Older nodes skip unknown fields 9 and 10, and nodes calculate the hash overdata_bytes.chainandformat_versionindata, as older nodes do. It sizes and hashesdatawithout them, and it validates, stores and emits casts without them. A cast that has either field in its signed hash but nodata_bytestherefore fails with an invalid-hash error. Nodes MUST keep this pre-activation rule permanently, so that old blocks replay the same.ChainedCastsis not active, and to stored messages. Release step 5 says when nodes can stop applying it to stored messages.4) Storage and rate limits
CastAddmessage. It uses one cast storage slot, and it counts against the current rate limit.chainadds up to 4 bytes to the first cast of a chain. It adds 33 to 35 bytes to each later cast (more for a larger fid).format_versionadds 2 bytes to a cast that sets it.5) Reading a chain (non-consensus)
This section is guidance for clients. Nodes do not enforce it.
chainandformat_versionfromdata_bytes. Some nodes and libraries re-encodedataand can remove unknown fields. Clients SHOULD ignore achainthat does not decode. Over HTTP, read thechainandformatVersionfields of the JSON cast body. Nodes from the release with this change include them; older nodes do not.chainthat fails. Nodes do not check casts that were in blocks before activation.fidwhoserootis that cast. Membership is byroot, not by the reply tree.countis different from thecountof the cast at index 0. If thatcountis more than 0, clients SHOULD drop casts at or after it.countis more than 0, the chain is complete when each index belowcounthas a cast. Ifcountis 0, the chain is still growing, and a client cannot detect a missing last cast./v1/castsByFidwithstartTimestamp, or gRPCGetAllCastMessagesByFidwithstart_timestamp. These also returnCastRemovemessages. Clients SHOULD set the page size.6) Format 1: article Markdown (standard)
A chain whose cast at index 0 has
format_version1 is an article. Each of its casts SHOULD haveformat_version1. The Text rules apply to any cast withformat_version1.Casts
CastIdembeds) are always embeds. A link preview is a URL embed. If the URL cannot be an embed (for example, it is more than 256 bytes), it stays in the text as a line that contains only the URL.Text
The text is close to GitHub-flavoured Markdown, plus
++underline++and$$LaTeX. Each block starts on a new line.\) continues the block on the next line.#is a heading,##is a subheading, and>is a quote.-is a bulleted list item. A number followed by.is a numbered list item; readers number the items themselves. Two spaces of indent mark each nested level.---is a divider.$$...$$on one line, or the lines between two lines of$$.|cell|cell|. A|-|-|row follows the header row. Cells are plain text;\|,\\and\-are escapes.httporhttpsURL is a link preview.**bold**,_italic_,~~strikethrough~~,++underline++and[text](url)._) between two letters or digits is literal text.\ * _ ~ + [ ]and a line break. Before other characters, it is literal. A backslash at the start of a line stops the line from reading as block syntax.mentionsto the text before they parse it. In code and LaTeX,@nameis text.If the format changes in a way that older readers cannot read, the new format MUST use a new
format_versionvalue.Implementation in Snapchain
Key changes
ChainCast, the optionalCastAddBody.chain, andCastAddBody.format_version.ChainedCastsis active.format_versionhas no rule.cast_add_body.chainandcast_add_body.format_version, both defined byChainedCasts. Before a field's feature is active, nodes use the table to treat that field as unknown, as section 3 requires: ifdata_bytesdoes not decode, they decode it again without the field, and they remove the field fromdatabefore they size, hash, validate, store or emit a message. Reads of stored messages use the decode step for every field in the table, because stored messages include ones from before activation. A later field needs one new entry.ChainedCastsin the next free engine version.chainandformatVersionto the JSON cast body, omitted when absent or 0. Build the JSON fromdata_byteswhen it is present. HTTP JSON has nodata_bytes, so without this, HTTP clients cannot see either field.What doesn't change
CastType, the text limits, the embed limit and the Pro rules.Performance
The validation reads only the message. It adds no database reads and no index writes.
Rationale
Why a field and not a new
CastTypevalue?CastTypesets the size of a cast. A chain cast can be any size, so a new value would need its own size rules and its own Pro rules. A field keeps the two concepts separate. Libraries that do not know a newCastTypevalue reject the message. Libraries that do not know a new field read the cast as a normal cast.Why no rule for one cast per index?
A uniqueness rule needs a new index in the cast store and a lookup for each chain cast. Readers use the latest cast at each index instead. This also lets authors update a part, and it supports chains that keep growing.
Why not require the previous cast, or the first cast, to exist?
The mempool orders messages by timestamp in whole seconds, and then by hash. A client that posts a chain quickly can send a later cast before an earlier cast is in a block. A rule that needs the earlier cast would reject a valid chain. Readers can see a gap from
indexandcount.Why does
count = 0mean a growing chain?Some chains, for example a log of updates, do not have a known end. With
count = 0they can grow. Withcountmore than 0, a reader can tell a complete chain from a partial chain.Why the block version for activation?
All other validation rules use the block version, and blocks from before activation then replay the same.
Why not do nothing?
Clients would continue to use conventions, for example marker embeds. Each convention uses an embed slot, cannot show the end of an article, and must stay in every client permanently.
Backward Compatibility
format_versionshow the text as plain text.chainread a chain cast as a normal cast. They see the casts as a reply thread by the author, because each cast replies to the cast before it.dataremove both fields. Clients that readdata_byteskeep them.chain. Section 3 keeps them and upgraded validators in agreement.Security and Privacy Considerations
root.fidmust be equal to thefidof the message.MAX_CHAIN_PARTSkeeps the values ofindexandcountin a known range.httpandhttpslinks, so that a link cannot run a script.chainandformat_versioncontain no new personal data.chaincontains the id of a public cast and two numbers.format_versionis a number.Release
ChainedCastsoff on mainnet and testnet.CastAddmessages that do not decode with the new schema without the fallback. Publish the result.message.proto.ChainedCastson testnet, then on mainnet. The mainnet activation MUST be at least one week after the release, so that read nodes have time to upgrade. Activation date: TBD.chainandformat_versionbefore activation. Nodes accept them as unknown fields, and readers check the rules (section 5).chainorformat_versionwithdata_bytes. Withoutdata_bytes, old and new nodes reject them with an invalid-hash error.Impact:
format_versionandchainfromdata_bytesand follow sections 5 and 6.chainandformat_version, store them fromdata_bytes. Casts without them do not change.References
CastTypetoCastAddBody.TEN_K_CAST.All reactions