-
Notifications
You must be signed in to change notification settings - Fork 138
/
actions_sovereign_chain.go
161 lines (141 loc) · 4.79 KB
/
actions_sovereign_chain.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
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"time"
)
type StartSovereignChainAction struct {
Chain ChainID
Validators []StartChainValidator
// Genesis changes specific to this action, appended to genesis changes defined in chain config
GenesisChanges string
}
// calls a simplified startup script (start-sovereign.sh) and runs a validator node
// upgrades are simpler with a single validator node since only one node needs to be upgraded
func (tr Chain) startSovereignChain(
action StartSovereignChainAction,
verbose bool,
) {
chainConfig := tr.testConfig.chainConfigs["sover"]
type jsonValAttrs struct {
Mnemonic string `json:"mnemonic"`
Allocation string `json:"allocation"`
Stake string `json:"stake"`
ValId string `json:"val_id"`
PrivValidatorKey string `json:"priv_validator_key"`
NodeKey string `json:"node_key"`
IpSuffix string `json:"ip_suffix"`
ConsumerMnemonic string `json:"consumer_mnemonic"`
ConsumerPrivValidatorKey string `json:"consumer_priv_validator_key"`
StartWithConsumerKey bool `json:"start_with_consumer_key"`
}
var validators []jsonValAttrs
for _, val := range action.Validators {
validators = append(validators, jsonValAttrs{
Mnemonic: tr.testConfig.validatorConfigs[val.Id].Mnemonic,
NodeKey: tr.testConfig.validatorConfigs[val.Id].NodeKey,
ValId: fmt.Sprint(val.Id),
PrivValidatorKey: tr.testConfig.validatorConfigs[val.Id].PrivValidatorKey,
Allocation: fmt.Sprint(val.Allocation) + "stake",
Stake: fmt.Sprint(val.Stake) + "stake",
IpSuffix: tr.testConfig.validatorConfigs[val.Id].IpSuffix,
ConsumerMnemonic: tr.testConfig.validatorConfigs[val.Id].ConsumerMnemonic,
ConsumerPrivValidatorKey: tr.testConfig.validatorConfigs[val.Id].ConsumerPrivValidatorKey,
// if true node will be started with consumer key for each consumer chain
StartWithConsumerKey: tr.testConfig.validatorConfigs[val.Id].UseConsumerKey,
})
}
vals, err := json.Marshal(validators)
if err != nil {
log.Fatal(err)
}
// Concat genesis changes defined in chain config, with any custom genesis changes for this chain instantiation
var genesisChanges string
if action.GenesisChanges != "" {
genesisChanges = chainConfig.GenesisChanges + " | " + action.GenesisChanges
} else {
genesisChanges = chainConfig.GenesisChanges
}
isConsumer := chainConfig.BinaryName != "interchain-security-pd"
testScriptPath := tr.target.GetTestScriptPath(isConsumer, "start-sovereign.sh")
cmd := tr.target.ExecCommand("/bin/bash", testScriptPath, chainConfig.BinaryName, string(vals),
string(chainConfig.ChainId), chainConfig.IpPrefix, genesisChanges,
tr.testConfig.tendermintConfigOverride)
cmdReader, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
cmd.Stderr = cmd.Stdout
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(cmdReader)
for scanner.Scan() {
out := scanner.Text()
if verbose {
fmt.Println("startSovereignChain: " + out)
}
if out == done {
break
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
tr.addChainToRelayer(AddChainToRelayerAction{
Chain: action.Chain,
Validator: action.Validators[0].Id,
}, verbose)
}
type LegacyUpgradeProposalAction struct {
ChainID ChainID
UpgradeTitle string
Proposer ValidatorID
UpgradeHeight uint64
}
func (tr *Chain) submitLegacyUpgradeProposal(action LegacyUpgradeProposalAction, verbose bool) {
submit := fmt.Sprintf(
`%s tx gov submit-legacy-proposal software-upgrade %s \
--title %s \
--deposit 10000000stake \
--upgrade-height %s \
--upgrade-info "perform changeover" \
--description "perform changeover" \
--gas 900000 \
--from validator%s \
--keyring-backend test \
--chain-id %s \
--home %s \
--node %s \
--no-validate \
-y`,
tr.testConfig.chainConfigs[ChainID("sover")].BinaryName,
action.UpgradeTitle,
action.UpgradeTitle,
fmt.Sprint(action.UpgradeHeight),
action.Proposer,
tr.testConfig.chainConfigs[ChainID("sover")].ChainId,
tr.getValidatorHome(ChainID("sover"), action.Proposer),
tr.getValidatorNode(ChainID("sover"), action.Proposer),
)
cmd := tr.target.ExecCommand("/bin/bash", "-c", submit)
if verbose {
fmt.Println("submitUpgradeProposal cmd:", cmd.String())
}
bz, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}
tr.waitBlocks(action.ChainID, 1, 15*time.Second)
}
type WaitUntilBlockAction struct {
Block uint
Chain ChainID
}
func (tr *Chain) waitUntilBlockOnChain(action WaitUntilBlockAction) {
fmt.Println("waitUntilBlockOnChain is waiting for block:", action.Block)
tr.waitUntilBlock(action.Chain, action.Block, 120*time.Second)
fmt.Println("waitUntilBlockOnChain done waiting for block:", action.Block)
}