Use special container type for token balances#2074
Open
pmconrad wants to merge 59 commits intobitshares:developfrom
Open
Use special container type for token balances#2074pmconrad wants to merge 59 commits intobitshares:developfrom
pmconrad wants to merge 59 commits intobitshares:developfrom
Conversation
Contributor
Author
|
API incompatibilities are (mostly) resolved, tests working, replay working (up to 37M blocks anyway). |
abitmore
reviewed
Dec 28, 2019
| // BitShares mainnet has a negative genesis balance of 250M BTS. It stems from the BitShares-1 | ||
| // snapshot, and was created in BitShares-1 by someone exploiting an overflow bug. | ||
| // This means that there are 250M more BTS in existence than was previously assumed. The -250M BTS | ||
| // are added to the total supply colculation, i. e. the total supply is 250M higher than indicated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements an idea originally mentioned by @nathanhourt . His observation was that we use the
assettype for two fundamentally different concepts, which is inherently dangerous.A real-world analogy for the asset type could be, for example, a slip of paper reading "$ 1.00". The two fundamentally different concepts that match this type are, for example, a price tag in a supermarket on the one hand, and a bank note on the other. The important difference is that the bank note carries value, whereas the price tag only carries information. A consequence of this is, for example, that it is not possible to copy a bank note (or at least strictly forbidden), whereas it is perfectly ok to copy the price tag.
So, in order to model an equivalent for the "bank note" concept, this PR creates a new type
stored_value. It employs RAII concepts, in the sense that it can only be moved around, not copied.On top of that, this PR implements a simple bookkeeping concept: account balances cannot be created from nothing, nor can they be destroyed into nothing. Every creation or destruction of a balance must have a counterpart in another account. For this, a
stored_debttype is introduced. Every token balance is issued by astored_debt, and only astored_debtcan destroy (aka burn) balances. Instances ofstored_debtandstored_valuecan only be destructed successfully if their contained amount is zero. This should ensure that no tokens are lost, and none can be created from nothing, as happened e. g. in #429.Unfortunately, the beauty of the general concept is somewhat undermined by the way in which our database transaction system works. I. e.
undo_dbcopies objects, and restores them upon rollback, by copying back the original value. Similarly, things are complicated by API calls returning copies of internal database objects.This PR affects some API changes, i. e. the structure of certain database objects has changed slightly.