Skip to content

Commit

Permalink
rename match engine to sealing engine (onflow#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing authored Apr 1, 2021
1 parent 2bbcd3e commit d79eba7
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 167 deletions.
12 changes: 6 additions & 6 deletions cmd/consensus/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Consensus
# Consensus

The consensus node is responsible for deciding on the subjective ordering of the transactions that will be executed by the execution nodes. They do so by running a consensus algorithm for the blockchain, whereas each block payload contains an ordered list of collection guarantees received from collection node clusters.

Expand All @@ -21,7 +21,7 @@ This document provides a high-level overview of the consensus node architecture.
- [Compliance](#compliance)
- [Synchronization](#synchronization)
- [Provider](#provider)
- [Matching](#matching)
- [Sealing](#sealing)
- [Modules](#modules)
- [Protocol State](#protocol-state)
- [Block Builder](#block-builder)
Expand Down Expand Up @@ -116,13 +116,13 @@ The `provider` engine is responsible for providing blocks to the non-consensus p

At the moment, it simply receives each block proposal from the compliance engine and broadcasts it to all interested nodes on its communication channel.

### [Matching](../../engine/consensus/matching)
### [Sealing](../../engine/consensus/sealing)

The `matching` engine is responsible for receiving execution receipts and result approvals, as well as generating the block seals for them.
The `sealing` engine is responsible for receiving execution receipts and result approvals, as well as generating the block seals for them.

Whenever an execution receipt or a result approval are received by the matching engine, it will perform all possible validity checks on it before adding it to the respective memory pool.
Whenever an execution receipt or a result approval are received by the sealing engine, it will perform all possible validity checks on it before adding it to the respective memory pool.

If the related result or chunk is new, the matching engine checks if there are any results in its memory pool that can be fully verified with the received result approvals. Once this is the case, it creates the related block seal and adds it to the memory pool for block construction.
If the related result or chunk is new, the sealing engine checks if there are any results in its memory pool that can be fully verified with the received result approvals. Once this is the case, it creates the related block seal and adds it to the memory pool for block construction.


## Modules
Expand Down
12 changes: 6 additions & 6 deletions cmd/consensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
synceng "github.com/onflow/flow-go/engine/common/synchronization"
"github.com/onflow/flow-go/engine/consensus/compliance"
"github.com/onflow/flow-go/engine/consensus/ingestion"
"github.com/onflow/flow-go/engine/consensus/matching"
"github.com/onflow/flow-go/engine/consensus/provider"
"github.com/onflow/flow-go/engine/consensus/sealing"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/encodable"
"github.com/onflow/flow-go/model/encoding"
Expand Down Expand Up @@ -112,8 +112,8 @@ func main() {
flags.DurationVar(&blockRateDelay, "block-rate-delay", 500*time.Millisecond, "the delay to broadcast block proposal in order to control block production rate")
flags.UintVar(&chunkAlpha, "chunk-alpha", chmodule.DefaultChunkAssignmentAlpha, "number of verifiers that should be assigned to each chunk")
flags.UintVar(&requiredApprovalsForSealVerification, "required-verification-seal-approvals", validation.DefaultRequiredApprovalsForSealValidation, "minimum number of approvals that are required to verify a seal")
flags.UintVar(&requiredApprovalsForSealConstruction, "required-construction-seal-approvals", matching.DefaultRequiredApprovalsForSealConstruction, "minimum number of approvals that are required to construct a seal")
flags.BoolVar(&emergencySealing, "emergency-sealing-active", matching.DefaultEmergencySealingActive, "(de)activation of emergency sealing")
flags.UintVar(&requiredApprovalsForSealConstruction, "required-construction-seal-approvals", sealing.DefaultRequiredApprovalsForSealConstruction, "minimum number of approvals that are required to construct a seal")
flags.BoolVar(&emergencySealing, "emergency-sealing-active", sealing.DefaultEmergencySealingActive, "(de)activation of emergency sealing")
}).
Module("consensus node metrics", func(node *cmd.FlowNodeBuilder) error {
conMetrics = metrics.NewConsensusCollector(node.Tracer, node.MetricsRegisterer)
Expand Down Expand Up @@ -220,7 +220,7 @@ func main() {
syncCore, err = synchronization.New(node.Logger, synchronization.DefaultConfig())
return err
}).
Component("matching engine", func(node *cmd.FlowNodeBuilder) (module.ReadyDoneAware, error) {
Component("sealing engine", func(node *cmd.FlowNodeBuilder) (module.ReadyDoneAware, error) {

receiptRequester, err = requester.New(
node.Logger,
Expand All @@ -238,7 +238,7 @@ func main() {
return nil, err
}

match, err := matching.NewEngine(
match, err := sealing.NewEngine(
node.Logger,
node.Metrics.Engine,
node.Tracer,
Expand Down Expand Up @@ -454,7 +454,7 @@ func main() {
return sync, nil
}).
Component("receipt requester engine", func(node *cmd.FlowNodeBuilder) (module.ReadyDoneAware, error) {
// created with matching engine
// created with sealing engine
return receiptRequester, nil
}).
Run()
Expand Down
2 changes: 1 addition & 1 deletion engine/consensus/compliance/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (e *Engine) consumeEvents() {
// Public methods of `Core` are supposed to handle all errors internally.
// Here if error happens it means that internal state is corrupted or we have caught
// exception while processing. In such case best just to abort the node.
e.log.Fatal().Err(err).Msgf("fatal internal error in matching core logic")
e.log.Fatal().Err(err).Msgf("fatal internal error in sealing core logic")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// (c) 2019 Dapper Labs - ALL RIGHTS RESERVED

package matching
package sealing

import (
"context"
Expand All @@ -15,8 +15,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/onflow/flow-go/engine/consensus/matching/sealingtracker"

"github.com/onflow/flow-go/engine/consensus/sealing/tracker"
"github.com/onflow/flow-go/state"

"github.com/onflow/flow-go/engine"
Expand Down Expand Up @@ -113,7 +112,7 @@ func NewCore(
approvalConduit network.Conduit,
) (*Core, error) {
c := &Core{
log: log.With().Str("engine", "matching.Core").Logger(),
log: log.With().Str("engine", "sealing.Core").Logger(),
coreMetrics: coreMetrics,
tracer: tracer,
mempool: mempool,
Expand Down Expand Up @@ -562,9 +561,9 @@ func (c *Core) CheckSealing() error {
// function. It also filters out results that have an incorrect sub-graph.
// It specifically returns the information for the next unsealed results which will
// be useful for debugging the potential sealing halt issue
func (c *Core) sealableResults() (flow.IncorporatedResultList, *sealingtracker.SealingTracker, error) {
func (c *Core) sealableResults() (flow.IncorporatedResultList, *tracker.SealingTracker, error) {
// tracker to collection information about the _current_ sealing check.
sealingTracker := sealingtracker.NewSealingTracker(c.state)
sealingTracker := tracker.NewSealingTracker(c.state)

lastFinalized, err := c.state.Final().Head()
if err != nil {
Expand All @@ -580,7 +579,7 @@ func (c *Core) sealableResults() (flow.IncorporatedResultList, *sealingtracker.S
continue
}
if err != nil {
return nil, nil, fmt.Errorf("internal error matching chunk approvals to incorporated result: %w", err)
return nil, nil, fmt.Errorf("internal error sealing chunk approvals to incorporated result: %w", err)
}
sealableWithEnoughApprovals := sealingStatus.SufficientApprovalsForSealing
sealingTracker.Track(sealingStatus)
Expand All @@ -590,7 +589,7 @@ func (c *Core) sealableResults() (flow.IncorporatedResultList, *sealingtracker.S
if !sealableWithEnoughApprovals {
emergencySealable, err = c.emergencySealable(incorporatedResult, lastFinalized)
if err != nil {
return nil, nil, fmt.Errorf("internal error matching chunk approvals to incorporated result: %w", err)
return nil, nil, fmt.Errorf("internal error sealing chunk approvals to incorporated result: %w", err)
}
sealingStatus.SetQualifiesForEmergencySealing(emergencySealable)
}
Expand Down Expand Up @@ -631,10 +630,10 @@ func (c *Core) sealableResults() (flow.IncorporatedResultList, *sealingtracker.S
// have a child yet. Then, the chunk assignment cannot be computed.
// - All other errors are unexpected and symptoms of internal bugs, uncovered edge cases,
// or a corrupted internal node state. These are all fatal failures.
func (c *Core) hasEnoughApprovals(incorporatedResult *flow.IncorporatedResult) (*sealingtracker.SealingRecord, error) {
func (c *Core) hasEnoughApprovals(incorporatedResult *flow.IncorporatedResult) (*tracker.SealingRecord, error) {
// shortcut: if we don't require any approvals, any incorporatedResult has enough approvals
if c.requiredApprovalsForSealConstruction == 0 {
return sealingtracker.NewRecordWithSufficientApprovals(incorporatedResult), nil
return tracker.NewRecordWithSufficientApprovals(incorporatedResult), nil
}

// chunk assigment is based on the first block in the fork that incorporates the result
Expand All @@ -653,7 +652,7 @@ func (c *Core) hasEnoughApprovals(incorporatedResult *flow.IncorporatedResult) (
// To be valid, an Execution Receipt must have a system chunk, which is verified by the receipt
// validator. Encountering a receipt without any chunks is a fatal internal error, as such receipts
// should have never made it into the mempool in the first place. We explicitly check this here,
// so we don't have to worry about this edge case when matching approvals to chunks (below).
// so we don't have to worry about this edge case when sealing approvals to chunks (below).
if len(incorporatedResult.Result.Chunks) == 0 {
return nil, fmt.Errorf("incorporated result with zero chunks in mempool")
}
Expand Down Expand Up @@ -687,12 +686,12 @@ func (c *Core) hasEnoughApprovals(incorporatedResult *flow.IncorporatedResult) (

// abort checking approvals for incorporatedResult if current chunk has insufficient approvals
if incorporatedResult.NumberSignatures(chunk.Index) < c.requiredApprovalsForSealConstruction {
return sealingtracker.NewRecordWithInsufficientApprovals(incorporatedResult, chunk.Index), nil
return tracker.NewRecordWithInsufficientApprovals(incorporatedResult, chunk.Index), nil
}
}

// all chunks have sufficient approvals
return sealingtracker.NewRecordWithSufficientApprovals(incorporatedResult), nil
return tracker.NewRecordWithSufficientApprovals(incorporatedResult), nil
}

// emergencySealable determines whether an incorporated Result qualifies for "emergency sealing".
Expand Down Expand Up @@ -969,8 +968,8 @@ HEIGHT_LOOP:
continue
}

// Without the logic below, the matching engine would produce IncorporatedResults
// only from receipts received directly from ENs. Matching Core would not know about
// Without the logic below, the sealing engine would produce IncorporatedResults
// only from receipts received directly from ENs. sealing Core would not know about
// Receipts that are incorporated by other nodes in their blocks blocks (but never
// received directly from the EN). Also, Receipt might have been lost from the
// mempool during a node crash. Hence we check also if we have the receipts in
Expand Down
Loading

0 comments on commit d79eba7

Please sign in to comment.