github.com/koko1123/flow-go-1@v0.29.6/state/protocol/events.go (about)

     1  package protocol
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/model/flow"
     5  )
     6  
     7  // Consumer defines a set of events that occur within the protocol state, that
     8  // can be propagated to other components via an implementation of this interface.
     9  // Collectively, these are referred to as "Protocol Events".
    10  //
    11  // Protocol events are guaranteed to be delivered at least once. Subscribers must
    12  // handle multiple deliveries.
    13  //
    14  // CAUTION: Protocol event subscriber callbacks are invoked synchronously in the
    15  // critical path of protocol state mutations. Most subscribers should immediately
    16  // spawn a goroutine to handle the notification to avoid blocking protocol state
    17  // progression, especially for frequent protocol events (eg. BlockFinalized).
    18  //
    19  // NOTE: the epoch-related callbacks are only called once the fork containing
    20  // the relevant event has been finalized.
    21  type Consumer interface {
    22  
    23  	// BlockFinalized is called when a block is finalized.
    24  	// Formally, this callback is informationally idempotent. I.e. the consumer
    25  	// of this callback must handle repeated calls for the same block.
    26  	BlockFinalized(block *flow.Header)
    27  
    28  	// BlockProcessable is called when a correct block is encountered
    29  	// that is ready to be processed (i.e. it is connected to the finalized
    30  	// chain and its source of randomness is available).
    31  	// Formally, this callback is informationally idempotent. I.e. the consumer
    32  	// of this callback must handle repeated calls for the same block.
    33  	BlockProcessable(block *flow.Header)
    34  
    35  	// EpochTransition is called when we transition to a new epoch. This is
    36  	// equivalent to the beginning of the new epoch's staking phase and the end
    37  	// of the previous epoch's epoch committed phase.
    38  	//
    39  	// The block parameter is the first block of the new epoch.
    40  	//
    41  	// NOTE: Only called once the transition has been finalized.
    42  	EpochTransition(newEpochCounter uint64, first *flow.Header)
    43  
    44  	// EpochSetupPhaseStarted is called when we begin the epoch setup phase for
    45  	// the current epoch. This is equivalent to the end of the epoch staking
    46  	// phase for the current epoch.
    47  	//
    48  	// Referencing the diagram below, the event is emitted when block c is incorporated.
    49  	// The block parameter is the first block of the epoch setup phase (block c).
    50  	//
    51  	// |<-- Epoch N ------------------------------------------------->|
    52  	// |<-- StakingPhase -->|<-- SetupPhase -->|<-- CommittedPhase -->|
    53  	//                    ^--- block A - this block's execution result contains an EpochSetup event
    54  	//                      ^--- block b - contains seal for block A
    55  	//                         ^--- block c - contains qc for block b, first block of Setup phase
    56  	//                           ^--- block d - finalizes block c, triggers EpochSetupPhaseStarted event
    57  	//
    58  	// NOTE: Only called once the phase transition has been finalized.
    59  	EpochSetupPhaseStarted(currentEpochCounter uint64, first *flow.Header)
    60  
    61  	// EpochCommittedPhaseStarted is called when we begin the epoch committed phase
    62  	// for the current epoch. This is equivalent to the end of the epoch setup
    63  	// phase for the current epoch.
    64  	//
    65  	// Referencing the diagram below, the event is emitted when block f is received.
    66  	// The block parameter is the first block of the epoch committed phase (block f).
    67  	//
    68  	// |<-- Epoch N ------------------------------------------------->|
    69  	// |<-- StakingPhase -->|<-- SetupPhase -->|<-- CommittedPhase -->|
    70  	//                                       ^--- block D - this block's execution result contains an EpochCommit event
    71  	//                                         ^--- block e - contains seal for block D
    72  	//                                            ^--- block f - contains qc for block e, first block of Committed phase
    73  	//                                              ^--- block g - finalizes block f, triggers EpochCommittedPhaseStarted event
    74  	///
    75  	//
    76  	// NOTE: Only called once the phase transition has been finalized.
    77  	EpochCommittedPhaseStarted(currentEpochCounter uint64, first *flow.Header)
    78  }