The warp sync request handler will respond request that arrives from the sync/warp protocol. The handler has as one dependency the WarpSyncProvider which is an interface that generates the proofs.
type WarpSyncProvider interface {
// Generate proof starting at given block hash. The proof is accumulated until maximum proof
// size is reached.
generate(startHeader: *types.Header) (encodedProof []byte, err error)
// Get current list of authorities. This is supposed to be genesis authorities when starting sync.
current_authorities() []types.Authorities
}
The Warp Proof Request is a SCALE codec structure send through the wire.
Here's a impl suggestion based on substrate
type OutgoingResponse struct {
payload []byte
}
type Request struct {
peer peer.ID
payload []byte
pendingResponse chan OutgoingResponse
}
type WarpSyncRequestHandler struct {
backend WarpSyncProvider
// receive is a channel where the requests acquired in the network
// layer reaches the handler
receiver chan Request
}
func (w *WarpSyncRequestHandler) handleRequest(payload []byte, pendingResponse chan OutgoingResponse) error {
// unmarshal the payload
// use the backend to generate the warp proof
// send the response through pendingResponse channel
}
func (w *WarpSyncRequestHandler) Run() {
for request := w.receiver {
err := w.handleRequest(request.payload, request.pendingResponse)
...
}
}
Acceptance Criteria
[ ] Create the p2p protocol using the template /{genesis_hash}/sync/warp
[ ] Handling messages that arrives from the network
[ ] Creating tests mocking the WarpSyncProvider (backend)
Description
The warp sync request handler will respond request that arrives from the
sync/warp
protocol. The handler has as one dependency theWarpSyncProvider
which is an interface that generates the proofs.The
MAX_RESPONSE_SIZE
is16 * 1024 * 1024
ref WarpSyncProvider trait
The Warp Proof Request is a SCALE codec structure send through the wire.
Here's a impl suggestion based on substrate
Acceptance Criteria
/{genesis_hash}/sync/warp