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

Change tokens supply #1179

Merged
merged 53 commits into from
Oct 23, 2023
Merged

Change tokens supply #1179

merged 53 commits into from
Oct 23, 2023

Conversation

azarovh
Copy link
Member

@azarovh azarovh commented Sep 14, 2023

I have to apologise for the size of this PR. It should've been split in 2 but I didn't see a good way to do it without painful rebase of multiple commits and right now it's too late.

Closes #1206

  • New OutputValue::TokenV1 type. To simplify transfer/burning of tokens and also make issuance unambiguous and authorisable.
  • New TxOutput::Tokens type that replaces OutputValue::Transfer(TokenIssuance) with explicit purposes.
  • Support for minting/redeeming tokens as well as locking supply
  • New tokens-accounting crate to handle token supply logic

This PR also attempts to support the logic in the wallet. But it was too much for me so I stubbed it in many places and also commented out some checks in tests. All places that I touched there are marked with "TODO: add support for tokens v1" as well as the link to the issue #1237

@azarovh azarovh changed the title Increase tokens supply Change tokens supply Sep 14, 2023
@azarovh azarovh force-pushed the feat/increase_tokens_supply branch 2 times, most recently from 4b2a5fb to 88996c1 Compare September 28, 2023 13:01
@azarovh azarovh marked this pull request as ready for review September 28, 2023 13:34
@azarovh azarovh requested a review from OBorce September 28, 2023 13:41
@TheQuantumPhysicist
Copy link
Collaborator

Besides the comments I made, this is fine. But there's a huge lack of testing. We need to test the hell out of this. The tests should include all kinds of random combinations of:

  • Issuance
  • Burning
  • Transfer
  • Restock/Redeem, or whatever it's gonna be called

And all other possible operations. And every step in these tests should be followed by checking the tokens info/state.

Before merging this, we should also add the wallet functionality.

@azarovh azarovh marked this pull request as draft October 6, 2023 15:52
@azarovh azarovh force-pushed the feat/increase_tokens_supply branch from 88996c1 to 86f5df1 Compare October 6, 2023 15:54
Copy link
Contributor

@OBorce OBorce left a comment

Choose a reason for hiding this comment

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

It would be good to have a test with both mint and unmint in the same transaction and test the undo, I believe it might be a buggy but might be wrong.

Otherwise seems good.

chainstate/test-suite/src/tests/fungible_tokens_v1.rs Outdated Show resolved Hide resolved
.decrement()
.map_or(CachedOperation::Erase, CachedOperation::Write);
self.account_nonce.insert(account, new_nonce);
self.unspend_input_from_account(account_input)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

From the code above it looks like multiple token supply change inputs are allowed, so I guess one can do mint(nonce 1) + unmint(nonce 2) in the same transaction.
In unspend_input_from_account will the nonce will not be rolled back properly, as it uses decrement from the total count ?

Copy link
Member Author

Choose a reason for hiding this comment

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

From the code above it looks like multiple token supply change inputs are allowed

Yes that's allowed, I've added tests to recheck that and they work fine.

as it uses decrement from the total count

It increments and decrements per input. I think the name of the method that is used (get_account_nonce_count) is confusing. It should be just get_account_nonce

Comment on lines 900 to 903
undos
.into_inner()
.into_iter()
.try_for_each(|undo| self.tokens_accounting_cache.undo(undo))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

similar concern for a mint + unmint in the same transaction and the order of the undos, are the undos processed in reverse order?

If they are not, given a scenario that we first mint 10 tokens, and then mint 20 and burn 25.
the final state should be 5 tokens, but on undo of the last transaction
if it iterates from the first input it will need to undo the mint of 20 which should fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! It actually works because the undos are associative deltas. I'll change the order for the sake of readability and make sure you case is convered in tests

Copy link
Member Author

Choose a reason for hiding this comment

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

it might mess up with DeltaData, I'll check

Copy link
Member Author

Choose a reason for hiding this comment

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

An interesting case that worked anyway because of the lack of checks on undo is mint + lock in the same tx, which should've failed with an error but worked anyway. I added additional checks and reversed the order of processing the undo.

Also I reversed it for pos accounting outputs, but I can't see the case to reproduce

@TheQuantumPhysicist TheQuantumPhysicist merged commit 54a8a8e into master Oct 23, 2023
31 checks passed
@TheQuantumPhysicist TheQuantumPhysicist deleted the feat/increase_tokens_supply branch October 23, 2023 20:27
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

Successfully merging this pull request may close these issues.

Make it possible to increase the token supply for MLS-01 tokens
6 participants