Skip to content

Commit

Permalink
Merge pull request #5407 from oasisprotocol/ptrus/fix/blocking-status
Browse files Browse the repository at this point in the history
fix: control status blocking before chain init with runtimes
  • Loading branch information
ptrus authored Oct 19, 2023
2 parents f63c447 + 22d3afd commit 0d68f8a
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 138 deletions.
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
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
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/byzantine_beacon_vrf.go
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
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/consensus_state_sync.go
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
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/min_transact_balance.go
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
152 changes: 152 additions & 0 deletions go/oasis-test-runner/scenario/e2e/runtime/early_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package runtime

import (
"context"
"errors"
"fmt"
"time"

consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario/e2e"
)

var (
// EarlyQuery is the early query scenario where we query a validator node before the network
// has started and there are no committed blocks.
EarlyQuery scenario.Scenario = &earlyQueryImpl{
Scenario: e2e.NewScenario("early-query"),
}

// EarlyQueryInitHeight is the same as EarlyQuery scenario but with an initial height set.
EarlyQueryInitHeight scenario.Scenario = &earlyQueryImpl{
Scenario: e2e.NewScenario("early-query/init-height"),
initialHeight: 42,
}

// EarlyQueryRuntime is the early query scenario where we query a runtime node.
EarlyQueryRuntime scenario.Scenario = &earlyQueryImpl{
Scenario: NewScenario("early-query", nil),
runtime: true,
}
)

type earlyQueryImpl struct {
scenario.Scenario

runtime bool
initialHeight int64
}

func (sc *earlyQueryImpl) Clone() scenario.Scenario {
return &earlyQueryImpl{
Scenario: sc.Scenario.Clone(),
runtime: sc.runtime,
initialHeight: sc.initialHeight,
}
}

func (sc *earlyQueryImpl) Fixture() (*oasis.NetworkFixture, error) {
f, err := sc.Scenario.Fixture()
if err != nil {
return nil, err
}

f.Network.SetInsecureBeacon()

// Set initial height.
f.Network.InitialHeight = sc.initialHeight

// Only one validator should actually start to prevent the network from committing any blocks.
f.Validators[1].NoAutoStart = true
f.Validators[2].NoAutoStart = true

return f, nil
}

func (sc *earlyQueryImpl) Run(ctx context.Context, _ *env.Env) error {
// Start the network.
var err error
if err = sc.Network().Start(); err != nil {
return err
}

var ctrl *oasis.Controller
switch sc.runtime {
case false:
ctrl = sc.Network().Controller()
case true:
// Use the compute worker node in the runtime scenario.
ctrl, err = oasis.NewController(sc.Network().ComputeWorkers()[0].SocketPath())
if err != nil {
return fmt.Errorf("failed to create controller for compute node: %w", err)
}

}

// Perform consensus queries.
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

// StateToGenesis.
_, err = ctrl.Consensus.StateToGenesis(ctx, consensus.HeightLatest)
if !errors.Is(err, consensus.ErrNoCommittedBlocks) {
return fmt.Errorf("StateToGenesis query should fail with ErrNoCommittedBlocks (got: %s)", err)
}
// GetBlock.
_, err = ctrl.Consensus.GetBlock(ctx, consensus.HeightLatest)
if !errors.Is(err, consensus.ErrNoCommittedBlocks) {
return fmt.Errorf("GetBlock query should fail with ErrNoCommittedBlocks (got: %s)", err)
}
// GetTransactions.
_, err = ctrl.Consensus.GetTransactions(ctx, consensus.HeightLatest)
if !errors.Is(err, consensus.ErrNoCommittedBlocks) {
return fmt.Errorf("GetTransactions query should fail with ErrNoCommittedBlocks (got: %s)", err)
}
// GetTransactionsWithResults.
_, err = ctrl.Consensus.GetTransactionsWithResults(ctx, consensus.HeightLatest)
if !errors.Is(err, consensus.ErrNoCommittedBlocks) {
return fmt.Errorf("GetTransactionsWithResults query should fail with ErrNoCommittedBlocks (got: %s)", err)
}

switch sc.runtime {
case false:
// GetStatus on validator.
status, err := ctrl.GetStatus(ctx)
if err != nil {
return fmt.Errorf("failed to get status for node: %w", err)
}
if status.Consensus.Status != consensus.StatusStateSyncing {
return fmt.Errorf("node reports as ready before chain is initialized")
}
if status.Consensus.LatestHeight != 0 {
return fmt.Errorf("node reports non-zero latest height before chain is initialized")
}
if !status.Consensus.IsValidator {
return fmt.Errorf("node does not report itself to be a validator at genesis")
}
case true:
// GetStatus on a compute node.
status, err := ctrl.GetStatus(ctx)
if err != nil {
return fmt.Errorf("failed to get status for compute node: %w", err)
}
fmt.Println(status)
if status.Consensus.Status != consensus.StatusStateSyncing {
return fmt.Errorf("node reports as ready before chain is initialized")
}
if status.Consensus.LatestHeight != 0 {
return fmt.Errorf("node reports non-zero latest height before chain is initialized")
}
if status.Consensus.IsValidator {
return fmt.Errorf("compute node does report itself to be a validator at genesis")
}
if len(status.Runtimes) < 1 {
return fmt.Errorf("compute node status does not contain any runtimes")
}
}

return nil
}
6 changes: 5 additions & 1 deletion go/oasis-test-runner/scenario/e2e/runtime/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (sc *Scenario) Clone() scenario.Scenario {
testClient = sc.TestClient.Clone()
}
return &Scenario{
Scenario: sc.Scenario.Clone(),
Scenario: *sc.Scenario.Clone().(*e2e.Scenario),
TestClient: testClient,
debugNoRandomInitialEpoch: sc.debugNoRandomInitialEpoch,
debugWeakAlphaOk: sc.debugWeakAlphaOk,
Expand Down Expand Up @@ -362,6 +362,10 @@ func RegisterScenarios() error {
TrustRootChangeFailsTest,
// Archive node API test.
ArchiveAPI,
// Early query tests.
EarlyQuery,
EarlyQueryInitHeight,
EarlyQueryRuntime,
} {
if err := cmd.Register(s); err != nil {
return err
Expand Down
Loading

0 comments on commit 0d68f8a

Please sign in to comment.