-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stateless validation] Real ChunkStateWitness struct, and prototype v…
…alidation logic (#10381) This fills in the ChunkStateWitness struct with real data that would be included in a chunk state witness. It also includes a prototype implementation for validating the ChunkStateWitness against the chain, which includes a pre-validation part where the ChainStore is used to retrieve necessary blocks and chunk headers (to verify receipts and transactions against), as well as the main validation part where transactions and receipts are applied with the runtime. This verification logic is untested right now because the state witness production part is not implemented. #9292
- Loading branch information
1 parent
0a98fbd
commit 6001359
Showing
11 changed files
with
562 additions
and
117 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use near_primitives::hash::CryptoHash; | ||
use rand::seq::SliceRandom; | ||
use rand::SeedableRng; | ||
use rand_chacha::ChaCha20Rng; | ||
|
||
pub fn shuffle_receipt_proofs<ReceiptProofType>( | ||
receipt_proofs: &mut Vec<ReceiptProofType>, | ||
block_hash: &CryptoHash, | ||
) { | ||
let mut slice = [0u8; 32]; | ||
slice.copy_from_slice(block_hash.as_ref()); | ||
let mut rng: ChaCha20Rng = SeedableRng::from_seed(slice); | ||
receipt_proofs.shuffle(&mut rng); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::sharding::shuffle_receipt_proofs; | ||
use near_primitives::hash::CryptoHash; | ||
|
||
#[test] | ||
pub fn receipt_randomness_reproducibility() { | ||
// Sanity check that the receipt shuffling implementation does not change. | ||
let mut receipt_proofs = vec![0, 1, 2, 3, 4, 5, 6]; | ||
shuffle_receipt_proofs(&mut receipt_proofs, &CryptoHash::hash_bytes(&[1, 2, 3, 4, 5])); | ||
assert_eq!(receipt_proofs, vec![2, 3, 1, 4, 0, 5, 6],); | ||
} | ||
} |
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.