-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3624 from filecoin-project/blocksync-refactor
blocksync: introduce interfaces; rename to ChainExchange (abbrev. chainxchg)
- Loading branch information
Showing
15 changed files
with
217 additions
and
185 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Package exchange contains the ChainExchange server and client components. | ||
// | ||
// ChainExchange is the basic chain synchronization protocol of Filecoin. | ||
// ChainExchange is an RPC-oriented protocol, with a single operation to | ||
// request blocks for now. | ||
// | ||
// A request contains a start anchor block (referred to with a CID), and a | ||
// amount of blocks requested beyond the anchor (including the anchor itself). | ||
// | ||
// A client can also pass options, encoded as a 64-bit bitfield. Lotus supports | ||
// two options at the moment: | ||
// | ||
// - include block contents | ||
// - include block messages | ||
// | ||
// The response will include a status code, an optional message, and the | ||
// response payload in case of success. The payload is a slice of serialized | ||
// tipsets. | ||
package exchange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package exchange | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/libp2p/go-libp2p-core/network" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
|
||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
// Server is the responder side of the ChainExchange protocol. It accepts | ||
// requests from clients and services them by returning the requested | ||
// chain data. | ||
type Server interface { | ||
// HandleStream is the protocol handler to be registered on a libp2p | ||
// protocol router. | ||
// | ||
// In the current version of the protocol, streams are single-use. The | ||
// server will read a single Request, and will respond with a single | ||
// Response. It will dispose of the stream straight after. | ||
HandleStream(stream network.Stream) | ||
} | ||
|
||
// Client is the requesting side of the ChainExchange protocol. It acts as | ||
// a proxy for other components to request chain data from peers. It is chiefly | ||
// used by the Syncer. | ||
type Client interface { | ||
// GetBlocks fetches block headers from the network, from the provided | ||
// tipset *backwards*, returning as many tipsets as the count parameter, | ||
// or less. | ||
GetBlocks(ctx context.Context, tsk types.TipSetKey, count int) ([]*types.TipSet, error) | ||
|
||
// GetChainMessages fetches messages from the network, from the provided | ||
// tipset *backwards*, returning the messages from as many tipsets as the | ||
// count parameter, or less. | ||
GetChainMessages(ctx context.Context, head *types.TipSet, length uint64) ([]*CompactedMessages, error) | ||
|
||
// GetFullTipSet fetches a full tipset from a given peer. If successful, | ||
// the fetched object contains block headers and all messages in full form. | ||
GetFullTipSet(ctx context.Context, peer peer.ID, tsk types.TipSetKey) (*store.FullTipSet, error) | ||
|
||
// AddPeer adds a peer to the pool of peers that the Client requests | ||
// data from. | ||
AddPeer(peer peer.ID) | ||
|
||
// RemovePeer removes a peer from the pool of peers that the Client | ||
// requests data from. | ||
RemovePeer(peer peer.ID) | ||
} |
Oops, something went wrong.