Skip to content

Commit

Permalink
status: Expose datetime of most recent block
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jun 25, 2023
1 parent 7062d20 commit df67795
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
14 changes: 12 additions & 2 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,18 @@ components:

Status:
type: object
required: [latest_block, latest_update]
required: [latest_block, latest_block_time, latest_update]
properties:
latest_block:
type: integer
format: int64
description: The height of the most recent indexed block. Query a synced Oasis node for the latest block produced.
example: *block_height_1
latest_block_time:
type: string
format: date-time
description: The RFC 3339 formatted consensus time of when the most recent block was produced.
example: *iso_timestamp_2
latest_update:
type: string
format: date-time
Expand Down Expand Up @@ -2342,7 +2347,7 @@ components:

RuntimeStatus:
type: object
required: [active_nodes, latest_block, latest_update]
required: [active_nodes, latest_block, latest_block_time, latest_update]
properties:
active_nodes:
type: integer
Expand All @@ -2353,6 +2358,11 @@ components:
format: int64
description: The height of the most recent indexed block (also sometimes referred to as "round") for this runtime. Query a synced Oasis node for the latest block produced.
example: *block_height_1
latest_block_time:
type: string
format: date-time
description: The RFC 3339 formatted consensus time of when the latest indexed block for this runtime was produced.
example: *iso_timestamp_2
latest_update:
type: string
format: date-time
Expand Down
19 changes: 19 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ func (c *StorageClient) Status(ctx context.Context) (*Status, error) {
// https://github.com/oasisprotocol/oasis-core/blob/5985dc5c2844de28241b7b16b19d91a86e5cbeda/docs/oasis-node/cli.md?plain=1#L41
s.LatestUpdate = s.LatestUpdate.Truncate(time.Second)

// Query latest block for info.
if err := c.db.QueryRow(
ctx,
queries.Block,
s.LatestBlock,
).Scan(nil, nil, &s.LatestBlockTime, nil); err != nil {
return nil, wrapError(err)
}

return &s, nil
}

Expand Down Expand Up @@ -1502,6 +1511,16 @@ func (c *StorageClient) RuntimeStatus(ctx context.Context) (*RuntimeStatus, erro
// https://github.com/oasisprotocol/oasis-core/blob/5985dc5c2844de28241b7b16b19d91a86e5cbeda/docs/oasis-node/cli.md?plain=1#L41
s.LatestUpdate = s.LatestUpdate.Truncate(time.Second)

// Query latest block for info.
if err := c.db.QueryRow(
ctx,
queries.RuntimeBlock,
runtimeName,
s.LatestBlock,
).Scan(nil, nil, &s.LatestBlockTime, nil, nil, nil); err != nil {
return nil, wrapError(err)
}

// Query active nodes.
if err := c.db.QueryRow(
ctx,
Expand Down
5 changes: 5 additions & 0 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ const (
LIMIT $6::bigint
OFFSET $7::bigint`

RuntimeBlock = `
SELECT round, block_hash, timestamp, num_transactions, size, gas_used
FROM chain.runtime_blocks
WHERE (runtime = $1) AND (round = $2::bigint)`

RuntimeTransactions = `
SELECT
txs.round,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/expected/emerald_status.body
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"active_nodes": 28,
"latest_block": 1003598,
"latest_block_time": "2022-04-11T13:38:14Z",
"latest_update": "UNINTERESTING"
}
1 change: 1 addition & 0 deletions tests/e2e_regression/expected/status.body
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"latest_block": 8049056,
"latest_block_time": "2022-04-11T11:12:48Z",
"latest_update": "UNINTERESTING"
}

0 comments on commit df67795

Please sign in to comment.