github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/state/protocol/params.go (about)

     1  package protocol
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  )
     6  
     7  // Params are parameters of the protocol state, divided into parameters of
     8  // this specific instance of the state (varies from node to node) and global
     9  // parameters of the state.
    10  type Params interface {
    11  	InstanceParams
    12  	GlobalParams
    13  }
    14  
    15  // InstanceParams represents protocol state parameters that vary between instances.
    16  // For example, two nodes both running in the same spork on Flow Mainnet may have
    17  // different instance params.
    18  type InstanceParams interface {
    19  
    20  	// FinalizedRoot returns the finalized root header of the current protocol state. This will be
    21  	// the head of the protocol state snapshot used to bootstrap this state and
    22  	// may differ from node to node for the same protocol state.
    23  	FinalizedRoot() *flow.Header
    24  
    25  	// SealedRoot returns the sealed root block. If it's different from FinalizedRoot() block,
    26  	// it means the node is bootstrapped from mid-spork.
    27  	SealedRoot() *flow.Header
    28  
    29  	// Seal returns the root block seal of the current protocol state. This is the seal for the
    30  	// `SealedRoot` block that was used to bootstrap this state. It may differ from node to node.
    31  	Seal() *flow.Seal
    32  
    33  	// EpochFallbackTriggered returns whether Epoch Fallback Mode [EFM] has been triggered.
    34  	// EFM is a permanent, spork-scoped state which is triggered when the next
    35  	// epoch fails to be committed in the allocated time. Once EFM is triggered,
    36  	// it will remain in effect until the next spork.
    37  	// TODO for 'leaving Epoch Fallback via special service event'
    38  	// No errors are expected during normal operation.
    39  	EpochFallbackTriggered() (bool, error)
    40  }
    41  
    42  // GlobalParams represents protocol state parameters that do not vary between instances.
    43  // Any nodes running in the same spork, on the same network (same chain ID) must
    44  // have the same global params.
    45  type GlobalParams interface {
    46  
    47  	// ChainID returns the chain ID for the current Flow network. The chain ID
    48  	// uniquely identifies a Flow network in perpetuity across epochs and sporks.
    49  	ChainID() flow.ChainID
    50  
    51  	// SporkID returns the unique identifier for this network within the current spork.
    52  	// This ID is determined at the beginning of a spork during bootstrapping and is
    53  	// part of the root protocol state snapshot.
    54  	SporkID() flow.Identifier
    55  
    56  	// SporkRootBlockHeight returns the height of the spork's root block.
    57  	// This value is determined at the beginning of a spork during bootstrapping.
    58  	// If node uses a sealing segment for bootstrapping then this value will be carried over
    59  	// as part of snapshot.
    60  	SporkRootBlockHeight() uint64
    61  
    62  	// ProtocolVersion returns the protocol version, the major software version
    63  	// of the protocol software.
    64  	ProtocolVersion() uint
    65  
    66  	// EpochCommitSafetyThreshold [t] defines a deadline for sealing the EpochCommit
    67  	// service event near the end of each epoch - the "epoch commitment deadline".
    68  	// Given a safety threshold t, the deadline for an epoch with final view f is:
    69  	//   Epoch Commitment Deadline: d=f-t
    70  	//
    71  	//                     Epoch Commitment Deadline
    72  	//   EPOCH N           ↓                 EPOCH N+1
    73  	//   ...---------------|---------------| |-----...
    74  	//   view:             d<·····t·······>f
    75  	//
    76  	// DEFINITION:
    77  	// This deadline is used to determine when to trigger epoch emergency fallback mode.
    78  	// Epoch Emergency Fallback mode is triggered when the EpochCommit service event
    79  	// fails to be sealed.
    80  	//
    81  	// Example: A service event is emitted in block A. The seal for A is included in C.
    82  	// A<-B(RA)<-C(SA)<-...<-R
    83  	//
    84  	// A service event S is considered sealed w.r.t. a reference block R if:
    85  	// * S was emitted during execution of some block A, s.t. A is an ancestor of R
    86  	// * The seal for block A was included in some block C, s.t C is an ancestor of R
    87  	//
    88  	// When we finalize the first block B with B.View >= d:
    89  	//  - HAPPY PATH: If an EpochCommit service event has been sealed w.r.t. B, no action is taken.
    90  	//  - FALLBACK PATH: If no EpochCommit service event has been sealed w.r.t. B,
    91  	//    Epoch Fallback Mode [EFM] is triggered.
    92  	//
    93  	// CONTEXT:
    94  	// The epoch commitment deadline exists to ensure that all nodes agree on
    95  	// whether Epoch Fallback Mode is triggered for a particular epoch, before
    96  	// the epoch actually ends. In particular, all nodes will agree about EFM
    97  	// being triggered (or not) if at least one block with view in [d, f] is
    98  	// finalized - in other words, we require at least one block being finalized
    99  	// after the epoch commitment deadline, and before the next epoch begins.
   100  	//
   101  	// It should be noted that we are employing a heuristic here, which succeeds with
   102  	// overwhelming probability of nearly 1. However, theoretically it is possible that
   103  	// no blocks are finalized within t views. In this edge case, the nodes would have not
   104  	// detected the epoch commit phase failing and the protocol would just halt at the end
   105  	// of the epoch. However, we emphasize that this is extremely unlikely, because the
   106  	// probability of randomly selecting t faulty leaders in sequence decays to zero
   107  	// exponentially with increasing t. Furthermore, failing to finalize blocks for a
   108  	// noticeable period entails halting block sealing, which would trigger human
   109  	// intervention on much smaller time scales than t views.
   110  	// Therefore, t should be chosen such that it takes more than 30mins to pass t views
   111  	// under happy path operation. Significant larger values are ok, but t views equalling
   112  	// 30 mins should be seen as a lower bound.
   113  	//
   114  	// When selecting a threshold value, ensure:
   115  	//  * The deadline is after the end of the DKG, with enough buffer between
   116  	//    the two that the EpochCommit event is overwhelmingly likely to be emitted
   117  	//    before the deadline, if it is emitted at all.
   118  	//  * The buffer between the deadline and the final view of the epoch is large
   119  	//    enough that the network is overwhelming likely to finalize at least one
   120  	//    block with a view in this range
   121  	//
   122  	EpochCommitSafetyThreshold() uint64
   123  }