Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account balance checking #109

Open
RubeRad opened this issue Jan 4, 2023 · 8 comments
Open

Account balance checking #109

RubeRad opened this issue Jan 4, 2023 · 8 comments

Comments

@RubeRad
Copy link

RubeRad commented Jan 4, 2023

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)

@anders94
Copy link
Owner

anders94 commented Jan 4, 2023

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. ;)

@RubeRad
Copy link
Author

RubeRad commented Jan 5, 2023

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

@Dsueiro68
Copy link

👍👍

@anders94
Copy link
Owner

anders94 commented Feb 8, 2023

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.

@RubeRad
Copy link
Author

RubeRad commented Feb 10, 2023

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

@anders94
Copy link
Owner

anders94 commented Feb 10, 2023

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.

@Asad-ullah1
Copy link

Asad-ullah1 commented Oct 21, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@anders94 @RubeRad @Asad-ullah1 @Dsueiro68 and others