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

Use special container type for token balances #2074

Open
wants to merge 59 commits into
base: develop
Choose a base branch
from

Conversation

pmconrad
Copy link
Contributor

@pmconrad pmconrad commented Dec 4, 2019

This PR implements an idea originally mentioned by @nathanhourt . His observation was that we use the asset type 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_debt type is introduced. Every token balance is issued by a stored_debt, and only a stored_debt can destroy (aka burn) balances. Instances of stored_debt and stored_value can 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_db copies 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.

@pmconrad pmconrad added 2d Developing Status indicating currently designing and developing a solution 3c Enhancement Classification indicating a change to the functionality of the existing imlementation 5a Docs Needed Status specific to Documentation indicating the need for proper documentation to be added 6 API Impact flag identifying the application programing interface (API) labels Dec 4, 2019
@pmconrad pmconrad added this to the 4.1.0 - Feature Release milestone Dec 4, 2019
@pmconrad pmconrad marked this pull request as ready for review December 27, 2019 14:26
@pmconrad
Copy link
Contributor Author

API incompatibilities are (mostly) resolved, tests working, replay working (up to 37M blocks anyway).

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo colculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d Developing Status indicating currently designing and developing a solution 3c Enhancement Classification indicating a change to the functionality of the existing imlementation 5a Docs Needed Status specific to Documentation indicating the need for proper documentation to be added 6 API Impact flag identifying the application programing interface (API)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants