github.com/onflow/flow-go@v0.33.17/engine/access/state_stream/state_stream.go (about)

     1  package state_stream
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/onflow/flow-go/model/flow"
     8  	"github.com/onflow/flow-go/module/executiondatasync/execution_data"
     9  )
    10  
    11  const (
    12  	// DefaultSendBufferSize is the default buffer size for the subscription's send channel.
    13  	// The size is chosen to balance memory overhead from each subscription with performance when
    14  	// streaming existing data.
    15  	DefaultSendBufferSize = 10
    16  
    17  	// DefaultMaxGlobalStreams defines the default max number of streams that can be open at the same time.
    18  	DefaultMaxGlobalStreams = 1000
    19  
    20  	// DefaultCacheSize defines the default max number of objects for the execution data cache.
    21  	DefaultCacheSize = 100
    22  
    23  	// DefaultSendTimeout is the default timeout for sending a message to the client. After the timeout
    24  	// expires, the connection is closed.
    25  	DefaultSendTimeout = 30 * time.Second
    26  
    27  	// DefaultResponseLimit is default max responses per second allowed on a stream. After exceeding
    28  	// the limit, the stream is paused until more capacity is available.
    29  	DefaultResponseLimit = float64(0)
    30  
    31  	// DefaultHeartbeatInterval specifies the block interval at which heartbeat messages should be sent.
    32  	DefaultHeartbeatInterval = 1
    33  
    34  	// DefaultRegisterIDsRequestLimit defines the default limit of register IDs for a single request to the get register endpoint
    35  	DefaultRegisterIDsRequestLimit = 100
    36  )
    37  
    38  // API represents an interface that defines methods for interacting with a blockchain's execution data and events.
    39  type API interface {
    40  	// GetExecutionDataByBlockID retrieves execution data for a specific block by its block ID.
    41  	GetExecutionDataByBlockID(ctx context.Context, blockID flow.Identifier) (*execution_data.BlockExecutionData, error)
    42  	// SubscribeExecutionData subscribes to execution data starting from a specific block ID and block height.
    43  	SubscribeExecutionData(ctx context.Context, startBlockID flow.Identifier, startBlockHeight uint64) Subscription
    44  	// SubscribeEvents subscribes to events starting from a specific block ID and block height, with an optional event filter.
    45  	SubscribeEvents(ctx context.Context, startBlockID flow.Identifier, startHeight uint64, filter EventFilter) Subscription
    46  	// GetRegisterValues returns register values for a set of register IDs at the provided block height.
    47  	GetRegisterValues(registerIDs flow.RegisterIDs, height uint64) ([]flow.RegisterValue, error)
    48  }
    49  
    50  // Subscription represents a streaming request, and handles the communication between the grpc handler
    51  // and the backend implementation.
    52  type Subscription interface {
    53  	// ID returns the unique identifier for this subscription used for logging
    54  	ID() string
    55  
    56  	// Channel returns the channel from which subscription data can be read
    57  	Channel() <-chan interface{}
    58  
    59  	// Err returns the error that caused the subscription to fail
    60  	Err() error
    61  }
    62  
    63  // Streamable represents a subscription that can be streamed.
    64  type Streamable interface {
    65  	ID() string
    66  	Close()
    67  	Fail(error)
    68  	Send(context.Context, interface{}, time.Duration) error
    69  	Next(context.Context) (interface{}, error)
    70  }