Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[vms/proposervm] Set build block time correctly when anyone can propose #3197

Merged
merged 3 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion vms/proposervm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (vm *VM) getPostDurangoSlotTime(
delay = max(delay, vm.MinBlkDelay)
return parentTimestamp.Add(delay), nil
case errors.Is(err, proposer.ErrAnyoneCanPropose):
return parentTimestamp.Add(vm.MinBlkDelay), err
return parentTimestamp.Add(vm.MinBlkDelay), nil
default:
return time.Time{}, err
}
Expand Down
65 changes: 65 additions & 0 deletions vms/proposervm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2388,3 +2388,68 @@ func TestHistoricalBlockDeletion(t *testing.T) {
issueBlock()
requireNumHeights(newNumHistoricalBlocks)
}

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

var (
activationTime = time.Unix(0, 0)
durangoTime = activationTime
)
coreVM, valState, proVM, _ := initTestProposerVM(t, activationTime, durangoTime, 0)
defer func() {
require.NoError(proVM.Shutdown(context.Background()))
}()

valState.GetValidatorSetF = func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
// If there are no validators, anyone should be able to propose a block.
return map[ids.NodeID]*validators.GetValidatorOutput{}, nil
}

coreBlk := snowmantest.BuildChild(snowmantest.Genesis)
statelessBlock, err := statelessblock.BuildUnsigned(
snowmantest.GenesisID,
proVM.Time(),
0,
coreBlk.Bytes(),
)
require.NoError(err)

coreVM.GetBlockF = func(_ context.Context, blkID ids.ID) (snowman.Block, error) {
switch blkID {
case snowmantest.GenesisID:
return snowmantest.Genesis, nil
case coreBlk.ID():
return coreBlk, nil
default:
return nil, errUnknownBlock
}
}
coreVM.ParseBlockF = func(_ context.Context, b []byte) (snowman.Block, error) {
switch {
case bytes.Equal(b, snowmantest.GenesisBytes):
return snowmantest.Genesis, nil
case bytes.Equal(b, coreBlk.Bytes()):
return coreBlk, nil
default:
return nil, errUnknownBlock
}
}

statefulBlock, err := proVM.ParseBlock(context.Background(), statelessBlock.Bytes())
require.NoError(err)

require.NoError(statefulBlock.Verify(context.Background()))

currentTime := proVM.Clock.Time().Truncate(time.Second)
parentTimestamp := statefulBlock.Timestamp()
slotTime, err := proVM.getPostDurangoSlotTime(
context.Background(),
statefulBlock.Height()+1,
statelessBlock.PChainHeight(),
proposer.TimeToSlot(parentTimestamp, currentTime),
parentTimestamp,
)
require.NoError(err)
require.Equal(parentTimestamp.Add(proVM.MinBlkDelay), slotTime)
}
Loading