mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 12:26:19 +00:00
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:
parent
48e7785367
commit
32c78a907c
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ out/
|
|||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
yarn-error.log
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"command": {
|
"command": {
|
||||||
|
2
packages/cache/package.json
vendored
2
packages/cache/package.json
vendored
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/cache",
|
"name": "@cerc-io/cache",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "Generic object cache",
|
"description": "Generic object cache",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/cli",
|
"name": "@cerc-io/cli",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -12,13 +12,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.7.1",
|
"@apollo/client": "^3.7.1",
|
||||||
"@cerc-io/cache": "^0.2.59",
|
"@cerc-io/cache": "^0.2.60",
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.59",
|
"@cerc-io/ipld-eth-client": "^0.2.60",
|
||||||
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
|
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
|
||||||
"@cerc-io/nitro-node": "^0.1.11",
|
"@cerc-io/nitro-node": "^0.1.11",
|
||||||
"@cerc-io/peer": "^0.2.59",
|
"@cerc-io/peer": "^0.2.60",
|
||||||
"@cerc-io/rpc-eth-client": "^0.2.59",
|
"@cerc-io/rpc-eth-client": "^0.2.60",
|
||||||
"@cerc-io/util": "^0.2.59",
|
"@cerc-io/util": "^0.2.60",
|
||||||
"@ethersproject/providers": "^5.4.4",
|
"@ethersproject/providers": "^5.4.4",
|
||||||
"@graphql-tools/utils": "^9.1.1",
|
"@graphql-tools/utils": "^9.1.1",
|
||||||
"@ipld/dag-cbor": "^8.0.0",
|
"@ipld/dag-cbor": "^8.0.0",
|
||||||
|
@ -192,6 +192,7 @@ export class ServerCmd {
|
|||||||
maxConnections: peerConfig.maxConnections,
|
maxConnections: peerConfig.maxConnections,
|
||||||
dialTimeout: peerConfig.dialTimeout,
|
dialTimeout: peerConfig.dialTimeout,
|
||||||
pubsub: peerConfig.pubsub,
|
pubsub: peerConfig.pubsub,
|
||||||
|
directPeers: peerConfig.directPeers,
|
||||||
enableDebugInfo: peerConfig.enableDebugInfo
|
enableDebugInfo: peerConfig.enableDebugInfo
|
||||||
};
|
};
|
||||||
await this._peer.init(peerNodeInit, peerIdObj);
|
await this._peer.init(peerNodeInit, peerIdObj);
|
||||||
@ -204,6 +205,10 @@ export class ServerCmd {
|
|||||||
|
|
||||||
async initConsensus (): Promise<Consensus | undefined> {
|
async initConsensus (): Promise<Consensus | undefined> {
|
||||||
const p2pConfig = this._baseCmd.config.server.p2p;
|
const p2pConfig = this._baseCmd.config.server.p2p;
|
||||||
|
if (!p2pConfig || !p2pConfig.consensus) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { consensus: consensusConfig } = p2pConfig;
|
const { consensus: consensusConfig } = p2pConfig;
|
||||||
|
|
||||||
// Setup consensus engine if enabled
|
// Setup consensus engine if enabled
|
||||||
@ -213,14 +218,14 @@ export class ServerCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(this.peer);
|
assert(this.peer);
|
||||||
const watcherPartyPeers = readParty(consensusConfig.watcherPartyFile);
|
const watcherPartyPeers = readParty(consensusConfig.watcherPartyPeersFile);
|
||||||
|
|
||||||
// Create and initialize the consensus engine
|
// Create and initialize the consensus engine
|
||||||
this._consensus = new Consensus({
|
this._consensus = new Consensus({
|
||||||
peer: this.peer,
|
peer: this.peer,
|
||||||
publicKey: consensusConfig.publicKey,
|
publicKey: consensusConfig.publicKey,
|
||||||
privateKey: consensusConfig.privateKey,
|
privateKey: consensusConfig.privateKey,
|
||||||
party: watcherPartyPeers
|
partyPeers: watcherPartyPeers
|
||||||
});
|
});
|
||||||
|
|
||||||
// Connect registers the required p2p protocol handlers and starts the engine
|
// Connect registers the required p2p protocol handlers and starts the engine
|
||||||
@ -247,7 +252,7 @@ export class ServerCmd {
|
|||||||
} = this._baseCmd.config;
|
} = this._baseCmd.config;
|
||||||
|
|
||||||
// Nitro requires p2p peer to be enabled
|
// Nitro requires p2p peer to be enabled
|
||||||
if (!enablePeer) {
|
if (!enablePeer || !nitroConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/codegen",
|
"name": "@cerc-io/codegen",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "Code generator",
|
"description": "Code generator",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/util": "^0.2.59",
|
"@cerc-io/util": "^0.2.60",
|
||||||
"@graphql-tools/load-files": "^6.5.2",
|
"@graphql-tools/load-files": "^6.5.2",
|
||||||
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
|
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
|
||||||
"@solidity-parser/parser": "^0.13.2",
|
"@solidity-parser/parser": "^0.13.2",
|
||||||
|
@ -41,12 +41,12 @@
|
|||||||
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.3.19",
|
"@apollo/client": "^3.3.19",
|
||||||
"@cerc-io/cli": "^0.2.59",
|
"@cerc-io/cli": "^0.2.60",
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.59",
|
"@cerc-io/ipld-eth-client": "^0.2.60",
|
||||||
"@cerc-io/solidity-mapper": "^0.2.59",
|
"@cerc-io/solidity-mapper": "^0.2.60",
|
||||||
"@cerc-io/util": "^0.2.59",
|
"@cerc-io/util": "^0.2.60",
|
||||||
{{#if (subgraphPath)}}
|
{{#if (subgraphPath)}}
|
||||||
"@cerc-io/graph-node": "^0.2.59",
|
"@cerc-io/graph-node": "^0.2.60",
|
||||||
{{/if}}
|
{{/if}}
|
||||||
"@ethersproject/providers": "^5.4.4",
|
"@ethersproject/providers": "^5.4.4",
|
||||||
"apollo-type-bigint": "^0.1.3",
|
"apollo-type-bigint": "^0.1.3",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/graph-node",
|
"name": "@cerc-io/graph-node",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cerc-io/solidity-mapper": "^0.2.59",
|
"@cerc-io/solidity-mapper": "^0.2.60",
|
||||||
"@ethersproject/providers": "^5.4.4",
|
"@ethersproject/providers": "^5.4.4",
|
||||||
"@graphprotocol/graph-ts": "^0.22.0",
|
"@graphprotocol/graph-ts": "^0.22.0",
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
@ -51,9 +51,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.3.19",
|
"@apollo/client": "^3.3.19",
|
||||||
"@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2",
|
"@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2",
|
||||||
"@cerc-io/cache": "^0.2.59",
|
"@cerc-io/cache": "^0.2.60",
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.59",
|
"@cerc-io/ipld-eth-client": "^0.2.60",
|
||||||
"@cerc-io/util": "^0.2.59",
|
"@cerc-io/util": "^0.2.60",
|
||||||
"@types/json-diff": "^0.5.2",
|
"@types/json-diff": "^0.5.2",
|
||||||
"@types/yargs": "^17.0.0",
|
"@types/yargs": "^17.0.0",
|
||||||
"bn.js": "^4.11.9",
|
"bn.js": "^4.11.9",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/ipld-eth-client",
|
"name": "@cerc-io/ipld-eth-client",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "IPLD ETH Client",
|
"description": "IPLD ETH Client",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -20,7 +20,7 @@
|
|||||||
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.7.1",
|
"@apollo/client": "^3.7.1",
|
||||||
"@cerc-io/cache": "^0.2.59",
|
"@cerc-io/cache": "^0.2.60",
|
||||||
"cross-fetch": "^3.1.4",
|
"cross-fetch": "^3.1.4",
|
||||||
"debug": "^4.3.1",
|
"debug": "^4.3.1",
|
||||||
"ethers": "^5.4.4",
|
"ethers": "^5.4.4",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/peer",
|
"name": "@cerc-io/peer",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "libp2p module",
|
"description": "libp2p module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"exports": "./dist/index.js",
|
"exports": "./dist/index.js",
|
||||||
|
@ -66,6 +66,7 @@ export interface PeerInitConfig {
|
|||||||
minConnections?: number;
|
minConnections?: number;
|
||||||
dialTimeout?: number;
|
dialTimeout?: number;
|
||||||
pubsub?: PubsubType;
|
pubsub?: PubsubType;
|
||||||
|
directPeers?: string[];
|
||||||
enableDebugInfo?: boolean;
|
enableDebugInfo?: boolean;
|
||||||
transports?: Libp2pInit['transports'];
|
transports?: Libp2pInit['transports'];
|
||||||
listenMultiaddrs?: string[];
|
listenMultiaddrs?: string[];
|
||||||
@ -158,7 +159,7 @@ export class Peer {
|
|||||||
},
|
},
|
||||||
connectionEncryption: [noise()],
|
connectionEncryption: [noise()],
|
||||||
streamMuxers: [mplex(), yamux()],
|
streamMuxers: [mplex(), yamux()],
|
||||||
pubsub: initPubsub(initOptions.pubsub),
|
pubsub: initPubsub(initOptions.pubsub, initOptions.directPeers),
|
||||||
peerDiscovery: [
|
peerDiscovery: [
|
||||||
// Use pubsub based discovery; relay server acts as a peer discovery source
|
// Use pubsub based discovery; relay server acts as a peer discovery source
|
||||||
pubsubPeerDiscovery({
|
pubsubPeerDiscovery({
|
||||||
|
@ -11,9 +11,11 @@ import assert from 'assert';
|
|||||||
import { Libp2p } from '@cerc-io/libp2p';
|
import { Libp2p } from '@cerc-io/libp2p';
|
||||||
import { Multiaddr } from '@multiformats/multiaddr';
|
import { Multiaddr } from '@multiformats/multiaddr';
|
||||||
import type { PeerId } from '@libp2p/interface-peer-id';
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
||||||
|
import { peerIdFromString } from '@libp2p/peer-id';
|
||||||
import type { Connection } from '@libp2p/interface-connection';
|
import type { Connection } from '@libp2p/interface-connection';
|
||||||
import { floodsub } from '@libp2p/floodsub';
|
import { floodsub } from '@libp2p/floodsub';
|
||||||
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
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 { 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';
|
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;
|
let pubsub: any;
|
||||||
switch (pubsubType || DEFAULT_PUBSUB_TYPE) {
|
switch (pubsubType || DEFAULT_PUBSUB_TYPE) {
|
||||||
case 'floodsub':
|
case 'floodsub':
|
||||||
@ -188,8 +190,12 @@ export const initPubsub = (pubsubType?: PubsubType): any => {
|
|||||||
case 'gossipsub':
|
case 'gossipsub':
|
||||||
pubsub = gossipsub({
|
pubsub = gossipsub({
|
||||||
globalSignaturePolicy: PUBSUB_SIGNATURE_POLICY,
|
globalSignaturePolicy: PUBSUB_SIGNATURE_POLICY,
|
||||||
allowPublishToZeroPeers: true
|
allowPublishToZeroPeers: true,
|
||||||
|
directPeers: directPeers?.map((directPeer: string): AddrInfo => {
|
||||||
|
return { id: peerIdFromString(directPeer), addrs: [] };
|
||||||
|
}) || []
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`${ERR_INVALID_PUBSUB_TYPE}: ${pubsubType}`);
|
throw new Error(`${ERR_INVALID_PUBSUB_TYPE}: ${pubsubType}`);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/rpc-eth-client",
|
"name": "@cerc-io/rpc-eth-client",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "RPC ETH Client",
|
"description": "RPC ETH Client",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -19,9 +19,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/cache": "^0.2.59",
|
"@cerc-io/cache": "^0.2.60",
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.59",
|
"@cerc-io/ipld-eth-client": "^0.2.60",
|
||||||
"@cerc-io/util": "^0.2.59",
|
"@cerc-io/util": "^0.2.60",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"ethers": "^5.4.4",
|
"ethers": "^5.4.4",
|
||||||
"left-pad": "^1.3.0",
|
"left-pad": "^1.3.0",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/solidity-mapper",
|
"name": "@cerc-io/solidity-mapper",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.59",
|
"@cerc-io/ipld-eth-client": "^0.2.60",
|
||||||
"@ethersproject/abi": "^5.3.0",
|
"@ethersproject/abi": "^5.3.0",
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/test",
|
"name": "@cerc-io/test",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/tracing-client",
|
"name": "@cerc-io/tracing-client",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"description": "ETH VM tracing client",
|
"description": "ETH VM tracing client",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/util",
|
"name": "@cerc-io/util",
|
||||||
"version": "0.2.59",
|
"version": "0.2.60",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/utils.keyvaluecache": "^1.0.1",
|
"@apollo/utils.keyvaluecache": "^1.0.1",
|
||||||
"@cerc-io/nitro-node": "^0.1.11",
|
"@cerc-io/nitro-node": "^0.1.11",
|
||||||
"@cerc-io/peer": "^0.2.59",
|
"@cerc-io/peer": "^0.2.60",
|
||||||
"@cerc-io/solidity-mapper": "^0.2.59",
|
"@cerc-io/solidity-mapper": "^0.2.60",
|
||||||
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
|
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
|
||||||
"@ethersproject/providers": "^5.4.4",
|
"@ethersproject/providers": "^5.4.4",
|
||||||
"@graphql-tools/schema": "^9.0.10",
|
"@graphql-tools/schema": "^9.0.10",
|
||||||
@ -49,7 +49,7 @@
|
|||||||
"yargs": "^17.0.1"
|
"yargs": "^17.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cerc-io/cache": "^0.2.59",
|
"@cerc-io/cache": "^0.2.60",
|
||||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||||
"@types/bunyan": "^1.8.8",
|
"@types/bunyan": "^1.8.8",
|
||||||
"@types/express": "^4.17.14",
|
"@types/express": "^4.17.14",
|
||||||
|
@ -119,6 +119,9 @@ export interface PeerConfig {
|
|||||||
// Pubsub to use ('floodsub' | 'gossipsub')
|
// Pubsub to use ('floodsub' | 'gossipsub')
|
||||||
pubsub?: PubsubType;
|
pubsub?: PubsubType;
|
||||||
|
|
||||||
|
// Direct peers list (only required with gossipsub)
|
||||||
|
directPeers?: string[];
|
||||||
|
|
||||||
// Participate in exchange of debug info over pubsub
|
// Participate in exchange of debug info over pubsub
|
||||||
enableDebugInfo?: boolean;
|
enableDebugInfo?: boolean;
|
||||||
|
|
||||||
@ -167,7 +170,7 @@ export interface ConsensusConfig {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
watcherPartyFile: string;
|
watcherPartyPeersFile: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// P2P config
|
// P2P config
|
||||||
|
@ -25,7 +25,7 @@ const log = debug(LOG_NAMESPACE);
|
|||||||
|
|
||||||
const CONSENSUS_PROTOCOL = '/consensus/1.0.0';
|
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 RETRY_SLEEP_DURATION = 15 * 1000; // 15 seconds
|
||||||
|
|
||||||
const DEFAULT_HEARTBEAT = 300;
|
const DEFAULT_HEARTBEAT = 300;
|
||||||
@ -51,7 +51,7 @@ export interface ConsensusOptions {
|
|||||||
publicKey: string;
|
publicKey: string;
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
|
|
||||||
party: PartyPeer[];
|
partyPeers: PartyPeer[];
|
||||||
|
|
||||||
// For Mokka options (ISettingsInterface)
|
// For Mokka options (ISettingsInterface)
|
||||||
heartbeat?: number;
|
heartbeat?: number;
|
||||||
@ -62,7 +62,7 @@ export interface ConsensusOptions {
|
|||||||
|
|
||||||
export class Consensus extends Mokka {
|
export class Consensus extends Mokka {
|
||||||
peer: Peer;
|
peer: Peer;
|
||||||
party: PartyPeer[];
|
partyPeers: PartyPeer[];
|
||||||
|
|
||||||
private messageStreamMap: Map<string, Pushable<any>> = new Map();
|
private messageStreamMap: Map<string, Pushable<any>> = new Map();
|
||||||
|
|
||||||
@ -98,11 +98,11 @@ export class Consensus extends Mokka {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.peer = options.peer;
|
this.peer = options.peer;
|
||||||
this.party = options.party;
|
this.partyPeers = options.partyPeers;
|
||||||
|
|
||||||
// Add peer nodes in the party
|
// Add peer nodes in the party
|
||||||
// TODO: Skip initialization if party not provided?
|
// 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}`;
|
const address = `${partyPeer.peerId}/${partyPeer.publicKey}`;
|
||||||
this.nodeApi.join(address);
|
this.nodeApi.join(address);
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ export class Consensus extends Mokka {
|
|||||||
const { peerIdFromString } = await import('@libp2p/peer-id');
|
const { peerIdFromString } = await import('@libp2p/peer-id');
|
||||||
|
|
||||||
// Close all consensus protocol streams
|
// 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))) {
|
for (const conn of this.peer.node.getConnections(peerIdFromString(partyPeer.peerId))) {
|
||||||
conn.streams.forEach(stream => {
|
conn.streams.forEach(stream => {
|
||||||
if (stream.stat.protocol === CONSENSUS_PROTOCOL) {
|
if (stream.stat.protocol === CONSENSUS_PROTOCOL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user