Skip to content

Commit a70eb8c

Browse files
committed
Merge remote-tracking branch 'origin/indexing_latency_method'
2 parents c820c91 + df80dae commit a70eb8c

13 files changed

+583
-151
lines changed

api/openapi.json

+41
Original file line numberDiff line numberDiff line change
@@ -4416,6 +4416,23 @@
44164416
],
44174417
"type": "object"
44184418
},
4419+
"ServiceStatus": {
4420+
"properties": {
4421+
"indexing_latency": {
4422+
"example": 100,
4423+
"type": "integer"
4424+
},
4425+
"rest_online": {
4426+
"default": true,
4427+
"type": "boolean"
4428+
}
4429+
},
4430+
"required": [
4431+
"indexing_latency",
4432+
"rest_online"
4433+
],
4434+
"type": "object"
4435+
},
44194436
"SizeLimitsConfig": {
44204437
"properties": {
44214438
"max_acc_state_bits": {
@@ -8940,6 +8957,30 @@
89408957
]
89418958
}
89428959
},
8960+
"/v2/status": {
8961+
"get": {
8962+
"description": "Reduce indexing latency",
8963+
"operationId": "reduceIndexingLatency",
8964+
"responses": {
8965+
"200": {
8966+
"content": {
8967+
"application/json": {
8968+
"schema": {
8969+
"$ref": "#/components/schemas/ServiceStatus"
8970+
}
8971+
}
8972+
},
8973+
"description": "indexing latency"
8974+
},
8975+
"default": {
8976+
"$ref": "#/components/responses/Error"
8977+
}
8978+
},
8979+
"tags": [
8980+
"Blockchain"
8981+
]
8982+
}
8983+
},
89438984
"/v2/storage/providers": {
89448985
"get": {
89458986
"description": "Get TON storage providers deployed to the blockchain.",

api/openapi.yml

+27-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ servers:
1111
- url: "https://testnet.tonapi.io"
1212
- url: "http://localhost:8081"
1313
paths:
14+
/v2/status:
15+
get:
16+
description: Reduce indexing latency
17+
operationId: reduceIndexingLatency
18+
tags:
19+
- Blockchain
20+
responses:
21+
'200':
22+
description: indexing latency
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/ServiceStatus'
27+
'default':
28+
$ref: '#/components/responses/Error'
1429
/v2/blockchain/blocks/{block_id}:
1530
get:
1631
description: Get blockchain block data
@@ -2982,7 +2997,18 @@ components:
29822997
$ref: '#/components/schemas/BlockCurrencyCollection'
29832998
minted:
29842999
$ref: '#/components/schemas/BlockCurrencyCollection'
2985-
3000+
ServiceStatus:
3001+
type: object
3002+
required:
3003+
- indexing_latency
3004+
- rest_online
3005+
properties:
3006+
rest_online:
3007+
type: boolean
3008+
default: true
3009+
indexing_latency:
3010+
type: integer
3011+
example: 100
29863012
BlockchainBlock:
29873013
type: object
29883014
required:

pkg/api/blockchain_handlers.go

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ import (
2121
"github.com/tonkeeper/tongo/ton"
2222
)
2323

24+
func (h *Handler) ReduceIndexingLatency(ctx context.Context) (*oas.ServiceStatus, error) {
25+
indexingLatency, err := h.storage.ReduceIndexingLatency(ctx)
26+
if errors.Is(err, core.ErrEntityNotFound) {
27+
return nil, toError(http.StatusInternalServerError, err)
28+
}
29+
var restOnline = true
30+
if err != nil {
31+
restOnline = false
32+
}
33+
return &oas.ServiceStatus{
34+
IndexingLatency: int(indexingLatency),
35+
RestOnline: restOnline,
36+
}, nil
37+
}
38+
2439
func (h *Handler) GetBlockchainBlock(ctx context.Context, params oas.GetBlockchainBlockParams) (*oas.BlockchainBlock, error) {
2540
blockID, err := ton.ParseBlockID(params.BlockID)
2641
if err != nil {

pkg/api/interfaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type storage interface {
4141
GetDnsExpiring(ctx context.Context, id tongo.AccountID, period *int) ([]core.DnsExpiring, error)
4242
GetLogs(ctx context.Context, account tongo.AccountID, destination *tlb.MsgAddress, limit int, beforeLT uint64) ([]core.Message, error)
4343
GetAccountDiff(ctx context.Context, account tongo.AccountID, startTime int64, endTime int64) (int64, error)
44+
ReduceIndexingLatency(ctx context.Context) (int64, error)
4445

4546
GetTrace(ctx context.Context, hash tongo.Bits256) (*core.Trace, error)
4647
SearchTraces(ctx context.Context, a tongo.AccountID, limit int, beforeLT, startTime, endTime *int64, initiator bool) ([]tongo.Bits256, error)

pkg/litestorage/account.go

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/ed25519"
66
"errors"
7+
"time"
78

89
"github.com/tonkeeper/tongo/tlb"
910
tongoWallet "github.com/tonkeeper/tongo/wallet"
@@ -46,3 +47,12 @@ func (s *LiteStorage) SearchAccountsByPubKey(pubKey ed25519.PublicKey) ([]tongo.
4647
func (s *LiteStorage) GetAccountDiff(ctx context.Context, account tongo.AccountID, startTime int64, endTime int64) (int64, error) {
4748
return 0, errors.New("not implemented")
4849
}
50+
51+
func (s *LiteStorage) ReduceIndexingLatency(ctx context.Context) (int64, error) {
52+
blockHeader, err := s.LastMasterchainBlockHeader(ctx)
53+
if err != nil {
54+
return 0, err
55+
}
56+
latency := time.Now().Unix() - int64(blockHeader.GenUtime)
57+
return latency, nil
58+
}

pkg/oas/oas_defaults_gen.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_handlers_gen.go

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_json_gen.go

+114
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)