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

     1  // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
     2  
     3  package protocol
     4  
     5  import (
     6  	"github.com/koko1123/flow-go-1/model/flow"
     7  )
     8  
     9  // Snapshot represents an immutable snapshot of the protocol state
    10  // at a specific block, denoted as the Head block.
    11  // The Snapshot is fork-specific and only accounts for the information contained
    12  // in blocks along this fork up to (including) Head.
    13  // It allows us to read the parameters at the selected block in a deterministic manner.
    14  //
    15  // TODO Epoch / Snapshot API Structure:  Currently Epoch and Snapshot APIs
    16  // are structured to allow chained queries to be used without error checking
    17  // at each call where errors might occur. Instead, errors are cached in the
    18  // resulting struct (eg. invalid.Epoch) until the query chain ends with a
    19  // function which can return an error. This has some negative effects:
    20  //  1. Cached intermediary errors result in more complex error handling
    21  //     a) each final call of the chained query needs to handle all intermediary errors, every time
    22  //     b) intermediary errors must be handled by dependencies on the final call of the query chain (eg. conversion functions)
    23  //  2. The error caching pattern encourages potentially dangerous snapshot query patterns
    24  //
    25  // See https://github.com/dapperlabs/flow-go/issues/6368 for details and proposal
    26  //
    27  // TODO document error returns
    28  type Snapshot interface {
    29  
    30  	// Head returns the latest block at the selected point of the protocol state
    31  	// history. It can represent either a finalized or ambiguous block,
    32  	// depending on our selection criteria. Either way, it's the block on which
    33  	// we should build the next block in the context of the selected state.
    34  	// TODO document error returns
    35  	Head() (*flow.Header, error)
    36  
    37  	// QuorumCertificate returns a valid quorum certificate for the header at
    38  	// this snapshot, if one exists.
    39  	// TODO document error returns
    40  	QuorumCertificate() (*flow.QuorumCertificate, error)
    41  
    42  	// Identities returns a list of identities at the selected point of the
    43  	// protocol state history. At the beginning of an epoch, this list includes
    44  	// identities from the previous epoch that are un-staking during the current
    45  	// epoch. At the end of an epoch, this includes identities scheduled to join
    46  	// in the next epoch but are not active yet.
    47  	//
    48  	// Identities are guaranteed to be returned in canonical order (order.Canonical).
    49  	//
    50  	// It allows us to provide optional upfront filters which can be used by the
    51  	// implementation to speed up database lookups.
    52  	// TODO document error returns
    53  	Identities(selector flow.IdentityFilter) (flow.IdentityList, error)
    54  
    55  	// Identity attempts to retrieve the node with the given identifier at the
    56  	// selected point of the protocol state history. It will error if it doesn't exist.
    57  	// TODO document error returns
    58  	Identity(nodeID flow.Identifier) (*flow.Identity, error)
    59  
    60  	// SealedResult returns the most recent included seal as of this block and
    61  	// the corresponding execution result. The seal may have been included in a
    62  	// parent block, if this block is empty. If this block contains multiple
    63  	// seals, this returns the seal for the block with the greatest height.
    64  	// TODO document error returns
    65  	SealedResult() (*flow.ExecutionResult, *flow.Seal, error)
    66  
    67  	// Commit returns the state commitment of the most recently included seal
    68  	// as of this block. It represents the sealed state.
    69  	// TODO document error returns
    70  	Commit() (flow.StateCommitment, error)
    71  
    72  	// SealingSegment returns the chain segment such that the highest block
    73  	// is this snapshot's reference block and the lowest block
    74  	// is the most recently sealed block as of this snapshot (ie. the block
    75  	// referenced by LatestSeal). The segment is in ascending height order.
    76  	//
    77  	// TAIL <- B1 <- ... <- BN <- HEAD
    78  	//
    79  	// NOTE 1: TAIL is not always sealed by HEAD. In the case that the head of
    80  	// the snapshot contains no seals, TAIL must be sealed by the first ancestor
    81  	// of HEAD which contains any seal.
    82  	//
    83  	// NOTE 2: In the special case of a root snapshot generated for a spork,
    84  	// the sealing segment has exactly one block (the root block for the spork).
    85  	// For all other snapshots, the sealing segment contains at least 2 blocks.
    86  	//
    87  	// NOTE 3: It is often the case that a block inside the segment will contain
    88  	// an execution receipt in it's payload that references an execution result
    89  	// missing from the payload. These missing execution results are stored on the
    90  	// flow.SealingSegment.ExecutionResults field.
    91  	// TODO document error returns
    92  	SealingSegment() (*flow.SealingSegment, error)
    93  
    94  	// Descendants returns the IDs of all descendants of the Head block. The IDs
    95  	// are ordered such that parents are included before their children. These
    96  	// are NOT guaranteed to have been validated by HotStuff.
    97  	// TODO document error returns
    98  	Descendants() ([]flow.Identifier, error)
    99  
   100  	// ValidDescendants returns the IDs of all descendants of the Head block.
   101  	// The IDs are ordered such that parents are included before their children. Includes
   102  	// only blocks that have been validated by HotStuff.
   103  	// TODO document error returns
   104  	ValidDescendants() ([]flow.Identifier, error)
   105  
   106  	// RandomSource returns the source of randomness derived from the
   107  	// Head block.
   108  	// NOTE: not to be confused with the epoch source of randomness!
   109  	// error returns:
   110  	//  * NoValidChildBlockError indicates that no valid child block is known
   111  	//    (which contains the block's source of randomness)
   112  	//  * unexpected errors should be considered symptoms of internal bugs
   113  	// TODO document error returns
   114  	RandomSource() ([]byte, error)
   115  
   116  	// Phase returns the epoch phase for the current epoch, as of the Head block.
   117  	// TODO document error returns
   118  	Phase() (flow.EpochPhase, error)
   119  
   120  	// Epochs returns a query object enabling querying detailed information about
   121  	// various epochs.
   122  	//
   123  	// For epochs that are in the future w.r.t. the Head block, some of Epoch's
   124  	// methods may return errors, since the Epoch Preparation Protocol may be
   125  	// in-progress and incomplete for the epoch.
   126  	Epochs() EpochQuery
   127  
   128  	// Params returns global parameters of the state this snapshot is taken from.
   129  	Params() GlobalParams
   130  }