Skip to content

Commit

Permalink
new design
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenwang1996 committed Apr 10, 2024
1 parent fa6df40 commit af38aef
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions neps/nep-0541.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ We discuss the implementation of two important pieces of the proposal, receipt p

### Receipt Processing

A max heap is created in the state for storing priorities of delayed receipts. More specifically, we add a trie column `RECEIPTS_PRIORITY_QUEUE: u8 = 13`. Each value in this heap is of the form
```rust
struct ReceiptPriority {
/// index of the corresponding receipt in the delayed receipts queue. Use u32 here to save some space in the state
receipt_index: u32
/// priority of the receipt
priority: u64
}
```
Since each value is quite small and we don't expect the delayed receipt queue to be extremely long (even if there are 100k delayed receipts, it is only 1.2MB in size), and it only needs to be read and write once per chunk, this heap can be stored as a single value in the state.
Priorities of delayed receipts are stored as trie keys under a new trie column `RECEIPTS_PRIORITY_QUEUE: u8 = 13`. More specifically, `priority: u64` will be used as trie key and each value for the key is a `u64`, which stores the index of the corresponding receipt in the delayed receipt queue. When we start processing prioritized receipts, we always start iterating from the rightmost key.

The receipt processing order is roughly as follows:

Expand All @@ -98,18 +89,6 @@ def process_priority_receipts(delayed_receipts, incoming_receipts, gas_limit):
```

Check failure on line 89 in neps/nep-0541.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

neps/nep-0541.md:89 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
The regular order of receipt processing (same as today) resumes after `process_priority_receipts` is finished.

Note that to efficiently delete from the max heap as part of FIFO receipt processing, a delayed receipt should also store its position in the max heap. This would allow for a O(logn) deletion. In other words, the process of persisting a delayed receipt is as follows:
```python

def store_delayed_receipt(receipt):
# index in the delayed receipt queue
next_available_index = get_delayed_receipt_index()
# get the index of the receipt priority structure in the heap
priority_index = store_receipt_priority(ReceiptPriority(receipt.priority, next_available_index))
# store the actual receipt with index in the heap
store_receipt(DelayedReceipt(receipt, priority_index))
```

### Validator Reward

Even though conceptually, a chunk producer is rewarded a portion of the priority fee for each transaction included in the chunk. We cannot implement this naively due to two reasons:
Expand Down

0 comments on commit af38aef

Please sign in to comment.