Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mock mining UTXO check to avoid unnecessary complaints #5845

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ lto = "fat"
[profile.release-lite]
inherits = "release"
lto = "thin"

[node]
miner = true
mock_mining = true
40 changes: 26 additions & 14 deletions testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,39 +1689,51 @@ impl BitcoinRegtestController {
utxos_to_exclude: Option<UTXOSet>,
block_height: u64,
) -> Result<(Transaction, UTXOSet), BurnchainControllerError> {
let utxos = if let Some(utxos) = utxos_to_include {
// in RBF, you have to consume the same UTXOs
utxos
// If mock mining is on, don't even check for UTXOs—return a dummy Tx/UTXO set.
if self.config.get_node_config(false).mock_mining {
let transaction = Transaction {
input: vec![],
output: vec![],
version: 1,
lock_time: 0,
};
let transaction_utxos = UTXOSet {
bhh: BurnchainHeaderHash::zero(),
utxos: vec![],
};
return Ok((transaction, transaction_utxos));
}

// Otherwise, we're not in mock mining; fetch or use existing UTXOs
let utxos = if let Some(included) = utxos_to_include {
// For RBF or re-sending, we might force using the same UTXOs
included
} else {
// Fetch some UTXOs
// Otherwise, fetch UTXOs from our Bitcoin RPC
let addr = self.get_miner_address(epoch_id, public_key);
match self.get_utxos(
epoch_id,
public_key,
total_required,
utxos_to_exclude,
block_height,
) {
match self.get_utxos(epoch_id, public_key, total_required, utxos_to_exclude, block_height) {
Some(utxos) => utxos,
None => {
warn!(
"No UTXOs for {} ({}) in epoch {epoch_id}",
"No UTXOs for {} ({}) in epoch {}",
&public_key.to_hex(),
&addr2str(&addr)
&addr2str(&addr),
epoch_id
);
return Err(BurnchainControllerError::NoUTXOs);
}
}
};

// Prepare a backbone for the tx
// Build your real transaction here
let transaction = Transaction {
input: vec![],
output: vec![],
version: 1,
lock_time: 0,
};

// Finally return the transaction and the chosen UTXOs
Ok((transaction, utxos))
}

Expand Down