mint

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

x/mint

Abstract

celestia-app's x/mint is a fork of the Cosmos SDK x/mint module that makes some changes to the inflation mechanism. The changes were motivated by a desire for Celestia to have a pre-determined inflation schedule. See ADR-019 for more details.

Inflation Schedule
Year Inflation (%)
0 8.00
1 7.20
2 6.48
3 5.832
4 5.2488
5 4.72392
6 4.251528
7 3.8263752
8 3.44373768
9 3.099363912
10 2.7894275208
11 2.51048476872
12 2.259436291848
13 2.0334926626632
14 1.83014339639688
15 1.647129056757192
16 1.50
17 1.50
18 1.50
19 1.50
20 1.50
  • Year indicates the number of years elapsed since chain genesis.
  • Inflation (%) indicates the percentage of the total supply that will be minted in the next year.

Terms

  • Inflation Rate: The percentage of the total supply that will be minted each year. The inflation rate is calculated once per year on the anniversary of chain genesis based on the number of years elapsed since genesis. The inflation rate is calculated as InitialInflationRate * ((1 - DisinflationRate) ^ YearsSinceGenesis). See ./types/constants.go for the constants used in this module.
  • Annual Provisions: The total amount of tokens that will be minted each year. Annual provisions are calculated once per year on the anniversary of chain genesis based on the total supply and the inflation rate. Annual provisions are calculated as TotalSupply * InflationRate
  • Block Provision: The amount of tokens that will be minted in the current block. Block provisions are calculated once per block based on the annual provisions and the number of nanoseconds elapsed between the current block and the previous block. Block provisions are calculated as AnnualProvisions * (NanosecondsSincePreviousBlock / NanosecondsPerYear)

State

See ./types/minter.go for the Minter struct which contains this module's state.

State Transitions

The Minter struct is updated every block via BeginBlocker.

Begin Block

See BeginBlocker in ./abci.go.

Events

An event is emitted every block when a block provision is minted. See mintBlockProvision in ./abci.go.

Client

CLI
$ celestia-appd query mint annual-provisions
80235005639941.760000000000000000
$ celestia-appd query mint genesis-time
2023-05-09 00:56:15.59304 +0000 UTC
$ celestia-appd query mint inflation
0.080000000000000000

Genesis State

The genesis state is defined in ./types/genesis.go.

Params

All params have been removed from this module because they should not be modifiable via governance. The constants used in this module are defined in ./types/constants.go and they are subject to change via hardforks.

Tests

See ./test/mint_test.go for an integration test suite for this module.

Assumptions and Considerations

For the Gregorian calendar, the average length of the calendar year (the mean year) across the complete leap cycle of 400 years is 365.2425 days (97 out of 400 years are leap years).

Source: https://en.wikipedia.org/wiki/Year#Calendar_year

This module assumes DaysPerYear = 365.2425 so when modifying tests, developers must define durations based on this assumption because ordinary durations won't return the expected results. In other words:

// oneYear is 31,556,952 seconds which will likely return expected results in tests
oneYear := time.Duration(minttypes.NanosecondsPerYear)

// oneYear is 31,536,000 seconds which will likely return unexpected results in tests
oneYear := time.Hour * 24 * 365
Security

Q: Can validators manipulate the amount of tokens minted due to inflation?

A:

This x/mint module calculates block provisions based on block timestamps so it is important to understand how block timestamps work in CometBFT. In CometBFT, block timestamps are monotonically increasing. A block's timestamp is the median of the Vote.Time fields from vote messages, where each vote's timestamp is weighted based on the voting power of the validator that cast it.

Based on BFT time, a block's timestamp is manipulatable by malicious validators if they control > 1/3 of the total voting power. Consequently, if malicious validators control > 1/3 of the total voting power, they could manipulate a block's timestamp to some arbitrary value (e.g. one year in the future) effectively advancing the inflation schedule by a year.

It is worth noting that in the scenario above, a CometBFT light client will reject a block if the block's timestamp is > 10 seconds ahead of the light client's current time. See verifyNewHeaderAndVals and defaultMaxClockDrift. Therefore, it seems infeasible for a malicious validator set with > 1/3 total voting power to manipulate the inflation schedule by more than 10 seconds.

Implementation

See x/mint for the implementation of this module.

References

  1. ADR-019

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginBlocker

func BeginBlocker(ctx sdk.Context, k keeper.Keeper)

BeginBlocker updates the inflation rate, annual provisions, and then mints the block provision for the current block.

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module for the mint module.

func NewAppModule

func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper) AppModule

NewAppModule creates a new AppModule object. If the InflationCalculationFn argument is nil, then the SDK's default inflation function will be used.

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the mint module.

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

ConsensusVersion implements AppModule/ConsensusVersion.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the mint module.

func (AppModule) GenerateGenesisState

func (AppModule) GenerateGenesisState(_ *module.SimulationState)

GenerateGenesisState is a no-op.

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the mint module. It returns no validator updates.

func (AppModule) LegacyQuerierHandler

func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier

LegacyQuerierHandler returns nil because this module doesn't support the legacy querier or Amino codec.

func (AppModule) Name

func (AppModule) Name() string

Name returns the mint module's name.

func (AppModule) ProposalContents

ProposalContents doesn't return any content functions for governance proposals.

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the mint module's querier route name.

func (AppModule) RegisterInvariants

func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants registers the mint module invariants.

func (AppModule) RegisterServices

func (am AppModule) RegisterServices(cfg module.Configurator)

RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries.

func (AppModule) RegisterStoreDecoder

func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry)

RegisterStoreDecoder registers a decoder for mint module's types.

func (AppModule) Route deprecated

func (AppModule) Route() sdk.Route

Deprecated: Route returns the message routing key for the mint module.

func (AppModule) WeightedOperations

func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation

WeightedOperations doesn't return any mint module operation.

type AppModuleBasic

type AppModuleBasic struct {
	// contains filtered or unexported fields
}

AppModuleBasic defines the basic application module used by the mint module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the mint module.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd() *cobra.Command

GetQueryCmd returns the root query command for the mint module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd() *cobra.Command

GetTxCmd returns no root tx command for the mint module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the mint module's name.

func (AppModuleBasic) RegisterGRPCGatewayRoutes

func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux)

RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module.

func (AppModuleBasic) RegisterInterfaces

func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry)

RegisterInterfaces registers the module's interface types

func (AppModuleBasic) RegisterLegacyAminoCodec

func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino)

RegisterLegacyAminoCodec registers the mint module's types on the given LegacyAmino codec.

func (AppModuleBasic) ValidateGenesis

ValidateGenesis performs genesis state validation for the mint module.

Directories

Path Synopsis
client
cli
Package types is a reverse proxy.
Package types is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL