Skip to content

Commit

Permalink
Create ApplyingChunk.md (#223)
Browse files Browse the repository at this point in the history
* Create ApplyingChunk.md

* Update specs/RuntimeSpec/ApplyingChunk.md

* Update specs/RuntimeSpec/ApplyingChunk.md

* Update README.md

* Update ApplyingChunk.md

* Update ApplyingChunk.md

* Update specs/RuntimeSpec/ApplyingChunk.md

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>

* Update specs/RuntimeSpec/ApplyingChunk.md

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>

* Update specs/RuntimeSpec/ApplyingChunk.md

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>

* Update specs/RuntimeSpec/ApplyingChunk.md

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>

* Update specs/RuntimeSpec/ApplyingChunk.md

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>

Co-authored-by: Aleksandr Logunov <the.aleksandr.logunov@gmail.com>
  • Loading branch information
EgorKulikov and Aleksandr Logunov committed Jun 24, 2021
1 parent 11e5164 commit 47f2860
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions specs/RuntimeSpec/ApplyingChunk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Applying chunk

## Inputs and outputs

Runtime.apply takes following inputs:
* trie and current state root
* *validator_accounts_update*
* *incoming_receipts*
* *transactions*

and produces following outputs:
* new state root
* *validator_proposals*
* *outgoing_receipts*
* (executed receipt) *outcomes*
* *proof*

## Processing order

* If this is first block of an epoch, dispense [epoch rewards](../Economics/README.md#validator-rewards-calculation) to validators (in order of *validator_accounts_update.stake_info*)
* Slash locked balance for malicious behavior (in order of *validator_accounts_update.slashing_info*)
* If [treasury account](../Economics/README.md#protocol-treasury) was not one of validators and this is first block of an epoch, dispense treasury account reward
* If this is first block of new version or first block with chunk of new version, apply corresponding migrations
* If this block do not have chunk for this shard, end process early
* Process [transactions](Transactions.md) (in order of *transactions*)
* Process local [receipts](Receipts.md) (in order of *transactions* that generated them)
* Process delayed [receipts](Receipts.md) (ordered first by block where they were generated, then first local receipts based on order of generating *transactions*,
then incoming receipts, ordered by *incoming_receipts* order)
* Process incoming [receipts](Receipts.md) (ordered by *incoming_receipts*)

When processing receipts we track gas used (including gas used on migrations). If we use up gas limit, we immediately stop to process delayed receipts, and for local and incoming
receipts we add them to delayed receipts)

* If any of the delayed receipts were processed or any new receipts were delayed, update indices of first and last unprocessed receipts in state
* Remove duplicate validator proposals (for each account we only keep last one in receipts processing order)

Please note that local receipts are receipts generated by transaction where receiver is the same as signer of the transaction

## Delayed receipts

In each block we have maximal amount of Gas we can use to process receipts and migrations, currently 500 TGas. If any incoming or local receipts are not processed due to lack of remaining Gas, they are stored in state with key <pre>TrieKey::DelayedReceipt { id }</pre> where id is unique index for each shard, assigned consecutively. Currently sender does not need to stake any tokens to store delayed receipts. State also contains special key <pre>TrieKey::DelayedReceiptIndices</pre> where first and last ids of delayed receipts not yet processed are stored.
1 change: 1 addition & 0 deletions specs/RuntimeSpec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

See:
- [Runtime](Runtime.md)
- [ApplyingChunk](ApplyingChunk.md)
- [FunctionCall](FunctionCall.md)
- [Transactions](Transactions.md)
- [Actions](Actions.md)
Expand Down

0 comments on commit 47f2860

Please sign in to comment.