Add a config option to set gossipub direct peers (#414)

* Add support for setting gossipsub direct peers

* Use string array for direct peers config

* Handle empty nitro and consensus config

* Increase consensus write retry attempts

* Rename config option for watcher party peers file

* Handle directPeers array being passed undefined

* Upgrade package versions

---------

Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
This commit is contained in:
prathamesh0 2023-09-22 13:46:20 +05:30 committed by GitHub
parent 48e7785367
commit 32c78a907c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 65 additions and 48 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ out/
.vscode
.idea
yarn-error.log

View File

@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.2.59",
"version": "0.2.60",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/cache",
"version": "0.2.59",
"version": "0.2.60",
"description": "Generic object cache",
"main": "dist/index.js",
"scripts": {

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/cli",
"version": "0.2.59",
"version": "0.2.60",
"main": "dist/index.js",
"license": "AGPL-3.0",
"scripts": {
@ -12,13 +12,13 @@
},
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.59",
"@cerc-io/ipld-eth-client": "^0.2.59",
"@cerc-io/cache": "^0.2.60",
"@cerc-io/ipld-eth-client": "^0.2.60",
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
"@cerc-io/nitro-node": "^0.1.11",
"@cerc-io/peer": "^0.2.59",
"@cerc-io/rpc-eth-client": "^0.2.59",
"@cerc-io/util": "^0.2.59",
"@cerc-io/peer": "^0.2.60",
"@cerc-io/rpc-eth-client": "^0.2.60",
"@cerc-io/util": "^0.2.60",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/utils": "^9.1.1",
"@ipld/dag-cbor": "^8.0.0",

View File

@ -192,6 +192,7 @@ export class ServerCmd {
maxConnections: peerConfig.maxConnections,
dialTimeout: peerConfig.dialTimeout,
pubsub: peerConfig.pubsub,
directPeers: peerConfig.directPeers,
enableDebugInfo: peerConfig.enableDebugInfo
};
await this._peer.init(peerNodeInit, peerIdObj);
@ -204,6 +205,10 @@ export class ServerCmd {
async initConsensus (): Promise<Consensus | undefined> {
const p2pConfig = this._baseCmd.config.server.p2p;
if (!p2pConfig || !p2pConfig.consensus) {
return;
}
const { consensus: consensusConfig } = p2pConfig;
// Setup consensus engine if enabled
@ -213,14 +218,14 @@ export class ServerCmd {
}
assert(this.peer);
const watcherPartyPeers = readParty(consensusConfig.watcherPartyFile);
const watcherPartyPeers = readParty(consensusConfig.watcherPartyPeersFile);
// Create and initialize the consensus engine
this._consensus = new Consensus({
peer: this.peer,
publicKey: consensusConfig.publicKey,
privateKey: consensusConfig.privateKey,
party: watcherPartyPeers
partyPeers: watcherPartyPeers
});
// Connect registers the required p2p protocol handlers and starts the engine
@ -247,7 +252,7 @@ export class ServerCmd {
} = this._baseCmd.config;
// Nitro requires p2p peer to be enabled
if (!enablePeer) {
if (!enablePeer || !nitroConfig) {
return;
}

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/codegen",
"version": "0.2.59",
"version": "0.2.60",
"description": "Code generator",
"private": true,
"main": "index.js",
@ -20,7 +20,7 @@
},
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@cerc-io/util": "^0.2.59",
"@cerc-io/util": "^0.2.60",
"@graphql-tools/load-files": "^6.5.2",
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
"@solidity-parser/parser": "^0.13.2",

View File

@ -41,12 +41,12 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.59",
"@cerc-io/ipld-eth-client": "^0.2.59",
"@cerc-io/solidity-mapper": "^0.2.59",
"@cerc-io/util": "^0.2.59",
"@cerc-io/cli": "^0.2.60",
"@cerc-io/ipld-eth-client": "^0.2.60",
"@cerc-io/solidity-mapper": "^0.2.60",
"@cerc-io/util": "^0.2.60",
{{#if (subgraphPath)}}
"@cerc-io/graph-node": "^0.2.59",
"@cerc-io/graph-node": "^0.2.60",
{{/if}}
"@ethersproject/providers": "^5.4.4",
"apollo-type-bigint": "^0.1.3",

View File

@ -1,10 +1,10 @@
{
"name": "@cerc-io/graph-node",
"version": "0.2.59",
"version": "0.2.60",
"main": "dist/index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@cerc-io/solidity-mapper": "^0.2.59",
"@cerc-io/solidity-mapper": "^0.2.60",
"@ethersproject/providers": "^5.4.4",
"@graphprotocol/graph-ts": "^0.22.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
@ -51,9 +51,9 @@
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2",
"@cerc-io/cache": "^0.2.59",
"@cerc-io/ipld-eth-client": "^0.2.59",
"@cerc-io/util": "^0.2.59",
"@cerc-io/cache": "^0.2.60",
"@cerc-io/ipld-eth-client": "^0.2.60",
"@cerc-io/util": "^0.2.60",
"@types/json-diff": "^0.5.2",
"@types/yargs": "^17.0.0",
"bn.js": "^4.11.9",

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/ipld-eth-client",
"version": "0.2.59",
"version": "0.2.60",
"description": "IPLD ETH Client",
"main": "dist/index.js",
"scripts": {
@ -20,7 +20,7 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.59",
"@cerc-io/cache": "^0.2.60",
"cross-fetch": "^3.1.4",
"debug": "^4.3.1",
"ethers": "^5.4.4",

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/peer",
"version": "0.2.59",
"version": "0.2.60",
"description": "libp2p module",
"main": "dist/index.js",
"exports": "./dist/index.js",

View File

@ -66,6 +66,7 @@ export interface PeerInitConfig {
minConnections?: number;
dialTimeout?: number;
pubsub?: PubsubType;
directPeers?: string[];
enableDebugInfo?: boolean;
transports?: Libp2pInit['transports'];
listenMultiaddrs?: string[];
@ -158,7 +159,7 @@ export class Peer {
},
connectionEncryption: [noise()],
streamMuxers: [mplex(), yamux()],
pubsub: initPubsub(initOptions.pubsub),
pubsub: initPubsub(initOptions.pubsub, initOptions.directPeers),
peerDiscovery: [
// Use pubsub based discovery; relay server acts as a peer discovery source
pubsubPeerDiscovery({

View File

@ -11,9 +11,11 @@ import assert from 'assert';
import { Libp2p } from '@cerc-io/libp2p';
import { Multiaddr } from '@multiformats/multiaddr';
import type { PeerId } from '@libp2p/interface-peer-id';
import { peerIdFromString } from '@libp2p/peer-id';
import type { Connection } from '@libp2p/interface-connection';
import { floodsub } from '@libp2p/floodsub';
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
import { AddrInfo } from '@chainsafe/libp2p-gossipsub/types';
import { ConnectionInfo, ConnectionType, DebugMsg, DebugPeerInfo, DebugResponse, SelfInfo } from '../types/debug-info.js';
import { DEBUG_INFO_TOPIC, DEFAULT_PUBSUB_TYPE, P2P_WEBRTC_STAR_ID, PUBSUB_SIGNATURE_POLICY } from '../constants.js';
@ -179,7 +181,7 @@ export const wsPeerFilter = (multiaddrs: Multiaddr[]): Multiaddr[] => {
});
};
export const initPubsub = (pubsubType?: PubsubType): any => {
export const initPubsub = (pubsubType?: PubsubType, directPeers?: string[]): any => {
let pubsub: any;
switch (pubsubType || DEFAULT_PUBSUB_TYPE) {
case 'floodsub':
@ -188,8 +190,12 @@ export const initPubsub = (pubsubType?: PubsubType): any => {
case 'gossipsub':
pubsub = gossipsub({
globalSignaturePolicy: PUBSUB_SIGNATURE_POLICY,
allowPublishToZeroPeers: true
allowPublishToZeroPeers: true,
directPeers: directPeers?.map((directPeer: string): AddrInfo => {
return { id: peerIdFromString(directPeer), addrs: [] };
}) || []
});
break;
default:
throw new Error(`${ERR_INVALID_PUBSUB_TYPE}: ${pubsubType}`);

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/rpc-eth-client",
"version": "0.2.59",
"version": "0.2.60",
"description": "RPC ETH Client",
"main": "dist/index.js",
"scripts": {
@ -19,9 +19,9 @@
},
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@cerc-io/cache": "^0.2.59",
"@cerc-io/ipld-eth-client": "^0.2.59",
"@cerc-io/util": "^0.2.59",
"@cerc-io/cache": "^0.2.60",
"@cerc-io/ipld-eth-client": "^0.2.60",
"@cerc-io/util": "^0.2.60",
"chai": "^4.3.4",
"ethers": "^5.4.4",
"left-pad": "^1.3.0",

View File

@ -1,10 +1,10 @@
{
"name": "@cerc-io/solidity-mapper",
"version": "0.2.59",
"version": "0.2.60",
"main": "dist/index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@cerc-io/ipld-eth-client": "^0.2.59",
"@cerc-io/ipld-eth-client": "^0.2.60",
"@ethersproject/abi": "^5.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/test",
"version": "0.2.59",
"version": "0.2.60",
"main": "dist/index.js",
"license": "AGPL-3.0",
"private": true,

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/tracing-client",
"version": "0.2.59",
"version": "0.2.60",
"description": "ETH VM tracing client",
"main": "dist/index.js",
"scripts": {

View File

@ -1,13 +1,13 @@
{
"name": "@cerc-io/util",
"version": "0.2.59",
"version": "0.2.60",
"main": "dist/index.js",
"license": "AGPL-3.0",
"dependencies": {
"@apollo/utils.keyvaluecache": "^1.0.1",
"@cerc-io/nitro-node": "^0.1.11",
"@cerc-io/peer": "^0.2.59",
"@cerc-io/solidity-mapper": "^0.2.59",
"@cerc-io/peer": "^0.2.60",
"@cerc-io/solidity-mapper": "^0.2.60",
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/schema": "^9.0.10",
@ -49,7 +49,7 @@
"yargs": "^17.0.1"
},
"devDependencies": {
"@cerc-io/cache": "^0.2.59",
"@cerc-io/cache": "^0.2.60",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@types/bunyan": "^1.8.8",
"@types/express": "^4.17.14",

View File

@ -119,6 +119,9 @@ export interface PeerConfig {
// Pubsub to use ('floodsub' | 'gossipsub')
pubsub?: PubsubType;
// Direct peers list (only required with gossipsub)
directPeers?: string[];
// Participate in exchange of debug info over pubsub
enableDebugInfo?: boolean;
@ -167,7 +170,7 @@ export interface ConsensusConfig {
enabled: boolean;
publicKey: string;
privateKey: string;
watcherPartyFile: string;
watcherPartyPeersFile: string;
}
// P2P config

View File

@ -25,7 +25,7 @@ const log = debug(LOG_NAMESPACE);
const CONSENSUS_PROTOCOL = '/consensus/1.0.0';
const NUM_WRITE_ATTEMPTS = 20;
const NUM_WRITE_ATTEMPTS = 25;
const RETRY_SLEEP_DURATION = 15 * 1000; // 15 seconds
const DEFAULT_HEARTBEAT = 300;
@ -51,7 +51,7 @@ export interface ConsensusOptions {
publicKey: string;
privateKey: string;
party: PartyPeer[];
partyPeers: PartyPeer[];
// For Mokka options (ISettingsInterface)
heartbeat?: number;
@ -62,7 +62,7 @@ export interface ConsensusOptions {
export class Consensus extends Mokka {
peer: Peer;
party: PartyPeer[];
partyPeers: PartyPeer[];
private messageStreamMap: Map<string, Pushable<any>> = new Map();
@ -98,11 +98,11 @@ export class Consensus extends Mokka {
});
this.peer = options.peer;
this.party = options.party;
this.partyPeers = options.partyPeers;
// Add peer nodes in the party
// TODO: Skip initialization if party not provided?
for (const partyPeer of options.party) {
for (const partyPeer of options.partyPeers) {
const address = `${partyPeer.peerId}/${partyPeer.publicKey}`;
this.nodeApi.join(address);
}
@ -167,7 +167,7 @@ export class Consensus extends Mokka {
const { peerIdFromString } = await import('@libp2p/peer-id');
// Close all consensus protocol streams
for (const partyPeer of this.party) {
for (const partyPeer of this.partyPeers) {
for (const conn of this.peer.node.getConnections(peerIdFromString(partyPeer.peerId))) {
conn.streams.forEach(stream => {
if (stream.stat.protocol === CONSENSUS_PROTOCOL) {