-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stateless_validation] Introduce versioned BlockBody (#10411)
This PR introduces versioned BlockBody struct which would be a part of BlockV4. Note that this isn't being used with the current protocol version. Eventually with stateless validation, we are going to have chunk endorsements as part of the BlockBody, the structure of which would look something like this or equivalent (still undecided if we need `Vec<Vec<ChunkEndorsement>>` or `Vec<ChunkEndorsement>`) ``` pub struct BlockBodyV2 { pub chunks: Vec<ShardChunkHeader>, pub challenges: Challenges, // Data to confirm the correctness of randomness beacon output pub vrf_value: Value, pub vrf_proof: Proof, // Chunk Endorsements pub chunk_endorsements: Vec<ChunkEndorsement>, } ```
- Loading branch information
Shreyan Gupta
authored
Jan 12, 2024
1 parent
ac967f6
commit 12bfdda
Showing
7 changed files
with
222 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use near_crypto::vrf::{Proof, Value}; | ||
use near_primitives_core::hash::CryptoHash; | ||
use near_primitives_core::types::ProtocolVersion; | ||
|
||
use crate::challenge::Challenges; | ||
use crate::sharding::ShardChunkHeader; | ||
|
||
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, Eq, PartialEq)] | ||
pub struct BlockBodyV1 { | ||
pub chunks: Vec<ShardChunkHeader>, | ||
pub challenges: Challenges, | ||
|
||
// Data to confirm the correctness of randomness beacon output | ||
pub vrf_value: Value, | ||
pub vrf_proof: Proof, | ||
} | ||
|
||
impl BlockBodyV1 { | ||
pub fn compute_hash(&self) -> CryptoHash { | ||
CryptoHash::hash_borsh(self) | ||
} | ||
} | ||
|
||
// For now, we only have one version of block body. | ||
// Eventually with ChunkValidation, we would include ChunkEndorsement in BlockBodyV2 | ||
#[derive(BorshSerialize, BorshDeserialize, Clone, PartialEq, Eq, Debug)] | ||
pub enum BlockBody { | ||
V1(BlockBodyV1), | ||
} | ||
|
||
impl BlockBody { | ||
pub fn new( | ||
_protocol_version: ProtocolVersion, | ||
chunks: Vec<ShardChunkHeader>, | ||
challenges: Challenges, | ||
vrf_value: Value, | ||
vrf_proof: Proof, | ||
) -> Self { | ||
// Eventually we will have different versions of block body, but for now we only have V1. | ||
BlockBody::V1(BlockBodyV1 { chunks, challenges, vrf_value, vrf_proof }) | ||
} | ||
|
||
#[inline] | ||
pub fn chunks(&self) -> &[ShardChunkHeader] { | ||
match self { | ||
BlockBody::V1(body) => &body.chunks, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn challenges(&self) -> &Challenges { | ||
match self { | ||
BlockBody::V1(body) => &body.challenges, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn vrf_value(&self) -> &Value { | ||
match self { | ||
BlockBody::V1(body) => &body.vrf_value, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn vrf_proof(&self) -> &Proof { | ||
match self { | ||
BlockBody::V1(body) => &body.vrf_proof, | ||
} | ||
} | ||
|
||
pub fn compute_hash(&self) -> CryptoHash { | ||
match self { | ||
BlockBody::V1(body) => body.compute_hash(), | ||
} | ||
} | ||
} |
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.