Skip to content

Commit

Permalink
feat: Do not publish anchor commits to pubsub by default (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody authored Feb 23, 2024
1 parent d3d6a56 commit 306195d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/ceramic_integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ describe('Ceramic Integration Test', () => {
ceramic1 = await makeCeramicCore(ipfs3, `http://localhost:${casPort1}`, ganacheServer.url)
ceramic2 = await makeCeramicCore(ipfs4, `http://localhost:${casPort2}`, ganacheServer.url)

// Speed up polling interval to speed up test
ceramic1.context.anchorService.pollInterval = 100
ceramic2.context.anchorService.pollInterval = 100

// The two user-facing ceramic nodes need to have the same DID Provider so that they can modify
// each others streams.
const did = makeDID()
Expand Down Expand Up @@ -528,7 +532,7 @@ describe('CAR file', () => {

// Poll more often to speed up the test
const anchorService = ceramic.context.anchorService as any
anchorService.pollInterval = 200
anchorService.pollInterval = 100

// CAS: Do not publish to IPFS
const carFactory = new CARFactory()
Expand Down
7 changes: 0 additions & 7 deletions src/services/__tests__/anchor-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ describe('anchor service', () => {

await requestRepository.findAndMarkReady(0)

const publishSpy = jest.spyOn(ipfsService, 'publishAnchorCommit')
const [candidates] = await anchorService._findCandidates(requests, 0)
const merkleTree = await anchorService._buildMerkleTree(candidates)
const ipfsProofCid = await ipfsService.storeRecord({})
Expand All @@ -182,8 +181,6 @@ describe('anchor service', () => {
expect(candidates.length).toEqual(requests.length)
expect(anchors.length).toEqual(candidates.length)

expect(publishSpy).toBeCalledTimes(anchors.length)

// All requests are anchored, in a different order because of IpfsLeafCompare
expect(anchors.map((a) => a.requestId).sort()).toEqual(requests.map((r) => r.id).sort())
for (const [index, anchor] of anchors.entries()) {
Expand All @@ -197,10 +194,6 @@ describe('anchor service', () => {
expect(anchorRecord.prev.toString()).toEqual(request.cid)
expect(anchorRecord.proof).toEqual(ipfsProofCid)
expect(anchorRecord.path).toEqual(anchor.path)
expect(publishSpy.mock.calls[index]).toEqual([
anchor.cid,
StreamID.fromString(request.streamId),
])
}

expectPresent(anchors[0])
Expand Down
18 changes: 14 additions & 4 deletions src/services/anchor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,20 @@ export class AnchorService {

try {
await this.ipfsService.storeRecord(ipfsAnchorCommit)
await this.ipfsService.publishAnchorCommit(anchorCid, candidate.streamId)
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId}`
)

// Do not publish to pubsub by default
if (process.env['CAS_PUBSUB_PUBLISH']) {
// TODO: Remove this case entirely after js-ceramic no longer supports pubsub
await this.ipfsService.publishAnchorCommit(anchorCid, candidate.streamId)
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId} and published it to pubsub`
)
} else {
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId}`
)
}

return anchor
} catch (err) {
const msg = `Error publishing anchor commit of commit ${
Expand Down

0 comments on commit 306195d

Please sign in to comment.