-
Notifications
You must be signed in to change notification settings - Fork 42
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
chore: throw if more than one network config is passed #2056
Changes from 5 commits
2df10b7
e2c9a7a
641a499
09186af
f0720b2
6d714a5
26603fa
c1656ec
0439594
0aeed00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,30 +86,19 @@ | |
...pubsubService, | ||
...options?.services | ||
} | ||
}) as any as Libp2p; // TODO: make libp2p include it; | ||
Check warning on line 89 in packages/sdk/src/utils/libp2p.ts GitHub Actions / check
|
||
} | ||
|
||
export async function createLibp2pAndUpdateOptions( | ||
options: CreateWakuNodeOptions | ||
): Promise<Libp2p> { | ||
logWhichShardInfoIsUsed(options); | ||
|
||
if (options.contentTopics) { | ||
options.shardInfo = { contentTopics: options.contentTopics }; | ||
} | ||
|
||
const shardInfo = options.shardInfo | ||
? ensureShardingConfigured(options.shardInfo) | ||
: undefined; | ||
|
||
options.pubsubTopics = shardInfo?.pubsubTopics ?? | ||
options.pubsubTopics ?? [DefaultPubsubTopic]; | ||
const shardInfo = configureNetworkOptions(options); | ||
|
||
const libp2pOptions = options?.libp2p ?? {}; | ||
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; | ||
|
||
if (options?.defaultBootstrap) { | ||
peerDiscovery.push(...defaultPeerDiscoveries(options.pubsubTopics)); | ||
peerDiscovery.push(...defaultPeerDiscoveries(options.pubsubTopics!)); | ||
} | ||
|
||
if (options?.bootstrapPeers) { | ||
|
@@ -119,7 +108,7 @@ | |
libp2pOptions.peerDiscovery = peerDiscovery; | ||
|
||
const libp2p = await defaultLibp2p( | ||
shardInfo?.shardInfo, | ||
shardInfo, | ||
wakuGossipSub(options), | ||
libp2pOptions, | ||
options?.userAgent | ||
|
@@ -128,6 +117,37 @@ | |
return libp2p; | ||
} | ||
|
||
function configureNetworkOptions( | ||
options: CreateWakuNodeOptions | ||
): ShardInfo | undefined { | ||
const flags = [ | ||
options.contentTopics, | ||
options.pubsubTopics, | ||
options.shardInfo | ||
].filter((v) => !!v); | ||
|
||
if (flags.length > 1) { | ||
throw Error( | ||
"Too many network configurations, pass only: pubsubTopic, contentTopics or shardInfo." | ||
weboko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
logWhichShardInfoIsUsed(options); | ||
|
||
if (options.contentTopics) { | ||
options.shardInfo = { contentTopics: options.contentTopics }; | ||
} | ||
|
||
const shardInfo = options.shardInfo | ||
? ensureShardingConfigured(options.shardInfo) | ||
: undefined; | ||
|
||
options.pubsubTopics = shardInfo?.pubsubTopics ?? | ||
options.pubsubTopics ?? [DefaultPubsubTopic]; | ||
Comment on lines
+137
to
+146
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. nit: Let's follow the same 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. I think usage of |
||
|
||
return shardInfo?.shardInfo; | ||
} | ||
|
||
function logWhichShardInfoIsUsed(options: CreateWakuNodeOptions): void { | ||
if (options.pubsubTopics) { | ||
logger.info("Using pubsubTopics array to bootstrap the node."); | ||
|
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.
Can we workaround not having to enforce its definition by adding a
!
?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.
It is due to update happening inside of a function so TS don't pick it up and complains.
To address this I think we should fully rework the approach to options and my proposal is here with draft PR #2073