Skip to content

Commit

Permalink
Merge pull request #362 from onflow/alex/sealing-shortcuts
Browse files Browse the repository at this point in the history
revised scheduling of sealing check
  • Loading branch information
Alexander Hentschel authored Feb 3, 2021
2 parents 2f91d5b + d0b1d3a commit eb11ae0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions engine/consensus/matching/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ func New(
return nil, fmt.Errorf("could not register for requesting approvals: %w", err)
}

// Context:
// We expect a lot more Approvals compared to blocks or receipts. However, the level of
// information only changes significantly with new blocks or new receipts.
// We used to kick off the sealing check after every approval and receipt. In cases where
// the sealing check takes a lot more time than processing the actual messages (which we
// assume for the current implementation), we incur a large overhead as we check a lot
// of conditions, which only change with new blocks or new receipts.
// TEMPORARY FIX: to avoid sealing checks to monopolize the engine and delay processing
// of receipts and approvals. Specifically, we schedule sealing checks every 2 seconds.
e.unit.LaunchPeriodically(e.checkSealing, 2*time.Second, 120*time.Second)

return e, nil
}

Expand Down Expand Up @@ -226,12 +237,20 @@ func (e *Engine) process(originID flow.Identifier, event interface{}) error {
return e.onReceipt(originID, ev)
case *flow.ResultApproval:
e.engineMetrics.MessageReceived(metrics.EngineMatching, metrics.MessageResultApproval)
if e.requiredApprovalsForSealConstruction < 1 {
// if we don't require approvals to construct a seal, don't even process approvals.
return nil
}
e.unit.Lock()
defer e.unit.Unlock()
defer e.engineMetrics.MessageHandled(metrics.EngineMatching, metrics.MessageResultApproval)
return e.onApproval(originID, ev)
case *messages.ApprovalResponse:
e.engineMetrics.MessageReceived(metrics.EngineMatching, metrics.MessageResultApproval)
if e.requiredApprovalsForSealConstruction < 1 {
// if we don't require approvals to construct a seal, don't even process approvals.
return nil
}
e.unit.Lock()
defer e.unit.Unlock()
defer e.engineMetrics.MessageHandled(metrics.EngineMatching, metrics.MessageResultApproval)
Expand Down Expand Up @@ -324,9 +343,6 @@ func (e *Engine) onReceipt(originID flow.Identifier, receipt *flow.ExecutionRece

log.Info().Msg("execution result processed and stored")

// kick off a check for potential seal formation
e.unit.Launch(e.checkSealing)

return nil
}

Expand Down Expand Up @@ -436,9 +452,6 @@ func (e *Engine) onApproval(originID flow.Identifier, approval *flow.ResultAppro
}
e.mempool.MempoolEntries(metrics.ResourceApproval, e.approvals.Size())

// kick off a check for potential seal formation
e.unit.Launch(e.checkSealing)

return nil
}

Expand Down

0 comments on commit eb11ae0

Please sign in to comment.