Skip to content

Commit

Permalink
feat: witness car store
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed May 12, 2024
1 parent 2133de8 commit 3118905
Show file tree
Hide file tree
Showing 16 changed files with 3,639 additions and 130 deletions.
7 changes: 7 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
"s3BucketName": "myS3Bucket",
"s3Endpoint": ""
},
"witnessStorage": {
"awsRegion": "us-east-1",
"dynamoDbEndpoint": "",
"dynamoDbTableName": "",
"dynamoDbTtl": "",
"mode": "inmemory"
},
"ipfsConfig": {
"url": "http://localhost:5001",
"pubsubTopic": "/ceramic/testnet-clay",
Expand Down
7 changes: 7 additions & 0 deletions config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
"s3BucketName": "@@S3_BUCKET_NAME",
"s3Endpoint": "@@S3_ENDPOINT"
},
"witnessStorage": {
"awsRegion": "@@AWS_REGION",
"dynamoDbEndpoint": "@@DYNAMODB_ENDPOINT",
"dynamoDbTableName": "@@DYNAMODB_WITNESS_TABLE",
"dynamoDbTtl": "@@DYNAMODB_WITNESS_TTL",
"mode": "@@WITNESS_CAR_STORAGE_MODE"
},
"ipfsConfig": {
"url": "@@IPFS_API_URL",
"pubsubTopic": "@@IPFS_PUBSUB_TOPIC",
Expand Down
7 changes: 7 additions & 0 deletions config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
"s3BucketName": "@@S3_BUCKET_NAME",
"s3Endpoint": "@@S3_ENDPOINT"
},
"witnessStorage": {
"awsRegion": "@@AWS_REGION",
"dynamoDbEndpoint": "@@DYNAMODB_ENDPOINT",
"dynamoDbTableName": "@@DYNAMODB_WITNESS_TABLE",
"dynamoDbTtl": "@@DYNAMODB_WITNESS_TTL",
"mode": "@@WITNESS_CAR_STORAGE_MODE"
},
"ipfsConfig": {
"url": "@@IPFS_API_URL",
"pubsubTopic": "@@IPFS_PUBSUB_TOPIC",
Expand Down
3 changes: 3 additions & 0 deletions config/env/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"mode": "s3",
"s3BucketName": "ceramic-tnet-cas"
},
"witnessStorage": {
"mode": "inmemory"
},
"blockchain": {
"selectedConnector": "ethereum",
"connectors": {
Expand Down
3,333 changes: 3,321 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
}
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.574.0",
"@aws-sdk/client-sqs": "^3.348.0",
"@ceramicnetwork/anchor-utils": "^1.11.0-rc.0",
"@ceramicnetwork/codecs": "^1.3.0-rc.0",
Expand Down
24 changes: 14 additions & 10 deletions src/__tests__/ceramic_integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
test,
} from '@jest/globals'

import { CeramicDaemon, DaemonConfig } from '@ceramicnetwork/cli'
import { Ceramic } from '@ceramicnetwork/core'
import { AnchorStatus, fetchJson, IpfsApi, Stream } from '@ceramicnetwork/common'
import { ServiceMetrics as Metrics } from '@ceramicnetwork/observability'
Expand Down Expand Up @@ -46,6 +45,7 @@ import type { Injector } from 'typed-inject'
import { createInjector } from 'typed-inject'
import { teeDbConnection } from './tee-db-connection.util.js'
import { CARFactory, type CAR } from 'cartonne'
import { InMemoryWitnessService } from '../services/witness-service.js'

process.env.NODE_ENV = 'test'

Expand Down Expand Up @@ -200,6 +200,9 @@ async function makeCAS(
configCopy.carStorage = {
mode: 'inmemory',
}
configCopy.witnessStorage = {
mode: 'inmemory',
}
return new CeramicAnchorApp(
container.provideValue('config', configCopy).provideValue('dbConnection', dbConnection)
)
Expand Down Expand Up @@ -282,7 +285,9 @@ describe('Ceramic Integration Test', () => {
}

// Now make sure all ipfs nodes are connected to all other ipfs nodes
const ipfsNodes = process.env['CAS_USE_IPFS_STORAGE'] ? [ipfs1, ipfs2, ipfs3, ipfs4] : [ipfs3, ipfs4]
const ipfsNodes = process.env['CAS_USE_IPFS_STORAGE']
? [ipfs1, ipfs2, ipfs3, ipfs4]
: [ipfs3, ipfs4]
for (const [i] of ipfsNodes.entries()) {
for (const [j] of ipfsNodes.entries()) {
if (i == j) {
Expand Down Expand Up @@ -566,12 +571,11 @@ describe('CAR file', () => {

// Intercept witness CAR built on CAS side
let witnessCAR: CAR
const witnessService = cas.container.resolve('witnessService')
const buildWitnessCAR = witnessService.buildWitnessCAR.bind(witnessCAR)
const witnessService = new InMemoryWitnessService()
const spyBuildWitnessCAR = jest
.spyOn(witnessService, 'buildWitnessCAR')
.spyOn(cas.container.resolve('witnessService'), 'build')
.mockImplementation((anchorCommitCID, merkleCAR) => {
witnessCAR = buildWitnessCAR(anchorCommitCID, merkleCAR)
witnessCAR = witnessService.build(anchorCommitCID, merkleCAR)
return witnessCAR
})

Expand Down Expand Up @@ -612,8 +616,8 @@ describe('Metrics Options', () => {
port: casPort,
useSmartContractAnchors: true,
metrics: {
instanceIdentifier: '234fffffffffffffffffffffffffffffffff9726129'
}
instanceIdentifier: '234fffffffffffffffffffffffffffffffff9726129',
},
})
await cas.start()
// Teardown
Expand All @@ -626,8 +630,8 @@ describe('Metrics Options', () => {
port: casPort,
useSmartContractAnchors: true,
metrics: {
instanceIdentifier: ''
}
instanceIdentifier: '',
},
})
await cas2.start()
await cas2.stop()
Expand Down
9 changes: 6 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
ValidationSqsQueueService,
} from './services/queue/sqs-queue-service.js'
import { makeMerkleCarService, type IMerkleCarService } from './services/merkle-car-service.js'
import { WitnessService } from './services/witness-service.js'
import { makeWitnessService, type IWitnessService } from './services/witness-service.js'

type DependenciesContext = {
config: Config
Expand All @@ -66,7 +66,7 @@ type ProvidedContext = {
requestService: RequestService
merkleCarService: IMerkleCarService
continualAnchoringScheduler: TaskSchedulerService
witnessService: WitnessService
witnessService: IWitnessService
} & DependenciesContext

/**
Expand Down Expand Up @@ -107,10 +107,10 @@ export class CeramicAnchorApp {
.provideClass('anchorBatchQueueService', AnchorBatchSqsQueueService)
.provideClass('validationQueueService', ValidationSqsQueueService)
.provideFactory('merkleCarService', makeMerkleCarService)
.provideFactory('witnessService', makeWitnessService)
.provideClass('anchorService', AnchorService)
.provideClass('markReadyScheduler', TaskSchedulerService)
.provideClass('healthcheckService', HealthcheckService)
.provideClass('witnessService', WitnessService)
.provideClass('requestPresentationService', RequestPresentationService)
.provideClass('anchorRequestParamsParser', AnchorRequestParamsParser)
.provideClass('requestService', RequestService)
Expand Down Expand Up @@ -161,6 +161,9 @@ export class CeramicAnchorApp {
await ipfsService.init()
}

const witnessService = this.container.resolve('witnessService')
await witnessService.init()

switch (this.mode) {
case AppMode.SERVER:
await this._startServer()
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/__tests__/request-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { AnchorRequestParamsParser } from '../../ancillary/anchor-request-params
import { expectPresent } from '../../__tests__/expect-present.util.js'
import { RequestService } from '../../services/request-service.js'
import { ValidationSqsQueueService } from '../../services/queue/sqs-queue-service.js'
import { WitnessService } from '../../services/witness-service.js'
import { makeWitnessService } from '../../services/witness-service.js'
import { makeMerkleCarService } from '../../services/merkle-car-service.js'

type Tokens = {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('createRequest', () => {
.provideClass('anchorRepository', AnchorRepository)
.provideClass('ipfsService', MockIpfsService)
.provideFactory('merkleCarService', makeMerkleCarService)
.provideClass('witnessService', WitnessService)
.provideFactory('witnessService', makeWitnessService)
.provideClass('requestPresentationService', RequestPresentationService)
.provideClass('metadataService', MockMetadataService)
.provideClass('anchorRequestParamsParser', AnchorRequestParamsParser)
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('createRequest', () => {
.provideClass('anchorRepository', AnchorRepository)
.provideClass('ipfsService', MockIpfsService)
.provideFactory('merkleCarService', makeMerkleCarService)
.provideClass('witnessService', WitnessService)
.provideFactory('witnessService', makeWitnessService)
.provideClass('requestPresentationService', RequestPresentationService)
.provideClass('metadataService', MockMetadataService)
.provideClass('anchorRequestParamsParser', AnchorRequestParamsParser)
Expand Down
3 changes: 3 additions & 0 deletions src/services/__tests__/anchor-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { FakeFactory } from './fake-factory.util.js'
import { FakeEthereumBlockchainService } from './fake-ethereum-blockchain-service.util.js'
import { MockEventProducerService } from './mock-event-producer-service.util.js'
import { type IMerkleCarService, makeMerkleCarService } from '../merkle-car-service.js'
import { type IWitnessService, makeWitnessService } from '../witness-service.js'

process.env['NODE_ENV'] = 'test'

Expand Down Expand Up @@ -68,6 +69,7 @@ type Context = {
metadataService: IMetadataService
metadataRepository: MetadataRepository
merkleCarService: IMerkleCarService
witnessService: IWitnessService
anchorBatchQueueService: MockQueueService<any>
blockchainService: FakeEthereumBlockchainService
}
Expand Down Expand Up @@ -117,6 +119,7 @@ describe('anchor service', () => {
.provideClass('metadataService', MetadataService)
.provideClass('anchorBatchQueueService', MockQueueService<AnchorBatchQMessage>)
.provideFactory('merkleCarService', makeMerkleCarService)
.provideFactory('witnessService', makeWitnessService)
.provideClass('anchorService', AnchorService)

ipfsService = injector.resolve('ipfsService')
Expand Down
4 changes: 2 additions & 2 deletions src/services/__tests__/request-presentation-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import type {
} from '../../repositories/anchor-repository.type.js'
import { generateRequest } from '../../__tests__/test-utils.js'
import { InMemoryMerkleCarService } from '../merkle-car-service.js'
import { WitnessService } from '../witness-service.js'
import { InMemoryWitnessService } from '../witness-service.js'
import { CID } from 'multiformats/cid'

const anchorRepository = {
findByRequest: jest.fn(),
} as unknown as IAnchorRepository
const merkleCarService = new InMemoryMerkleCarService()
const witnessService = new WitnessService()
const witnessService = new InMemoryWitnessService()

const service = new RequestPresentationService(anchorRepository, merkleCarService, witnessService)

Expand Down
Loading

0 comments on commit 3118905

Please sign in to comment.