Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT/23.0.x] #5407 #5408 #5410 #5409

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/5407.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix stuck `control status` on runtime nodes before initialization
1 change: 1 addition & 0 deletions .changelog/5408.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix showing empty peer IDs in the Consensus light client status output
1 change: 1 addition & 0 deletions .changelog/5410.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config/migrate: Automatically configure external P2P addresses for validators
2 changes: 2 additions & 0 deletions go/consensus/cometbft/light/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func (lp *lightClientProvider) Initialized() <-chan struct{} {
func (lp *lightClientProvider) PeerID() string {
peer := lp.getPeer()
if peer == nil {
// This happens if a provider is not yet initialized, or
// (less likely) if a peer was just dropped and no new peer is available.
return ""
}
return peer.String()
Expand Down
4 changes: 3 additions & 1 deletion go/consensus/cometbft/light/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (c *client) GetStatus() (*consensus.LightClientStatus, error) {
}

for _, p := range c.providers {
status.PeerIDs = append(status.PeerIDs, p.PeerID())
if id := p.PeerID(); id != "" {
status.PeerIDs = append(status.PeerIDs, id)
}
}

return status, nil
Expand Down
34 changes: 33 additions & 1 deletion go/oasis-node/cmd/config/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"fmt"
"io"
"net/url"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -724,13 +725,44 @@ func doMigrateConfig(cmd *cobra.Command, args []string) {

// If a node has `consensus.validator` set to true and it does not have any runtimes configured,
// the new `mode` should be set to `validator`.
var isValidator bool
if newValidator, ok := m(newCfg["consensus"])["validator"]; ok {
isValidator, _ := newValidator.(bool)
isValidator, _ = newValidator.(bool)
if _, hasRuntimes := m(newCfg["runtime"])["paths"]; !hasRuntimes && isValidator {
nodeMode = "validator"
delete(m(newCfg["consensus"]), "validator")
}
}
// If node is a validator, it now requires external P2P addresses to have set.
if isValidator {
// Set P2P port if not set.
if _, ok := m(newCfg["p2p"])["port"]; !ok {
m(newCfg["p2p"])["port"] = 9200
}
// Set P2P registration addresses if not set.
if _, ok := m(m(newCfg["p2p"])["registration"])["addresses"]; !ok {
mkSubMap(m(newCfg["p2p"]), "registration")

// Parse host from consensus.external_address.
ea := m(newCfg["consensus"])["external_address"]
if eaStr, ok := ea.(string); ok {
url, err := url.Parse(eaStr)
if err != nil {
logger.Error("failed to parse URI from consensus.external_address", "err", err)
os.Exit(1)
}
m(m(newCfg["p2p"])["registration"])["addresses"] = []string{url.Hostname() + ":" + fmt.Sprintf("%d", m(newCfg["p2p"])["port"])}
} else {
logger.Warn("consensus.external_address missing, not configuring p2p.registration.addresses parameter", "address", ea)
}
} else {
logger.Warn("p2p.registration.addresses is already set, make sure the address port matches p2p.port")
}

}
if isValidator && (m(newCfg["p2p"])["port"] == nil || m(m(newCfg["p2p"])["registration"])["addresses"] == nil) {
logger.Warn("node is a validator but p2p.port or p2p.registration.addresses are not set")
}

// Check for options that are only available on the command-line.
if _, ok = oldCfg["debug"]; ok {
Expand Down
56 changes: 55 additions & 1 deletion go/oasis-node/cmd/config/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ genesis:
file: /storage/node/genesis.json

# Worker configuration.
worker:
worker:
p2p:
port: 9002
peer_outbound_queue_size: 42
Expand Down Expand Up @@ -261,6 +261,39 @@ worker:
entity: /node/entity/entity.json
`

// Validator node with external address set and no P2P address.
const testValidatorConfig2Raw = `
datadir: /node/data

log:
level:
default: info
tendermint: info
tendermint/context: error
format: JSON

genesis:
file: /node/etc/genesis.json

consensus:
validator: true

tendermint:
p2p:
# List of seed nodes to connect to.
# NOTE: You can add additional seed nodes to this list if you want.
seed:
- "E27F6B7A350B4CC2B48A6CBE94B0A02B0DCB0BF3@35.199.49.168:26656"
core:
external_address: tcp://4.3.2.1:26656

worker:
registration:
# In order for the node to register itself, the entity.json of the entity
# used to provision the node must be available on the node.
entity: /node/entity/entity.json
`

// Non-validator node from docs test configuration file.
const testDocsNonValidatorConfigRaw = `
datadir: /node/data
Expand Down Expand Up @@ -612,6 +645,27 @@ func TestConfigMigrationValidator(t *testing.T) {
require.Equal(newConfig.Consensus.Validator, false)
}

func TestConfigMigrationValidator2(t *testing.T) {
require := require.New(t)
newConfig := prepareTest(require, testValidatorConfig2Raw)

// Now check if the config struct fields actually match the original state.
require.Equal(newConfig.Mode, config.ModeValidator)
require.Equal(newConfig.Common.DataDir, "/node/data")
require.Equal(newConfig.Common.Log.Format, "JSON")
require.Equal(newConfig.Common.Log.Level["default"], "info")
require.Equal(newConfig.Common.Log.Level["cometbft"], "info")
require.Equal(newConfig.Common.Log.Level["cometbft/context"], "error")
require.Equal(newConfig.Genesis.File, "/node/etc/genesis.json")
require.Equal(newConfig.P2P.Seeds[0], "H6u9MtuoWRKn5DKSgarj/dzr2Z9BsjuRHgRAoXITOcU=@35.199.49.168:26656")
require.Equal(newConfig.P2P.Seeds[1], "H6u9MtuoWRKn5DKSgarj/dzr2Z9BsjuRHgRAoXITOcU=@35.199.49.168:9200")
require.Equal(newConfig.Consensus.Validator, false)
require.Equal(newConfig.Consensus.ExternalAddress, "tcp://4.3.2.1:26656")
require.Equal(newConfig.P2P.Port, uint16(9200))
require.Equal(len(newConfig.P2P.Registration.Addresses), 1)
require.Equal(newConfig.P2P.Registration.Addresses[0], "4.3.2.1:9200")
}

func TestConfigMigrationDocsNonValidator(t *testing.T) {
require := require.New(t)
newConfig := prepareTest(require, testDocsNonValidatorConfigRaw)
Expand Down
3 changes: 2 additions & 1 deletion go/oasis-node/cmd/node/node_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ func (n *Node) getRuntimeStatus(ctx context.Context) (map[common.Namespace]contr
}

// Fetch provisioner type.
_, provisioner, err := rt.Host(ctx)
_, provisioner, err := rt.Host()
switch {
case err != nil:
n.logger.Error("failed to fetch host configuration",
"err", err,
)
status.Provisioner = "pending"
case provisioner != nil:
status.Provisioner = provisioner.Name()
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type byzantineVRFBeaconImpl struct {

func (sc *byzantineVRFBeaconImpl) Clone() scenario.Scenario {
return &byzantineVRFBeaconImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
extraArgs: sc.extraArgs,
identitySeed: sc.identitySeed,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newChangeRewardScheduleImpl(name string, parameters *api.ChangeParametersPr

func (sc *changeRewardScheduleImpl) Clone() scenario.Scenario {
return &changeRewardScheduleImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
parameters: sc.parameters,
currentEpoch: sc.currentEpoch,
entityNonce: sc.entityNonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func newConsensusParameterUpgradeImpl(name string, parameters *api.ChangeParamet

func (sc *consensusParameterUpgradeImpl) Clone() scenario.Scenario {
return &consensusParameterUpgradeImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
parameters: sc.parameters,
upgradeChecker: sc.upgradeChecker,
currentEpoch: sc.currentEpoch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type consensusStateSyncImpl struct {

func (sc *consensusStateSyncImpl) Clone() scenario.Scenario {
return &consensusStateSyncImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/debond.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type debondImpl struct {

func (s *debondImpl) Clone() scenario.Scenario {
return &debondImpl{
Scenario: s.Scenario.Clone(),
Scenario: *s.Scenario.Clone().(*Scenario),
}
}

Expand Down
109 changes: 0 additions & 109 deletions go/oasis-test-runner/scenario/e2e/early_query.go

This file was deleted.

2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/gas_fees_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type gasFeesImpl struct {

func (sc *gasFeesImpl) Clone() scenario.Scenario {
return &gasFeesImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
dumpRestore: sc.dumpRestore,
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/genesis_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type genesisFileImpl struct {

func (s *genesisFileImpl) Clone() scenario.Scenario {
return &genesisFileImpl{
Scenario: s.Scenario.Clone(),
Scenario: *s.Scenario.Clone().(*Scenario),
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/identity_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type identityCLIImpl struct {

func (sc *identityCLIImpl) Clone() scenario.Scenario {
return &identityCLIImpl{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
dataDir: sc.dataDir,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (mtb *minTransactBalanceImpl) getAccountAndCheckNonce(ctx context.Context,

func (mtb *minTransactBalanceImpl) Clone() scenario.Scenario {
return &minTransactBalanceImpl{
Scenario: mtb.Scenario.Clone(),
Scenario: *mtb.Scenario.Clone().(*Scenario),
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/multiple_seeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (sc *multipleSeeds) Fixture() (*oasis.NetworkFixture, error) {

func (sc *multipleSeeds) Clone() scenario.Scenario {
return &multipleSeeds{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*Scenario),
}
}

Expand Down
Loading
Loading