Skip to content

Commit

Permalink
Merge #4392
Browse files Browse the repository at this point in the history
4392: Update `BlockV2` to hold `TransactionHash`es r=Fraser999 a=Fraser999

This PR updates the `BlockV2` types to handle `Transaction`s rather than just `Deploy`s.

As discussed in a recent standup, the `UserlandTransactionV1::Noop` variant was removed.

Closes [roadmap#183](casper-network/roadmap#183).

Co-authored-by: Fraser Hutchison <fraser@casperlabs.io>
  • Loading branch information
casperlabs-bors-ng[bot] and Fraser999 authored Nov 3, 2023
2 parents 797b823 + a118d05 commit 381ebcc
Show file tree
Hide file tree
Showing 65 changed files with 1,764 additions and 1,102 deletions.
2 changes: 0 additions & 2 deletions execution_engine/src/tracking_copy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,6 @@ fn validate_query_proof_should_work() {
panic!("query was not successful: {:?}", misfit_result)
};

println!("Validating the injected proof");

// Proof has been subject to an injection
assert_eq!(
tracking_copy::validate_query_proof(
Expand Down
24 changes: 21 additions & 3 deletions node/src/components/block_synchronizer/block_acquisition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing::{debug, error, info, trace, warn};

use casper_types::{
execution::ExecutionResult, Block, BlockHash, BlockHeader, DeployHash, DeployId, Digest, EraId,
FinalitySignature, ProtocolVersion, PublicKey,
FinalitySignature, ProtocolVersion, PublicKey, TransactionHash,
};

use crate::{
Expand Down Expand Up @@ -584,7 +584,16 @@ impl BlockAcquisitionState {
"BlockAcquisition: registering block for: {}",
header.block_hash()
);
let deploy_hashes = block.deploy_and_transfer_hashes().copied().collect();
let deploy_hashes = match &block {
Block::V1(v1) => v1.deploy_and_transfer_hashes().copied().collect(),
Block::V2(v2) => v2
.all_transactions()
.filter_map(|txn_hash| match txn_hash {
TransactionHash::Deploy(deploy_hash) => Some(*deploy_hash),
TransactionHash::V1(_) => None,
})
.collect(),
};
let deploy_acquisition =
DeployAcquisition::new_by_hash(deploy_hashes, need_execution_state);

Expand Down Expand Up @@ -1032,7 +1041,16 @@ impl BlockAcquisitionState {
"BlockAcquisition: registering execution result or chunk for: {}",
block.hash()
);
let deploy_hashes = block.deploy_and_transfer_hashes().copied().collect();
let deploy_hashes = match block.as_ref() {
Block::V1(v1) => v1.deploy_and_transfer_hashes().copied().collect(),
Block::V2(v2) => v2
.all_transactions()
.filter_map(|txn_hash| match txn_hash {
TransactionHash::Deploy(deploy_hash) => Some(*deploy_hash),
TransactionHash::V1(_) => None,
})
.collect(),
};
match exec_results_acq
.clone()
.apply_block_execution_results_or_chunk(
Expand Down
13 changes: 7 additions & 6 deletions node/src/components/block_synchronizer/block_builder/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{collections::BTreeMap, thread, time::Duration};

use casper_types::{testing::TestRng, Deploy, TestBlockBuilder};
use num_rational::Ratio;

use casper_types::{testing::TestRng, TestBlockBuilder, Transaction};

use crate::components::consensus::tests::utils::{ALICE_PUBLIC_KEY, ALICE_SECRET_KEY};

use super::*;
Expand Down Expand Up @@ -239,9 +240,9 @@ fn register_executable_block() {
Acceptance::NeededIt
);
// Set the builder's state to `HaveStrictFinalitySignatures`.
let expected_deploys = vec![Deploy::random(&mut rng)];
let expected_txns = vec![Transaction::random(&mut rng)];
let executable_block =
ExecutableBlock::from_block_and_deploys(block.clone(), expected_deploys.clone());
ExecutableBlock::from_block_and_transactions(block.clone(), expected_txns.clone());
builder.acquisition_state = BlockAcquisitionState::HaveStrictFinalitySignatures(
Box::new(block.clone().into()),
signature_acquisition.clone(),
Expand All @@ -253,7 +254,7 @@ fn register_executable_block() {
match &builder.acquisition_state {
BlockAcquisitionState::HaveExecutableBlock(actual_block, executable_block, enqueued) => {
assert_eq!(actual_block.hash(), block.hash());
assert_eq!(expected_deploys, *executable_block.deploys);
assert_eq!(expected_txns, *executable_block.transactions);
assert!(!enqueued);
}
_ => panic!("Unexpected outcome in registering finalized block"),
Expand Down Expand Up @@ -308,9 +309,9 @@ fn register_block_execution() {
Acceptance::NeededIt
);

let executable_block = Box::new(ExecutableBlock::from_block_and_deploys(
let executable_block = Box::new(ExecutableBlock::from_block_and_transactions(
block.clone(),
vec![Deploy::random(&mut rng)],
vec![Transaction::random(&mut rng)],
));
builder.acquisition_state =
BlockAcquisitionState::HaveExecutableBlock(Box::new(block.into()), executable_block, false);
Expand Down
11 changes: 9 additions & 2 deletions node/src/components/block_synchronizer/deploy_acquisition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use datasize::DataSize;
use tracing::debug;

use casper_types::{DeployHash, DeployId};
use casper_types::{DeployHash, DeployId, TransactionApprovalsHash};

use crate::types::ApprovalsHashes;

Expand Down Expand Up @@ -68,7 +68,14 @@ impl DeployAcquisition {
for ((deploy_hash, deploy_state), approvals_hash) in acquisition
.inner
.drain(..)
.zip(approvals_hashes.approvals_hashes())
.zip(approvals_hashes.approvals_hashes().iter().filter_map(
|txn_approvals_hash| match txn_approvals_hash {
TransactionApprovalsHash::Deploy(deploy_approvals_hash) => {
Some(deploy_approvals_hash)
}
TransactionApprovalsHash::V1(_) => None,
},
))
{
if !matches!(deploy_state, DeployState::Vacant) {
return Err(Error::EncounteredNonVacantDeployState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use rand::Rng;

use casper_storage::global_state::trie::merkle_proof::TrieMerkleProof;
use casper_types::{
testing::TestRng, AccessRights, CLValue, Deploy, StoredValue, TestBlockBuilder, URef,
testing::TestRng, AccessRights, CLValue, Deploy, StoredValue, TestBlockBuilder, Transaction,
URef,
};

use crate::types::ApprovalsHashes;
Expand All @@ -28,14 +29,18 @@ fn gen_approvals_hashes<'a, I: Iterator<Item = &'a Deploy> + Clone>(
deploys_iter: I,
) -> ApprovalsHashes {
let era = rng.gen_range(0..6);
let txns: Vec<_> = deploys_iter
.clone()
.map(|deploy| Transaction::from(deploy.clone()))
.collect();
let block = TestBlockBuilder::new()
.era(era)
.height(era * 10 + rng.gen_range(0..10))
.deploys(deploys_iter.clone())
.transactions(&txns)
.build(rng);

ApprovalsHashes::new(
block.hash(),
ApprovalsHashes::new_v1(
*block.hash(),
deploys_iter
.map(|deploy| deploy.compute_approvals_hash().unwrap())
.collect(),
Expand Down
Loading

0 comments on commit 381ebcc

Please sign in to comment.