Skip to content

Commit fe6de8b

Browse files
committed
Drop test_problematic_blocks_are_not_relayed_or_stored and expand test_static_problematic_tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 85695ff commit fe6de8b

File tree

2 files changed

+58
-365
lines changed

2 files changed

+58
-365
lines changed

stacks-node/src/tests/neon_integrations.rs

Lines changed: 0 additions & 323 deletions
Original file line numberDiff line numberDiff line change
@@ -8268,329 +8268,6 @@ fn test_problematic_blocks_are_not_mined() {
82688268
follower_channel.stop_chains_coordinator();
82698269
}
82708270

8271-
// TODO: test in epoch 2.1 with parser_v2
8272-
#[test]
8273-
#[ignore]
8274-
fn test_problematic_blocks_are_not_relayed_or_stored() {
8275-
if env::var("BITCOIND_TEST") != Ok("1".into()) {
8276-
return;
8277-
}
8278-
8279-
let bad_blocks_dir = "/tmp/bad-blocks-test_problematic_blocks_are_not_relayed_or_stored";
8280-
if fs::metadata(bad_blocks_dir).is_ok() {
8281-
fs::remove_dir_all(bad_blocks_dir).unwrap();
8282-
}
8283-
fs::create_dir_all(bad_blocks_dir).unwrap();
8284-
8285-
std::env::set_var("STACKS_BAD_BLOCKS_DIR", bad_blocks_dir);
8286-
8287-
let spender_sk_1 = StacksPrivateKey::from_hex(SK_1).unwrap();
8288-
let spender_sk_2 = StacksPrivateKey::from_hex(SK_2).unwrap();
8289-
let spender_sk_3 = StacksPrivateKey::from_hex(SK_3).unwrap();
8290-
let spender_stacks_addr_1 = to_addr(&spender_sk_1);
8291-
let spender_stacks_addr_2 = to_addr(&spender_sk_2);
8292-
let spender_stacks_addr_3 = to_addr(&spender_sk_3);
8293-
let spender_addr_1: PrincipalData = spender_stacks_addr_1.into();
8294-
let spender_addr_2: PrincipalData = spender_stacks_addr_2.into();
8295-
let spender_addr_3: PrincipalData = spender_stacks_addr_3.into();
8296-
8297-
let (mut conf, _) = neon_integration_test_conf();
8298-
8299-
conf.initial_balances.push(InitialBalance {
8300-
address: spender_addr_1,
8301-
amount: 1_000_000_000_000,
8302-
});
8303-
conf.initial_balances.push(InitialBalance {
8304-
address: spender_addr_2,
8305-
amount: 1_000_000_000_000,
8306-
});
8307-
conf.initial_balances.push(InitialBalance {
8308-
address: spender_addr_3,
8309-
amount: 1_000_000_000_000,
8310-
});
8311-
8312-
// force mainnet limits in 2.05 for this test
8313-
conf.burnchain.epochs = Some(EpochList::new(&[
8314-
StacksEpoch {
8315-
epoch_id: StacksEpochId::Epoch20,
8316-
start_height: 0,
8317-
end_height: 1,
8318-
block_limit: BLOCK_LIMIT_MAINNET_20.clone(),
8319-
network_epoch: PEER_VERSION_EPOCH_2_0,
8320-
},
8321-
StacksEpoch {
8322-
epoch_id: StacksEpochId::Epoch2_05,
8323-
start_height: 1,
8324-
end_height: 10_002,
8325-
block_limit: BLOCK_LIMIT_MAINNET_205.clone(),
8326-
network_epoch: PEER_VERSION_EPOCH_2_05,
8327-
},
8328-
StacksEpoch {
8329-
epoch_id: StacksEpochId::Epoch21,
8330-
start_height: 10_002,
8331-
end_height: 9223372036854775807,
8332-
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
8333-
network_epoch: PEER_VERSION_EPOCH_2_1,
8334-
},
8335-
]));
8336-
conf.burnchain.pox_2_activation = Some(10_003);
8337-
8338-
test_observer::spawn();
8339-
test_observer::register_any(&mut conf);
8340-
8341-
let mut btcd_controller = BitcoinCoreController::from_stx_config(&conf);
8342-
btcd_controller
8343-
.start_bitcoind()
8344-
.expect("Failed starting bitcoind");
8345-
8346-
let mut btc_regtest_controller = BitcoinRegtestController::new(conf.clone(), None);
8347-
let http_origin = format!("http://{}", &conf.node.rpc_bind);
8348-
8349-
// something just over the limit of the expression depth
8350-
let exceeds_repeat_factor = 32;
8351-
let tx_exceeds_body_start = "{ a : ".repeat(exceeds_repeat_factor as usize);
8352-
let tx_exceeds_body_end = "} ".repeat(exceeds_repeat_factor as usize);
8353-
let tx_exceeds_body = format!("{tx_exceeds_body_start}u1 {tx_exceeds_body_end}");
8354-
8355-
let tx_exceeds = make_contract_publish(
8356-
&spender_sk_2,
8357-
0,
8358-
(tx_exceeds_body.len() * 100) as u64,
8359-
conf.burnchain.chain_id,
8360-
"test-exceeds",
8361-
&tx_exceeds_body,
8362-
);
8363-
let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..])
8364-
.unwrap()
8365-
.txid();
8366-
8367-
let high_repeat_factor = 70;
8368-
let tx_high_body_start = "{ a : ".repeat(high_repeat_factor as usize);
8369-
let tx_high_body_end = "} ".repeat(high_repeat_factor as usize);
8370-
let tx_high_body = format!("{tx_high_body_start}u1 {tx_high_body_end}");
8371-
8372-
let tx_high = make_contract_publish(
8373-
&spender_sk_3,
8374-
0,
8375-
(tx_high_body.len() * 100) as u64,
8376-
conf.burnchain.chain_id,
8377-
"test-high",
8378-
&tx_high_body,
8379-
);
8380-
let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..])
8381-
.unwrap()
8382-
.txid();
8383-
8384-
btc_regtest_controller.bootstrap_chain(201);
8385-
8386-
eprintln!("Chain bootstrapped...");
8387-
8388-
let mut run_loop = neon::RunLoop::new(conf.clone());
8389-
let blocks_processed = run_loop.get_blocks_processed_arc();
8390-
let channel = run_loop.get_coordinator_channel().unwrap();
8391-
8392-
thread::spawn(move || run_loop.start(None, 0));
8393-
8394-
// Give the run loop some time to start up!
8395-
wait_for_runloop(&blocks_processed);
8396-
8397-
// First block wakes up the run loop.
8398-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
8399-
8400-
// Second block will hold our VRF registration.
8401-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
8402-
8403-
// Third block will be the first mined Stacks block.
8404-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
8405-
8406-
debug!("Submit problematic tx_exceeds transaction {tx_exceeds_txid}");
8407-
std::env::set_var("STACKS_DISABLE_TX_PROBLEMATIC_CHECK", "1");
8408-
submit_tx(&http_origin, &tx_exceeds);
8409-
assert!(get_unconfirmed_tx(&http_origin, &tx_exceeds_txid).is_some());
8410-
std::env::set_var("STACKS_DISABLE_TX_PROBLEMATIC_CHECK", "0");
8411-
8412-
let (_, mut cur_files) = find_new_files(bad_blocks_dir, &HashSet::new());
8413-
let old_tip_info = get_chain_info(&conf);
8414-
let mut all_new_files = vec![];
8415-
8416-
for _i in 0..5 {
8417-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
8418-
let cur_files_old = cur_files.clone();
8419-
let (mut new_files, cur_files_new) = find_new_files(bad_blocks_dir, &cur_files_old);
8420-
all_new_files.append(&mut new_files);
8421-
cur_files = cur_files_new;
8422-
}
8423-
8424-
let tip_info = get_chain_info(&conf);
8425-
8426-
// blocks were all processed
8427-
assert_eq!(
8428-
tip_info.stacks_tip_height,
8429-
old_tip_info.stacks_tip_height + 5
8430-
);
8431-
// no blocks considered problematic
8432-
assert!(all_new_files.is_empty());
8433-
8434-
// one block contained tx_exceeds
8435-
let blocks = test_observer::get_blocks();
8436-
let mut found = false;
8437-
for block in blocks {
8438-
let transactions = block.get("transactions").unwrap().as_array().unwrap();
8439-
for tx in transactions.iter() {
8440-
let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap();
8441-
if raw_tx == "0x00" {
8442-
continue;
8443-
}
8444-
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
8445-
let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
8446-
if let TransactionPayload::SmartContract(..) = &parsed.payload {
8447-
if parsed.txid() == tx_exceeds_txid {
8448-
found = true;
8449-
break;
8450-
}
8451-
}
8452-
}
8453-
}
8454-
8455-
assert!(found);
8456-
8457-
let tip = {
8458-
let sortdb = btc_regtest_controller.sortdb_mut();
8459-
let tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
8460-
eprintln!("Sort db tip: {}", tip.block_height);
8461-
tip
8462-
};
8463-
8464-
btc_regtest_controller.build_next_block(1);
8465-
8466-
// wait for runloop to advance
8467-
wait_for(30, || {
8468-
let sortdb = btc_regtest_controller.sortdb_mut();
8469-
let new_tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
8470-
Ok(new_tip.block_height > tip.block_height)
8471-
})
8472-
.expect("Runloop failed to advance");
8473-
8474-
// add another bad tx to the mempool.
8475-
// TODO: Forcibly mine a bad transaction to simulate a bad miner?
8476-
debug!("Submit problematic tx_high transaction {tx_high_txid}");
8477-
std::env::set_var("STACKS_DISABLE_TX_PROBLEMATIC_CHECK", "1");
8478-
submit_tx(&http_origin, &tx_high);
8479-
assert!(get_unconfirmed_tx(&http_origin, &tx_high_txid).is_some());
8480-
std::env::set_var("STACKS_DISABLE_TX_PROBLEMATIC_CHECK", "0");
8481-
8482-
let (_, mut cur_files) = find_new_files(bad_blocks_dir, &HashSet::new());
8483-
let old_tip_info = get_chain_info(&conf);
8484-
let mut all_new_files = vec![];
8485-
8486-
eprintln!("old_tip_info = {old_tip_info:?}");
8487-
8488-
// mine some blocks, and log problematic blocks
8489-
for _i in 0..6 {
8490-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
8491-
let cur_files_old = cur_files.clone();
8492-
let (mut new_files, cur_files_new) = find_new_files(bad_blocks_dir, &cur_files_old);
8493-
all_new_files.append(&mut new_files);
8494-
cur_files = cur_files_new;
8495-
}
8496-
8497-
let tip_info = get_chain_info(&conf);
8498-
8499-
// at least one block was mined (hard to say how many due to the raciness between the burnchain
8500-
// downloader and this thread).
8501-
info!(
8502-
"tip_info.stacks_tip_height = {}, old_tip_info.stacks_tip_height = {}",
8503-
tip_info.stacks_tip_height, old_tip_info.stacks_tip_height
8504-
);
8505-
assert!(tip_info.stacks_tip_height > old_tip_info.stacks_tip_height);
8506-
// one was problematic -- i.e. the one that included tx_high
8507-
assert_eq!(all_new_files.len(), 1);
8508-
8509-
// tx_high got mined by the miner
8510-
let blocks = test_observer::get_blocks();
8511-
let mut bad_block_height = None;
8512-
for block in blocks {
8513-
let transactions = block.get("transactions").unwrap().as_array().unwrap();
8514-
for tx in transactions.iter() {
8515-
let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap();
8516-
if raw_tx == "0x00" {
8517-
continue;
8518-
}
8519-
let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap();
8520-
let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
8521-
if let TransactionPayload::SmartContract(..) = &parsed.payload {
8522-
if parsed.txid() == tx_high_txid {
8523-
bad_block_height = Some(block.get("block_height").unwrap().as_u64().unwrap());
8524-
}
8525-
}
8526-
}
8527-
}
8528-
assert!(bad_block_height.is_some());
8529-
let bad_block_height = bad_block_height.unwrap();
8530-
8531-
// follower should not process bad_block_height or higher
8532-
let new_tip_info = get_chain_info(&conf);
8533-
8534-
eprintln!("\nBooting follower\n");
8535-
8536-
// verify that a follower node that boots up with this node as a bootstrap peer will process
8537-
// all of the blocks available, even if they are problematic, with the checks on.
8538-
let (follower_conf, _, pox_sync_comms, follower_channel) = spawn_follower_node(&conf);
8539-
8540-
eprintln!(
8541-
"\nFollower booted on port {},{}\n",
8542-
follower_conf.node.p2p_bind, follower_conf.node.rpc_bind
8543-
);
8544-
8545-
wait_for(300, || {
8546-
let follower_tip_info = get_chain_info(&follower_conf);
8547-
eprintln!(
8548-
"\nFollower is at burn block {} stacks block {} (bad_block is {bad_block_height})\n",
8549-
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height
8550-
);
8551-
Ok(
8552-
follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height
8553-
|| follower_tip_info.stacks_tip_height + 1 == bad_block_height,
8554-
)
8555-
})
8556-
.expect("Follower failed to advance");
8557-
8558-
// make sure we aren't just slow -- wait for the follower to do a few download passes
8559-
let num_download_passes = pox_sync_comms.get_download_passes();
8560-
eprintln!(
8561-
"\nFollower has performed {num_download_passes} download passes; wait for {}\n",
8562-
num_download_passes + 5
8563-
);
8564-
8565-
wait_for(30, || {
8566-
eprintln!(
8567-
"\nFollower has performed {} download passes; wait for {}\n",
8568-
pox_sync_comms.get_download_passes(),
8569-
num_download_passes + 5
8570-
);
8571-
Ok(pox_sync_comms.get_download_passes() >= num_download_passes + 5)
8572-
})
8573-
.expect("Follower failed to perform download passes");
8574-
8575-
eprintln!(
8576-
"\nFollower has performed {} download passes\n",
8577-
pox_sync_comms.get_download_passes()
8578-
);
8579-
8580-
let follower_tip_info = get_chain_info(&follower_conf);
8581-
eprintln!(
8582-
"\nFollower is at burn block {} stacks block {} (bad block is {bad_block_height})\n",
8583-
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height
8584-
);
8585-
8586-
// follower rejects the bad block
8587-
assert_eq!(follower_tip_info.stacks_tip_height, bad_block_height - 1);
8588-
8589-
test_observer::clear();
8590-
channel.stop_chains_coordinator();
8591-
follower_channel.stop_chains_coordinator();
8592-
}
8593-
85948271
/// Verify that we push all boot receipts even before bootstrapping
85958272
#[test]
85968273
#[ignore]

0 commit comments

Comments
 (0)