From 98d314d10a2c6eef3906ff781a933dc793a5cab6 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Tue, 10 Nov 2020 14:52:11 +0100 Subject: [PATCH] go/consensus/tendermint: Fix early GetStatus with initial height > 1 --- .changelog/3481.bugfix.md | 1 + go/consensus/tendermint/full/full.go | 6 ++++- go/oasis-test-runner/scenario/e2e/e2e.go | 1 + .../scenario/e2e/early_query.go | 26 ++++++++++++++----- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 .changelog/3481.bugfix.md diff --git a/.changelog/3481.bugfix.md b/.changelog/3481.bugfix.md new file mode 100644 index 00000000000..3799d89013b --- /dev/null +++ b/.changelog/3481.bugfix.md @@ -0,0 +1 @@ +go/consensus/tendermint: Fix early GetStatus with initial height > 1 diff --git a/go/consensus/tendermint/full/full.go b/go/consensus/tendermint/full/full.go index 515717fff45..99bd2601481 100644 --- a/go/consensus/tendermint/full/full.go +++ b/go/consensus/tendermint/full/full.go @@ -815,7 +815,11 @@ func (t *fullService) GetStatus(ctx context.Context) (*consensusAPI.Status, erro status.NodePeers = peers // Check if the local node is in the validator set for the latest (uncommitted) block. - vals, err := t.stateStore.LoadValidators(status.LatestHeight + 1) + valSetHeight := status.LatestHeight + 1 + if valSetHeight < status.GenesisHeight { + valSetHeight = status.GenesisHeight + } + vals, err := t.stateStore.LoadValidators(valSetHeight) if err != nil { return nil, fmt.Errorf("failed to load validator set: %w", err) } diff --git a/go/oasis-test-runner/scenario/e2e/e2e.go b/go/oasis-test-runner/scenario/e2e/e2e.go index c610aa2a97f..b5e48db4965 100644 --- a/go/oasis-test-runner/scenario/e2e/e2e.go +++ b/go/oasis-test-runner/scenario/e2e/e2e.go @@ -331,6 +331,7 @@ func RegisterScenarios() error { Debond, // Early query test. EarlyQuery, + EarlyQueryInitHeight, // Consensus state sync. ConsensusStateSync, // Multiple seeds test. diff --git a/go/oasis-test-runner/scenario/e2e/early_query.go b/go/oasis-test-runner/scenario/e2e/early_query.go index 9531009d545..3eca1d2bc66 100644 --- a/go/oasis-test-runner/scenario/e2e/early_query.go +++ b/go/oasis-test-runner/scenario/e2e/early_query.go @@ -12,19 +12,30 @@ import ( "github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario" ) -// EarlyQuery is the early query scenario where we query a validator node before the network -// has started and there are no committed blocks. -var EarlyQuery scenario.Scenario = &earlyQueryImpl{ - E2E: *NewE2E("early-query"), -} +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{ + E2E: *NewE2E("early-query"), + } + + // EarlyQueryInitHeight is the same as EarlyQuery scenario but with an initial height set. + EarlyQueryInitHeight scenario.Scenario = &earlyQueryImpl{ + E2E: *NewE2E("early-query/init-height"), + initialHeight: 42, + } +) type earlyQueryImpl struct { E2E + + initialHeight int64 } func (sc *earlyQueryImpl) Clone() scenario.Scenario { return &earlyQueryImpl{ - E2E: sc.E2E.Clone(), + E2E: sc.E2E.Clone(), + initialHeight: sc.initialHeight, } } @@ -34,6 +45,9 @@ func (sc *earlyQueryImpl) Fixture() (*oasis.NetworkFixture, error) { return nil, err } + // 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