Bitcoin Forum
May 30, 2024, 07:25:01 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: About getnewaddress RPC API  (Read 73 times)
~DefaultTrust (OP)
Copper Member
Sr. Member
****
Offline Offline

Activity: 1554
Merit: 489

Stop the war!


View Profile
February 05, 2021, 08:57:57 PM
 #1

Hi

I am studying the work of the RPC API of the old bitcoin fork (dogecoin).

It seems that the getnewaddress function generates not one, but a whole pool of addresses there. So that the next call getnewaddress does not generating, but simply gets ready-made addresses from the pool.

That is, something like this:

the first call getnewaddress generates an array [addr1, addr2, ... addrN] and outputs "addr1"
second call to getnewaddress yields "addr2"

***

The N-th call gives "addrN"

The N + 1 - th call again generates [addrN1, addrN2, ... addrNN] and outputs "addrN1"

and so on...

I wonder if I understand correctly how getnewaddress works? Has anything changed in the newest versions of Bitcoin RPC?

Do not trust bitcointalk fascists: leonello; Snork1979; ivan1975
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
February 05, 2021, 09:52:00 PM
Merited by ABCbits (1), ~DefaultTrust (1)
 #2

It's to do with the "keypool"... the system used to maintain 100 keys in a "pool", modern versions of Bitcoin Core have a pool of 1000... so it does the generation all at once and fills the pool up. Once it runs out of available keys in the pool, it then regenerates another 1000 (or 100 for the older versions etc).

For older (non-hd) wallets... it's important to make regular backups, otherwise, you might be using addresses/keys that aren't actually backed up! Shocked (This is a non-issue for HD wallets).

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
~DefaultTrust (OP)
Copper Member
Sr. Member
****
Offline Offline

Activity: 1554
Merit: 489

Stop the war!


View Profile
February 05, 2021, 10:33:10 PM
 #3

It's to do with the "keypool"... the system used to maintain 100 keys in a "pool", modern versions of Bitcoin Core have a pool of 1000... so it does the generation all at once and fills the pool up. Once it runs out of available keys in the pool, it then regenerates another 1000 (or 100 for the older versions etc).

For older (non-hd) wallets... it's important to make regular backups, otherwise, you might be using addresses/keys that aren't actually backed up! Shocked (This is a non-issue for HD wallets).

Clear. Thanks.

I noticed another interesting thing. It looks like addresses from the pool are being used for change. I'm not sure about this. But it seems to me that sometimes  getnewaddress does output with address that already have balance (comes from change)

Like this:

the first call getnewaddress generates an array [addr1, addr2, ... addrN] and outputs "addr1"

If I call sendmany then one of [addr2, ... addrN] is used for change ("addrK" then got a balance)!

One of the subsequent calls getnewaddress does output "addrK".

I'm pretty sure this is exactly how it works in Dogecoin. Does newest Bitcoin RPC work the same way?

Do not trust bitcointalk fascists: leonello; Snork1979; ivan1975
nc50lc
Legendary
*
Offline Offline

Activity: 2422
Merit: 5658


Self-proclaimed Genius


View Profile
February 06, 2021, 03:26:02 AM
Merited by ABCbits (1), ~DefaultTrust (1)
 #4

It's to do with the "keypool"... the system used to maintain 100 keys in a "pool", modern versions of Bitcoin Core have a pool of 1000... -snip-
I'm pretty sure this is exactly how it works in Dogecoin. Does newest Bitcoin RPC work the same way?
In Bitcoin core whether it's RPC or the GUI, the change will be sent to a "change address" derived from a different hdkeypath m/0'/1'/.
And those wont be used as "receiving" addresses nor return in getnewaddress command.

In addition to HCP's reply, just like "receiving address", Bitcoin core has a reserve keypool for the change addresses that consist of 1000 key pairs.
So there's a total of 2000 reserved keys.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
~DefaultTrust (OP)
Copper Member
Sr. Member
****
Offline Offline

Activity: 1554
Merit: 489

Stop the war!


View Profile
February 06, 2021, 11:09:43 AM
 #5

Thank you, guys  Smiley

Do not trust bitcointalk fascists: leonello; Snork1979; ivan1975
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!