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

Fix negative ETA caused by rollback in vm.SetState #3036

Merged
merged 3 commits into from
May 21, 2024
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
16 changes: 8 additions & 8 deletions snow/engine/snowman/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ func (b *Bootstrapper) Clear(context.Context) error {
}

func (b *Bootstrapper) Start(ctx context.Context, startReqID uint32) error {
b.Ctx.State.Set(snow.EngineState{
Type: p2p.EngineType_ENGINE_TYPE_SNOWMAN,
State: snow.Bootstrapping,
})
if err := b.VM.SetState(ctx, snow.Bootstrapping); err != nil {
return fmt.Errorf("failed to notify VM that bootstrapping has started: %w", err)
}

lastAccepted, err := b.getLastAccepted(ctx)
if err != nil {
return err
Expand All @@ -161,14 +169,6 @@ func (b *Bootstrapper) Start(ctx context.Context, startReqID uint32) error {
zap.Uint64("lastAcceptedHeight", lastAcceptedHeight),
)

b.Ctx.State.Set(snow.EngineState{
Type: p2p.EngineType_ENGINE_TYPE_SNOWMAN,
State: snow.Bootstrapping,
})
if err := b.VM.SetState(ctx, snow.Bootstrapping); err != nil {
return fmt.Errorf("failed to notify VM that bootstrapping has started: %w", err)
}

// Set the starting height
b.startingHeight = lastAcceptedHeight
b.requestID = startReqID
Expand Down
31 changes: 31 additions & 0 deletions snow/engine/snowman/bootstrap/bootstrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,37 @@ func TestBootstrapperReceiveStaleAncestorsMessage(t *testing.T) {
require.Equal(snow.Bootstrapping, config.Ctx.State.Get().State)
}

func TestBootstrapperRollbackOnSetState(t *testing.T) {
require := require.New(t)

config, _, _, vm := newConfig(t)

blks := snowmantest.BuildChain(2)
initializeVMWithBlockchain(vm, blks)

blks[1].StatusV = choices.Accepted

bs, err := New(
config,
func(context.Context, uint32) error {
config.Ctx.State.Set(snow.EngineState{
Type: p2ppb.EngineType_ENGINE_TYPE_SNOWMAN,
State: snow.NormalOp,
})
return nil
},
)
require.NoError(err)

vm.SetStateF = func(context.Context, snow.State) error {
blks[1].StatusV = choices.Processing
return nil
}

require.NoError(bs.Start(context.Background(), 0))
require.Equal(blks[0].HeightV, bs.startingHeight)
}

func initializeVMWithBlockchain(vm *block.TestVM, blocks []*snowmantest.Block) {
vm.CantSetState = false
vm.LastAcceptedF = func(context.Context) (ids.ID, error) {
Expand Down
Loading