-
Notifications
You must be signed in to change notification settings - Fork 293
/
default_overrides.go
272 lines (234 loc) · 9.22 KB
/
default_overrides.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package app
import (
"encoding/json"
"fmt"
"time"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/x/mint"
minttypes "github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/codec"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distribution "github.com/cosmos/cosmos-sdk/x/distribution"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibc "github.com/cosmos/ibc-go/v6/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v6/modules/core/02-client/client"
ibctypes "github.com/cosmos/ibc-go/v6/modules/core/types"
tmcfg "github.com/tendermint/tendermint/config"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)
// bankModule defines a custom wrapper around the x/bank module's AppModuleBasic
// implementation to provide custom default genesis state.
type bankModule struct {
bank.AppModuleBasic
}
// DefaultGenesis returns custom x/bank module genesis state.
func (bankModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
metadata := banktypes.Metadata{
Description: "The native token of the Celestia network.",
Base: BondDenom,
Name: DisplayDenom,
Display: DisplayDenom,
Symbol: DisplayDenom,
DenomUnits: []*banktypes.DenomUnit{
{
Denom: BondDenom,
Exponent: 0,
Aliases: []string{
BondDenomAlias,
},
},
{
Denom: DisplayDenom,
Exponent: 6,
Aliases: []string{},
},
},
}
genState := banktypes.DefaultGenesisState()
genState.DenomMetadata = append(genState.DenomMetadata, metadata)
return cdc.MustMarshalJSON(genState)
}
// stakingModule wraps the x/staking module in order to overwrite specific
// ModuleManager APIs.
type stakingModule struct {
staking.AppModuleBasic
}
// DefaultGenesis returns custom x/staking module genesis state.
func (stakingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := stakingtypes.DefaultParams()
params.UnbondingTime = appconsts.DefaultUnbondingTime
params.BondDenom = BondDenom
params.MinCommissionRate = sdk.NewDecWithPrec(5, 2) // 5%
return cdc.MustMarshalJSON(&stakingtypes.GenesisState{
Params: params,
})
}
// stakingModule wraps the x/staking module in order to overwrite specific
// ModuleManager APIs.
type slashingModule struct {
slashing.AppModuleBasic
}
// DefaultGenesis returns custom x/staking module genesis state.
func (slashingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := slashingtypes.DefaultParams()
params.MinSignedPerWindow = sdk.NewDecWithPrec(75, 2) // 75%
params.SignedBlocksWindow = 5000
params.DowntimeJailDuration = time.Minute * 1
params.SlashFractionDoubleSign = sdk.NewDecWithPrec(2, 2) // 2%
params.SlashFractionDowntime = sdk.ZeroDec() // 0%
return cdc.MustMarshalJSON(&slashingtypes.GenesisState{
Params: params,
})
}
type crisisModule struct {
crisis.AppModuleBasic
}
// DefaultGenesis returns custom x/crisis module genesis state.
func (crisisModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(&crisistypes.GenesisState{
ConstantFee: sdk.NewCoin(BondDenom, sdk.NewInt(1000)),
})
}
type distributionModule struct {
distribution.AppModuleBasic
}
// DefaultGenesis returns custom x/distribution module genesis state.
func (distributionModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := distributiontypes.DefaultParams()
params.BaseProposerReward = sdk.ZeroDec() // 0%
params.BonusProposerReward = sdk.ZeroDec() // 0%
return cdc.MustMarshalJSON(&distributiontypes.GenesisState{
Params: params,
})
}
type ibcModule struct {
ibc.AppModuleBasic
}
// DefaultGenesis returns custom x/ibc module genesis state.
func (ibcModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
// per ibc documentation, this value should be 3-5 times the expected block
// time. The expected block time is 15 seconds, therefore this value is 75
// seconds.
maxBlockTime := appconsts.GoalBlockTime * 5
gs := ibctypes.DefaultGenesisState()
gs.ClientGenesis.Params.AllowedClients = []string{"06-solomachine", "07-tendermint"}
gs.ConnectionGenesis.Params.MaxExpectedTimePerBlock = uint64(maxBlockTime.Nanoseconds())
return cdc.MustMarshalJSON(gs)
}
type mintModule struct {
mint.AppModuleBasic
}
// DefaultGenesis returns custom x/mint module genesis state.
func (mintModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := minttypes.DefaultGenesisState()
genState.BondDenom = BondDenom
return cdc.MustMarshalJSON(genState)
}
func newGovModule() govModule {
return govModule{gov.NewAppModuleBasic(getLegacyProposalHandlers())}
}
// govModule is a custom wrapper around the x/gov module's AppModuleBasic
// implementation to provide custom default genesis state.
type govModule struct {
gov.AppModuleBasic
}
// DefaultGenesis returns custom x/gov module genesis state.
func (govModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := govtypes.DefaultGenesisState()
day := time.Duration(time.Hour * 24)
oneWeek := day * 7
genState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(BondDenom, sdk.NewInt(10_000_000_000))) // 10,000 TIA
genState.DepositParams.MaxDepositPeriod = &oneWeek
genState.VotingParams.VotingPeriod = &oneWeek
return cdc.MustMarshalJSON(genState)
}
func getLegacyProposalHandlers() (result []govclient.ProposalHandler) {
result = append(result,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
)
return result
}
// DefaultConsensusParams returns a ConsensusParams with a MaxBytes
// determined using a goal square size.
func DefaultConsensusParams() *tmproto.ConsensusParams {
return &tmproto.ConsensusParams{
Block: DefaultBlockParams(),
Evidence: DefaultEvidenceParams(),
Validator: coretypes.DefaultValidatorParams(),
Version: tmproto.VersionParams{
AppVersion: DefaultInitialVersion,
},
}
}
// DefaultBlockParams returns a default BlockParams with a MaxBytes determined
// using a goal square size.
func DefaultBlockParams() tmproto.BlockParams {
return tmproto.BlockParams{
MaxBytes: appconsts.DefaultMaxBytes,
MaxGas: -1,
TimeIotaMs: 1, // 1ms
}
}
// DefaultEvidenceParams returns a default EvidenceParams with a MaxAge
// determined using a goal block time.
func DefaultEvidenceParams() tmproto.EvidenceParams {
evdParams := coretypes.DefaultEvidenceParams()
evdParams.MaxAgeDuration = appconsts.DefaultUnbondingTime
evdParams.MaxAgeNumBlocks = int64(appconsts.DefaultUnbondingTime.Seconds())/int64(appconsts.GoalBlockTime.Seconds()) + 1
return evdParams
}
func DefaultConsensusConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()
// Set broadcast timeout to be 50 seconds in order to avoid timeouts for long block times
// TODO: make TimeoutBroadcastTx configurable per https://github.com/celestiaorg/celestia-app/issues/1034
cfg.RPC.TimeoutBroadcastTxCommit = 50 * time.Second
cfg.RPC.MaxBodyBytes = int64(8388608) // 8 MiB
cfg.Mempool.TTLNumBlocks = 5
cfg.Mempool.TTLDuration = time.Duration(cfg.Mempool.TTLNumBlocks) * appconsts.GoalBlockTime
// Given that there is a stateful transaction size check in CheckTx,
// We set a loose upper bound on what we expect the transaction to
// be based on the upper bound size of the entire block for the given
// version. This acts as a first line of DoS protection
upperBoundBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * appconsts.ContinuationSparseShareContentSize
cfg.Mempool.MaxTxBytes = upperBoundBytes
cfg.Mempool.MaxTxsBytes = int64(upperBoundBytes) * cfg.Mempool.TTLNumBlocks
cfg.Mempool.Version = "v1" // prioritized mempool
cfg.Consensus.TimeoutPropose = appconsts.TimeoutPropose
cfg.Consensus.TimeoutCommit = appconsts.TimeoutCommit
cfg.Consensus.SkipTimeoutCommit = false
cfg.TxIndex.Indexer = "null"
cfg.Storage.DiscardABCIResponses = true
return cfg
}
func DefaultAppConfig() *serverconfig.Config {
cfg := serverconfig.DefaultConfig()
cfg.API.Enable = false
cfg.GRPC.Enable = false
cfg.GRPCWeb.Enable = false
// the default snapshot interval was determined by picking a large enough
// value as to not dramatically increase resource requirements while also
// being greater than zero so that there are more nodes that will serve
// snapshots to nodes that state sync
cfg.StateSync.SnapshotInterval = 1500
cfg.StateSync.SnapshotKeepRecent = 2
cfg.MinGasPrices = fmt.Sprintf("%v%s", appconsts.DefaultMinGasPrice, BondDenom)
return cfg
}