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