Skip to content

Commit

Permalink
Merge pull request #5688 from oasisprotocol/peternose/trivial/fix-han…
Browse files Browse the repository at this point in the history
…doff-interval

go/keymanager/churp: Fix handoff interval
  • Loading branch information
peternose committed May 8, 2024
2 parents 43d9c61 + c67a315 commit fe32bd2
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 69 deletions.
Empty file added .changelog/5688.trivial.md
Empty file.
2 changes: 1 addition & 1 deletion go/consensus/cometbft/apps/keymanager/churp/epoch.go
Expand Up @@ -23,7 +23,7 @@ func (ext *churpExt) onEpochChange(ctx *tmapi.Context, epoch beacon.EpochTime) e
}

for _, status := range statuses {
if status.NextHandoff == churp.HandoffsDisabled {
if status.HandoffsDisabled() {
continue
}

Expand Down
53 changes: 29 additions & 24 deletions go/consensus/cometbft/apps/keymanager/churp/txs.go
Expand Up @@ -247,20 +247,19 @@ func (ext *churpExt) apply(ctx *tmapi.Context, req *churp.SignedApplicationReque
return fmt.Errorf("keymanager: churp: non-existing ID: %d", req.Application.ID)
}

// Check if handoffs are enabled.
if status.HandoffsDisabled() {
return fmt.Errorf("keymanager: churp: handoffs disabled")
}

// Allow applications one epoch before the next handoff.
now, err := ext.state.GetCurrentEpoch(ctx)
if err != nil {
return err
}

switch status.NextHandoff {
case churp.HandoffsDisabled:
return fmt.Errorf("keymanager: churp: handoffs disabled")
case now + 1:
default:
if status.NextHandoff != now+1 {
return fmt.Errorf("keymanager: churp: submissions closed")
}

if status.NextHandoff != req.Application.Epoch {
return fmt.Errorf("keymanager: churp: invalid handoff: got %d, expected %d", req.Application.Epoch, status.NextHandoff)
}
Expand Down Expand Up @@ -339,20 +338,19 @@ func (ext *churpExt) confirm(ctx *tmapi.Context, req *churp.SignedConfirmationRe
return fmt.Errorf("keymanager: churp: non-existing ID: %d", req.Confirmation.ID)
}

// Check if handoffs are enabled.
if status.HandoffsDisabled() {
return fmt.Errorf("keymanager: churp: handoffs disabled")
}

// Allow confirmations only during the next handoff.
now, err := ext.state.GetCurrentEpoch(ctx)
if err != nil {
return err
}

switch status.NextHandoff {
case churp.HandoffsDisabled:
return fmt.Errorf("keymanager: churp: handoffs disabled")
case now:
default:
if status.NextHandoff != now {
return fmt.Errorf("keymanager: churp: confirmations closed")
}

if status.NextHandoff != req.Confirmation.Epoch {
return fmt.Errorf("keymanager: churp: invalid handoff: got %d, expected %d", req.Confirmation.Epoch, status.NextHandoff)
}
Expand Down Expand Up @@ -441,10 +439,6 @@ func addStakeClaim(ctx *tmapi.Context, entityID signature.PublicKey, runtimeID c
}

entityAddr := staking.NewAddress(entityID)
if err != nil {
return err
}

claim := churp.StakeClaim(runtimeID, churpID)
thresholds := churp.StakeThresholds()

Expand Down Expand Up @@ -519,19 +513,30 @@ func tryFinalizeHandoff(status *churp.Status, epochChange bool) bool {
return false
})

// Compute the next handoff epoch.
nextHandoff := churp.HandoffsDisabled
if status.Handoff < churp.HandoffsDisabled-status.HandoffInterval {
nextHandoff = status.NextHandoff + status.HandoffInterval
}

// Give nodes an extra epoch for application submission.
if epochChange && status.HandoffInterval == 1 && nextHandoff < churp.HandoffsDisabled {
nextHandoff++
}

// Disable handoffs when overflow happens.
if nextHandoff == churp.HandoffsDisabled {
status.HandoffInterval = 0
}

// Update fields.
status.Handoff = status.NextHandoff
status.Checksum = status.NextChecksum
status.Committee = committee
status.NextHandoff = status.Handoff + status.HandoffInterval
status.NextHandoff = nextHandoff
status.NextChecksum = nil
status.Applications = nil

// Give nodes an extra epoch for application submission.
if epochChange && status.HandoffInterval == 1 {
status.NextHandoff++
}

return true
}

Expand Down

0 comments on commit fe32bd2

Please sign in to comment.