diff --git a/vms/proposervm/block.go b/vms/proposervm/block.go index 9c2ac8a3c38a..893b8a9eec01 100644 --- a/vms/proposervm/block.go +++ b/vms/proposervm/block.go @@ -183,6 +183,7 @@ func (p *postForkCommonComponents) buildChild( ctx context.Context, parentID ids.ID, parentTimestamp time.Time, + parentHeight uint64, parentPChainHeight uint64, ) (Block, error) { // Child's timestamp is the later of now and this block's timestamp @@ -203,13 +204,24 @@ func (p *postForkCommonComponents) buildChild( return nil, err } - buildUnsignedBlock, err := p.shouldBuildBlock( - ctx, - parentID, - parentTimestamp, - parentPChainHeight, - newTimestamp, - ) + buildUnsignedBlock := true + if p.vm.IsDurangoActivated(parentTimestamp) { + err = p.shouldPostDurangoBuildBlock( + ctx, + parentTimestamp, + parentHeight, + parentPChainHeight, + newTimestamp, + ) + } else { + buildUnsignedBlock, err = p.shouldPreDurangoBuildBlock( + ctx, + parentID, + parentTimestamp, + parentPChainHeight, + newTimestamp, + ) + } if err != nil { return nil, err } @@ -361,7 +373,25 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay( return nil } -func (p *postForkCommonComponents) shouldBuildBlock( +func (p *postForkCommonComponents) shouldPostDurangoBuildBlock( + ctx context.Context, + parentTimestamp time.Time, + parentHeight uint64, + parentPChainHeight uint64, + newTimestamp time.Time, +) error { + expectedProposerID, err := p.vm.Windower.ExpectedProposer(ctx, parentHeight+1, parentPChainHeight, newTimestamp, parentTimestamp) + if err != nil { + return err + } + if expectedProposerID != p.vm.ctx.NodeID { + return errProposerWindowNotStarted + } + + return nil +} + +func (p *postForkCommonComponents) shouldPreDurangoBuildBlock( ctx context.Context, parentID ids.ID, parentTimestamp time.Time, diff --git a/vms/proposervm/block_test.go b/vms/proposervm/block_test.go index b3fd8d0d5dbc..478a92c334f5 100644 --- a/vms/proposervm/block_test.go +++ b/vms/proposervm/block_test.go @@ -40,10 +40,11 @@ func TestPostForkCommonComponents_buildChild(t *testing.T) { pChainHeight := uint64(1337) parentID := ids.GenerateTestID() parentTimestamp := time.Now() + parentHeight := uint64(1234) blkID := ids.GenerateTestID() innerBlk := snowman.NewMockBlock(ctrl) innerBlk.EXPECT().ID().Return(blkID).AnyTimes() - innerBlk.EXPECT().Height().Return(pChainHeight - 1).AnyTimes() + innerBlk.EXPECT().Height().Return(parentHeight + 1).AnyTimes() builtBlk := snowman.NewMockBlock(ctrl) builtBlk.EXPECT().Bytes().Return([]byte{1, 2, 3}).AnyTimes() builtBlk.EXPECT().ID().Return(ids.GenerateTestID()).AnyTimes() @@ -85,6 +86,7 @@ func TestPostForkCommonComponents_buildChild(t *testing.T) { context.Background(), parentID, parentTimestamp, + parentHeight, pChainHeight-1, ) require.NoError(err) diff --git a/vms/proposervm/post_fork_block.go b/vms/proposervm/post_fork_block.go index 28d127d33f70..bea8ead5d851 100644 --- a/vms/proposervm/post_fork_block.go +++ b/vms/proposervm/post_fork_block.go @@ -149,6 +149,7 @@ func (b *postForkBlock) buildChild(ctx context.Context) (Block, error) { ctx, b.ID(), b.Timestamp(), + b.Height(), b.PChainHeight(), ) } diff --git a/vms/proposervm/post_fork_option.go b/vms/proposervm/post_fork_option.go index 047a01c477fd..fa3f86cbcca1 100644 --- a/vms/proposervm/post_fork_option.go +++ b/vms/proposervm/post_fork_option.go @@ -121,6 +121,7 @@ func (b *postForkOption) buildChild(ctx context.Context) (Block, error) { ctx, parentID, b.Timestamp(), + b.Height(), parentPChainHeight, ) }