forked from lino-network/lino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
236 lines (219 loc) · 8.6 KB
/
genesis.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
package app
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
wire "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lino-network/lino/param"
"github.com/lino-network/lino/types"
globalModel "github.com/lino-network/lino/x/global/model"
crypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmtypes "github.com/tendermint/tendermint/types"
)
// genesis state for blockchain
type GenesisState struct {
LoadPrevStates bool `json:"load_prev_states"`
Accounts []GenesisAccount `json:"accounts"`
ReservePool types.Coin `json:"reserve_pool"`
InitCoinPrice types.MiniDollar `json:"init_coin_price"`
Developers []GenesisAppDeveloper `json:"developers"`
GenesisParam GenesisParam `json:"genesis_param"`
InitGlobalMeta globalModel.InitParamList `json:"init_global_meta"`
}
// genesis account will get coin to the address and register user
// if genesis account is validator, it will be added to validator list automatically
type GenesisAccount struct {
Name string `json:"name"`
Coin types.Coin `json:"coin"`
ResetKey crypto.PubKey `json:"reset_key"`
TransactionKey crypto.PubKey `json:"transaction_key"`
AppKey crypto.PubKey `json:"app_key"`
IsValidator bool `json:"is_validator"`
ValPubKey crypto.PubKey `json:"validator_pub_key"`
}
// GenesisAppDeveloper - register developer in genesis phase
type GenesisAppDeveloper struct {
Name string `json:"name"`
Website string `json:"web_site"`
Description string `json:"description"`
AppMetaData string `json:"app_meta_data"`
}
// GenesisParam - genesis parameters
type GenesisParam struct {
InitFromConfig bool `json:"init_from_config"`
param.GlobalAllocationParam
param.VoteParam
param.ProposalParam
param.DeveloperParam
param.ValidatorParam
param.CoinDayParam
param.BandwidthParam
param.AccountParam
param.PostParam
param.ReputationParam
param.PriceParam
}
// LinoBlockchainGenTx - init genesis account
func LinoBlockchainGenTx(cdc *wire.Codec, pk crypto.PubKey) (
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
resetPriv := secp256k1.GenPrivKey()
transactionPriv := secp256k1.GenPrivKey()
appPriv := secp256k1.GenPrivKey()
fmt.Println("reset private key is:", strings.ToUpper(hex.EncodeToString(resetPriv.Bytes())))
fmt.Println("transaction private key is:", strings.ToUpper(hex.EncodeToString(transactionPriv.Bytes())))
fmt.Println("app private key is:", strings.ToUpper(hex.EncodeToString(appPriv.Bytes())))
totalCoin := types.NewCoinFromInt64(10000000000 * types.Decimals)
genesisAcc := GenesisAccount{
Name: "lino",
Coin: totalCoin,
ResetKey: resetPriv.PubKey(),
TransactionKey: transactionPriv.PubKey(),
AppKey: appPriv.PubKey(),
IsValidator: true,
ValPubKey: pk,
}
var bz []byte
bz, err = wire.MarshalJSONIndent(cdc, genesisAcc)
if err != nil {
return
}
appGenTx = json.RawMessage(bz)
validator = tmtypes.GenesisValidator{
PubKey: pk,
Power: 1000,
}
return
}
// LinoBlockchainGenState - default genesis file
func LinoBlockchainGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {
if len(appGenTxs) == 0 {
err = errors.New("must provide at least genesis transaction")
return
}
// totalLino := "10000000000"
genesisState := GenesisState{
LoadPrevStates: false,
Accounts: []GenesisAccount{},
ReservePool: types.NewCoinFromInt64(0),
InitCoinPrice: types.NewMiniDollar(1200),
Developers: []GenesisAppDeveloper{},
GenesisParam: GenesisParam{
true,
param.GlobalAllocationParam{
GlobalGrowthRate: types.NewDecFromRat(98, 1000),
ContentCreatorAllocation: types.NewDecFromRat(65, 100),
DeveloperAllocation: types.NewDecFromRat(10, 100),
ValidatorAllocation: types.NewDecFromRat(5, 100),
},
param.VoteParam{
MinStakeIn: types.NewCoinFromInt64(1000 * types.Decimals),
VoterCoinReturnIntervalSec: int64(7 * 24 * 3600),
VoterCoinReturnTimes: int64(7),
DelegatorCoinReturnIntervalSec: int64(7 * 24 * 3600),
DelegatorCoinReturnTimes: int64(7),
},
param.ProposalParam{
ContentCensorshipDecideSec: int64(24 * 7 * 3600),
ContentCensorshipPassRatio: types.NewDecFromRat(50, 100),
ContentCensorshipPassVotes: types.NewCoinFromInt64(10000 * types.Decimals),
ContentCensorshipMinDeposit: types.NewCoinFromInt64(100 * types.Decimals),
ChangeParamDecideSec: int64(24 * 7 * 3600),
ChangeParamPassRatio: types.NewDecFromRat(70, 100),
ChangeParamPassVotes: types.NewCoinFromInt64(1000000 * types.Decimals),
ChangeParamMinDeposit: types.NewCoinFromInt64(100000 * types.Decimals),
ProtocolUpgradeDecideSec: int64(24 * 7 * 3600),
ProtocolUpgradePassRatio: types.NewDecFromRat(80, 100),
ProtocolUpgradePassVotes: types.NewCoinFromInt64(10000000 * types.Decimals),
ProtocolUpgradeMinDeposit: types.NewCoinFromInt64(1000000 * types.Decimals),
},
param.DeveloperParam{
DeveloperMinDeposit: types.NewCoinFromInt64(1000000 * types.Decimals),
DeveloperCoinReturnIntervalSec: int64(7 * 24 * 3600),
DeveloperCoinReturnTimes: int64(7),
},
param.ValidatorParam{
ValidatorMinDeposit: types.NewCoinFromInt64(200000 * types.Decimals),
ValidatorCoinReturnIntervalSec: int64(7 * 24 * 3600),
ValidatorCoinReturnTimes: int64(7),
PenaltyMissCommit: types.NewCoinFromInt64(200 * types.Decimals),
PenaltyByzantine: types.NewCoinFromInt64(1000 * types.Decimals),
AbsentCommitLimitation: int64(600), // 30min
OncallSize: int64(22),
StandbySize: int64(7),
ValidatorRevokePendingSec: int64(7 * 24 * 3600),
OncallInflationWeight: int64(2),
StandbyInflationWeight: int64(1),
MaxVotedValidators: int64(3),
SlashLimitation: int64(5),
},
param.CoinDayParam{
SecondsToRecoverCoinDay: int64(7 * 24 * 3600),
},
param.BandwidthParam{
SecondsToRecoverBandwidth: int64(7 * 24 * 3600),
CapacityUsagePerTransaction: types.NewCoinFromInt64(1 * types.Decimals),
VirtualCoin: types.NewCoinFromInt64(1 * types.Decimals),
GeneralMsgQuotaRatio: types.NewDecFromRat(20, 100),
GeneralMsgEMAFactor: types.NewDecFromRat(1, 10),
AppMsgQuotaRatio: types.NewDecFromRat(80, 100),
AppMsgEMAFactor: types.NewDecFromRat(1, 10),
ExpectedMaxMPS: types.NewDecFromRat(300, 1),
MsgFeeFactorA: types.NewDecFromRat(6, 1),
MsgFeeFactorB: types.NewDecFromRat(10, 1),
MaxMPSDecayRate: types.NewDecFromRat(99, 100),
AppBandwidthPoolSize: types.NewDecFromRat(10, 1),
AppVacancyFactor: types.NewDecFromRat(69, 100),
AppPunishmentFactor: types.NewDecFromRat(14, 5),
},
param.AccountParam{
MinimumBalance: types.NewCoinFromInt64(0),
RegisterFee: types.NewCoinFromInt64(1 * types.Decimals),
FirstDepositFullCoinDayLimit: types.NewCoinFromInt64(1 * types.Decimals),
MaxNumFrozenMoney: 10,
},
param.PostParam{
ReportOrUpvoteIntervalSec: 24 * 3600,
PostIntervalSec: 600,
MaxReportReputation: types.NewCoinFromInt64(100 * types.Decimals),
},
param.ReputationParam{
BestContentIndexN: 200,
UserMaxN: 50,
},
param.PriceParam{
TestnetMode: true,
UpdateEverySec: int64(time.Hour.Seconds()),
FeedEverySec: int64((10 * time.Minute).Seconds()),
HistoryMaxLen: 71,
PenaltyMissFeed: types.NewCoinFromInt64(10000 * types.Decimals),
},
},
InitGlobalMeta: globalModel.InitParamList{
MaxTPS: sdk.NewDec(1000),
ConsumptionFreezingPeriodSec: 7 * 24 * 3600,
ConsumptionFrictionRate: types.NewDecFromRat(5, 100),
},
}
for _, genesisAccRaw := range appGenTxs {
var genesisAcc GenesisAccount
err = cdc.UnmarshalJSON(genesisAccRaw, &genesisAcc)
if err != nil {
return
}
genesisState.Accounts = append(genesisState.Accounts, genesisAcc)
}
genesisAppDeveloper := GenesisAppDeveloper{
Name: "lino",
Website: "https://lino.network/",
Description: "",
AppMetaData: "",
}
genesisState.Developers = append(genesisState.Developers, genesisAppDeveloper)
appState, err = wire.MarshalJSONIndent(cdc, genesisState)
return
}