mirror of
https://github.com/ChainSafe/lodestar.git
synced 2026-05-02 03:01:08 -04:00
**Motivation** - per spec, we should not issue more than 2 requests per protocol per peer https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/p2p-interface.md#constants - we should be able to self detect that and see `REQUEST_ERROR_RATE_LIMITED` instead of sending requests to peer and get `RESPONSE_ERROR_RATE_LIMITED` **Description** - Implement SelfRateLimiter - before sending out a request, call `selfRateLimiter.allows()` - after finishing a request, call `selfRateLimiter.requestCompleted()` - check for disconnected peers automatically, similar to `RateLimiterGRCA` - RangeSync already manage active requests and prevent that from happening, see #8166 - UnknownBlockSync needs to implement the same thing, tracked in #8182 part of #8033 --------- Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
Lodestar Eth Consensus Req/Resp Protocol
This package is part of ChainSafe's Lodestar project
Typescript implementation of the Ethereum Consensus Req/Resp protocol
Usage
import {Libp2p} from "libp2p";
import {ssz} from "@lodestar/types";
import {ReqResp, ContextBytesType, Protocol, Encoding} from "@lodestar/reqresp";
import {ForkName, GENESIS_EPOCH} from "@lodestar/params";
import {Logger} from "@lodestar/utils";
async function getReqResp(libp2p: Libp2p, logger: Logger): Promise<void> {
const reqResp = new ReqResp({libp2p, logger, metricsRegister: null});
// Register a PONG handler to respond with caller's Ping request
const pingProtocol: Protocol = {
method: "ping",
version: 1,
encoding: Encoding.SSZ_SNAPPY,
contextBytes: {type: ContextBytesType.Empty},
requestSizes: ssz.phase0.Ping,
responseSizes: () => ssz.phase0.Ping,
handler: async function* (req) {
yield {
data: req.data,
boundary: {fork: ForkName.phase0, epoch: GENESIS_EPOCH},
};
},
};
reqResp.registerProtocol(pingProtocol);
}
Prerequisites
What you need
You will need to go over the specification.
Getting started
- Follow the installation guide to install Lodestar.
- Quickly try out the whole stack by starting a local testnet.
Contributors
Read our contributors document, submit an issue or talk to us on our discord!
License
Apache-2.0 ChainSafe Systems