approvals

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2021 License: AGPL-3.0 Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultEmergencySealingThreshold = 400

DefaultEmergencySealingThreshold is the default number of blocks which indicates that ER should be sealed using emergency sealing.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedSignatures

type AggregatedSignatures struct {
	// contains filtered or unexported fields
}

AggregatedSignatures is an utility struct that provides concurrency safe access to map of aggregated signatures indexed by chunk index

func NewAggregatedSignatures

func NewAggregatedSignatures(chunks uint64) *AggregatedSignatures

func (*AggregatedSignatures) ChunksWithoutAggregatedSignature added in v0.17.6

func (as *AggregatedSignatures) ChunksWithoutAggregatedSignature() []uint64

ChunksWithoutAggregatedSignature returns indexes of chunks that don't have an aggregated signature

func (*AggregatedSignatures) Collect

Collect returns array with aggregated signature for each chunk

func (*AggregatedSignatures) HasSignature

func (as *AggregatedSignatures) HasSignature(chunkIndex uint64) bool

HasSignature returns boolean depending if we have signature for particular chunk

func (*AggregatedSignatures) PutSignature

func (as *AggregatedSignatures) PutSignature(chunkIndex uint64, aggregatedSignature flow.AggregatedSignature) uint64

PutSignature adds the AggregatedSignature from the collector to `aggregatedSignatures`. The returned int is the resulting number of approved chunks.

type ApprovalCollector

type ApprovalCollector struct {
	// contains filtered or unexported fields
}

ApprovalCollector is responsible for distributing work to chunk collectorTree, collecting aggregated signatures for chunks that reached seal construction threshold, creating and submitting seal candidates once signatures for every chunk are aggregated.

func NewApprovalCollector

func NewApprovalCollector(result *flow.IncorporatedResult, incorporatedBlock *flow.Header, assignment *chunks.Assignment, seals mempool.IncorporatedResultSeals, requiredApprovalsForSealConstruction uint) *ApprovalCollector

func (*ApprovalCollector) CollectMissingVerifiers

func (c *ApprovalCollector) CollectMissingVerifiers() map[uint64]flow.IdentifierList

CollectMissingVerifiers collects ids of verifiers who haven't provided an approval for particular chunk Returns: map { ChunkIndex -> []VerifierId }

func (*ApprovalCollector) IncorporatedBlock

func (c *ApprovalCollector) IncorporatedBlock() *flow.Header

IncorporatedBlock returns the block which incorporates execution result

func (*ApprovalCollector) IncorporatedBlockID

func (c *ApprovalCollector) IncorporatedBlockID() flow.Identifier

IncorporatedBlockID returns the ID of block which incorporates execution result

func (*ApprovalCollector) ProcessApproval

func (c *ApprovalCollector) ProcessApproval(approval *flow.ResultApproval) error

ProcessApproval performs processing of result approvals and bookkeeping of aggregated signatures for every chunk. Triggers sealing of execution result when processed last result approval needed for sealing. Returns: - engine.InvalidInputError - result approval is invalid - exception in case of any other error, usually this is not expected - nil on success

func (*ApprovalCollector) SealResult

func (c *ApprovalCollector) SealResult() error

type AssignmentCollector

type AssignmentCollector struct {
	ResultID flow.Identifier // ID of execution result

	BlockHeight uint64 // height of block targeted by execution result
	// contains filtered or unexported fields
}

AssignmentCollector Context:

  • When the same result is incorporated in multiple different forks, unique verifier assignment is determined for each fork.
  • The assignment collector is intended to encapsulate the known assignments for a particular execution result.

AssignmentCollector has a strict ordering of processing, before processing approvals at least one incorporated result has to be processed. AssignmentCollector takes advantage of internal caching to speed up processing approvals for different assignments AssignmentCollector is responsible for validating approvals on result-level (checking signature, identity). TODO: currently AssignmentCollector doesn't cleanup collectorTree when blocks that incorporate results get orphaned For BFT milestone we need to ensure that this cleanup is properly implemented and all orphan collectorTree are pruned by height when fork gets orphaned

func NewAssignmentCollector

func NewAssignmentCollector(result *flow.ExecutionResult, state protocol.State, headers storage.Headers, assigner module.ChunkAssigner, seals mempool.IncorporatedResultSeals,
	sigVerifier module.Verifier, approvalConduit network.Conduit, requestTracker *RequestTracker, requiredApprovalsForSealConstruction uint,
) (*AssignmentCollector, error)

func (*AssignmentCollector) BlockID

func (ac *AssignmentCollector) BlockID() flow.Identifier

BlockID returns the ID of the executed block

func (*AssignmentCollector) CheckEmergencySealing

func (ac *AssignmentCollector) CheckEmergencySealing(finalizedBlockHeight uint64) error

func (*AssignmentCollector) ProcessApproval

func (ac *AssignmentCollector) ProcessApproval(approval *flow.ResultApproval) error

func (*AssignmentCollector) ProcessIncorporatedResult

func (ac *AssignmentCollector) ProcessIncorporatedResult(incorporatedResult *flow.IncorporatedResult) error

func (*AssignmentCollector) RequestMissingApprovals

func (ac *AssignmentCollector) RequestMissingApprovals(sealingTracker *tracker.SealingTracker, maxHeightForRequesting uint64) (int, error)

RequestMissingApprovals traverses all collectors and requests missing approval for every chunk that didn't get enough approvals from verifiers. Returns number of requests made and error in case something goes wrong.

type AssignmentCollectorTree

type AssignmentCollectorTree struct {
	// contains filtered or unexported fields
}

AssignmentCollectorTree is a mempool holding assignment collectors, which is aware of the tree structure formed by the execution results. The mempool supports pruning by height: only collectors descending from the latest finalized block are relevant. Safe for concurrent access. Internally, the mempool utilizes the LevelledForrest.

func NewAssignmentCollectorTree

func NewAssignmentCollectorTree(lastSealed *flow.Header, headers storage.Headers, createCollector NewCollectorFactoryMethod) *AssignmentCollectorTree

func (*AssignmentCollectorTree) FinalizeForkAtLevel

func (t *AssignmentCollectorTree) FinalizeForkAtLevel(finalized *flow.Header, sealed *flow.Header) error

FinalizeForkAtLevel performs finalization of fork which is stored in leveled forest. When block is finalized we can mark other forks as orphan and stop processing approvals for it. Eventually all forks will be cleaned up by height

func (*AssignmentCollectorTree) GetCollector

func (t *AssignmentCollectorTree) GetCollector(resultID flow.Identifier) (*AssignmentCollector, bool)

GetCollector returns collector by ID and whether it is processable or not

func (*AssignmentCollectorTree) GetCollectorsByInterval

func (t *AssignmentCollectorTree) GetCollectorsByInterval(from, to uint64) []*AssignmentCollector

GetCollectorsByInterval returns processable collectors that satisfy interval [from; to)

func (*AssignmentCollectorTree) GetOrCreateCollector

func (t *AssignmentCollectorTree) GetOrCreateCollector(result *flow.ExecutionResult) (*LazyInitCollector, error)

GetOrCreateCollector performs lazy initialization of AssignmentCollector using double-checked locking.

func (*AssignmentCollectorTree) GetSize added in v0.17.6

func (t *AssignmentCollectorTree) GetSize() uint64

func (*AssignmentCollectorTree) PruneUpToHeight

func (t *AssignmentCollectorTree) PruneUpToHeight(limit uint64) ([]flow.Identifier, error)

PruneUpToHeight prunes all results for all assignment collectors with height up to but NOT INCLUDING `limit`. Noop, if limit is lower than the previous value (caution: this is different than the levelled forest's convention). Returns list of resultIDs that were pruned

type BaseApprovalsTestSuite

type BaseApprovalsTestSuite struct {
	suite.Suite

	ParentBlock         flow.Header     // parent of sealing candidate
	Block               flow.Header     // candidate for sealing
	IncorporatedBlock   flow.Header     // block that incorporated result
	VerID               flow.Identifier // for convenience, node id of first verifier
	Chunks              flow.ChunkList  // list of chunks of execution result
	ChunksAssignment    *chunks.Assignment
	AuthorizedVerifiers map[flow.Identifier]*flow.Identity // map of authorized verifier identities for execution result
	IncorporatedResult  *flow.IncorporatedResult
}

BaseApprovalsTestSuite is a base suite for testing approvals processing related functionality At nutshell generates mock data that can be used to create approvals and provides all needed data to validate those approvals for respected execution result.

func (*BaseApprovalsTestSuite) SetupTest

func (s *BaseApprovalsTestSuite) SetupTest()

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a utility structure that encapsulates map that stores result approvals and provides concurrent access to it.

func NewApprovalsCache

func NewApprovalsCache(capacity uint) *Cache

func (*Cache) All

func (c *Cache) All() []*flow.ResultApproval

All returns all stored approvals

func (*Cache) Get

func (c *Cache) Get(approvalID flow.Identifier) *flow.ResultApproval

Get returns approval that is saved in cache

func (*Cache) Put

func (c *Cache) Put(approval *flow.ResultApproval) bool

Put saves approval into cache; returns true iff approval was newly added

type ChunkApprovalCollector

type ChunkApprovalCollector struct {
	// contains filtered or unexported fields
}

ChunkApprovalCollector implements logic for checking chunks against assignments as well as accumulating signatures of already checked approvals.

func NewChunkApprovalCollector

func NewChunkApprovalCollector(assignment map[flow.Identifier]struct{}, requiredApprovalsForSealConstruction uint) *ChunkApprovalCollector

func (*ChunkApprovalCollector) GetMissingSigners

func (c *ChunkApprovalCollector) GetMissingSigners() flow.IdentifierList

GetMissingSigners returns ids of approvers that are present in assignment but didn't provide approvals

func (*ChunkApprovalCollector) ProcessApproval

func (c *ChunkApprovalCollector) ProcessApproval(approval *flow.ResultApproval) (flow.AggregatedSignature, bool)

ProcessApproval performs processing and bookkeeping of single approval

type GetCachedBlockHeight

type GetCachedBlockHeight = func(blockID flow.Identifier) (uint64, error)

helper functor that can be used to retrieve cached block height

type IncorporatedResultSeals

type IncorporatedResultSeals struct {
	// contains filtered or unexported fields
}

IncorporatedResultSeals implements the incorporated result seals memory pool of the consensus nodes. ATTENTION: this is a temporary wrapper for `mempool.IncorporatedResultSeals` to enforce that there are at least 2 receipts from _different_ ENs committing to the same incorporated result. This wrapper should only be used with `Core`.

func NewIncorporatedResultSeals

func NewIncorporatedResultSeals(mempool mempool.IncorporatedResultSeals, receiptsDB storage.ExecutionReceipts) *IncorporatedResultSeals

NewIncorporatedResultSeals creates a mempool for the incorporated result seals

func (*IncorporatedResultSeals) Add

Add adds an IncorporatedResultSeal to the mempool

func (*IncorporatedResultSeals) All

All returns all the items in the mempool

func (*IncorporatedResultSeals) ByID

ByID gets an IncorporatedResultSeal by IncorporatedResult ID

func (*IncorporatedResultSeals) Clear

func (ir *IncorporatedResultSeals) Clear()

Clear removes all entities from the pool.

func (*IncorporatedResultSeals) Limit added in v0.17.6

func (ir *IncorporatedResultSeals) Limit() uint

Limit returns the size limit of the mempool

func (*IncorporatedResultSeals) RegisterEjectionCallbacks

func (ir *IncorporatedResultSeals) RegisterEjectionCallbacks(callbacks ...mempool.OnEjection)

RegisterEjectionCallbacks adds the provided OnEjection callbacks

func (*IncorporatedResultSeals) Rem

Rem removes an IncorporatedResultSeal from the mempool

func (*IncorporatedResultSeals) Size added in v0.17.6

func (ir *IncorporatedResultSeals) Size() uint

Size returns the number of items in the mempool

type LazyInitCollector

type LazyInitCollector struct {
	Collector   *AssignmentCollector
	Processable bool // whether collector is processable
	Created     bool // whether collector was created or retrieved from cache
}

LazyInitCollector is a helper structure that is used to return collector which is lazy initialized

type LruCache

type LruCache struct {
	// contains filtered or unexported fields
}

LruCache is a wrapper over `simplelru.LRUCache` that provides needed api for processing result approvals Extends functionality of `simplelru.LRUCache` by introducing additional index for quicker access.

func NewApprovalsLRUCache

func NewApprovalsLRUCache(limit uint) *LruCache

func (*LruCache) Get

func (c *LruCache) Get(approvalID flow.Identifier) *flow.ResultApproval

func (*LruCache) Peek

func (c *LruCache) Peek(approvalID flow.Identifier) *flow.ResultApproval

func (*LruCache) Put

func (c *LruCache) Put(approval *flow.ResultApproval)

func (*LruCache) TakeByResultID

func (c *LruCache) TakeByResultID(resultID flow.Identifier) []*flow.ResultApproval

type NewCollectorFactoryMethod

type NewCollectorFactoryMethod = func(result *flow.ExecutionResult) (*AssignmentCollector, error)

NewCollector is a factory method to generate an AssignmentCollector for an execution result

type RequestTracker added in v0.17.6

type RequestTracker struct {
	// contains filtered or unexported fields
}

RequestTracker is an index of RequestTrackerItems indexed by execution result Index on result ID, incorporated block ID and chunk index. Is concurrency-safe.

func NewRequestTracker added in v0.17.6

func NewRequestTracker(blackoutPeriodMin, blackoutPeriodMax int) *RequestTracker

NewRequestTracker instantiates a new RequestTracker with blackout periods between min and max seconds.

func (*RequestTracker) Get added in v0.17.6

func (rt *RequestTracker) Get(resultID, incorporatedBlockID flow.Identifier, chunkIndex uint64) RequestTrackerItem

Get returns the tracker item for a specific chunk, and creates a new one if it doesn't exist.

func (*RequestTracker) GetAllIds added in v0.17.6

func (rt *RequestTracker) GetAllIds() []flow.Identifier

GetAllIds returns all result IDs that we are indexing

func (*RequestTracker) Remove added in v0.17.6

func (rt *RequestTracker) Remove(resultIDs ...flow.Identifier)

Remove removes all entries pertaining to an execution result

func (*RequestTracker) Set added in v0.17.6

func (rt *RequestTracker) Set(resultID, incorporatedBlockID flow.Identifier, chunkIndex uint64, item RequestTrackerItem)

Set inserts or updates the tracker item for a specific chunk.

type RequestTrackerItem added in v0.17.6

type RequestTrackerItem struct {
	Requests    uint
	NextTimeout time.Time
	// contains filtered or unexported fields
}

RequestTrackerItem is an object that keeps track of how many times a request has been made, as well as the time until a new request can be made. It is not concurrency-safe.

func NewRequestTrackerItem added in v0.17.6

func NewRequestTrackerItem(blackoutPeriodMin, blackoutPeriodMax int) RequestTrackerItem

NewRequestTrackerItem instantiates a new RequestTrackerItem where the NextTimeout is evaluated to the current time plus a random blackout period contained between min and max.

func (*RequestTrackerItem) IsBlackout added in v0.17.6

func (i *RequestTrackerItem) IsBlackout() bool

func (*RequestTrackerItem) Update added in v0.17.6

func (i *RequestTrackerItem) Update()

Update increments the number of requests and recomputes the NextTimeout.

type SignatureCollector added in v0.17.6

type SignatureCollector struct {
	// contains filtered or unexported fields
}

SignatureCollector contains a set of of signatures from verifiers attesting to the validity of an execution result chunk. NOT concurrency safe. TODO: this will be replaced with stateful BLS aggregation

func NewSignatureCollector added in v0.17.6

func NewSignatureCollector() SignatureCollector

NewSignatureCollector instantiates a new SignatureCollector

func (*SignatureCollector) Add added in v0.17.6

func (c *SignatureCollector) Add(signerID flow.Identifier, signature crypto.Signature)

Add appends a signature. Only the _first_ signature is retained for each signerID.

func (*SignatureCollector) BySigner added in v0.17.6

func (c *SignatureCollector) BySigner(signerID flow.Identifier) (*crypto.Signature, bool)

BySigner returns a signer's signature if it exists

func (*SignatureCollector) HasSigned added in v0.17.6

func (c *SignatureCollector) HasSigned(signerID flow.Identifier) bool

HasSigned checks if signer has already provided a signature

func (*SignatureCollector) NumberSignatures added in v0.17.6

func (c *SignatureCollector) NumberSignatures() uint

NumberSignatures returns the number of stored (distinct) signatures

func (*SignatureCollector) ToAggregatedSignature added in v0.17.6

func (c *SignatureCollector) ToAggregatedSignature() flow.AggregatedSignature

ToAggregatedSignature generates an aggregated signature from all signatures in the SignatureCollector

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL