Skip to content

Commit 1ab46a1

Browse files
authored
Merge pull request #169 from lysyi3m/feature/add-consensus-info-endpoint
feat: add GET /v0/consensusInfo endpoint
2 parents 7ae7149 + d074e62 commit 1ab46a1

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [unreleased]
44

5+
- Add `GET` endpoint `/v0/consensusInfo` for getting the current consensus status from the node, including last finalized block, best block, protocol version, and timing parameters.
6+
57
## [0.45.0] - 2026-02-23
68

79
- Add `GET` endpoint `/v0/genesisHash` for getting the genesis block hash for the connected network.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cooldowns and the available balance) and get the info if an account is on any al
5353
* `GET /v0/keyAccounts/{public key}`: get accounts associated with a given public key. Optionally filter the result for simple accounts.
5454
* `POST /v0/transakOnRamp`: create a URL to initiate purchasing CCDs through the Transak on-ramp.
5555
* `GET /v0/genesisHash`: get the genesis block hash for the connected network.
56+
* `GET /v0/consensusInfo`: get the current consensus status from the node.
5657

5758
### Errors
5859

@@ -1496,6 +1497,53 @@ Example response:
14961497
}
14971498
```
14981499

1500+
## Consensus info
1501+
1502+
A GET request to `/v0/consensusInfo` returns the current consensus status from the node.
1503+
1504+
The response always includes:
1505+
1506+
| Field | Type | Description |
1507+
|---|---|---|
1508+
| `bestBlock` | string (hex) | Hash of the current best block |
1509+
| `bestBlockHeight` | number | Absolute height of the best block |
1510+
| `genesisBlock` | string (hex) | Hash of the genesis block |
1511+
| `genesisTime` | string (ISO 8601) | Timestamp of the genesis block |
1512+
| `lastFinalizedBlock` | string (hex) | Hash of the last finalized block |
1513+
| `lastFinalizedBlockHeight` | number | Absolute height of the last finalized block |
1514+
| `lastFinalizedTime` | string (ISO 8601) or null | Time of last verified finalization |
1515+
| `epochDuration` | number | Current epoch duration in milliseconds |
1516+
| `protocolVersion` | number | Currently active protocol version |
1517+
| `genesisIndex` | number | Number of chain restarts via protocol updates |
1518+
| `currentEraGenesisBlock` | string (hex) | Genesis block hash of the current era |
1519+
| `currentEraGenesisTime` | string (ISO 8601) | Start time of the current era |
1520+
1521+
Additionally, `slotDuration` (slot duration in milliseconds) is included for protocol versions 1–5, and `concordiumBFTStatus` is included for protocol version 6 and later.
1522+
1523+
Example response (protocol version 6+):
1524+
1525+
```json
1526+
{
1527+
"bestBlock": "63e2571547f8e9b7dbef849ab5fce5eae7fe96a1ab94b52e1adcb62adcab3e42",
1528+
"bestBlockHeight": 12345678,
1529+
"genesisBlock": "853288fa5a45554d3cbbf8a756b85abcbfddf28e752b13223eb747209a4d0d3c",
1530+
"genesisTime": "2021-06-09T10:00:00Z",
1531+
"lastFinalizedBlock": "a5e75c2419f539dfbde1fcc41c2c2b8dd1b9f0a0d4a2fd3d5e52c75a1b00000",
1532+
"lastFinalizedBlockHeight": 12345677,
1533+
"lastFinalizedTime": "2024-01-15T12:00:00Z",
1534+
"epochDuration": 3600000,
1535+
"protocolVersion": 6,
1536+
"genesisIndex": 5,
1537+
"currentEraGenesisBlock": "9dd9aee09a3b6d9c3f48e4f3df4f8b2c1e4d7a9b2f6c8e1d3a5b7c9e2f4a6b8",
1538+
"currentEraGenesisTime": "2024-01-01T00:00:00Z",
1539+
"concordiumBFTStatus": {
1540+
"currentTimeoutDuration": 10000,
1541+
"currentRound": 42,
1542+
"currentEpoch": 100,
1543+
"triggerBlockTime": "2024-01-15T12:00:00Z"
1544+
}
1545+
}
1546+
```
14991547

15001548
# Deployment
15011549

src/Proxy.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ mkYesod
324324
/v0/keyAccounts/#Text KeyAccounts GET
325325
/v0/transakOnRamp TransakOnRamp POST
326326
/v0/genesisHash GenesisHash GET
327+
/v0/consensusInfo ConsensusInfoR GET
327328
|]
328329

329330
instance Yesod Proxy where
@@ -2979,6 +2980,40 @@ getGenesisHash =
29792980
let genesisBlock = object ["genesis_block" .= csGenesisBlock cInfo]
29802981
sendResponse $ toJSON genesisBlock
29812982

2983+
-- | Returns the current consensus status from the node.
2984+
-- This includes key information about the chain state such as the last finalized block,
2985+
-- best block, protocol version, and timing parameters.
2986+
getConsensusInfoR :: Handler TypedContent
2987+
getConsensusInfoR =
2988+
runGRPC getConsensusInfo $ \cInfo -> do
2989+
let consensusInfoObject =
2990+
object $
2991+
[ "bestBlock" .= csBestBlock cInfo,
2992+
"bestBlockHeight" .= csBestBlockHeight cInfo,
2993+
"genesisBlock" .= csGenesisBlock cInfo,
2994+
"genesisTime" .= csGenesisTime cInfo,
2995+
"lastFinalizedBlock" .= csLastFinalizedBlock cInfo,
2996+
"lastFinalizedBlockHeight" .= csLastFinalizedBlockHeight cInfo,
2997+
"lastFinalizedTime" .= csLastFinalizedTime cInfo,
2998+
"epochDuration" .= csEpochDuration cInfo,
2999+
"protocolVersion" .= csProtocolVersion cInfo,
3000+
"genesisIndex" .= csGenesisIndex cInfo,
3001+
"currentEraGenesisBlock" .= csCurrentEraGenesisBlock cInfo,
3002+
"currentEraGenesisTime" .= csCurrentEraGenesisTime cInfo
3003+
]
3004+
++ maybe [] (\sd -> ["slotDuration" .= sd]) (csSlotDuration cInfo)
3005+
++ maybe [] (\bft -> ["concordiumBFTStatus" .= bftObject bft]) (csConcordiumBFTStatus cInfo)
3006+
$(logOther "Trace") "Successfully got consensus info."
3007+
sendResponse $ toJSON consensusInfoObject
3008+
where
3009+
bftObject bft =
3010+
object
3011+
[ "currentTimeoutDuration" .= cbftsCurrentTimeoutDuration bft,
3012+
"currentRound" .= cbftsCurrentRound bft,
3013+
"currentEpoch" .= cbftsCurrentEpoch bft,
3014+
"triggerBlockTime" .= cbftsTriggerBlockTime bft
3015+
]
3016+
29823017
-- | Create a Transak on-ramp session. This requires an "address" parameter to be specified, which
29833018
-- will be the address of the account to which the purchased funds will be sent.
29843019
postTransakOnRamp :: Handler TypedContent

0 commit comments

Comments
 (0)