Skip to content

Commit

Permalink
Fix platformvm.SetPreference
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Dec 6, 2023
1 parent ada692a commit 60a9c37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestNoErrorOnUnexpectedSetPreferenceDuringBootstrapping(t *testing.T) {
require.NoError(shutdownEnvironment(env))
}()

require.False(env.blkManager.SetPreference(ids.GenerateTestID())) // should not panic
require.True(env.blkManager.SetPreference(ids.GenerateTestID())) // should not panic
}

func TestGetNextStakerToReward(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func (m *manager) NewBlock(blk block.Block) snowman.Block {
}
}

func (m *manager) SetPreference(blockID ids.ID) (updated bool) {
updated = m.preferred == blockID
m.preferred = blockID
func (m *manager) SetPreference(blkID ids.ID) bool {
updated := m.preferred != blkID
m.preferred = blkID
return updated
}

Expand Down
15 changes: 15 additions & 0 deletions vms/platformvm/block/executor/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@ func TestManagerLastAccepted(t *testing.T) {

require.Equal(t, lastAcceptedID, manager.LastAccepted())
}

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

initialPreference := ids.GenerateTestID()
manager := &manager{
preferred: initialPreference,
}
require.False(manager.SetPreference(initialPreference))

newPreference := ids.GenerateTestID()
require.True(manager.SetPreference(newPreference))
require.False(manager.SetPreference(newPreference))
require.True(manager.SetPreference(initialPreference))
}

0 comments on commit 60a9c37

Please sign in to comment.