Skip to content

Commit 4f1906e

Browse files
committed
Remove engine.Unit from Assigner engine and Fetcher engine
The engine.Unit was only used for its context. In similar situations, other code uses a context.Background() instead.
1 parent 656cbd5 commit 4f1906e

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

engine/verification/assigner/engine.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/rs/zerolog"
99
"github.com/rs/zerolog/log"
1010

11-
"github.com/onflow/flow-go/engine"
1211
"github.com/onflow/flow-go/model/chunks"
1312
"github.com/onflow/flow-go/model/flow"
1413
"github.com/onflow/flow-go/model/flow/filter"
@@ -24,7 +23,6 @@ import (
2423
// to me to verify, and then save it to the chunks job queue for the
2524
// fetcher engine to process.
2625
type Engine struct {
27-
unit *engine.Unit
2826
log zerolog.Logger
2927
metrics module.VerificationMetrics
3028
tracer module.Tracer
@@ -36,8 +34,11 @@ type Engine struct {
3634
blockConsumerNotifier module.ProcessingNotifier // to report a block has been processed.
3735
stopAtHeight uint64
3836
stopAtBlockID atomic.Value
37+
*module.NoopReadyDoneAware
3938
}
4039

40+
var _ module.ReadyDoneAware = (*Engine)(nil)
41+
4142
func New(
4243
log zerolog.Logger,
4344
metrics module.VerificationMetrics,
@@ -50,7 +51,6 @@ func New(
5051
stopAtHeight uint64,
5152
) *Engine {
5253
e := &Engine{
53-
unit: engine.NewUnit(),
5454
log: log.With().Str("engine", "assigner").Logger(),
5555
metrics: metrics,
5656
tracer: tracer,
@@ -69,14 +69,6 @@ func (e *Engine) WithBlockConsumerNotifier(notifier module.ProcessingNotifier) {
6969
e.blockConsumerNotifier = notifier
7070
}
7171

72-
func (e *Engine) Ready() <-chan struct{} {
73-
return e.unit.Ready()
74-
}
75-
76-
func (e *Engine) Done() <-chan struct{} {
77-
return e.unit.Done()
78-
}
79-
8072
// resultChunkAssignment receives an execution result that appears in a finalized incorporating block.
8173
// In case this verification node is authorized at the reference block of this execution receipt's result,
8274
// chunk assignment is computed for the result, and the list of assigned chunks returned.
@@ -164,7 +156,8 @@ func (e *Engine) processChunk(chunk *flow.Chunk, resultID flow.Identifier, block
164156
func (e *Engine) ProcessFinalizedBlock(block *flow.Block) {
165157
blockID := block.ID()
166158

167-
span, ctx := e.tracer.StartBlockSpan(e.unit.Ctx(), blockID, trace.VERProcessFinalizedBlock)
159+
// We don't have any existing information and don't need cancellation, so use a background (empty) context
160+
span, ctx := e.tracer.StartBlockSpan(context.Background(), blockID, trace.VERProcessFinalizedBlock)
168161
defer span.End()
169162

170163
e.processFinalizedBlock(ctx, block)

engine/verification/fetcher/engine.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
// to the verifier engine.
3535
type Engine struct {
3636
// common
37-
unit *engine.Unit
3837
state protocol.State // used to verify the origin ID of chunk data response, and sealing status.
3938

4039
// monitoring
@@ -72,7 +71,6 @@ func New(
7271
stopAtHeight uint64,
7372
) *Engine {
7473
e := &Engine{
75-
unit: engine.NewUnit(),
7674
metrics: metrics,
7775
tracer: tracer,
7876
log: log.With().Str("engine", "fetcher").Logger(),
@@ -104,16 +102,12 @@ func (e *Engine) Ready() <-chan struct{} {
104102
if e.chunkConsumerNotifier == nil {
105103
e.log.Fatal().Msg("missing chunk consumer notifier callback in verification fetcher engine")
106104
}
107-
return e.unit.Ready(func() {
108-
<-e.requester.Ready()
109-
})
105+
return e.requester.Ready()
110106
}
111107

112108
// Done terminates the engine and returns a channel that is closed when the termination is done
113109
func (e *Engine) Done() <-chan struct{} {
114-
return e.unit.Done(func() {
115-
<-e.requester.Done()
116-
})
110+
return e.requester.Done()
117111
}
118112

119113
// ProcessAssignedChunk is the entry point of fetcher engine.
@@ -169,7 +163,8 @@ func (e *Engine) ProcessAssignedChunk(locator *chunks.Locator) {
169163
// processAssignedChunkWithTracing encapsulates the logic of processing assigned chunk with tracing enabled.
170164
func (e *Engine) processAssignedChunkWithTracing(chunk *flow.Chunk, result *flow.ExecutionResult, chunkLocatorID flow.Identifier) (bool, uint64, error) {
171165

172-
span, _ := e.tracer.StartBlockSpan(e.unit.Ctx(), result.BlockID, trace.VERProcessAssignedChunk)
166+
// We don't have any existing information and don't need cancellation, so use a background (empty) context
167+
span, _ := e.tracer.StartBlockSpan(context.Background(), result.BlockID, trace.VERProcessAssignedChunk)
173168
span.SetAttributes(attribute.Int("collection_index", int(chunk.CollectionIndex)))
174169
defer span.End()
175170

0 commit comments

Comments
 (0)