Bitcoin Forum
May 10, 2024, 09:55:09 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How is an account/address balance calculated?  (Read 1259 times)
floe (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 25, 2011, 12:54:37 PM
 #1

Hello everyone, I've been reading a bit of the bitcoin wiki and I'm really impressed by the technical details.

However, I have one question: how is the balance of a single address or an account calculated?
AFAICT, this is the sum over all transactions in the longest chain involving that address, correct?

If yes, this leads to the next question: won't the amount of computation needed to scan through the
entire chain become prohibitive at some point? Especially if the number of transactions increases at
a similar rate as, e.g. the global hash rate?

Florian
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715334909
Hero Member
*
Offline Offline

Posts: 1715334909

View Profile Personal Message (Offline)

Ignore
1715334909
Reply with quote  #2

1715334909
Report to moderator
Garrett Burgwardt
Sr. Member
****
Offline Offline

Activity: 406
Merit: 256


View Profile
May 25, 2011, 01:03:00 PM
 #2

Hello everyone, I've been reading a bit of the bitcoin wiki and I'm really impressed by the technical details.

However, I have one question: how is the balance of a single address or an account calculated?
AFAICT, this is the sum over all transactions in the longest chain involving that address, correct?

If yes, this leads to the next question: won't the amount of computation needed to scan through the
entire chain become prohibitive at some point? Especially if the number of transactions increases at
a similar rate as, e.g. the global hash rate?

Florian

1. Yep, that's how it works, kind of...

2. The only thing you're missing is that you don't need to go back through the entire chain- just to the previous transaction where it came under that address' control. Since every time you send coins it verifies that there is a tx where the coins came under your control, the block chain forms a transaction chain that is self building.

basically, you only need to look at the tx that gave the coins to the address that is spending them, not all the way back to generation- the blockchain already does that.
floe (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 25, 2011, 03:17:04 PM
 #3

1. Yep, that's how it works, kind of...
OK, so I got that right :-)

2. The only thing you're missing is that you don't need to go back through the entire chain- just to the previous transaction where it came under that address' control. Since every time you send coins it verifies that there is a tx where the coins came under your control, the block chain forms a transaction chain that is self building.

basically, you only need to look at the tx that gave the coins to the address that is spending them, not all the way back to generation- the blockchain already does that.
OK, I think I got that too. So scanning the entire block chain is only necessary if, say, you want to know the balance for an address that is not your own? Even then, you probably can scan backwards from the current block and stop when you've found all generation transactions.

Florian
Garrett Burgwardt
Sr. Member
****
Offline Offline

Activity: 406
Merit: 256


View Profile
May 25, 2011, 03:51:51 PM
 #4

It doesn't matter who owns the address- you only need to see what addresses have coins credited to them- miners take care of making sure double spends don't happen. Just look to the block that last credits addressses.
compro01
Hero Member
*****
Offline Offline

Activity: 590
Merit: 500



View Profile
May 25, 2011, 04:47:11 PM
 #5

OK, I think I got that too. So scanning the entire block chain is only necessary if, say, you want to know the balance for an address that is not your own? Even then, you probably can scan backwards from the current block and stop when you've found all generation transactions.

Florian

or if you think the client missed a transaction announcement (e.g. internet outage, power outage, or something else that removes you from the network for a considerable length of time) and somehow missed it when you came back up and pulled the intervening blocks.  that's what the -rescan flag is for.  it forces the client to scan through the whole blockchain looking for transactions involving an address/keypair that you have in your wallet file.
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!