Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
DAWN-610 ⁃ Context Free Actions #1387
Context Free Actions
Some computations necessary to build consensus are expensive from either a computational or block space perspective, or both. For example, the proof for inter-blockchain communication (IBC) is large, and validating it can only pass or fail. Once a block is irreversible, this code path and data is useless (unless someone is performing a verbose revalidation of the chain).
Witness Actions provide a means to perform intense checks in a way that the computation is cheaper during production/validation and both computation and block space are prunable.
This is conceptually equivalent to Segregated Witness for the EOS.IO blockchain.
New Action Type
Witness Actions are a new type of action which may only read its own payload and a new section of transaction data referred to as "witness data". They are otherwise identical to normal actions.
In the example of IBC this action's payload would be the provably retired action from the foreign chain and a block ID from the foreign chain whose state includes the transaction.
In an example of a document publication platform (PUB) this action's payload would be the hash of a document to publish.
Transactions will contain a new section of data that provides witness data. Witness data is anything needed to process a witness action that doesn not need to persist if you can assume the action processed successfully. This is a broader definition that most cryptographic witness data would include.
In the example of IBC, witness data would be the merkle proof that the retired action was present in a particular block on the foreign chain and the merkle proof that said block is included in the chain represented by the block ID listed in the action payload
In an example of PUB the witness data would be the plaintext document.
Witness Data Access API
Witness actions can only read their payload and the associated witness data. They cannot write anything. They merely succeed in whole or fail. This makes them stateless or context-free and allows trivial parallel processing.
In the example of IBC, the WebAssembly code will use this API and the action payload to
In an example of PUB, the WebAssembly code will use this API and the action payload to
Sibling Action API
Non-witness actions will have access to a new API which allows them to
In the example of IBC, the normal action will assert that a sibling action existed routed to the proper action name, with a properly formed payload (the transaction and block ID of the foreign chain). It can then proceed to do stateful processing based on the assumption that this sibling action succeeded and therefore the given action was included in the foreign chain
In the example of PUB, the normal action will assert that a sibling action existed with the given hash as a payload and proceed to mark the document as published based on the assumption that this sibling action succeeded and therefore the given hash IS the hash of the desired document.
As witness action processing will happen substantially in parallel, it becomes harder to account for in resource controls. However, as it depends on no state data it should also be possible to compute, ahead of time and deterministically, what resources this will consume.
A transaction will commit to this resource usage, the same way it will commit to packed size as part of #1386
Note, this commitment will only cover the resources spent on retiring witness actions. All normal actions are not deterministically billable ahead-of-time as they depend on state that is considered volatile until the precise moment a transaction is retired. If a transaction fails, the resources billed to it ahead of time for witness data will be refunded.
As part of this, the block structure (on disk and wire) will change such that all witness data and signatures are part of an explicit and well-contained section. This section can be truncated off of blocks when they are considered irreversible and will remain replay/re-indexable as irreversibility proves that all dependent processing "passes" and can therefore be implied
Notes from Dan re: Sibling Action API
➤ Kevin Heifner commented:
We have a few tests (one?) that actually exercises apply_block . I think we should add some context-free-action tests that generate a block on one tester and then push that block into another to exercise CFA on apply_block