Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fuel/fuel-dump/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export class FuelDumper extends Dumper<BlockData, Options> {
return block.block.header.prevRoot
}

protected getBlockTimestamp(block: BlockData): number {
const TAI64_UNIX_OFFSET = BigInt("4611686018427387914");
const taiTimestamp = BigInt(block.block.header.time);
const unixTimeMs = taiTimestamp - TAI64_UNIX_OFFSET;
return Number(unixTimeMs);
}

protected validateChainContinuity(): boolean {
return false
}
Expand Down
4 changes: 4 additions & 0 deletions solana/solana-dump/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class SolanaDumper extends Dumper<Block, Options> {
return block.block.previousBlockhash
}

protected getBlockTimestamp(block: Block): number {
return Number(block.block.blockTime) ?? 0
}

@def
private solanaRpc(): Rpc {
return new Rpc(this.rpc())
Expand Down
4 changes: 4 additions & 0 deletions substrate/substrate-dump/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ export class SubstrateDumper extends Dumper<BlockData, Options> {
protected getPrevBlockHash(block: BlockData): string {
return block.block.block.header.parentHash
}

protected getBlockTimestamp(block: BlockData): number {
return (Date.now() / 1000); //mocked timestamp for now
}
}
4 changes: 4 additions & 0 deletions tron/tron-dump/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class TronDumper extends Dumper<BlockData, Options> {
return block.block.block_header.raw_data.parentHash
}

protected getBlockTimestamp(block: BlockData): number {
return block.block.block_header.raw_data.timestamp ?? 0
}

@def
httpApi(): HttpApi {
let client = new TronHttpClient({
Expand Down
7 changes: 7 additions & 0 deletions util/util-internal-dump-cli/src/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export abstract class Dumper<B extends {hash: string, height: number}, O extends

protected abstract getPrevBlockHash(block: B): string

protected abstract getBlockTimestamp(block: B): number

protected setUpProgram(program: Command): void {}

protected getDefaultChunkSize(): number {
Expand Down Expand Up @@ -176,6 +178,11 @@ export abstract class Dumper<B extends {hash: string, height: number}, O extends
}
}

const lastBlock = last(blocks)
const receivedTimestamp = Math.floor(Date.now() / 1000)
const mintedTimestamp = this.getBlockTimestamp(lastBlock)
this.prometheus().setLatestBlockMetrics(lastBlock.height, receivedTimestamp, mintedTimestamp)

yield blocks

progress.setCurrentValue(last(blocks).height)
Expand Down
27 changes: 27 additions & 0 deletions util/util-internal-dump-cli/src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class PrometheusServer {
private lastWrittenBlockGauge: Gauge
private rpcRequestsGauge: Gauge
private s3RequestsCounter: Counter
private latestBlockNumberGauge: Gauge
private latestBlockReceivedTimestampGauge: Gauge
private latestBlockMintedTimestampGauge: Gauge

constructor(
private port: number,
Expand Down Expand Up @@ -39,6 +42,24 @@ export class PrometheusServer {
registers: [this.registry]
})

this.latestBlockNumberGauge = new Gauge({
name: 'sqd_latest_block_number',
help: 'Latest block number received',
registers: [this.registry]
})

this.latestBlockReceivedTimestampGauge = new Gauge({
name: 'sqd_latest_block_received_timestamp',
help: 'Timestamp when latest block was received',
registers: [this.registry]
})

this.latestBlockMintedTimestampGauge = new Gauge({
name: 'sqd_latest_block_minted_timestamp',
help: 'Timestamp when latest block was minted',
registers: [this.registry]
})

this.rpcRequestsGauge = new Gauge({
name: 'sqd_rpc_request_count',
help: 'Number of rpc requests made',
Expand Down Expand Up @@ -73,6 +94,12 @@ export class PrometheusServer {
this.lastWrittenBlockGauge.set(block)
}

setLatestBlockMetrics(blockNumber: number, receivedTimestamp: number, mintedTimestamp: number) {
this.latestBlockNumberGauge.set(blockNumber)
this.latestBlockReceivedTimestampGauge.set(receivedTimestamp)
this.latestBlockMintedTimestampGauge.set(mintedTimestamp)
}

incS3Requests(kind: string, value?: number) {
this.s3RequestsCounter.inc({kind}, value)
}
Expand Down
Loading