Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Feb 2, 2024
1 parent 0036adc commit 8adba69
Show file tree
Hide file tree
Showing 15 changed files with 728 additions and 123 deletions.
41 changes: 28 additions & 13 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ var (

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
providertypes.ConsumerRewardsPool: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)

Expand Down Expand Up @@ -300,6 +299,10 @@ func New(
scopedIBCProviderKeeper := app.CapabilityKeeper.ScopeToModule(providertypes.ModuleName)
app.CapabilityKeeper.Seal()

// add consumer chain module accounts to module account permissions
// this MUST be called before the AccountKeeper initialisation
app.addConsumerChainAccountToMacPerms()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
Expand All @@ -310,12 +313,10 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Remove the ConsumerRewardsPool from the group of blocked recipient addresses in bank
// Remove the consumer module accounts from the group of blocked recipient addresses in bank
// this is required for the provider chain to be able to receive tokens from
// the consumer chain
bankBlockedAddrs := app.ModuleAccountAddrs()
delete(bankBlockedAddrs, authtypes.NewModuleAddress(
providertypes.ConsumerRewardsPool).String())
// consumer chains
bankBlockedAddrs := app.BlockedModuleAccountAddrs()

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
Expand Down Expand Up @@ -947,3 +948,17 @@ func makeEncodingConfig() appencoding.EncodingConfig {
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}

func (app *App) addConsumerChainAccountToMacPerms() {
for _, c := range providertypes.ConsumerRewardPools {
maccPerms[c] = nil
}
}

func (app *App) BlockedModuleAccountAddrs() map[string]bool {
acctAddrs := app.ModuleAccountAddrs()
for _, c := range providertypes.ConsumerRewardPools {
delete(acctAddrs, c)
}
return acctAddrs
}
62 changes: 62 additions & 0 deletions reward-distribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# PSS: reward distribution design proposal

## Provider states

### x/ccv/provider

- in-store: consumer chain Id -> opted-in validators mapping
- in-store: consumer chain Id -> module account (reward fee pool) mapping
- code constant: consumer reward pools / module account name list
- in-store: last consumer module account index assigned

### x/banking

- consumer module account balances
- community fee pool balance (x/distr module account balance)

### x/auth

- consumer module accounts

### ABCI

- previous block validator votes used as an input to calculate the validators reward allocations (abci.CommitInfo)

### IBC packet

- handshake metadata storing the consumer reward fee pool, i.e. assigned module account on the provider

### Actions

- Provider app startup:

- Module accounts are created from the consumer reward pool list

- Provider App runtime:

- for each consumer addition proposal that passes, assign a reward pool to the associated consumer chain
- when a consumer chain completes the CCV handshake, send the reward pool address of the consumer in the handshake ACK packet
- In enblock:
- for each consumer reward pool
- filter fees using denoms whitelist
- send to distribution module account
- compute community and validators rewards
- allocate tokens to community pool and tokens

- Consumer app runtime (unchanged):
- After distribution period each block transfers fees collected to consumer reward pool



## Questions:

- Should the consumer module accounts rather be stored as a code constant or a states?

- Reward "pool" Naming conventions:

- In the SDK, the community pool refers to a FeePool type struct that tracks the validators rewards.
The distribution module account holds the tokens and tracks the validator rewards using different states.
- In PSS, the consumer reward are received through an IBC transfers. That entails that it's hard to define from which consumer sent the reward.
- How can we determine for how long a validator opted in?
- Ask SDK the security
Loading

0 comments on commit 8adba69

Please sign in to comment.