Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status: Expose datetime of most recent block #462

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}