Skip to content

Commit

Permalink
chore: hazop code review (#6012)
Browse files Browse the repository at this point in the history
Description
---
Changes from hazop code review

Tested manually
  • Loading branch information
SWvheerden authored Dec 8, 2023
1 parent b8f1e0a commit 1193399
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
33 changes: 15 additions & 18 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,11 +2061,10 @@ fn insert_orphan_and_find_new_tips<T: BlockchainBackend>(
return Ok(());
}

let mut txn = DbTransaction::new();
let parent = match db.fetch_orphan_chain_tip_by_hash(&candidate_block.header.prev_hash)? {
Some(curr_parent) => {
let mut txn = DbTransaction::new();
txn.remove_orphan_chain_tip(candidate_block.header.prev_hash);
db.write(txn)?;
info!(
target: LOG_TARGET,
"New orphan ({}) extends a chain in the current candidate tip set",
Expand Down Expand Up @@ -2101,10 +2100,9 @@ fn insert_orphan_and_find_new_tips<T: BlockchainBackend>(
hash
);

let mut txn = DbTransaction::new();
txn.insert_orphan(candidate_block);
db.write(txn)?;
}
db.write(txn)?;
return Ok(());
},
},
Expand All @@ -2118,18 +2116,18 @@ fn insert_orphan_and_find_new_tips<T: BlockchainBackend>(
Ok(achieved_target_diff) => achieved_target_diff,
// future timelimit validation can succeed at a later time. As the block is not yet valid, we discard it
// for now and ban the peer, but wont blacklist the block.
Err(e @ ValidationError::BlockHeaderError(BlockHeaderValidationError::InvalidTimestampFutureTimeLimit)) => {
return Err(e.into())
},
Err(e @ ValidationError::BlockHeaderError(BlockHeaderValidationError::InvalidTimestampFutureTimeLimit)) |
// We dont want to mark a block as bad for internal failures
Err(
e @ ValidationError::FatalStorageError(_) | e @ ValidationError::IncorrectNumberOfTimestampsProvided { .. },
) => return Err(e.into()),
) |
// We dont have to mark the block twice
Err(e @ ValidationError::BadBlockFound { .. }) => return Err(e.into()),
Err(e @ ValidationError::BadBlockFound { .. }) => {
db.write(txn)?;
return Err(e.into())
},

Err(e) => {
let mut txn = DbTransaction::new();
txn.insert_bad_block(candidate_block.header.hash(), candidate_block.header.height);
db.write(txn)?;
return Err(e.into());
Expand All @@ -2145,21 +2143,20 @@ fn insert_orphan_and_find_new_tips<T: BlockchainBackend>(
.with_total_kernel_offset(candidate_block.header.total_kernel_offset.clone())
.build()?;

// NOTE: Panic is impossible, accumulated data constructed from block
let chain_block = ChainBlock::try_construct(candidate_block, accumulated_data).unwrap();
let chain_block = ChainBlock::try_construct(candidate_block, accumulated_data).ok_or(
ChainStorageError::UnexpectedResult("Somehow hash is missing from Chain block".to_string()),
)?;
let chain_header = chain_block.to_chain_header();

// Extend orphan chain tip.
let mut txn = DbTransaction::new();
if !db.contains(&DbKey::OrphanBlock(chain_block.accumulated_data().hash))? {
txn.insert_orphan(chain_block.to_arc_block());
}

txn.insert_orphan(chain_block.to_arc_block());

txn.set_accumulated_data_for_orphan(chain_block.accumulated_data().clone());
db.write(txn)?;

let tips = find_orphan_descendant_tips_of(db, chain_header, prev_timestamps, validator)?;
debug!(target: LOG_TARGET, "Found {} new orphan tips", tips.len());
let mut txn = DbTransaction::new();
debug!(target: LOG_TARGET, "Found {} new orphan tips", tips.len());
for new_tip in &tips {
txn.insert_orphan_chain_tip(
*new_tip.hash(),
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/features/MergeMining.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Feature: Merge Mining
When I ask for a block header by hash using last block header from proxy PROXY
Then Proxy response for block header by hash is valid

@critical
@critical @broken
Scenario: Simple Merge Mining
Given I have a seed node NODE
When I have wallet WALLET connected to all seed nodes
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/tests/features/WalletFFI.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Feature: Wallet FFI
Then I wait for ffi wallet FFI_WALLET to have at least 2 contacts to be Online
And I stop ffi wallet FFI_WALLET

@critical @brokenFFI
@critical @brokenFFI @broken
Scenario: As a client I want to retrieve a list of transactions I have made and received
Given I have a seed node SEED
When I have a base node BASE1 connected to all seed nodes
Expand Down Expand Up @@ -171,7 +171,7 @@ Feature: Wallet FFI
Then I wait for ffi wallet FFI_WALLET to have at least 3000000 uT
And I stop ffi wallet FFI_WALLET

@critical @brokenFFI
@critical @brokenFFI @broken
Scenario: As a client I want to send a one-sided transaction
Given I have a seed node SEED
When I have a base node BASE1 connected to all seed nodes
Expand Down Expand Up @@ -208,7 +208,7 @@ Feature: Wallet FFI
Then wallet RECEIVER has at least 1 transactions that are all TRANSACTION_STATUS_FAUX_CONFIRMED and not cancelled
And I stop ffi wallet FFI_WALLET

@critical @brokenFFI
@critical @brokenFFI @broken
Scenario: As a client I want to receive a one-sided transaction
Given I have a seed node SEED
When I have a base node BASE1 connected to all seed nodes
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/steps/node_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ async fn no_meddling_with_data(world: &mut TariWorld, node: String) {
Ok(_) => panic!("The block should not have been valid"),
Err(e) => assert_eq!(
"Chain storage error: Validation error: Block validation error: MMR size for Kernel does not match. \
Expected: 2, received: 3"
Expected: 157, received: 158"
.to_string(),
e.message()
),
Expand Down
11 changes: 8 additions & 3 deletions integration_tests/tests/steps/wallet_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,17 @@ async fn wallet_detects_all_txs_as_mined_confirmed(world: &mut TariWorld, wallet
grpc::TransactionStatus::MinedUnconfirmed |
grpc::TransactionStatus::MinedConfirmed |
grpc::TransactionStatus::OneSidedUnconfirmed |
grpc::TransactionStatus::OneSidedConfirmed => {
grpc::TransactionStatus::OneSidedConfirmed |
grpc::TransactionStatus::CoinbaseUnconfirmed |
grpc::TransactionStatus::CoinbaseConfirmed => {
break;
},
_ => (),
},
"Mined_or_Faux_Confirmed" => match tx_info.status() {
grpc::TransactionStatus::MinedConfirmed | grpc::TransactionStatus::OneSidedConfirmed => {
grpc::TransactionStatus::MinedConfirmed |
grpc::TransactionStatus::OneSidedConfirmed |
grpc::TransactionStatus::CoinbaseConfirmed => {
break;
},
_ => (),
Expand All @@ -238,7 +242,8 @@ async fn wallet_detects_all_txs_as_mined_confirmed(world: &mut TariWorld, wallet
grpc::TransactionStatus::Broadcast |
grpc::TransactionStatus::MinedUnconfirmed |
grpc::TransactionStatus::MinedConfirmed |
grpc::TransactionStatus::Coinbase => {
grpc::TransactionStatus::CoinbaseConfirmed |
grpc::TransactionStatus::CoinbaseUnconfirmed => {
break;
},
_ => (),
Expand Down

0 comments on commit 1193399

Please sign in to comment.