Skip to content

Commit 587e8a3

Browse files
committed
Add tx_volume across all layers
1 parent 207cdbf commit 587e8a3

File tree

14 files changed

+110
-12
lines changed

14 files changed

+110
-12
lines changed

.changelog/1199.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`/v1/stats/tx_volume` Endpoint returns tx_volume for all layers

api/spec/v1.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,26 @@ paths:
16501650
$ref: '#/components/schemas/RoflMarketInstanceList'
16511651
<<: *common_error_responses
16521652

1653+
/stats/tx_volume:
1654+
get:
1655+
summary: |
1656+
Returns a timeline of the transaction volume at the chosen granularity
1657+
combined for all layers.
1658+
parameters:
1659+
- *limit
1660+
- *offset
1661+
- *window_size_seconds
1662+
- *window_step_seconds
1663+
responses:
1664+
'200':
1665+
description: |
1666+
A JSON object containing a list of TPS values for each interval.
1667+
content:
1668+
application/json:
1669+
schema:
1670+
$ref: '#/components/schemas/TxVolumeList'
1671+
<<: *common_error_responses
1672+
16531673
/{layer}/stats/tx_volume:
16541674
get:
16551675
summary: |

api/v1/strict_server.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,27 @@ func (srv *StrictServerImpl) GetConsensusProposalsProposalIdVotes(ctx context.Co
228228
return apiTypes.GetConsensusProposalsProposalIdVotes200JSONResponse(*votes), nil
229229
}
230230

231+
func (srv *StrictServerImpl) GetStatsTxVolume(ctx context.Context, request apiTypes.GetStatsTxVolumeRequestObject) (apiTypes.GetStatsTxVolumeResponseObject, error) {
232+
params := apiTypes.GetLayerStatsTxVolumeParams{
233+
WindowStepSeconds: request.Params.WindowStepSeconds,
234+
WindowSizeSeconds: request.Params.WindowSizeSeconds,
235+
Limit: request.Params.Limit,
236+
Offset: request.Params.Offset,
237+
}
238+
volumeList, err := srv.dbClient.TxVolumes(ctx, nil, params)
239+
if err != nil {
240+
return nil, err
241+
}
242+
return apiTypes.GetStatsTxVolume200JSONResponse(*volumeList), nil
243+
}
244+
231245
func (srv *StrictServerImpl) GetLayerStatsTxVolume(ctx context.Context, request apiTypes.GetLayerStatsTxVolumeRequestObject) (apiTypes.GetLayerStatsTxVolumeResponseObject, error) {
232246
// Additional param validation.
233247
if !request.Layer.IsValid() {
234248
return nil, &apiTypes.InvalidParamFormatError{ParamName: "layer", Err: fmt.Errorf("not a valid enum value: %s", request.Layer)}
235249
}
236250

237-
volumeList, err := srv.dbClient.TxVolumes(ctx, request.Layer, request.Params)
251+
volumeList, err := srv.dbClient.TxVolumes(ctx, &request.Layer, request.Params)
238252
if err != nil {
239253
return nil, err
240254
}

storage/client/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime
29132913
}
29142914

29152915
// TxVolumes returns a list of transaction volumes per time window.
2916-
func (c *StorageClient) TxVolumes(ctx context.Context, layer apiTypes.Layer, p apiTypes.GetLayerStatsTxVolumeParams) (*TxVolumeList, error) {
2916+
func (c *StorageClient) TxVolumes(ctx context.Context, layer *apiTypes.Layer, p apiTypes.GetLayerStatsTxVolumeParams) (*TxVolumeList, error) {
29172917
var query string
29182918

29192919
switch {
@@ -2931,10 +2931,14 @@ func (c *StorageClient) TxVolumes(ctx context.Context, layer apiTypes.Layer, p a
29312931
return nil, fmt.Errorf("invalid window size parameters: %w", apiCommon.ErrBadRequest)
29322932
}
29332933

2934+
var l *common.Layer
2935+
if layer != nil {
2936+
l = common.Ptr(translateLayer(*layer))
2937+
}
29342938
rows, err := c.db.Query(
29352939
ctx,
29362940
query,
2937-
translateLayer(layer),
2941+
l,
29382942
p.Limit,
29392943
p.Offset,
29402944
)

storage/client/queries/queries.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,29 +1194,47 @@ const (
11941194

11951195
// FineTxVolumes returns the fine-grained query for 5-minute sampled tx volume windows.
11961196
FineTxVolumes = `
1197-
SELECT window_end, tx_volume
1198-
FROM stats.min5_tx_volume
1199-
WHERE layer = $1::text
1197+
SELECT
1198+
window_end,
1199+
SUM(tx_volume) AS tx_volume
1200+
FROM
1201+
stats.min5_tx_volume
1202+
WHERE
1203+
($1::text IS NULL OR layer = $1::text)
1204+
GROUP BY
1205+
window_end
12001206
ORDER BY
12011207
window_end DESC
12021208
LIMIT $2::bigint
12031209
OFFSET $3::bigint`
12041210

12051211
// FineDailyTxVolumes returns the query for daily tx volume windows.
12061212
FineDailyTxVolumes = `
1207-
SELECT window_end, tx_volume
1208-
FROM stats.daily_tx_volume
1209-
WHERE layer = $1::text
1213+
SELECT
1214+
window_end,
1215+
SUM(tx_volume) AS tx_volume
1216+
FROM
1217+
stats.daily_tx_volume
1218+
WHERE
1219+
($1::text IS NULL OR layer = $1::text)
1220+
GROUP BY
1221+
window_end
12101222
ORDER BY
12111223
window_end DESC
12121224
LIMIT $2::bigint
12131225
OFFSET $3::bigint`
12141226

12151227
// DailyTxVolumes returns the query for daily sampled daily tx volume windows.
12161228
DailyTxVolumes = `
1217-
SELECT window_end, tx_volume
1218-
FROM stats.daily_tx_volume
1219-
WHERE (layer = $1::text AND (window_end AT TIME ZONE 'UTC')::time = '00:00:00')
1229+
SELECT
1230+
window_end,
1231+
SUM(tx_volume) AS tx_volume
1232+
FROM
1233+
stats.daily_tx_volume
1234+
WHERE
1235+
($1::text IS NULL OR layer = $1::text) AND (window_end AT TIME ZONE 'UTC')::time = '00:00:00'
1236+
GROUP BY
1237+
window_end
12201238
ORDER BY
12211239
window_end DESC
12221240
LIMIT $2::bigint

tests/e2e_regression/common_test_cases.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ commonTestCases=(
4141
'accounts_extraneous_key /v1/consensus/accounts?foo=bar'
4242

4343
'recent_blocks /v1/recent_blocks'
44+
'tx_volume_all_layers /v1/stats/tx_volume'
4445

4546
'blocks /v1/consensus/blocks'
4647
'bad_account /v1/consensus/accounts/oasis1aaaaaaa'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"window_size_seconds": 86400,
3+
"windows": []
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"window_size_seconds": 86400,
3+
"windows": []
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+

0 commit comments

Comments
 (0)