Skip to content

Commit 4e0bf1c

Browse files
authored
Merge branch 'develop' into fix/5193-stackerdb-decoherence
2 parents 707f7cb + 0146ba2 commit 4e0bf1c

File tree

6 files changed

+67
-5
lines changed

6 files changed

+67
-5
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
- tests::neon_integrations::min_txs
7575
- tests::neon_integrations::vote_for_aggregate_key_burn_op_test
7676
- tests::neon_integrations::mock_miner_replay
77+
- tests::neon_integrations::listunspent_max_utxos
7778
- tests::epoch_25::microblocks_disabled
7879
- tests::should_succeed_handling_malformed_and_valid_txs
7980
- tests::nakamoto_integrations::simple_neon_integration

testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,10 @@ impl UTXOSet {
23142314
pub fn total_available(&self) -> u64 {
23152315
self.utxos.iter().map(|o| o.amount).sum()
23162316
}
2317+
2318+
pub fn num_utxos(&self) -> usize {
2319+
self.utxos.len()
2320+
}
23172321
}
23182322

23192323
#[derive(Debug, Clone)]
@@ -2607,7 +2611,7 @@ impl BitcoinRPCRequest {
26072611
max_conf.into(),
26082612
addresses.into(),
26092613
include_unsafe.into(),
2610-
json!({ "minimumAmount": minimum_amount }),
2614+
json!({ "minimumAmount": minimum_amount, "maximumCount": config.burnchain.max_unspent_utxos }),
26112615
],
26122616
id: "stacks".to_string(),
26132617
jsonrpc: "2.0".to_string(),

testnet/stacks-node/src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,10 @@ pub struct BurnchainConfig {
14461446
/// fault injection to simulate a slow burnchain peer.
14471447
/// Delay burnchain block downloads by the given number of millseconds
14481448
pub fault_injection_burnchain_block_delay: u64,
1449+
/// The maximum number of unspent UTXOs to request from the bitcoin node.
1450+
/// This value is passed as the `maximumCount` query option to the
1451+
/// `listunspent` RPC call.
1452+
pub max_unspent_utxos: Option<u64>,
14491453
}
14501454

14511455
impl BurnchainConfig {
@@ -1486,6 +1490,7 @@ impl BurnchainConfig {
14861490
ast_precheck_size_height: None,
14871491
affirmation_overrides: HashMap::new(),
14881492
fault_injection_burnchain_block_delay: 0,
1493+
max_unspent_utxos: Some(1024),
14891494
}
14901495
}
14911496
pub fn get_rpc_url(&self, wallet: Option<String>) -> String {
@@ -1582,6 +1587,7 @@ pub struct BurnchainConfigFile {
15821587
pub ast_precheck_size_height: Option<u64>,
15831588
pub affirmation_overrides: Option<Vec<AffirmationOverride>>,
15841589
pub fault_injection_burnchain_block_delay: Option<u64>,
1590+
pub max_unspent_utxos: Option<u64>,
15851591
}
15861592

15871593
impl BurnchainConfigFile {
@@ -1797,6 +1803,13 @@ impl BurnchainConfigFile {
17971803
fault_injection_burnchain_block_delay: self
17981804
.fault_injection_burnchain_block_delay
17991805
.unwrap_or(default_burnchain_config.fault_injection_burnchain_block_delay),
1806+
max_unspent_utxos: self
1807+
.max_unspent_utxos
1808+
.map(|val| {
1809+
assert!(val <= 1024, "Value for max_unspent_utxos should be <= 1024");
1810+
val
1811+
})
1812+
.or(default_burnchain_config.max_unspent_utxos),
18001813
};
18011814

18021815
if let BitcoinNetworkType::Mainnet = config.get_bitcoin_network().1 {

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,8 +2274,6 @@ fn correct_burn_outs() {
22742274

22752275
let mut last_block_time = None;
22762276
for block in new_blocks_with_reward_set.iter() {
2277-
let cycle_number = block["cycle_number"].as_u64().unwrap();
2278-
let reward_set = block["reward_set"].as_object().unwrap();
22792277
if let Some(block_time) = block["block_time"].as_u64() {
22802278
if let Some(last) = last_block_time {
22812279
assert!(block_time > last, "Block times should be increasing");

testnet/stacks-node/src/tests/neon_integrations.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use stacks::net::atlas::{
6262
AtlasConfig, AtlasDB, GetAttachmentResponse, GetAttachmentsInvResponse,
6363
MAX_ATTACHMENT_INV_PAGES_PER_REQUEST,
6464
};
65+
use stacks::types::PublicKey;
6566
use stacks::util_lib::boot::{boot_code_addr, boot_code_id};
6667
use stacks::util_lib::db::{query_row_columns, query_rows, u64_to_sql};
6768
use stacks::util_lib::signed_structured_data::pox4::{
@@ -82,7 +83,7 @@ use super::{
8283
make_microblock, make_stacks_transfer, make_stacks_transfer_mblock_only, to_addr, ADDR_4, SK_1,
8384
SK_2, SK_3,
8485
};
85-
use crate::burnchains::bitcoin_regtest_controller::{self, BitcoinRPCRequest, UTXO};
86+
use crate::burnchains::bitcoin_regtest_controller::{self, addr2str, BitcoinRPCRequest, UTXO};
8687
use crate::config::{EventKeyType, EventObserverConfig, FeeEstimatorName, InitialBalance};
8788
use crate::neon_node::RelayerThread;
8889
use crate::operations::BurnchainOpSigner;
@@ -12794,3 +12795,49 @@ fn mock_miner_replay() {
1279412795
miner_channel.stop_chains_coordinator();
1279512796
follower_channel.stop_chains_coordinator();
1279612797
}
12798+
12799+
#[test]
12800+
#[ignore]
12801+
/// Verify that the config option, `burnchain.max_unspent_utxos`, is respected.
12802+
fn listunspent_max_utxos() {
12803+
if env::var("BITCOIND_TEST") != Ok("1".into()) {
12804+
return;
12805+
}
12806+
12807+
let (mut conf, _miner_account) = neon_integration_test_conf();
12808+
let prom_bind = format!("{}:{}", "127.0.0.1", 6000);
12809+
conf.node.prometheus_bind = Some(prom_bind.clone());
12810+
12811+
conf.burnchain.max_rbf = 1000000;
12812+
conf.burnchain.max_unspent_utxos = Some(10);
12813+
12814+
let mut btcd_controller = BitcoinCoreController::new(conf.clone());
12815+
btcd_controller
12816+
.start_bitcoind()
12817+
.map_err(|_e| ())
12818+
.expect("Failed starting bitcoind");
12819+
12820+
let mut btc_regtest_controller = BitcoinRegtestController::new(conf.clone(), None);
12821+
12822+
btc_regtest_controller.bootstrap_chain(201);
12823+
12824+
eprintln!("Chain bootstrapped...");
12825+
12826+
let keychain = Keychain::default(conf.node.seed.clone());
12827+
let mut op_signer = keychain.generate_op_signer();
12828+
12829+
let (_, network_id) = conf.burnchain.get_bitcoin_network();
12830+
let hash160 = Hash160::from_data(&op_signer.get_public_key().to_bytes());
12831+
let address = BitcoinAddress::from_bytes_legacy(
12832+
network_id,
12833+
LegacyBitcoinAddressType::PublicKeyHash,
12834+
&hash160.0,
12835+
)
12836+
.expect("Public key incorrect");
12837+
12838+
let filter_addresses = vec![addr2str(&address)];
12839+
12840+
let res = BitcoinRPCRequest::list_unspent(&conf, filter_addresses, false, 1, &None, 0);
12841+
let utxos = res.expect("Failed to get utxos");
12842+
assert_eq!(utxos.num_utxos(), 10);
12843+
}

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,6 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
47934793
// Induce block N+2 to get mined
47944794
let transfer_tx =
47954795
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
4796-
sender_nonce += 1;
47974796

47984797
let tx = submit_tx(&http_origin, &transfer_tx);
47994798
info!("Submitted tx {tx} in to attempt to mine block N+2");

0 commit comments

Comments
 (0)