ceramicnetwork / js-ceramic

Typescript implementation of the Ceramic protocol
http://ceramic.network
Other
414 stars 127 forks source link

feat: verify ceramic-one network matches js-ceramic at startup #3259

Closed dav1do closed 1 month ago

dav1do commented 1 month ago

Description

We now query ceramic-one to make sure we're using the same network. We error if there's a mismatch and log a warning if the endpoint doesn't exist/respond. The default for both binaries is testnet-clay and we start successfully. Local is slightly odd as ceramic one has the concept of network ID, which we don't verify explicitly as it was either started for tests with the flag by us, or js-ceramic expects only local and the ID is specific to ceramic-one, so as long as we're both on local we're aok.

Uses the changes introduced in rust-ceramic #441.

How Has This Been Tested?

Tested locally, examples of mismatch and and old version:

[2024-07-17T18:24:05.578Z] ERROR: Error: Recon: failed to verify network as js-ceramic is using testnet-clay but ceramic-one is on local-0. Pass --network to the js-ceramic or ceramic-one daemon to make them match.
[2024-07-17T18:24:05.578Z] IMPORTANT: Closing Ceramic instance
[2024-07-17T18:24:05.580Z] IMPORTANT: Ceramic instance closed successfully
Ceramic daemon failed to start up:
Error: Recon: failed to verify network as js-ceramic is using testnet-clay but ceramic-one is on local-0. Pass --network to the js-ceramic or ceramic-one daemon to make them match.
    at ReconApi.verifyNetwork (file:///Users/david/3box/js-ceramic/packages/core/lib/recon.js:66:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ReconApi.init (file:///Users/david/3box/js-ceramic/packages/core/lib/recon.js:47:9)
    at async Repository.init (file:///Users/david/3box/js-ceramic/packages/core/lib/state-management/repository.js:100:9)
    at async Ceramic._init (file:///Users/david/3box/js-ceramic/packages/core/lib/ceramic.js:217:13)
    at async CeramicDaemon.create (file:///Users/david/3box/js-ceramic/packages/cli/lib/ceramic-daemon.js:181:9)
    at async CeramicCliUtils.createDaemon (file:///Users/david/3box/js-ceramic/packages/cli/lib/ceramic-cli-utils.js:148:24)
    at async Command.<anonymous> (file:///Users/david/3box/js-ceramic/packages/cli/lib/bin/ceramic.js:30:5)

# when running with an old version of ceramic-one
[2024-07-17T18:27:47.297Z] IMPORTANT: Connecting to ceramic network 'testnet-clay' using ceramic-one with Recon for data synchronization.
[2024-07-17T18:27:47.325Z] WARNING: Recon: failed to verify network with error Error: HTTP request to 'http://127.0.0.1:5101/ceramic/network' failed with status 'Not Found': . This is likely due to an older version of ceramic-one and you should upgrade.
[2024-07-17T18:27:47.331Z] IMPORTANT: Connecting to bootstrap peers for network testnet-clay
[2024-07-17T18:27:47.908Z] IMPORTANT: Connected to anchor service 'https://cas-clay.3boxlabs.com' with supported anchor chains ['eip155:100']
[2024-07-17T18:27:47.910Z] WARNING: No pinned streams detected. This is expected if this is the first time this node has been run, but may indicate a problem with the node's persistence setup if it should have pinned streams
[2024-07-17T18:27:47.917Z] IMPORTANT: Ceramic API running on 0.0.0.0:7007'

PR checklist

Before submitting this PR, please make sure:

References:

Please list relevant documentation (e.g. tech specs, articles, related work etc.) relevant to this change, and note if the documentation has been updated.

linear[bot] commented 1 month ago

AES-209 Error if js-ceramic and C1 mismatch on what network they are using

dav1do commented 1 month ago

lgtm

rebased and updated to use /ceramic/config/network based on changes in rust-ceramic PR.