Repository navigation
feat(libp2p): validate config options at startup - #3659
sharmis-tp wants to merge 3 commits into
Conversation
|
The validation calls should happen inside of the constructors. The constructor should validate only parts of the config that class uses directly. Config options that get passed to sub-module classes are validated by those sub-modules. The validation code should live somewhere by the constructor that calls it in most cases. Some of the utilities, like multiaddrInput, could go in a new file inside of @libp2p/utils in a file named valibot.ts. Try with just the Libp2p class and one of the sub-modules. |
|
Thanks @tabcat, reworked as you suggested:
Tests: a new One note: |
Description
Related #1573
Adds config validation to the libp2p package only, as suggested on the issue; other modules can follow. validateConfig() now checks the options this package consumes directly with a valibot schema and fails fast with an InvalidParametersError that names the field, e.g. "Invalid libp2p config: addresses.listen.1 is not a valid multiaddr: foo".
Validated: address lists (listen, announce, noAnnounce, appendAnnounce, connectionManager.allow/deny) must parse as multiaddrs; connection manager limits and timeouts must be non-negative numbers (Infinity allowed); maxConnections must be > 0; connectionMonitor flags must be booleans; transportManager.faultTolerance must be a FaultTolerance value. Unknown keys are allowed so services keep their own options.
Notes & open questions
Change checklist