github.com/onflow/flow-go@v0.33.17/engine/execution/computation/query/entropy_provider.go (about)

     1  package query
     2  
     3  import (
     4  	"github.com/onflow/flow-go/fvm/environment"
     5  	"github.com/onflow/flow-go/model/flow"
     6  	"github.com/onflow/flow-go/state/protocol"
     7  )
     8  
     9  // EntropyProviderPerBlock is an abstraction for entropy providers
    10  // that can be used in `QueryExecutor`.
    11  //
    12  // `EntropyProvider` is defined in `fvm/environment` and abstracts the
    13  // distributed random source used by the protocol.
    14  //
    15  // For a full-protocol node implementation , `EntropyProvider` is implemented
    16  // by the protocol `Snapshot`, while `EntropyProviderPerBlock` is implemented
    17  // by the protocol `State`.
    18  // For nodes answering script queries that do not participate in the protocol,
    19  // `EntropyProvider` and `EntropyProviderPerBlock` can be implemented by other
    20  // components that provide the source of randomness for each block.
    21  type EntropyProviderPerBlock interface {
    22  	// AtBlockID returns an entropy provider at the given block ID.
    23  	AtBlockID(blockID flow.Identifier) environment.EntropyProvider
    24  }
    25  
    26  // protocolStateWrapper implements `EntropyProviderPerBlock`
    27  var _ EntropyProviderPerBlock = protocolStateWrapper{}
    28  
    29  type protocolStateWrapper struct {
    30  	protocol.State
    31  }
    32  
    33  // NewProtocolStateWrapper wraps a protocol.State input as an `EntropyProviderPerBlock`
    34  func NewProtocolStateWrapper(s protocol.State) EntropyProviderPerBlock {
    35  	return protocolStateWrapper{s}
    36  }
    37  
    38  func (p protocolStateWrapper) AtBlockID(blockID flow.Identifier) environment.EntropyProvider {
    39  	return environment.EntropyProvider(p.State.AtBlockID(blockID))
    40  }