Why Nostr? What is Njump?
2023-06-07 01:22:41
in reply to

John Smith [ARCHIVE] on Nostr: šŸ“… Original date posted:2011-06-24 šŸ—’ļø Summary of this message: Jan is seeking ...

šŸ“… Original date posted:2011-06-24
šŸ—’ļø Summary of this message: Jan is seeking advice on how to improve the speed of "getbalance" in Instawallet; a suggestion is made to scan the wallet every time a block comes in.
šŸ“ Original message:Jan,

On Thu, Jun 23, 2011 at 9:51 PM, <jan at uos.de> wrote:

> Hi there!
>
> Instawallet has enjoyed steady growth and I'm running into a bottleneck
> now with "getbalance <someaccounthere>" taking quite some time to
> complete. My understanding is, that this is because bitcoind runs
> through all relevant transactions each time anew to compute the balance.
> I was hoping the list could give me some pointers/ideas on how I can
> improve this.
>

I think the easiest way to speed this up would be to scan the wallet every
time a block comes in or something else changes in the block chain (or, if
you prefer, some pre-set interval of N minutes). Then go over the entire
wallet and the accumulate balances for all accounts. This could be done in
amortized linear time using a hash_map.

1) This reduces the time the API takes to return the balance for an account
to a predictable, very short time. Just the time to look up the balance in
the hash table (and return 0 on miss). The number crunching happens in the
network thread, not while you're waiting on the API.

2) Less bug-prone than "incremental caching" as you propose, and doesn't
require determining which accounts are influenced by a new block

3) Block chain reorgs are no problem.

JS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20110624/3762c70c/attachment.html>;
Author Public Key
npub1e4lupyw4vuuhfsmt726ud69555re66pph90kwx0afpt346e9k7zsd4jafl