-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blocksync: introduce interfaces; rename to ChainExchange (abbrev. chainxchg) #3624
Changes from all commits
55b1456
453e826
878ffaf
b33db9c
cb3b0ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - descending? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
// 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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "backwards" mean here? Decending in height?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!