Post
Topic
Board Development & Technical Discussion
Merits 3 from 2 users
Topic OP
Comment my bitcoin address generation workflow
by
coolbits
on 11/12/2024, 21:39:16 UTC
⭐ Merited by ABCbits (2) ,garlonicon (1)
Hi all,

So I'm reviving a paused project and it involves receiving bitcoin deposits from users, each user getting assigned a distinct deposit address.

My concern is to be able to safely backup the private keys in case the bitcoin node crashes.

A few years ago, using a vanilla BDB wallet, I implemented it by pre-generating a large list of addresses through "getnewaddress", setting like half of them to the "change" label, using "dumpprivkey" on them all, encrypting the file and saving it somewhere safe. In case of a dramatic crash, I could just import those private keys on the new server, and recover control of all UTXOs.

Enter the descriptor wallets.

While I have no doubt descriptors are vastly superior to whatever we had before (I skipped the hdseed era alltogether), there is an obvious problem - they are a lot trickier to deal with if you're not THAT well versed into bitcoin core. So after a few days of wading through docs, stackexchange, random articles here and there, I came up with a workflow and would appreciate if somebody with a clue could (in)validate it.

My concern is obviously to make sure I never lose an UTXO due to a server/disk disaster. I'll use "test" for the wallet name as I'm working with the testnet. I suppose everything should translate to mainnet seamlessly. Bitcoin core version is 28.0. For the sake of the example, let's pretend that I want to generate 10k deposit addresses.


A. GET A SET OF DESCRIPTORS
  • start bitcoind
  • bitcoin-cli createwallet test
  • bitcoin-cli listdescriptors true
  • save the JSON output of the last command somewhere safe, name it descriptors.txt. I can always spend any coin received thanks to it.

B. GENERATE ADDRESSES
  • repeat 10,000 times: bitcoin-cli getnewaddress
  • save the output of the last command batch - it's the deposit addresses that I can now assign to users as needed

C. DISK CRASH - I HAVE A FRESH BITCOIN CORE SERVER
  • grab the descriptors.txt file
  • start bitcoind
  • bitcoin-cli createwallet test false true (we create an empty wallet with no descriptors)
  • use bitcoin-cli importdescriptors with the contents of descriptors.txt
  • repeat 10,000 times: bitcoin-cli getnewaddress (this is supposed to give us the exact same 10k addresses)
  • all done!



QUESTIONS:
  • Does it look reasonable?
  • What about change addresses? I couldn't figure out how to deal with them. My app uses sendtoaddress at this time and I'm not planning on implementing raw transactions for a bit. I need to make sure that a deposit address is never used for sending change and also that after descriptors restoring on a new server, I properly get all change UTXOs available and visible in listunspent and whatnot. Should I also "pre-generate" change addresses?
  • Is using "getnewaddress" the proper way to do it? Should I use something else, like "derivateaddresses" (but then "listreceivedbyaddress 0 true" doesn't display them)?

RHETORIC QUESTIONS:
  • Why oh why is there not an option to set a change address in "sendtoaddress"? I mean, I understand the privacy concern, but it could be disabled by default, so only people who don't care about concealing the payment/change discrimination would use it, on purpose. Maybe only allow it through RPC and disallow in the GUI, etc.[/size]
  • Is it me or dealing with crypto daemons only gets more complex as time passes, instead of getting simpler? Last Geth update ditching personal_ namespace commands just made stuff harder too. Sheesh.

Thanks for your comments.