stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 666 forks source link

`listunspent` issues #5224

Open obycode opened 2 days ago

obycode commented 2 days ago

There are two problems with the miners calls to listunspent: https://github.com/stacks-network/stacks-core/blob/b5250c60877fa3380b450a7b7e7e9d3e87da6112/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs#L2619-L2630

We added the maximumCount option to ensure that the response is not too large, because the HTTP library can only handle messages up to 16MB.

Problem 1

If we hit this limit, the bitcoind will return UTXOs oldest first. A miner's block commit needs to use the output of the previous block commit, so this will be a very recent UTXO, so it may be pruned from the results. This is a problem.

Problem 2

It seems that this option will not actually make it return maximumCount UTXOs. In a test in the nakamoto-3 network, if I call listunspent without this limit, it returns 2513 UTXOs, but then when I call it with the maximumCount set to 1024, it returns 365 UTXOs.

obycode commented 1 day ago

To avoid problem 1, @kantai's suggestion:

Yeah, realistically, the miner should always spend its last commit’s UTXO And add another input if necessary

We can make this change with low priority.