Skip to content

Remove Pre-Durango ProposerVM logic #3922

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
119 changes: 11 additions & 108 deletions vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
errPChainHeightNotMonotonic = errors.New("non monotonically increasing P-chain height")
errPChainHeightNotReached = errors.New("block P-chain height larger than current P-chain height")
errTimeTooAdvanced = errors.New("time is too far advanced")
errProposerWindowNotStarted = errors.New("proposer window hasn't started")
errUnexpectedProposer = errors.New("unexpected proposer for current window")
errProposerMismatch = errors.New("proposer mismatch")
errProposersNotActivated = errors.New("proposers haven't been activated yet")
Expand Down Expand Up @@ -140,12 +139,7 @@ func (p *postForkCommonComponents) Verify(
)
}

var shouldHaveProposer bool
if p.vm.Upgrades.IsDurangoActivated(parentTimestamp) {
shouldHaveProposer, err = p.verifyPostDurangoBlockDelay(ctx, parentTimestamp, parentPChainHeight, child)
} else {
shouldHaveProposer, err = p.verifyPreDurangoBlockDelay(ctx, parentTimestamp, parentPChainHeight, child)
}
shouldHaveProposer, err := p.verifyBlockDelay(ctx, parentTimestamp, parentPChainHeight, child)
if err != nil {
return err
}
Expand Down Expand Up @@ -203,24 +197,13 @@ func (p *postForkCommonComponents) buildChild(
return nil, err
}

var shouldBuildSignedBlock bool
if p.vm.Upgrades.IsDurangoActivated(parentTimestamp) {
shouldBuildSignedBlock, err = p.shouldBuildSignedBlockPostDurango(
ctx,
parentID,
parentTimestamp,
parentPChainHeight,
newTimestamp,
)
} else {
shouldBuildSignedBlock, err = p.shouldBuildSignedBlockPreDurango(
ctx,
parentID,
parentTimestamp,
parentPChainHeight,
newTimestamp,
)
}
shouldBuildSignedBlock, err := p.shouldBuildSignedBlock(
ctx,
parentID,
parentTimestamp,
parentPChainHeight,
newTimestamp,
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -332,42 +315,7 @@ func verifyIsNotOracleBlock(ctx context.Context, b snowman.Block) error {
}
}

func (p *postForkCommonComponents) verifyPreDurangoBlockDelay(
ctx context.Context,
parentTimestamp time.Time,
parentPChainHeight uint64,
blk *postForkBlock,
) (bool, error) {
var (
blkTimestamp = blk.Timestamp()
childHeight = blk.Height()
proposerID = blk.Proposer()
)
minDelay, err := p.vm.Windower.Delay(
ctx,
childHeight,
parentPChainHeight,
proposerID,
proposer.MaxVerifyWindows,
)
if err != nil {
p.vm.ctx.Log.Error("unexpected block verification failure",
zap.String("reason", "failed to calculate required timestamp delay"),
zap.Stringer("blkID", blk.ID()),
zap.Error(err),
)
return false, err
}

delay := blkTimestamp.Sub(parentTimestamp)
if delay < minDelay {
return false, fmt.Errorf("%w: delay %s < minDelay %s", errProposerWindowNotStarted, delay, minDelay)
}

return delay < proposer.MaxVerifyDelay, nil
}

func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
func (p *postForkCommonComponents) verifyBlockDelay(
ctx context.Context,
parentTimestamp time.Time,
parentPChainHeight uint64,
Expand Down Expand Up @@ -406,7 +354,7 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
}
}

func (p *postForkCommonComponents) shouldBuildSignedBlockPostDurango(
func (p *postForkCommonComponents) shouldBuildSignedBlock(
ctx context.Context,
parentID ids.ID,
parentTimestamp time.Time,
Expand Down Expand Up @@ -450,7 +398,7 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPostDurango(
//
// TODO: After Durango activates, restructure this logic to separate
// updating the scheduler from verifying the proposerID.
nextStartTime, err := p.vm.getPostDurangoSlotTime(
nextStartTime, err := p.vm.getSlotTime(
ctx,
parentHeight+1,
parentPChainHeight,
Expand All @@ -477,48 +425,3 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPostDurango(
p.vm.notifyInnerBlockReady()
return false, fmt.Errorf("%w: slot %d expects %s", errUnexpectedProposer, currentSlot, expectedProposerID)
}

func (p *postForkCommonComponents) shouldBuildSignedBlockPreDurango(
ctx context.Context,
parentID ids.ID,
parentTimestamp time.Time,
parentPChainHeight uint64,
newTimestamp time.Time,
) (bool, error) {
delay := newTimestamp.Sub(parentTimestamp)
if delay >= proposer.MaxBuildDelay {
return false, nil // time for any node to build an unsigned block
}

parentHeight := p.innerBlk.Height()
proposerID := p.vm.ctx.NodeID
minDelay, err := p.vm.Windower.Delay(ctx, parentHeight+1, parentPChainHeight, proposerID, proposer.MaxBuildWindows)
if err != nil {
p.vm.ctx.Log.Error("unexpected build block failure",
zap.String("reason", "failed to calculate required timestamp delay"),
zap.Stringer("parentID", parentID),
zap.Error(err),
)
return false, err
}

if delay >= minDelay {
// it's time for this node to propose a block. It'll be signed or
// unsigned depending on the delay
return delay < proposer.MaxVerifyDelay, nil
}

// It's not our turn to propose a block yet. This is likely caused by having
// previously notified the consensus engine to attempt to build a block on
// top of a block that is no longer the preferred block.
p.vm.ctx.Log.Debug("build block dropped",
zap.Time("parentTimestamp", parentTimestamp),
zap.Duration("minDelay", minDelay),
zap.Time("blockTimestamp", newTimestamp),
)

// In case the inner VM only issued one pendingTxs message, we should
// attempt to re-handle that once it is our turn to build the block.
p.vm.notifyInnerBlockReady()
return false, fmt.Errorf("%w: delay %s < minDelay %s", errProposerWindowNotStarted, delay, minDelay)
}
Loading
Loading