Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1199.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`/v1/stats/tx_volume` Endpoint returns tx_volume for all layers
20 changes: 20 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,26 @@ paths:
$ref: '#/components/schemas/RoflMarketInstanceList'
<<: *common_error_responses

/stats/tx_volume:
get:
summary: |
Returns a timeline of the transaction volume at the chosen granularity
combined for all layers.
parameters:
- *limit
- *offset
- *window_size_seconds
- *window_step_seconds
responses:
'200':
description: |
A JSON object containing a list of TPS values for each interval.
content:
application/json:
schema:
$ref: '#/components/schemas/TxVolumeList'
<<: *common_error_responses

/{layer}/stats/tx_volume:
get:
summary: |
Expand Down
16 changes: 15 additions & 1 deletion api/v1/strict_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,27 @@ func (srv *StrictServerImpl) GetConsensusProposalsProposalIdVotes(ctx context.Co
return apiTypes.GetConsensusProposalsProposalIdVotes200JSONResponse(*votes), nil
}

func (srv *StrictServerImpl) GetStatsTxVolume(ctx context.Context, request apiTypes.GetStatsTxVolumeRequestObject) (apiTypes.GetStatsTxVolumeResponseObject, error) {
params := apiTypes.GetLayerStatsTxVolumeParams{
WindowStepSeconds: request.Params.WindowStepSeconds,
WindowSizeSeconds: request.Params.WindowSizeSeconds,
Limit: request.Params.Limit,
Offset: request.Params.Offset,
}
volumeList, err := srv.dbClient.TxVolumes(ctx, nil, params)
if err != nil {
return nil, err
}
return apiTypes.GetStatsTxVolume200JSONResponse(*volumeList), nil
}

func (srv *StrictServerImpl) GetLayerStatsTxVolume(ctx context.Context, request apiTypes.GetLayerStatsTxVolumeRequestObject) (apiTypes.GetLayerStatsTxVolumeResponseObject, error) {
// Additional param validation.
if !request.Layer.IsValid() {
return nil, &apiTypes.InvalidParamFormatError{ParamName: "layer", Err: fmt.Errorf("not a valid enum value: %s", request.Layer)}
}

volumeList, err := srv.dbClient.TxVolumes(ctx, request.Layer, request.Params)
volumeList, err := srv.dbClient.TxVolumes(ctx, &request.Layer, request.Params)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime
}

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

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

var l *common.Layer
if layer != nil {
l = common.Ptr(translateLayer(*layer))
}
rows, err := c.db.Query(
ctx,
query,
translateLayer(layer),
l,
p.Limit,
p.Offset,
)
Expand Down
36 changes: 27 additions & 9 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,29 +1194,47 @@ const (

// FineTxVolumes returns the fine-grained query for 5-minute sampled tx volume windows.
FineTxVolumes = `
SELECT window_end, tx_volume
FROM stats.min5_tx_volume
WHERE layer = $1::text
SELECT
window_end,
SUM(tx_volume) AS tx_volume
FROM
stats.min5_tx_volume
WHERE
($1::text IS NULL OR layer = $1::text)
GROUP BY
window_end
ORDER BY
window_end DESC
LIMIT $2::bigint
OFFSET $3::bigint`

// FineDailyTxVolumes returns the query for daily tx volume windows.
FineDailyTxVolumes = `
SELECT window_end, tx_volume
FROM stats.daily_tx_volume
WHERE layer = $1::text
SELECT
window_end,
SUM(tx_volume) AS tx_volume
FROM
stats.daily_tx_volume
WHERE
($1::text IS NULL OR layer = $1::text)
GROUP BY
window_end
ORDER BY
window_end DESC
LIMIT $2::bigint
OFFSET $3::bigint`

// DailyTxVolumes returns the query for daily sampled daily tx volume windows.
DailyTxVolumes = `
SELECT window_end, tx_volume
FROM stats.daily_tx_volume
WHERE (layer = $1::text AND (window_end AT TIME ZONE 'UTC')::time = '00:00:00')
SELECT
window_end,
SUM(tx_volume) AS tx_volume
FROM
stats.daily_tx_volume
WHERE
($1::text IS NULL OR layer = $1::text) AND (window_end AT TIME ZONE 'UTC')::time = '00:00:00'
GROUP BY
window_end
ORDER BY
window_end DESC
LIMIT $2::bigint
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/common_test_cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ commonTestCases=(
'accounts_extraneous_key /v1/consensus/accounts?foo=bar'

'recent_blocks /v1/recent_blocks'
'tx_volume_all_layers /v1/stats/tx_volume'

'blocks /v1/consensus/blocks'
'bad_account /v1/consensus/accounts/oasis1aaaaaaa'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"window_size_seconds": 86400,
"windows": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"window_size_seconds": 86400,
"windows": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"window_size_seconds": 86400,
"windows": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"window_size_seconds": 86400,
"windows": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

Loading