Documentation ¶
Index ¶
- Constants
- func RegisterTxService(pool PendingTxAggregate, registrar Registrar, genesisID string, txPoolSize int, ...)
- type ComposedFetcher
- type EncodedBlockCert
- type Fetcher
- type FetcherClient
- type FetcherFactory
- type HTTPFetcher
- type HTTPTxSync
- type LedgerService
- type NetworkFetcher
- func (networkFetcher *NetworkFetcher) Close()
- func (networkFetcher *NetworkFetcher) FetchBlock(ctx context.Context, r basics.Round) (blk *bookkeeping.Block, cert *agreement.Certificate, rpcc FetcherClient, ...)
- func (networkFetcher *NetworkFetcher) NumPeers() int
- func (networkFetcher *NetworkFetcher) OutOfPeers(round basics.Round) bool
- type NetworkFetcherFactory
- type PeerSource
- type PendingTxAggregate
- type PreEncodedBlockCert
- type Registrar
- type TxService
- type TxSyncClient
- type TxSyncer
- type WsFetcher
- type WsFetcherService
- type WsGetBlockOut
- type WsGetBlockRequest
Constants ¶
const DefaultFetchTimeout = 20 * time.Second // TODO this should be in config
DefaultFetchTimeout is the default time a fetcher should wait for a block
const LedgerServiceBlockPath = "/v{version:[0-9.]+}/{genesisID}/block/{round:[0-9a-z]+}"
LedgerServiceBlockPath is the path to register LedgerService as a handler for when using gorilla/mux e.g. .Handle(LedgerServiceBlockPath, &ls)
const TxServiceHTTPPath = "/v1/{genesisID}/txsync"
TxServiceHTTPPath is the URL path to sync pending transactions from
Variables ¶
This section is empty.
Functions ¶
func RegisterTxService ¶
func RegisterTxService(pool PendingTxAggregate, registrar Registrar, genesisID string, txPoolSize int, responseSizeLimit int)
RegisterTxService creates a TxService around the provider transaction pool and registers it for RPC with the provided Registrar
Types ¶
type ComposedFetcher ¶
type ComposedFetcher struct {
// contains filtered or unexported fields
}
ComposedFetcher wraps multiple fetchers in some priority order
func (*ComposedFetcher) FetchBlock ¶
func (cf *ComposedFetcher) FetchBlock(ctx context.Context, r basics.Round) (blk *bookkeeping.Block, cert *agreement.Certificate, rpcc FetcherClient, err error)
FetchBlock implements Fetcher.FetchBlock
func (*ComposedFetcher) NumPeers ¶
func (cf *ComposedFetcher) NumPeers() int
NumPeers implements Fetcher.NumPeers
func (*ComposedFetcher) OutOfPeers ¶
func (cf *ComposedFetcher) OutOfPeers(round basics.Round) bool
OutOfPeers implements Fetcher.OutOfPeers
type EncodedBlockCert ¶
type EncodedBlockCert struct { Block bookkeeping.Block `codec:"block"` Certificate agreement.Certificate `codec:"cert"` }
EncodedBlockCert defines how GetBlockBytes encodes a block and its certificate
type Fetcher ¶
type Fetcher interface { // FetchBlock fetches a block for a given round. FetchBlock(ctx context.Context, r basics.Round) (*bookkeeping.Block, *agreement.Certificate, FetcherClient, error) // Whether the fetcher has anyone available to ask for the block associated with round OutOfPeers(round basics.Round) bool // NumPeers return the number of peers that this fetcher has available NumPeers() int // Close cleans up this fetcher Close() }
Fetcher queries the current block of the network, and fetches agreed-upon blocks
func MakeWsFetcher ¶
func MakeWsFetcher(log logging.Logger, tag protocol.Tag, peers []network.Peer, service *WsFetcherService) Fetcher
MakeWsFetcher creates a fetcher that fetches over the gossip network. It instantiates a NetworkFetcher under the hood, registers as a handler for the given message tag, and demuxes messages appropriately to the corresponding fetcher clients.
type FetcherClient ¶
type FetcherClient interface { GetBlockBytes(ctx context.Context, r basics.Round) (data []byte, err error) Address() string Close() error }
FetcherClient abstracts how to GetBlockBytes from a node on the net.
func MakeHTTPFetcher ¶
func MakeHTTPFetcher(log logging.Logger, peer network.HTTPPeer) (fc FetcherClient)
MakeHTTPFetcher wraps an HTTPPeer so that we can get blocks from it
type FetcherFactory ¶
type FetcherFactory interface { // Create a new fetcher New() Fetcher // Create a new fetcher that also fetches from backup peers over gossip network utilising given message tag NewOverGossip(requestTag protocol.Tag) Fetcher }
FetcherFactory creates fetchers
type HTTPFetcher ¶
type HTTPFetcher struct {
// contains filtered or unexported fields
}
HTTPFetcher implements FetcherClient doing an HTTP GET of the block
func (*HTTPFetcher) Address ¶
func (hf *HTTPFetcher) Address() string
Address is part of FetcherClient interface. Returns the root URL of the connected peer.
func (*HTTPFetcher) Close ¶
func (hf *HTTPFetcher) Close() error
Close is part of FetcherClient interface
Does nothing, leaves underlying client open because other HTTP requests from other interfaces could be open on it. Somewhere a Peer owns that connection and will close as needed.
func (*HTTPFetcher) GetBlockBytes ¶
GetBlockBytes gets a block. Core piece of FetcherClient interface
type HTTPTxSync ¶
type HTTPTxSync struct {
// contains filtered or unexported fields
}
HTTPTxSync implements the TxSyncClient interface over HTTP
func (*HTTPTxSync) Address ¶
func (hts *HTTPTxSync) Address() string
Address is part of TxSyncClient interface. Returns the root URL of the connected peer.
func (*HTTPTxSync) Close ¶
func (hts *HTTPTxSync) Close() error
Close is part of TxSyncClient interface
Does nothing, leaves underlying client open because other HTTP requests from other interfaces could be open on it. Somewhere a Peer owns that connection and will close as needed.
func (*HTTPTxSync) Sync ¶
func (hts *HTTPTxSync) Sync(ctx context.Context, bloom *bloom.Filter) (txgroups [][]transactions.SignedTxn, err error)
Sync gets pending transactions from a random peer. Part of TxSyncClient interface.
type LedgerService ¶
type LedgerService struct {
// contains filtered or unexported fields
}
LedgerService represents the Ledger RPC API
func RegisterLedgerService ¶
func RegisterLedgerService(config config.Local, ledger *data.Ledger, registrar Registrar, genesisID string) *LedgerService
RegisterLedgerService creates a LedgerService around the provider Ledger and registers it for RPC with the provided Registrar
func (*LedgerService) ListenForCatchupReq ¶
func (ls *LedgerService) ListenForCatchupReq(reqs <-chan network.IncomingMessage, stop chan struct{})
ListenForCatchupReq handles catchup getblock request
func (*LedgerService) ServeHTTP ¶
func (ls *LedgerService) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServerHTTP returns blocks Either /v{version}/block/{round} or ?b={round}&v={version} Uses gorilla/mux for path argument parsing.
func (*LedgerService) Start ¶
func (ls *LedgerService) Start()
Start listening to catchup requests over ws
func (*LedgerService) Stop ¶
func (ls *LedgerService) Stop()
Stop servicing catchup requests over ws
type NetworkFetcher ¶
type NetworkFetcher struct {
// contains filtered or unexported fields
}
NetworkFetcher fetches data from remote RPC clients
func (*NetworkFetcher) Close ¶
func (networkFetcher *NetworkFetcher) Close()
Close implements Fetcher. Nothing to clean up here.
func (*NetworkFetcher) FetchBlock ¶
func (networkFetcher *NetworkFetcher) FetchBlock(ctx context.Context, r basics.Round) (blk *bookkeeping.Block, cert *agreement.Certificate, rpcc FetcherClient, err error)
FetchBlock returns a block for round r
func (*NetworkFetcher) NumPeers ¶
func (networkFetcher *NetworkFetcher) NumPeers() int
NumPeers return the number of peers that this fetcher has available
func (*NetworkFetcher) OutOfPeers ¶
func (networkFetcher *NetworkFetcher) OutOfPeers(round basics.Round) bool
OutOfPeers returns whether there are any peers that may have the block of a particular round
type NetworkFetcherFactory ¶
type NetworkFetcherFactory struct {
// contains filtered or unexported fields
}
NetworkFetcherFactory creates network fetchers
func MakeNetworkFetcherFactory ¶
func MakeNetworkFetcherFactory(net PeerSource, peerLimit int, fs *WsFetcherService) NetworkFetcherFactory
MakeNetworkFetcherFactory returns a network fetcher factory, that associates fetchers with no more than peerLimit peers from the aggregator. WSClientSource can be nil, if no network exists to create clients from (defaults to http clients)
func (NetworkFetcherFactory) BuildFetcherClients ¶
func (factory NetworkFetcherFactory) BuildFetcherClients() []FetcherClient
BuildFetcherClients returns a set of clients we can fetch blocks from
func (NetworkFetcherFactory) New ¶
func (factory NetworkFetcherFactory) New() Fetcher
New returns a new fetcher
func (NetworkFetcherFactory) NewOverGossip ¶
func (factory NetworkFetcherFactory) NewOverGossip(tag protocol.Tag) Fetcher
NewOverGossip returns a gossip fetcher using the given message tag. We should never build two fetchers utilising the same tag. Why?
type PeerSource ¶
type PeerSource interface {
GetPeers(options ...network.PeerOption) []network.Peer
}
PeerSource is a subset of network.GossipNode
type PendingTxAggregate ¶
type PendingTxAggregate interface { PendingTxIDs() []transactions.Txid Pending() [][]transactions.SignedTxn }
PendingTxAggregate is a container of pending transactions
type PreEncodedBlockCert ¶
type PreEncodedBlockCert struct { Block codec.Raw `codec:"block"` Certificate codec.Raw `codec:"cert"` }
PreEncodedBlockCert defines how GetBlockBytes encodes a block and its certificate, using a pre-encoded Block and Certificate in msgpack format.
type Registrar ¶
type Registrar interface { // RegisterHTTPHandler path accepts gorilla/mux path annotations RegisterHTTPHandler(path string, handler http.Handler) // RegisterHandlers exposes global websocket handler registration RegisterHandlers(dispatch []network.TaggedMessageHandler) }
Registrar is subset of network.GossipNode
type TxService ¶
type TxService struct {
// contains filtered or unexported fields
}
TxService provides a service that allows a remote caller to retrieve missing pending transactions
type TxSyncClient ¶
type TxSyncClient interface { Sync(ctx context.Context, bloom *bloom.Filter) (txns [][]transactions.SignedTxn, err error) Address() string Close() error }
TxSyncClient abstracts sync-ing pending transactions from a peer.
type TxSyncer ¶
type TxSyncer struct {
// contains filtered or unexported fields
}
TxSyncer fetches pending transactions that are missing from its pool, and feeds them to the handler
func MakeTxSyncer ¶
func MakeTxSyncer(pool PendingTxAggregate, clientSource PeerSource, txHandler data.SolicitedTxHandler, syncInterval time.Duration, syncTimeout time.Duration, serverResponseSize int) *TxSyncer
MakeTxSyncer returns a TxSyncer
type WsFetcher ¶
type WsFetcher struct {
// contains filtered or unexported fields
}
WsFetcher implements Fetcher, getting the block over a custom websockets interface (bidirectional). Internally it keeps track of multiple peers and handles dropping them appropriately using a NetworkFetcher.
func (*WsFetcher) Close ¶
func (wsf *WsFetcher) Close()
Close calls a delegate close fn passed in by the parent of this fetcher
func (*WsFetcher) FetchBlock ¶
func (wsf *WsFetcher) FetchBlock(ctx context.Context, r basics.Round) (*bookkeeping.Block, *agreement.Certificate, FetcherClient, error)
FetchBlock implements Fetcher interface
type WsFetcherService ¶
type WsFetcherService struct {
// contains filtered or unexported fields
}
WsFetcherService exists for the express purpose or providing a global handler for fetcher gossip message response types
func RegisterWsFetcherService ¶
func RegisterWsFetcherService(log logging.Logger, registrar Registrar) *WsFetcherService
RegisterWsFetcherService creates and returns a WsFetcherService that services gossip fetcher responses
func (*WsFetcherService) RequestBlock ¶
func (fs *WsFetcherService) RequestBlock(ctx context.Context, target network.UnicastPeer, round basics.Round, tag protocol.Tag) (WsGetBlockOut, error)
RequestBlock send a request for block <round> and wait until it receives a response or a context expires.
type WsGetBlockOut ¶
WsGetBlockOut is a msgpack message delivered on responding to a block (not rpc-based though)
type WsGetBlockRequest ¶
type WsGetBlockRequest struct {
Round uint64 `json:"round"`
}
WsGetBlockRequest is a msgpack message requesting a block