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
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
76cc9ab
Move TokenId to a mod
azarovh Aug 29, 2023
1cae33f
Initial new TokenData types support
azarovh Aug 29, 2023
35e4e29
Impose reissuance fee
azarovh Aug 29, 2023
f3fd2f4
Add TokenIssuanceVersion
azarovh Aug 29, 2023
860e74a
Add token account type
azarovh Sep 8, 2023
1dfba25
Remove TokenReissuanceV1
azarovh Sep 8, 2023
d8bee0d
Minor
azarovh Sep 8, 2023
385a10a
Reconsider TokenSupply enum
azarovh Sep 10, 2023
f281bda
Initial tokens accounting impl
azarovh Sep 11, 2023
6fbb7a8
Initial integration into chainstate
azarovh Sep 12, 2023
cd68ffe
Implement tokens accounting operations
azarovh Sep 13, 2023
8062643
Connect inputs/outputs in tx_verifier
azarovh Sep 13, 2023
5e844b0
Flush data to db
azarovh Sep 13, 2023
220ee7b
Fix amount checks, utils and constraints
azarovh Sep 14, 2023
db39ebc
Support tokens accounting undo
azarovh Sep 14, 2023
e3bc2ae
Initial tests
azarovh Sep 14, 2023
5069b68
Add TxOutput::TokenIssuance
azarovh Sep 14, 2023
a918669
Add OutputValue::TokenV1
azarovh Sep 15, 2023
25cbf47
Get rid of TokenIssuanceVersion::CURRENT
azarovh Sep 15, 2023
0e2d0b0
Rework TxInput
azarovh Sep 25, 2023
b731dff
Rework TxOutput
azarovh Sep 25, 2023
c2872f7
Reconsider names
azarovh Sep 25, 2023
101be74
Add chainstate tests
azarovh Sep 26, 2023
11ea6f0
Fix all todos in chainstate
azarovh Sep 27, 2023
6203ff6
Fix mempool
azarovh Sep 27, 2023
b29b935
Fix functional tests
azarovh Sep 28, 2023
56393c4
Rename some tokens types
azarovh Sep 28, 2023
f61337a
Add TokenOutput::IssueNft
azarovh Sep 28, 2023
4077087
Fix tokens wallet functional tests
azarovh Sep 28, 2023
dc53647
Add upgrades::ChainstateUpgrade
azarovh Oct 8, 2023
85a94c5
Bump storage version
azarovh Oct 8, 2023
bafcf15
Rename to TokensOp and some small fixes
azarovh Oct 8, 2023
2207871
Add hierarchy tests
azarovh Oct 9, 2023
c91644f
Clean up io policy tests
azarovh Oct 10, 2023
6e138ea
Add tokens_accounting operations tests
azarovh Oct 10, 2023
cb1102d
Forbid all token v0 operations after fork
azarovh Oct 10, 2023
3c10ec8
Rework accounts and TxOutput for tokens supply
azarovh Oct 13, 2023
8d8bfef
Ensure nft cannot be printed
azarovh Oct 13, 2023
e131f80
Additional test for constraints accumulator
azarovh Oct 13, 2023
d298db2
Remove amount from TokenCirculatingSupply
azarovh Oct 13, 2023
9715f8c
Rename redeem to unmint
azarovh Oct 13, 2023
3a0509e
Fix unmint with multiple utxos
azarovh Oct 13, 2023
b2d2751
More docs and fixes
azarovh Oct 15, 2023
7835c1a
Make TokenIssuanceVersion an enum
azarovh Oct 16, 2023
ce66e6e
Fix more comments
azarovh Oct 18, 2023
92da420
Add signature tests
azarovh Oct 18, 2023
36df9ac
Store aux data for new nft token output
azarovh Oct 19, 2023
c47ba05
Add expensive-reads feature
azarovh Oct 20, 2023
25a95e9
Fix more comments
azarovh Oct 20, 2023
be391a9
Rename accounts
azarovh Oct 20, 2023
0fad4bf
Remove TxOutput::TokenOp
azarovh Oct 20, 2023
6cd5f00
Token timelock test
azarovh Oct 23, 2023
c10c66d
Fix undo when op in a single tx
azarovh Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ members = [
"test", # Integration tests.
"test-rpc-functions", # RPC functions specifically for tests.
"test-utils", # Various utilities for tests.
"tokens-accounting", # Tokens accounting
"utils", # Various utilities.
"utxo", # Utxo and related utilities (cache, undo, etc.).
"wallet", # Wallet primitives.
Expand Down
26 changes: 12 additions & 14 deletions blockprod/src/detail/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use common::{
stakelock::StakePoolData,
transaction::TxInput,
ConsensusUpgrade, Destination, GenBlock, Genesis, NetUpgrades, OutPointSourceId, PoolId,
RequiredConsensus, TxOutput, UpgradeVersion,
RequiredConsensus, TxOutput,
},
primitives::{per_thousand::PerThousand, time, Amount, BlockHeight, Id, H256},
time_getter::TimeGetter,
Expand Down Expand Up @@ -999,16 +999,16 @@ mod produce_block {
let override_chain_config = {
let net_upgrades = NetUpgrades::initialize(vec![(
BlockHeight::new(0),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::PoW {
ConsensusUpgrade::PoW {
// Make difficulty impossible so the cancel from
// the mock job manager is always seen before
// solving the block
initial_difficulty: Uint256::ZERO.into(),
}),
},
)])
.expect("Net upgrade is valid");

Builder::new(ChainType::Regtest).net_upgrades(net_upgrades).build()
Builder::new(ChainType::Regtest).consensus_upgrades(net_upgrades).build()
};

let (manager, chain_config, chainstate, mempool, p2p) =
Expand Down Expand Up @@ -1128,13 +1128,13 @@ mod produce_block {
let override_chain_config = {
let net_upgrades = NetUpgrades::initialize(vec![(
BlockHeight::new(0),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::PoW {
ConsensusUpgrade::PoW {
initial_difficulty: Uint256::MAX.into(),
}),
},
)])
.expect("Net upgrade is valid");

Builder::new(ChainType::Regtest).net_upgrades(net_upgrades).build()
Builder::new(ChainType::Regtest).consensus_upgrades(net_upgrades).build()
};

let (manager, chain_config, chainstate, mempool, p2p) =
Expand Down Expand Up @@ -1312,10 +1312,8 @@ mod produce_block {
},
];

let mut randomized_net_upgrades = vec![(
BlockHeight::new(0),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
)];
let mut randomized_net_upgrades =
vec![(BlockHeight::new(0), ConsensusUpgrade::IgnoreConsensus)];

let mut next_height_consensus_change = 1;

Expand All @@ -1324,7 +1322,7 @@ mod produce_block {

randomized_net_upgrades.push((
BlockHeight::new(next_height_consensus_change),
UpgradeVersion::ConsensusUpgrade(consensus_types[next_consensus_type].clone()),
consensus_types[next_consensus_type].clone(),
));

next_height_consensus_change += rng.gen_range(1..50);
Expand All @@ -1335,7 +1333,7 @@ mod produce_block {

Builder::new(ChainType::Regtest)
.genesis_custom(genesis_block)
.net_upgrades(net_upgrades)
.consensus_upgrades(net_upgrades)
.build()
};

Expand Down Expand Up @@ -1384,7 +1382,7 @@ mod produce_block {
));

match chain_config
.net_upgrade()
.consensus_upgrades()
.consensus_status(BlockHeight::new(block_height))
{
RequiredConsensus::IgnoreConsensus => {
Expand Down
13 changes: 5 additions & 8 deletions blockprod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod tests {
pos_initial_difficulty,
stakelock::StakePoolData,
Block, ConsensusUpgrade, Destination, Genesis, NetUpgrades, PoSChainConfigBuilder,
TxOutput, UpgradeVersion,
TxOutput,
},
primitives::{per_thousand::PerThousand, Amount, BlockHeight, Idable, H256},
time_getter::TimeGetter,
Expand Down Expand Up @@ -324,23 +324,20 @@ mod tests {
);

let net_upgrades = NetUpgrades::initialize(vec![
(
BlockHeight::new(0),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
),
(BlockHeight::new(0), ConsensusUpgrade::IgnoreConsensus),
(
BlockHeight::new(1),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::PoS {
ConsensusUpgrade::PoS {
initial_difficulty: Some(pos_initial_difficulty(ChainType::Regtest).into()),
config: PoSChainConfigBuilder::new_for_unit_test().build(),
}),
},
),
])
.expect("Net upgrades are valid");

Builder::new(ChainType::Regtest)
.genesis_custom(genesis_block)
.net_upgrades(net_upgrades)
.consensus_upgrades(net_upgrades)
.build()
};

Expand Down
1 change: 1 addition & 0 deletions chainstate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rpc = {path = '../rpc'}
serialization = {path = "../serialization"}
subsystem = {path = '../subsystem'}
tx-verifier = {path = './tx-verifier'}
tokens-accounting = {path = '../tokens-accounting'}
utils = {path = '../utils'}
utxo = {path = '../utxo'}

Expand Down
34 changes: 33 additions & 1 deletion chainstate/src/detail/ban_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl BanScore for BlockError {
BlockError::InvariantErrorFailedToFindNewChainPath(_, _, _) => 0,
BlockError::InvariantErrorInvalidTip(_) => 0,
BlockError::InvariantErrorAttemptToConnectInvalidBlock(_) => 0,
BlockError::TokensAccountingError(err) => err.ban_score(),
}
}
}
Expand Down Expand Up @@ -149,6 +150,9 @@ impl BanScore for ConnectTransactionError {
ConnectTransactionError::MissingTransactionNonce(_) => 100,
ConnectTransactionError::FailedToIncrementAccountNonce => 0,
ConnectTransactionError::IOPolicyError(err, _) => err.ban_score(),
ConnectTransactionError::TokensAccountingError(err) => err.ban_score(),
ConnectTransactionError::TokensAccountingBlockUndoError(_) => 100,
ConnectTransactionError::TotalFeeRequiredOverflow => 100,
}
}
}
Expand All @@ -168,12 +172,14 @@ impl BanScore for SignatureDestinationGetterError {
match self {
SignatureDestinationGetterError::SpendingOutputInBlockReward => 100,
SignatureDestinationGetterError::SpendingFromAccountInBlockReward => 100,
SignatureDestinationGetterError::SigVerifyOfBurnedOutput => 100,
SignatureDestinationGetterError::SigVerifyOfNotSpendableOutput => 100,
SignatureDestinationGetterError::PoolDataNotFound(_) => 100,
SignatureDestinationGetterError::DelegationDataNotFound(_) => 100,
SignatureDestinationGetterError::SigVerifyPoSAccountingError(_) => 100,
SignatureDestinationGetterError::UtxoOutputNotFound(_) => 100,
SignatureDestinationGetterError::UtxoViewError(_) => 100,
SignatureDestinationGetterError::TokenDataNotFound(_) => 100,
SignatureDestinationGetterError::SigVerifyTokensAccountingError(_) => 100,
}
}
}
Expand All @@ -192,6 +198,8 @@ impl BanScore for TransactionVerifierStorageError {
TransactionVerifierStorageError::TransactionIndexDisabled => 0,
TransactionVerifierStorageError::PoSAccountingError(err) => err.ban_score(),
TransactionVerifierStorageError::AccountingBlockUndoError(_) => 100,
TransactionVerifierStorageError::TokensAccountingError(err) => err.ban_score(),
TransactionVerifierStorageError::TokensAccountingBlockUndoError(_) => 100,
}
}
}
Expand Down Expand Up @@ -275,6 +283,8 @@ impl BanScore for TokensError {
TokensError::TokensInBlockReward => 100,
TokensError::InvariantBrokenUndoIssuanceOnNonexistentToken(_) => 100,
TokensError::InvariantBrokenRegisterIssuanceWithDuplicateId(_) => 100,
TokensError::DeprecatedTokenOperationVersion(_, _) => 100,
TokensError::UnsupportedTokenIssuanceVersion(_, _) => 100,
}
}
}
Expand Down Expand Up @@ -503,4 +513,26 @@ impl BanScore for IOPolicyError {
}
}

impl BanScore for tokens_accounting::Error {
fn ban_score(&self) -> u32 {
match self {
tokens_accounting::Error::StorageError(_) => 0,
tokens_accounting::Error::AccountingError(_) => 100,
tokens_accounting::Error::TokenAlreadyExists(_) => 100,
tokens_accounting::Error::TokenDataNotFound(_) => 100,
tokens_accounting::Error::TokenDataNotFoundOnReversal(_) => 100,
tokens_accounting::Error::CirculatingSupplyNotFound(_) => 100,
tokens_accounting::Error::MintExceedsSupplyLimit(_, _, _) => 100,
tokens_accounting::Error::AmountOverflow => 100,
tokens_accounting::Error::CannotMintFromLockedSupply(_) => 100,
tokens_accounting::Error::CannotUnmintFromLockedSupply(_) => 100,
tokens_accounting::Error::NotEnoughCirculatingSupplyToUnmint(_, _, _) => 100,
tokens_accounting::Error::SupplyIsAlreadyLocked(_) => 100,
tokens_accounting::Error::CannotLockNotLockableSupply(_) => 100,
tokens_accounting::Error::ViewFail => 0,
tokens_accounting::Error::StorageWrite => 0,
}
}
}

// TODO: tests in which we simulate every possible case and test the score
4 changes: 3 additions & 1 deletion chainstate/src/detail/chainstateref/epoch_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ where
| TxOutput::LockThenTransfer(_, _, _)
| TxOutput::Burn(_)
| TxOutput::CreateDelegationId(_, _)
| TxOutput::DelegateStaking(_, _) => {
| TxOutput::DelegateStaking(_, _)
| TxOutput::IssueFungibleToken(_)
| TxOutput::IssueNft(_, _, _) => {
return Err(EpochSealError::SpendStakeError(
SpendStakeError::InvalidBlockRewardOutputType,
));
Expand Down
Loading
Loading