Skip to content

Commit

Permalink
go/worker/storage: Force checkpoint at genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Feb 18, 2022
1 parent 65e375d commit e6781e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
34 changes: 1 addition & 33 deletions go/oasis-test-runner/scenario/e2e/runtime/halt_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"reflect"
"time"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
)

var (
Expand Down Expand Up @@ -94,39 +92,9 @@ func (sc *haltRestoreImpl) Run(childEnv *env.Env) error { // nolint: gocyclo
}

if sc.suspendRuntime {
// Make sure all compute nodes are synced before stopping them. This can otherwise cause
// problems due to incompatible stale state.
sc.Logger.Info("waiting for message results to be processed")

blkCh, blkSub, blkErr := sc.Net.Controller().Roothash.WatchBlocks(ctx, fixture.Runtimes[1].ID)
if blkErr != nil {
return fmt.Errorf("failed to watch blocks: %w", blkErr)
}
defer blkSub.Close()

var latestBlk *block.Block
for {
select {
case annBlk := <-blkCh:
latestBlk = annBlk.Block
case <-time.After(30 * time.Second):
return fmt.Errorf("timeout while waiting for block")
}

if latestBlk.Header.MessagesHash.IsEmpty() {
break
}
}

// Stop compute nodes.
sc.Logger.Info("stopping compute nodes",
"latest_round", latestBlk.Header.Round,
"latest_state_root", latestBlk.Header.StateRoot,
)
sc.Logger.Info("stopping compute nodes")
for _, n := range sc.Net.ComputeWorkers() {
if _, err = n.WaitForRound(ctx, fixture.Runtimes[1].ID, latestBlk.Header.Round); err != nil {
return fmt.Errorf("failed to wait for round: %w", err)
}
if err = n.Stop(); err != nil {
return fmt.Errorf("failed to stop node: %w", err)
}
Expand Down
7 changes: 3 additions & 4 deletions go/storage/tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ func testBasic(t *testing.T, localBackend api.LocalBackend, backend api.Backend,

cps, err := backend.GetCheckpoints(ctx, &checkpoint.GetCheckpointsRequest{Version: 1, Namespace: namespace})
require.NoError(t, err, "GetCheckpoints")
require.Len(t, cps, 1, "GetCheckpoints should return one checkpoint")
require.Equal(t, cp, cps[0], "GetCheckpoints should return correct checkpoint metadata")
require.Len(t, cps[0].Chunks, 1, "checkpoint should have a single chunk")
require.Contains(t, cps, cp, "GetCheckpoints should return correct checkpoint metadata")
require.Len(t, cp.Chunks, 1, "checkpoint should have a single chunk")

var buf bytes.Buffer
chunk, err := cps[0].GetChunkMetadata(0)
chunk, err := cp.GetChunkMetadata(0)
require.NoError(t, err, "GetChunkMetadata")
err = backend.GetCheckpointChunk(ctx, chunk, &buf)
require.NoError(t, err, "GetCheckpointChunk")
Expand Down
9 changes: 5 additions & 4 deletions go/worker/storage/committee/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,10 @@ func (n *Node) initGenesis(rt *registryApi.Runtime, genesisBlock *block.Block) e
compatible = n.localStorage.NodeDB().HasRoot(stateRoot)
}

// If we are incompatible and the database is not empty, we cannot do anything. If the database
// is empty we assume the node will sync from a different node.
if !compatible && latestVersion > 0 {
// If we are incompatible and the local version is greater or the same as the genesis version,
// we cannot do anything. If the local version is lower we assume the node will sync from a
// different node.
if !compatible && latestVersion >= stateRoot.Version {
n.logger.Error("existing state is incompatible with runtime genesis state",
"genesis_state_root", genesisBlock.Header.StateRoot,
"genesis_round", genesisBlock.Header.Round,
Expand Down Expand Up @@ -856,7 +857,7 @@ func (n *Node) worker() { // nolint: gocyclo

// Notify the checkpointer of the genesis round so it can be checkpointed.
if n.checkpointer != nil {
n.checkpointer.NotifyNewVersion(genesisBlock.Header.Round)
n.checkpointer.ForceCheckpoint(genesisBlock.Header.Round)
n.checkpointer.Flush()
}

Expand Down

0 comments on commit e6781e6

Please sign in to comment.