github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/consensus/approvals/assignment_collector_base.go (about)

     1  package approvals
     2  
     3  import (
     4  	"github.com/gammazero/workerpool"
     5  	"github.com/rs/zerolog"
     6  
     7  	"github.com/onflow/crypto/hash"
     8  
     9  	"github.com/onflow/flow-go/model/flow"
    10  	"github.com/onflow/flow-go/module"
    11  	"github.com/onflow/flow-go/module/mempool"
    12  	"github.com/onflow/flow-go/network"
    13  	"github.com/onflow/flow-go/state/protocol"
    14  	"github.com/onflow/flow-go/storage"
    15  )
    16  
    17  // AssignmentCollectorBase holds the shared data and functionality for
    18  // implementations of the
    19  // AssignmentCollectorBase holds common dependencies and immutable values that are shared
    20  // by the different states of an AssignmentCollector. It is indented as the base struct
    21  // for the different `AssignmentCollectorState` implementations.
    22  type AssignmentCollectorBase struct {
    23  	log zerolog.Logger
    24  
    25  	workerPool                           *workerpool.WorkerPool
    26  	assigner                             module.ChunkAssigner            // component for computing chunk assignments
    27  	state                                protocol.State                  // protocol state
    28  	headers                              storage.Headers                 // used to query headers from storage
    29  	sigHasher                            hash.Hasher                     // used to verify result approval signatures
    30  	seals                                mempool.IncorporatedResultSeals // holds candidate seals for incorporated results that have acquired sufficient approvals; candidate seals are constructed  without consideration of the sealability of parent results
    31  	approvalConduit                      network.Conduit                 // used to request missing approvals from verification nodes
    32  	requestTracker                       *RequestTracker                 // used to keep track of number of approval requests, and blackout periods, by chunk
    33  	requiredApprovalsForSealConstruction uint                            // number of approvals that are required for each chunk to be sealed
    34  
    35  	result        *flow.ExecutionResult // execution result
    36  	resultID      flow.Identifier       // ID of execution result
    37  	executedBlock *flow.Header          // header of the executed block
    38  }
    39  
    40  func NewAssignmentCollectorBase(logger zerolog.Logger,
    41  	workerPool *workerpool.WorkerPool,
    42  	result *flow.ExecutionResult,
    43  	state protocol.State,
    44  	headers storage.Headers,
    45  	assigner module.ChunkAssigner,
    46  	seals mempool.IncorporatedResultSeals,
    47  	sigHasher hash.Hasher,
    48  	approvalConduit network.Conduit,
    49  	requestTracker *RequestTracker,
    50  	requiredApprovalsForSealConstruction uint,
    51  ) (AssignmentCollectorBase, error) {
    52  	executedBlock, err := headers.ByBlockID(result.BlockID)
    53  	if err != nil {
    54  		return AssignmentCollectorBase{}, err
    55  	}
    56  
    57  	return AssignmentCollectorBase{
    58  		log:                                  logger,
    59  		workerPool:                           workerPool,
    60  		assigner:                             assigner,
    61  		state:                                state,
    62  		headers:                              headers,
    63  		sigHasher:                            sigHasher,
    64  		seals:                                seals,
    65  		approvalConduit:                      approvalConduit,
    66  		requestTracker:                       requestTracker,
    67  		requiredApprovalsForSealConstruction: requiredApprovalsForSealConstruction,
    68  		result:                               result,
    69  		resultID:                             result.ID(),
    70  		executedBlock:                        executedBlock,
    71  	}, nil
    72  }
    73  
    74  func (cb *AssignmentCollectorBase) BlockID() flow.Identifier      { return cb.result.BlockID }
    75  func (cb *AssignmentCollectorBase) Block() *flow.Header           { return cb.executedBlock }
    76  func (cb *AssignmentCollectorBase) ResultID() flow.Identifier     { return cb.resultID }
    77  func (cb *AssignmentCollectorBase) Result() *flow.ExecutionResult { return cb.result }
    78  
    79  // OnInvalidApproval logs in invalid approval
    80  func (cb *AssignmentCollectorBase) OnInvalidApproval(approval *flow.ResultApproval, err error) {
    81  	cb.log.Error().Err(err).
    82  		Str("approver_id", approval.Body.ApproverID.String()).
    83  		Str("executed_block_id", approval.Body.BlockID.String()).
    84  		Str("result_id", approval.Body.ExecutionResultID.String()).
    85  		Str("approval_id", approval.ID().String()).
    86  		Msg("received invalid approval")
    87  }