diff --git a/neps/nep-0541.md b/neps/nep-0541.md index 02e3a0b81..f3f3d5b8b 100644 --- a/neps/nep-0541.md +++ b/neps/nep-0541.md @@ -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: @@ -98,18 +89,6 @@ def process_priority_receipts(delayed_receipts, incoming_receipts, gas_limit): ``` 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: