-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(congestion) - Correctly handle receipt gas and size calculation i…
…n protocol upgrades (#12031) For now just a request for comments. There are still a few missing pieces like adding tests and gating this feature by a protocol feature. Please let me know if this approach makes sense on a high level. This PR addresses the issue described in #11923. Please have a look at that first for context. This is a hacky implementation of option 1: "Store the receipts together with the gas and size when added and use that when removing the receipt from buffer." The basic idea is that instead of storing `Receipt` directly in state, it can be wrapped in a `StateStoredReceipt` together with the metadata that is needed to correctly handle protocol upgrades. In order to migrate from the old way of storing receipts I'm using a rather hacky solution. I implemented a custom serialization and deserialization for the `StateStoredReceipt`. Using that customization it's possible to discriminate between serialized Receipt and serialized StateStoredReceipt. I added a helper struct `ReceiptOrStateStoredReceipt` and I made it so that both Receipt and StateStoredReceipt can be deserialized directly to it. How to differentiate between `Receipt` and `StateStoredReceipt` ? * Receipt::V0 has first two bytes in the form of [x, 0] - the second byte is zero. * Receipt::V1 has first two bytes in the form of [1, x] - where x != 0 - the first byte is one and second is non-zero. * Receipt::Vn (future) has first two bytes in the form of [n, x] - where x != 0 * StateStoredReceipt has first two bytes in the for of [T, T] where T is a magic tag == u8::MAX. The `StateStoredReceipt` can be told apart from Receipt::V0 by the second byte. The `StateStoredReceipt` can be told apart from Receipt::Vn by the first byte. Receipt::V0 and Receipt::V1 can be told apart by the second byte as described in https://github.com/near/nearcore/blob/0e5e7c7234952d1db8cbbafc984b7c8e6a1ac0ba/core/primitives/src/receipt.rs#L105-L118 How will the migration from `Receipt` to `StateStoredReceipt` happen? * In the old protocol version receipts will be stored as `Receipt` * In the new protocol version receipts will be stored as `StateStoredReceipt` * In both version receipts will be read as `ReceiptOrStateStoredReceipt`. This covers the fun case where receipts are stored in the old version and read in the new version.
- Loading branch information
Showing
22 changed files
with
648 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,3 +268,5 @@ reject_tx_congestion_threshold: { | |
numerator: 1, | ||
denominator: 1, | ||
} | ||
|
||
use_state_stored_receipt: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,3 +259,5 @@ reject_tx_congestion_threshold: { | |
numerator: 1, | ||
denominator: 1, | ||
} | ||
|
||
use_state_stored_receipt: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.