anders94 / blockchain-demo

A web-based demonstration of blockchain concepts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Account balance checking

RubeRad opened this issue · comments

In the video (final Coinbase section), you mention that only Anders can transact to others in Block 2, because only Anders has a historical balance to transact from.

It would be a great enhancement if this final Coinbase implementation also made blocks Red/invalid if there are any attempts to transact from a source with insufficient balance (or maybe a different color-code, like purple? to indicate a different kind of invalidity than the Red for incorrect hash chaining)

(Another thought: maybe the "Mine" button is deactivated until the transactions are valid according to historical balances)

Yeah, that's exactly right. The demo doesn't attempt to reconcile all the spends to make sure nobody goes negative. I hand-waived that because I didn't think it was worth the effort to code that check. In a "real" system would absolutely would do those checks and perhapse make the UI work in one of the ways you propose.

I'm open to PRs if you want to add that check. ;)

I just might. I already plan to fork&PR to give you the changes I made for finer-resolution bit-strength difficulty.

I can see in blockchain.js how function updateChain() walks through the blocks of a particular 'chain' (peer?) and assembles string labels to get/set the prev/hash parts, so I expect I could figure out how to go through all the transactions and do the arithmetic

👍👍

I might suggest that rather than making the block red if a user is trying to spend money they don't have, you make the user's name red so you emphasize what rule has been violated. I do this with the signatures, for example. You can alter a transaction making both the signature and block go red but then you can re-mine the block so that goes green but there is nothing you can do to calculate a valid signature if you don't have the private key so that signature still stays red. I'd love to see the names also go red if they try to spend money they don't have so it is clear where the problem is.

Taking this to its logical conclusion, however, we should make the block's hash digest turn red instead of the entire block and maybe reserve the block going green only if ALL checks succeed. This change would make especially the latter part of my video visually inaccurate but... might be better. This would be a separate PR of course.

Also, thanks for posting a PR on more fine-grained difficulty work - that has been merged.

yw, thx for merging.

Good thoughts on the best way to visualize overspending. I'll have to digest it. I took a half-hearted stab at starting on this, but gave up. I should make some time for a more concerted effort. Start with a commit that just finds all the information and calculates if/where there's a problem, and then consider separately the UI to show it

I'd suggest that you calculate it forward in time. In other words, for each user that gets money (either by a coinbase transaction or a standard transaction) create an account for them adding whatever money they were given and subtracting whatever they spent. For example, as of the second block the object would look like this:

{
  Anders: 140,
  Sophia: 10,
  Lucas: 20,
  Emily: 15,
  Madison: 15
}

and then if someone goes negative, you paint them red.

Just a thought.

commented