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

     1  package invalid
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/koko1123/flow-go-1/model/flow"
     8  	"github.com/koko1123/flow-go-1/state"
     9  	"github.com/koko1123/flow-go-1/state/protocol"
    10  )
    11  
    12  // Snapshot represents a snapshot that does not exist or could not be queried.
    13  type Snapshot struct {
    14  	err error
    15  }
    16  
    17  // NewSnapshot returns a new invalid snapshot, containing an error describing why the
    18  // snapshot could not be retrieved. The following are expected
    19  // errors when constructing an invalid Snapshot:
    20  //   - state.ErrUnknownSnapshotReference if the reference point for the snapshot
    21  //     (height or block ID) does not resolve to a queriable block in the state.
    22  //   - generic error in case of unexpected critical internal corruption or bugs
    23  func NewSnapshot(err error) *Snapshot {
    24  	if errors.Is(err, state.ErrUnknownSnapshotReference) {
    25  		return &Snapshot{err: err}
    26  	}
    27  	return &Snapshot{fmt.Errorf("critical unexpected error querying snapshot: %w", err)}
    28  }
    29  
    30  // NewSnapshotf is NewSnapshot with ergonomic error formatting.
    31  func NewSnapshotf(msg string, args ...interface{}) *Snapshot {
    32  	return NewSnapshot(fmt.Errorf(msg, args...))
    33  }
    34  
    35  func (u *Snapshot) Head() (*flow.Header, error) {
    36  	return nil, u.err
    37  }
    38  
    39  func (u *Snapshot) QuorumCertificate() (*flow.QuorumCertificate, error) {
    40  	return nil, u.err
    41  }
    42  
    43  func (u *Snapshot) Phase() (flow.EpochPhase, error) {
    44  	return 0, u.err
    45  }
    46  
    47  func (u *Snapshot) Identities(_ flow.IdentityFilter) (flow.IdentityList, error) {
    48  	return nil, u.err
    49  }
    50  
    51  func (u *Snapshot) Identity(_ flow.Identifier) (*flow.Identity, error) {
    52  	return nil, u.err
    53  }
    54  
    55  func (u *Snapshot) Commit() (flow.StateCommitment, error) {
    56  	return flow.DummyStateCommitment, u.err
    57  }
    58  
    59  func (u *Snapshot) SealedResult() (*flow.ExecutionResult, *flow.Seal, error) {
    60  	return nil, nil, u.err
    61  }
    62  
    63  func (u *Snapshot) SealingSegment() (*flow.SealingSegment, error) {
    64  	return nil, u.err
    65  }
    66  
    67  func (u *Snapshot) Descendants() ([]flow.Identifier, error) {
    68  	return nil, u.err
    69  }
    70  
    71  func (u *Snapshot) ValidDescendants() ([]flow.Identifier, error) {
    72  	return nil, u.err
    73  }
    74  
    75  func (u *Snapshot) RandomSource() ([]byte, error) {
    76  	return nil, u.err
    77  }
    78  
    79  func (u *Snapshot) Params() protocol.GlobalParams {
    80  	return &Params{u.err}
    81  }