Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyan Gupta committed Jun 21, 2024
1 parent 05a34e6 commit 7a6e982
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fn build_chain_with_orphans() {
*last_block.header().next_bp_hash(),
CryptoHash::default(),
clock,
None,
);
assert_matches!(chain.process_block_test(&None, block).unwrap_err(), Error::Orphan);
assert_matches!(
Expand Down
8 changes: 6 additions & 2 deletions chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ impl Client {
prev_next_bp_hash
};

#[cfg(feature = "sandbox")]
let sandbox_delta_time = Some(self.sandbox_delta_time());
#[cfg(not(feature = "sandbox"))]
let sandbox_delta_time = None;

// Get block extra from previous block.
let block_merkle_tree = self.chain.chain_store().get_block_merkle_tree(&prev_hash)?;
let mut block_merkle_tree = PartialMerkleTree::clone(&block_merkle_tree);
Expand Down Expand Up @@ -798,8 +803,7 @@ impl Client {
next_bp_hash,
block_merkle_root,
self.clock.clone(),
#[cfg(feature = "sandbox")]
self.sandbox_delta_time(),
sandbox_delta_time,
);

// Update latest known even before returning block out, to prevent race conditions.
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/sync/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ mod test {
*last_block.header().next_bp_hash(),
block_merkle_tree.root(),
clock.clock(),
None,
);
block_merkle_tree.insert(*block.hash());
chain2.process_block_header(block.header(), &mut Vec::new()).unwrap(); // just to validate
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/test_utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub fn create_chunk(
*last_block.header().next_bp_hash(),
block_merkle_tree.root(),
client.clock.clone(),
None,
);
(
ProduceChunkResult {
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/tests/query_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn query_status_not_crash() {
block.header.next_bp_hash,
block_merkle_tree.root(),
Clock::real(),
None,
);
next_block.mut_header().get_mut().inner_lite.timestamp =
(next_block.header().timestamp() + Duration::seconds(60)).unix_timestamp_nanos()
Expand Down
1 change: 1 addition & 0 deletions chain/network/src/network_protocol/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn make_block(
CryptoHash::default(),
CryptoHash::default(),
clock,
None,
)
}

Expand Down
1 change: 1 addition & 0 deletions core/primitives/benches/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn create_block() -> Block {
CryptoHash::default(),
CryptoHash::default(),
Clock::real(),
None,
)
}

Expand Down
8 changes: 5 additions & 3 deletions core/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::validator_signer::ValidatorSigner;
use crate::version::{ProtocolVersion, SHARD_CHUNK_HEADER_UPGRADE_VERSION};
use borsh::{BorshDeserialize, BorshSerialize};
use near_crypto::Signature;
use near_time::{Clock, Utc};
use near_time::{Clock, Duration, Utc};
use primitive_types::U256;
use std::collections::BTreeMap;
use std::ops::Index;
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Block {
next_bp_hash: CryptoHash,
block_merkle_root: CryptoHash,
clock: Clock,
#[cfg(feature = "sandbox")] sandbox_delta_time: near_time::Duration,
sandbox_delta_time: Option<Duration>,
) -> Self {
// Collect aggregate of validators and gas usage/limits from chunks.
let mut prev_validator_proposals = vec![];
Expand Down Expand Up @@ -299,7 +299,9 @@ impl Block {
let new_total_supply = prev.total_supply() + minted_amount.unwrap_or(0) - balance_burnt;
let now = clock.now_utc().unix_timestamp_nanos() as u64;
#[cfg(feature = "sandbox")]
let now = now + sandbox_delta_time;
let now = now + sandbox_delta_time.unwrap().whole_nanoseconds() as u64;
#[cfg(not(feature = "sandbox"))]
debug_assert!(sandbox_delta_time.is_none());
let time = if now <= prev.raw_timestamp() { prev.raw_timestamp() + 1 } else { now };

let (vrf_value, vrf_proof) = signer.compute_vrf_with_proof(prev.random_value().as_ref());
Expand Down
1 change: 1 addition & 0 deletions core/primitives/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ impl TestBlockBuilder {
self.next_bp_hash,
self.block_merkle_root,
self.clock,
None,
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/src/tests/client/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn test_verify_block_double_sign_challenge() {
*b1.header().next_bp_hash(),
block_merkle_tree.root(),
Clock::real(),
None,
);
let epoch_id = b1.header().epoch_id().clone();
let valid_challenge = Challenge::produce(
Expand Down Expand Up @@ -438,6 +439,7 @@ fn test_verify_chunk_invalid_state_challenge() {
*last_block.header().next_bp_hash(),
block_merkle_tree.root(),
Clock::real(),
None,
);

let challenge_body =
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ fn receive_network_block() {
last_block.header.next_bp_hash,
block_merkle_tree.root(),
Clock::real(),
None,
);
actor_handles.client_actor.do_send(
BlockResponse { block, peer_id: PeerInfo::random().id, was_requested: false }
Expand Down Expand Up @@ -436,6 +437,7 @@ fn produce_block_with_approvals() {
last_block.header.next_bp_hash,
block_merkle_tree.root(),
Clock::real(),
None,
);
actor_handles.client_actor.do_send(
BlockResponse {
Expand Down Expand Up @@ -652,6 +654,7 @@ fn invalid_blocks_common(is_requested: bool) {
last_block.header.next_bp_hash,
block_merkle_tree.root(),
Clock::real(),
None,
);
// Send block with invalid chunk mask
let mut block = valid_block.clone();
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/tests/nearcore_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn add_blocks(
next_bp_hash,
block_merkle_tree.root(),
clock.clone(),
None,
);
block_merkle_tree.insert(*block.hash());
let _ = client.do_send(
Expand Down

0 comments on commit 7a6e982

Please sign in to comment.