QuarkChain / pyquarkchain

Python implementation of QuarkChain
https://quarkchain.io
MIT License
225 stars 114 forks source link

Fix total balance counting off-by-one #901

Closed ninjaahhh closed 4 years ago

ninjaahhh commented 4 years ago

893 has a non-obvious optimization which can reduce number of iterations but kinda unintuitive.

suppose we only have 1 active address, starting get_total_balance with None as the starter and 1 as limit, how many calls should we have? in my opinion, it should go like

  1. first run, returns (bal, <active address>)
  2. second run using that active address as starter (note it's exclusive on starter), returns (0, 0x0)

however previous code in #893 only needs one run returning (bal, 0x0) which essentially just looks ahead and skips that address when counting the total balance.

it's not wrong, but I prefer the more straightforward logic.

ninjaahhh commented 4 years ago

also removed the constraint that starter must be an existing address. seems unnecessary