Skip to content

Commit

Permalink
chore(refactor): Replace 'timestamp' with 'anchor' in BlockchainWriter (
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan authored Oct 22, 2018
1 parent 1ccc2ed commit c493da0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This is what the default configuration looks like:
bitcoinAddressPrivateKey: '',

enableTimestamping: false,
timestampIntervalInSeconds: 30,
anchorIntervalInSeconds: 30,
batchCreationIntervalInSeconds: 600
readNextDirectoryIntervalInSeconds: 30
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlockchainWriter/BlockchainWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const createContainer = (
.bind<BitcoinCore>('BitcoinCore')
.toConstantValue(new BitcoinCore(bitcoinRPCConfigurationToBitcoinCoreArguments(configuration)))
container.bind<ServiceConfiguration>('ServiceConfiguration').toConstantValue({
timestampIntervalInSeconds: configuration.timestampIntervalInSeconds,
anchorIntervalInSeconds: configuration.anchorIntervalInSeconds,
})
container.bind<ControllerConfiguration>('ClaimControllerConfiguration').toConstantValue(configuration)
container.bind<ExchangeConfiguration>('ExchangeConfiguration').toConstantValue(configuration.exchanges)
Expand Down
4 changes: 2 additions & 2 deletions src/BlockchainWriter/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class Controller {
this.exchange = exchange
}

async requestTimestamp(ipfsDirectoryHash: string): Promise<void> {
async requestAnchor(ipfsDirectoryHash: string): Promise<void> {
this.logger.debug({
method: 'timestampWithRetry',
method: 'requestAnchor',
ipfsDirectoryHash,
})
await this.dao.insertIpfsDirectoryHash(ipfsDirectoryHash)
Expand Down
17 changes: 7 additions & 10 deletions src/BlockchainWriter/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ export class Router {
}

async start() {
await this.messaging.consume(
this.exchange.batchWriterCreateNextBatchSuccess,
this.onBlockchainWriterRequestTimestampRequest
)
await this.messaging.consume(this.exchange.batchWriterCreateNextBatchSuccess, this.onCreateBatchSuccess)
}

onBlockchainWriterRequestTimestampRequest = async (message: any): Promise<void> => {
const logger = this.logger.child({ method: 'onBlockchainWriterRequestTimestampRequest' })
onCreateBatchSuccess = async (message: any): Promise<void> => {
const logger = this.logger.child({ method: 'onCreateBatchSuccess' })

const messageContent = message.content.toString()
const { ipfsDirectoryHash } = JSON.parse(messageContent)
Expand All @@ -43,19 +40,19 @@ export class Router {
{
ipfsDirectoryHash,
},
'creating timestamp request'
'Creating anchor request'
)

try {
await this.claimController.requestTimestamp(ipfsDirectoryHash)
logger.trace({ ipfsDirectoryHash }, 'Timestamp request created')
await this.claimController.requestAnchor(ipfsDirectoryHash)
logger.trace({ ipfsDirectoryHash }, 'Anchor request created')
} catch (error) {
logger.error(
{
error,
ipfsDirectoryHash,
},
'Timestamp request failure'
'Anchor request failure'
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/BlockchainWriter/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { childWithFileName } from 'Helpers/Logging'
import { Controller } from './Controller'

export interface ServiceConfiguration {
readonly timestampIntervalInSeconds: number
readonly anchorIntervalInSeconds: number
}

@injectable()
Expand All @@ -23,7 +23,7 @@ export class Service {
) {
this.logger = childWithFileName(logger, __filename)
this.claimController = claimController
this.interval = new Interval(this.timestampNextHash, 1000 * configuration.timestampIntervalInSeconds)
this.interval = new Interval(this.anchorNextHash, 1000 * configuration.anchorIntervalInSeconds)
}

async start() {
Expand All @@ -34,10 +34,10 @@ export class Service {
this.interval.stop()
}

private timestampNextHash = async () => {
const logger = this.logger.child({ method: 'timestampNextHash' })
private anchorNextHash = async () => {
const logger = this.logger.child({ method: 'anchorNextHash' })

logger.trace('Requesting Timestamping of Next Hash')
logger.trace('Requesting anchoring of next hash')

try {
await this.claimController.anchorNextIPFSDirectoryHash()
Expand All @@ -46,7 +46,7 @@ export class Service {
{
error,
},
'Uncaught exception while timestamping next hash'
'Uncaught exception while anchoring next hash'
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Configuration extends LoggingConfiguration, BitcoinRPCConfigura
readonly forceBlockHeight?: number

readonly enableTimestamping: boolean
readonly timestampIntervalInSeconds: number
readonly anchorIntervalInSeconds: number

readonly healthIntervalInSeconds: number

Expand Down Expand Up @@ -98,7 +98,7 @@ const defaultConfiguration: Configuration = {
blockchainReaderIntervalInSeconds: 5,

enableTimestamping: false,
timestampIntervalInSeconds: 30,
anchorIntervalInSeconds: 30,

healthIntervalInSeconds: 30,

Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export async function app(localVars: any = {}) {
rabbitmqUrl: configuration.rabbitmqUrl,
poetNetwork: configuration.poetNetwork,
poetVersion: configuration.poetVersion,
timestampIntervalInSeconds: configuration.timestampIntervalInSeconds,
anchorIntervalInSeconds: configuration.anchorIntervalInSeconds,
bitcoinUrl: configuration.bitcoinUrl,
bitcoinPort: configuration.bitcoinPort,
bitcoinNetwork: configuration.bitcoinNetwork,
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/claim_with_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getWorkFromNodeB = getWork(NODE_B_PORT)
const blockchainSettings = {
MINIMUM_BLOCK_HEIGHT: 100,
ENABLE_TIMESTAMPING: true,
TIMESTAMP_INTERVAL_IN_SECONDS: 10,
ANCHOR_INTERVAL_IN_SECONDS: 10,
BATCH_CREATION_INTERVAL_IN_SECONDS: 5,
READ_DIRECTORY_INTERVAL_IN_SECONDS: 5,
UPLOAD_CLAIM_INTERVAL_IN_SECONDS: 5,
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('A user can successfully submit a claim into the po.et network', async
}

// Wait for a claim batch to be submitted to the blockchain.
await delay(parseInt(process.env.TIMESTAMP_INTERVAL_IN_SECONDS || '10', 10) * 1000 * 2)
await delay(parseInt(process.env.ANCHOR_INTERVAL_IN_SECONDS || '10', 10) * 1000 * 2)

// mine N confirmation blocks on bitcoindA.
await bitcoindClientA.generate(parseInt(process.env.CONFIRMATION_BLOCKS || '1', 10))
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createDatabase = async (prefix: string) => {

const defaultBlockchainSettings = {
MINIMUM_BLOCK_HEIGHT: 100,
TIMESTAMP_INTERVAL_IN_SECONDS: 10,
ANCHOR_INTERVAL_IN_SECONDS: 10,
BATCH_CREATION_INTERVAL_IN_SECONDS: 5,
READ_DIRECTORY_INTERVAL_IN_SECONDS: 5,
UPLOAD_CLAIM_INTERVAL_IN_SECONDS: 5,
Expand Down

0 comments on commit c493da0

Please sign in to comment.