Skip to content

Commit bec37a7

Browse files
committed
Use VersionedCollapsingMergeTree and insert based deletes
1 parent c9db79f commit bec37a7

14 files changed

+372
-334
lines changed

api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type QueryParams struct {
4444

4545
// @Description Flag to enable abi decoding of tx data
4646
Decode bool `schema:"decode"`
47+
// @Description Flag to force consistent data at the expense of query speed
48+
ForceConsistentData bool `schema:"force_consistent_data"`
4749
}
4850

4951
// Meta represents metadata for a query response

internal/common/block.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66

77
type Block struct {
88
ChainId *big.Int `json:"chain_id" ch:"chain_id"`
9-
Number *big.Int `json:"number" ch:"number"`
9+
Number *big.Int `json:"block_number" ch:"block_number"`
1010
Hash string `json:"hash" ch:"hash"`
1111
ParentHash string `json:"parent_hash" ch:"parent_hash"`
12-
Timestamp uint64 `json:"timestamp" ch:"timestamp"`
12+
Timestamp uint64 `json:"block_timestamp" ch:"block_timestamp"`
1313
Nonce string `json:"nonce" ch:"nonce"`
1414
Sha3Uncles string `json:"sha3_uncles" ch:"sha3_uncles"`
1515
MixHash string `json:"mix_hash" ch:"mix_hash"`
@@ -27,6 +27,8 @@ type Block struct {
2727
GasUsed *big.Int `json:"gas_used" ch:"gas_used"`
2828
WithdrawalsRoot string `json:"withdrawals_root" ch:"withdrawals_root"`
2929
BaseFeePerGas uint64 `json:"base_fee_per_gas" ch:"base_fee_per_gas"`
30+
Sign int8 `json:"sign" ch:"sign"`
31+
InsertTimestamp uint64 `json:"insert_timestamp" ch:"insert_timestamp"`
3032
}
3133

3234
type BlockData struct {

internal/common/log.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type Log struct {
2525
Topic1 string `json:"topic_1" ch:"topic_1"`
2626
Topic2 string `json:"topic_2" ch:"topic_2"`
2727
Topic3 string `json:"topic_3" ch:"topic_3"`
28+
Sign int8 `json:"sign" ch:"sign"`
29+
InsertTimestamp uint64 `json:"insert_timestamp" ch:"insert_timestamp"`
2830
}
2931

3032
func (l *Log) GetTopic(index int) (string, error) {

internal/common/trace.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Trace struct {
2626
Author string `json:"author" ch:"author"`
2727
RewardType string `json:"reward_type" ch:"reward_type"`
2828
RefundAddress string `json:"refund_address" ch:"refund_address"`
29+
Sign int8 `json:"sign" ch:"sign"`
30+
InsertTimestamp uint64 `json:"insert_timestamp" ch:"insert_timestamp"`
2931
}
3032

3133
type RawTraces = []map[string]interface{}

internal/common/transaction.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type Transaction struct {
4040
BlobGasPrice *big.Int `json:"blob_gas_price" ch:"blob_gas_price" swaggertype:"string"`
4141
LogsBloom *string `json:"logs_bloom" ch:"logs_bloom"`
4242
Status *uint64 `json:"status" ch:"status"`
43+
Sign int8 `json:"sign" ch:"sign"`
44+
InsertTimestamp uint64 `json:"insert_timestamp" ch:"insert_timestamp"`
4345
}
4446

4547
type DecodedTransactionData struct {

internal/handlers/blocks_handlers.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type BlockModel struct {
4848
// @Param page query int false "Page number for pagination"
4949
// @Param limit query int false "Number of items per page" default(5)
5050
// @Param aggregate query []string false "List of aggregate functions to apply"
51+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
5152
// @Success 200 {object} api.QueryResponse{data=[]BlockModel}
5253
// @Failure 400 {object} api.Error
5354
// @Failure 401 {object} api.Error
@@ -79,12 +80,13 @@ func handleBlocksRequest(c *gin.Context) {
7980

8081
// Prepare the QueryFilter
8182
qf := storage.QueryFilter{
82-
FilterParams: queryParams.FilterParams,
83-
ChainId: chainId,
84-
SortBy: queryParams.SortBy,
85-
SortOrder: queryParams.SortOrder,
86-
Page: queryParams.Page,
87-
Limit: queryParams.Limit,
83+
FilterParams: queryParams.FilterParams,
84+
ChainId: chainId,
85+
SortBy: queryParams.SortBy,
86+
SortOrder: queryParams.SortOrder,
87+
Page: queryParams.Page,
88+
Limit: queryParams.Limit,
89+
ForceConsistentData: queryParams.ForceConsistentData,
8890
}
8991

9092
// Initialize the QueryResult

internal/handlers/logs_handlers.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type DecodedLogModel struct {
6161
// @Param page query int false "Page number for pagination"
6262
// @Param limit query int false "Number of items per page" default(5)
6363
// @Param aggregate query []string false "List of aggregate functions to apply"
64+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
6465
// @Success 200 {object} api.QueryResponse{data=[]LogModel}
6566
// @Failure 400 {object} api.Error
6667
// @Failure 401 {object} api.Error
@@ -85,6 +86,7 @@ func GetLogs(c *gin.Context) {
8586
// @Param page query int false "Page number for pagination"
8687
// @Param limit query int false "Number of items per page" default(5)
8788
// @Param aggregate query []string false "List of aggregate functions to apply"
89+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
8890
// @Success 200 {object} api.QueryResponse{data=[]LogModel}
8991
// @Failure 400 {object} api.Error
9092
// @Failure 401 {object} api.Error
@@ -111,6 +113,7 @@ func GetLogsByContract(c *gin.Context) {
111113
// @Param page query int false "Page number for pagination"
112114
// @Param limit query int false "Number of items per page" default(5)
113115
// @Param aggregate query []string false "List of aggregate functions to apply"
116+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
114117
// @Success 200 {object} api.QueryResponse{data=[]DecodedLogModel}
115118
// @Failure 400 {object} api.Error
116119
// @Failure 401 {object} api.Error
@@ -154,14 +157,15 @@ func handleLogsRequest(c *gin.Context, contractAddress, signature string, eventA
154157

155158
// Prepare the QueryFilter
156159
qf := storage.QueryFilter{
157-
FilterParams: queryParams.FilterParams,
158-
ContractAddress: contractAddress,
159-
Signature: signatureHash,
160-
ChainId: chainId,
161-
SortBy: queryParams.SortBy,
162-
SortOrder: queryParams.SortOrder,
163-
Page: queryParams.Page,
164-
Limit: queryParams.Limit,
160+
FilterParams: queryParams.FilterParams,
161+
ContractAddress: contractAddress,
162+
Signature: signatureHash,
163+
ChainId: chainId,
164+
SortBy: queryParams.SortBy,
165+
SortOrder: queryParams.SortOrder,
166+
Page: queryParams.Page,
167+
Limit: queryParams.Limit,
168+
ForceConsistentData: queryParams.ForceConsistentData,
165169
}
166170

167171
// Initialize the QueryResult

internal/handlers/transactions_handlers.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type DecodedTransactionModel struct {
7373
// @Param page query int false "Page number for pagination"
7474
// @Param limit query int false "Number of items per page" default(5)
7575
// @Param aggregate query []string false "List of aggregate functions to apply"
76+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
7677
// @Success 200 {object} api.QueryResponse{data=[]TransactionModel}
7778
// @Failure 400 {object} api.Error
7879
// @Failure 401 {object} api.Error
@@ -97,6 +98,7 @@ func GetTransactions(c *gin.Context) {
9798
// @Param page query int false "Page number for pagination"
9899
// @Param limit query int false "Number of items per page" default(5)
99100
// @Param aggregate query []string false "List of aggregate functions to apply"
101+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
100102
// @Success 200 {object} api.QueryResponse{data=[]TransactionModel}
101103
// @Failure 400 {object} api.Error
102104
// @Failure 401 {object} api.Error
@@ -123,6 +125,7 @@ func GetTransactionsByContract(c *gin.Context) {
123125
// @Param page query int false "Page number for pagination"
124126
// @Param limit query int false "Number of items per page" default(5)
125127
// @Param aggregate query []string false "List of aggregate functions to apply"
128+
// @Param force_consistent_data query bool false "Force consistent data at the expense of query speed"
126129
// @Success 200 {object} api.QueryResponse{data=[]DecodedTransactionModel}
127130
// @Failure 400 {object} api.Error
128131
// @Failure 401 {object} api.Error
@@ -166,14 +169,15 @@ func handleTransactionsRequest(c *gin.Context, contractAddress, signature string
166169

167170
// Prepare the QueryFilter
168171
qf := storage.QueryFilter{
169-
FilterParams: queryParams.FilterParams,
170-
ContractAddress: contractAddress,
171-
Signature: signatureHash,
172-
ChainId: chainId,
173-
SortBy: queryParams.SortBy,
174-
SortOrder: queryParams.SortOrder,
175-
Page: queryParams.Page,
176-
Limit: queryParams.Limit,
172+
FilterParams: queryParams.FilterParams,
173+
ContractAddress: contractAddress,
174+
Signature: signatureHash,
175+
ChainId: chainId,
176+
SortBy: queryParams.SortBy,
177+
SortOrder: queryParams.SortOrder,
178+
Page: queryParams.Page,
179+
Limit: queryParams.Limit,
180+
ForceConsistentData: queryParams.ForceConsistentData,
177181
}
178182

179183
// Initialize the QueryResult

0 commit comments

Comments
 (0)