TruStory / truchain

⛓ A crypto-incentivized debate community
http://www.trustory.io
Other
33 stars 14 forks source link

Token inflation, validator staking/slashing, governance #798

Closed shanev closed 5 years ago

shanev commented 5 years ago
shanev commented 5 years ago

How do we fund module accounts / pools?

Questions:

A: must have module_name and module_permissions in genesis account

shanev commented 5 years ago
  address: cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta
  name: fee_collector
  permissions: []

  address: cosmos1ed82m7snyk8mux8xxpwygvtyq633a4k43rfp8l
  name: user_reward_tokens_pool
  permissions: []
shanev commented 5 years ago
    GenesisAccount struct {
        Address       sdk.AccAddress `json:"address" yaml:"address"`
        Coins         sdk.Coins      `json:"coins" yaml:"coins"`
        Sequence      uint64         `json:"sequence_number" yaml:"sequence_number"`
        AccountNumber uint64         `json:"account_number" yaml:"account_number"`

        OriginalVesting  sdk.Coins `json:"original_vesting" yaml:"original_vesting"`
        DelegatedFree    sdk.Coins `json:"delegated_free" yaml:"delegated_free"`
        DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"`
        StartTime        int64     `json:"start_time" yaml:"start_time"`
        EndTime          int64     `json:"end_time" yaml:"end_time"`

        ModuleName        string   `json:"module_name" yaml:"module_name"`
        ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"`
    }
shanev commented 5 years ago

A module account address is the cosmos address generated by sdk.AccAddress(crypto.AddressHash([]byte(MODULE_ACCOUNT_NAME)))

shanev commented 5 years ago

New issue:

E[2019-09-25|18:14:20.594] WARNING: Attempt to allocate proposer rewards to unknown proposer . This should happen only if the proposer unbonded completely within a single block, which generally should not happen except in exceptional circumstances (or fuzz testing). We recommend you investigate immediately. module=x/distribution
validator address cosmosvaloper1em44grl9ylmmnwawwp5fjn079kesatwpl2hn74
panic: UnmarshalBinaryLengthPrefixed cannot decode empty bytes

Seems we need to run an actual tesnet for inflation to work. See how much we can fake out in genesis to make progress. Try with docker localnet.

Update: Works with local docker testnet with 4 validators

shanev commented 5 years ago

migrate genesis with beta clone:

shanev commented 5 years ago

genutils should be:

  "genutil": {
      "gentxs": null
  },
shanev commented 5 years ago
panic: invariant broken: supply: total supply invariant
    sum of accounts coins: 100000000tru
    supply.Total:          253644628704484tru

    CRITICAL please submit the following transaction:
         tx crisis invariant-broken supply total-supply
shanev commented 5 years ago

Fix tests:

shanev commented 5 years ago

Fix initializing chain from scratch

shanev commented 5 years ago

Export is broken:

truchaind export > test.json
--- level 0 ---
2:48286["s/1,v208" .. "s/latest,v209"]

WARNING: State is not initialized. Returning genesis file.

Fixed: Bug in Cosmos: https://github.com/cosmos/cosmos-sdk/pull/5103/files#diff-bbb4aa0e4c30192fba47fc18e560af52R95

shanev commented 5 years ago

Error validating genesis: ERROR: error validating genesis file test.json: UnmarshalJSON cannot decode empty bytes

shanev commented 5 years ago

Iterating accounts to calculate supply is broken. Find out why it's blank:

panic: invariant broken: supply: total supply invariant
    sum of accounts coins:
    supply.Total:          253644628704484tru

    CRITICAL please submit the following transaction:
         tx crisis invariant-broken supply total-supply

A: Because Cosmos moved accounts to be under auth. Added migration command to CLI.

shanev commented 5 years ago

How to migrate chain with data:

# run trustory migration
python3 github.com/TruStory/truchain/contrib/migration/16-token-inflation.py --exported-genesis ~/genesis.json > genesis2.json

# run cosmos migration
truchaind migrate v0.38 ~/genesis2.json > ~/genesis3.json

# remove old chain data
rm -rf ~/.truchaind

# init chain
truchaind init test

# copy genesis to home folder
cp genesis3.json ~/.truchaind/config/genesis.json

# add back validator
truchaind gentx --name reward_broker --home-client ~/.octopus
truchaind collect-gentxs

# start
truchaind start
shanev commented 5 years ago

Issue with migrating the latest data:

panic: invariant broken: staking: bonded and not bonded module account coins invariant
    Pool's bonded tokens: 100000000
    sum of bonded tokens: 0
not bonded token invariance:
    Pool's not bonded tokens: 0
    sum of not bonded tokens: 0
module accounts total (bonded + not bonded):
    Module Accounts' tokens: 100000000
    sum tokens:              0

    CRITICAL please submit the following transaction:
         tx crisis invariant-broken staking module-accounts

For some reason, the bonded tokens pool starts with 100000000 tru. Remove it from genesis and re-try.

Update: This fucks up the supply because it adds 100000000 to it. Figure out where this is happening.

Update: This is because there's delegated shares in the staking module.

Solution: Write a migration to change it to 0.

shanev commented 5 years ago

Use fund pools instead of registrar/reward broker and minting out of thin air:

shanev commented 5 years ago

Module account for stakes: