8000 feat: add post-state-root data structs by pugachAG · Pull Request #9532 · near/nearcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add post-state-root data structs #9532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,8 @@ impl Chain {
state_root_node,
})
}

ShardChunk::V3(_) => todo!("#9535"),
};
Ok(shard_state_header)
}
Expand Down
26 changes: 5 additions & 21 deletions chain/chain/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use near_primitives::challenge::{
};
use near_primitives::hash::CryptoHash;
use near_primitives::merkle::merklize;
use near_primitives::sharding::{
ShardChunk, ShardChunkHeader, ShardChunkHeaderV1, ShardChunkHeaderV2, ShardChunkHeaderV3,
};
use near_primitives::sharding::{ShardChunk, ShardChunkHeader};
use near_primitives::transaction::SignedTransaction;
use near_primitives::types::chunk_extra::ChunkExtra;
use near_primitives::types::{AccountId, BlockHeight, EpochId, Nonce};
Expand All @@ -29,21 +27,10 @@ pub fn validate_chunk_proofs(
chunk: &ShardChunk,
epoch_manager: &dyn EpochManagerAdapter,
) -> Result<bool, Error> {
let correct_chunk_hash = match chunk {
ShardChunk::V1(chunk) => ShardChunkHeaderV1::compute_hash(&chunk.header.inner),
ShardChunk::V2(chunk) => match &chunk.header {
ShardChunkHeader::V1(header) => ShardChunkHeaderV1::compute_hash(&header.inner),
ShardChunkHeader::V2(header) => ShardChunkHeaderV2::compute_hash(&header.inner),
ShardChunkHeader::V3(header) => ShardChunkHeaderV3::compute_hash(&header.inner),
},
};

let header_hash = match chunk {
ShardChunk::V1(chunk) => chunk.header.chunk_hash(),
ShardChunk::V2(chunk) => chunk.header.chunk_hash(),
};
let correct_chunk_hash = chunk.compute_header_hash();

// 1. Checking chunk.header.hash
let header_hash = chunk.header_hash();
if header_hash != correct_chunk_hash {
byzantine_assert!(false);
return Ok(false);
Expand All @@ -70,11 +57,8 @@ pub fn validate_chunk_proofs(
return Ok(receipts.is_empty() && outgoing_receipts_root == CryptoHash::default());
} else {
let shard_layout = {
let prev_block_hash = match chunk {
ShardChunk::V1(chunk) => &chunk.header.inner.prev_block_hash,
ShardChunk::V2(chunk) => chunk.header.prev_block_hash(),
};
epoch_manager.get_shard_layout_from_prev_block(prev_block_hash)?
let prev_block_hash = chunk.prev_block_hash();
epoch_manager.get_shard_layout_from_prev_block(&prev_block_hash)?
};
let outgoing_receipts_hashes = Chain::build_receipts_hashes(receipts, &shard_layout);
let (receipts_root, _) = merklize(&outgoing_receipts_hashes);
Expand Down
2 changes: 1 addition & 1 deletion chain/network/src/network_protocol/borsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ pub(super) enum PeerMessage {
VersionedStateResponse(StateResponseInfo),
}
#[cfg(target_arch = "x86_64")] // Non-x86_64 doesn't match this requirement yet but it's not bad as it's not production-ready
const _: () = assert!(std::mem::size_of::<PeerMessage>() <= 1144, "PeerMessage > 1144 bytes");
const _: () = assert!(std::mem::size_of::<PeerMessage>() <= 1500, "PeerMessage > 1500 bytes");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what the value of having that and it breaks builds when new fields are added to block or chunk headers, so I'm increasing this value to avoid updating that after each new field is added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any comment or meaningful explanation in the PR where this was introduc 8000 ed? Given this is networking one guess would be something to do with MTU but I doubt that matters to us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, I couldn't find any meaningful explanation on why this is needed.
@saketh-are maybe you (as a networking expert 😄) know something about that?

3 changes: 3 additions & 0 deletions core/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ impl Block {
BlockHeader::BlockHeaderV4(_) => {
debug_assert_eq!(prev.block_ordinal() + 1, block_ordinal)
}
BlockHeader::BlockHeaderV5(_) => {
debug_assert_eq!(prev.block_ordinal() + 1, block_ordinal)
}
};

let body = BlockBody { chunks, challenges, vrf_value, vrf_proof };
Expand Down
Loading
0