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

     1  package inmem
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  	"github.com/onflow/flow-go/state/protocol"
     6  )
     7  
     8  // DynamicProtocolStateAdapter implements protocol.DynamicProtocolState by wrapping an InitialProtocolStateAdapter.
     9  type DynamicProtocolStateAdapter struct {
    10  	InitialProtocolStateAdapter
    11  	params protocol.GlobalParams
    12  }
    13  
    14  var _ protocol.DynamicProtocolState = (*DynamicProtocolStateAdapter)(nil)
    15  
    16  func NewDynamicProtocolStateAdapter(entry *flow.RichProtocolStateEntry, params protocol.GlobalParams) *DynamicProtocolStateAdapter {
    17  	return &DynamicProtocolStateAdapter{
    18  		InitialProtocolStateAdapter: InitialProtocolStateAdapter{
    19  			RichProtocolStateEntry: entry,
    20  		},
    21  		params: params,
    22  	}
    23  }
    24  
    25  func (s *DynamicProtocolStateAdapter) Identities() flow.IdentityList {
    26  	return s.RichProtocolStateEntry.CurrentEpochIdentityTable
    27  }
    28  
    29  func (s *DynamicProtocolStateAdapter) GlobalParams() protocol.GlobalParams {
    30  	return s.params
    31  }
    32  
    33  // InvalidEpochTransitionAttempted denotes whether an invalid epoch state transition was attempted
    34  // on the fork ending this block. Once the first block where this flag is true is finalized, epoch
    35  // fallback mode is triggered.
    36  // TODO for 'leaving Epoch Fallback via special service event': at the moment, this is a one-way transition and requires a spork to recover - need to revisit for sporkless EFM recovery
    37  func (s *DynamicProtocolStateAdapter) InvalidEpochTransitionAttempted() bool {
    38  	return s.ProtocolStateEntry.InvalidEpochTransitionAttempted
    39  }
    40  
    41  // PreviousEpochExists returns true if a previous epoch exists. This is true for all epoch
    42  // except those immediately following a spork.
    43  func (s *DynamicProtocolStateAdapter) PreviousEpochExists() bool {
    44  	return s.PreviousEpoch != nil
    45  }
    46  
    47  // EpochPhase returns the epoch phase for the current epoch.
    48  func (s *DynamicProtocolStateAdapter) EpochPhase() flow.EpochPhase {
    49  	return s.Entry().EpochPhase()
    50  }