Skip to content

Commit aaadff9

Browse files
authored
feat: zeta supply checks (#1358)
1 parent 4841dfd commit aaadff9

File tree

13 files changed

+1229
-262
lines changed

13 files changed

+1229
-262
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
* chore: increment handler version by @kingpinXD in https://github.com/zeta-chain/node/pull/1307
4242
* fix: begin blocker for mock mainnet by @kingpinXD in https://github.com/zeta-chain/node/pull/1308
4343

44+
### Unreleased:
45+
* add a new thread to zetaclient which checks zeta supply in all connected chains in every block
46+
4447

4548

cmd/zetaclientd/start.go

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func start(_ *cobra.Command, _ []string) error {
106106
go zetaBridge.ConfigUpdater(cfg)
107107

108108
// Generate TSS address . The Tss address is generated through Keygen ceremony. The TSS key is used to sign all outbound transactions .
109+
// The bridgePk is private key for the Hotkey. The Hotkey is used to sign all inbound transactions
109110
// Each node processes a portion of the key stored in ~/.tss by default . Custom location can be specified in config file during init.
110111
// After generating the key , the address is set on the zetacore
111112
bridgePk, err := zetaBridge.GetKeys().GetPrivateKey()
@@ -240,6 +241,14 @@ func start(_ *cobra.Command, _ []string) error {
240241
mo1 := mc.NewCoreObserver(zetaBridge, signerMap, chainClientMap, metrics, masterLogger, cfg, telemetryServer)
241242
mo1.MonitorCore()
242243

244+
zetaSupplyChecker, err := mc.NewZetaSupplyChecker(cfg, zetaBridge, masterLogger)
245+
if err != nil {
246+
startLogger.Err(err).Msg("NewZetaSupplyChecker")
247+
}
248+
if err == nil {
249+
zetaSupplyChecker.Start()
250+
defer zetaSupplyChecker.Stop()
251+
}
243252
startLogger.Info().Msgf("awaiting the os.Interrupt, syscall.SIGTERM signals...")
244253
ch := make(chan os.Signal, 1)
245254
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)

docs/openapi/openapi.swagger.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -26646,6 +26646,32 @@ paths:
2664626646
type: boolean
2664726647
tags:
2664826648
- Query
26649+
/zeta-chain/crosschain/cctxbyStatus/{status}:
26650+
get:
26651+
operationId: Query_CctxByStatus
26652+
responses:
26653+
"200":
26654+
description: A successful response.
26655+
schema:
26656+
$ref: '#/definitions/crosschainQueryCctxByStatusResponse'
26657+
default:
26658+
description: An unexpected error response.
26659+
schema:
26660+
$ref: '#/definitions/googlerpcStatus'
26661+
parameters:
26662+
- name: status
26663+
in: path
26664+
required: true
26665+
type: string
26666+
enum:
26667+
- PendingInbound
26668+
- PendingOutbound
26669+
- OutboundMined
26670+
- PendingRevert
26671+
- Reverted
26672+
- Aborted
26673+
tags:
26674+
- Query
2664926675
/zeta-chain/crosschain/chainNonces:
2665026676
get:
2665126677
summary: Queries a list of chainNonces items.
@@ -50834,6 +50860,14 @@ definitions:
5083450860
items:
5083550861
type: object
5083650862
$ref: '#/definitions/crosschainPendingNonces'
50863+
crosschainQueryCctxByStatusResponse:
50864+
type: object
50865+
properties:
50866+
CrossChainTx:
50867+
type: array
50868+
items:
50869+
type: object
50870+
$ref: '#/definitions/crosschainCrossChainTx'
5083750871
crosschainQueryConvertGasToZetaResponse:
5083850872
type: object
5083950873
properties:

proto/crosschain/query.proto

+11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ service Query {
143143
rpc TssHistory(QueryTssHistoryRequest) returns (QueryTssHistoryResponse) {
144144
option (google.api.http).get = "/zeta-chain/crosschain/tssHistory";
145145
}
146+
147+
rpc CctxByStatus(QueryCctxByStatusRequest) returns (QueryCctxByStatusResponse) {
148+
option (google.api.http).get = "/zeta-chain/crosschain/cctxbyStatus/{status}";
149+
}
150+
}
151+
152+
message QueryCctxByStatusRequest {
153+
CctxStatus status = 1;
154+
}
155+
message QueryCctxByStatusResponse {
156+
repeated CrossChainTx CrossChainTx = 1 [(gogoproto.nullable) = false];
146157
}
147158

148159
message QueryTssHistoryRequest {}

typescript/crosschain/query_pb.d.ts

+49-1
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,66 @@
55

66
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
77
import { Message, proto3 } from "@bufbuild/protobuf";
8+
import type { CctxStatus, CrossChainTx } from "./cross_chain_tx_pb.js";
89
import type { TSS } from "./tss_pb.js";
910
import type { Params } from "./params_pb.js";
1011
import type { OutTxTracker } from "./out_tx_tracker_pb.js";
1112
import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js";
1213
import type { InTxTracker } from "./in_tx_tracker_pb.js";
1314
import type { InTxHashToCctx } from "./in_tx_hash_to_cctx_pb.js";
14-
import type { CrossChainTx } from "./cross_chain_tx_pb.js";
1515
import type { GasPrice } from "./gas_price_pb.js";
1616
import type { ChainNonces } from "./chain_nonces_pb.js";
1717
import type { PendingNonces } from "./nonce_to_cctx_pb.js";
1818
import type { LastBlockHeight } from "./last_block_height_pb.js";
1919

20+
/**
21+
* @generated from message zetachain.zetacore.crosschain.QueryCctxByStatusRequest
22+
*/
23+
export declare class QueryCctxByStatusRequest extends Message<QueryCctxByStatusRequest> {
24+
/**
25+
* @generated from field: zetachain.zetacore.crosschain.CctxStatus status = 1;
26+
*/
27+
status: CctxStatus;
28+
29+
constructor(data?: PartialMessage<QueryCctxByStatusRequest>);
30+
31+
static readonly runtime: typeof proto3;
32+
static readonly typeName = "zetachain.zetacore.crosschain.QueryCctxByStatusRequest";
33+
static readonly fields: FieldList;
34+
35+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryCctxByStatusRequest;
36+
37+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryCctxByStatusRequest;
38+
39+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryCctxByStatusRequest;
40+
41+
static equals(a: QueryCctxByStatusRequest | PlainMessage<QueryCctxByStatusRequest> | undefined, b: QueryCctxByStatusRequest | PlainMessage<QueryCctxByStatusRequest> | undefined): boolean;
42+
}
43+
44+
/**
45+
* @generated from message zetachain.zetacore.crosschain.QueryCctxByStatusResponse
46+
*/
47+
export declare class QueryCctxByStatusResponse extends Message<QueryCctxByStatusResponse> {
48+
/**
49+
* @generated from field: repeated zetachain.zetacore.crosschain.CrossChainTx CrossChainTx = 1;
50+
*/
51+
CrossChainTx: CrossChainTx[];
52+
53+
constructor(data?: PartialMessage<QueryCctxByStatusResponse>);
54+
55+
static readonly runtime: typeof proto3;
56+
static readonly typeName = "zetachain.zetacore.crosschain.QueryCctxByStatusResponse";
57+
static readonly fields: FieldList;
58+
59+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryCctxByStatusResponse;
60+
61+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryCctxByStatusResponse;
62+
63+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryCctxByStatusResponse;
64+
65+
static equals(a: QueryCctxByStatusResponse | PlainMessage<QueryCctxByStatusResponse> | undefined, b: QueryCctxByStatusResponse | PlainMessage<QueryCctxByStatusResponse> | undefined): boolean;
66+
}
67+
2068
/**
2169
* @generated from message zetachain.zetacore.crosschain.QueryTssHistoryRequest
2270
*/

x/crosschain/keeper/keeper_cross_chain_tx.go

+23
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ func (k Keeper) CctxAll(c context.Context, req *types.QueryAllCctxRequest) (*typ
127127
return &types.QueryAllCctxResponse{CrossChainTx: sends, Pagination: pageRes}, nil
128128
}
129129

130+
func (k Keeper) CctxByStatus(c context.Context, req *types.QueryCctxByStatusRequest) (*types.QueryCctxByStatusResponse, error) {
131+
if req == nil {
132+
return nil, status.Error(codes.InvalidArgument, "invalid request")
133+
}
134+
ctx := sdk.UnwrapSDKContext(c)
135+
p := types.KeyPrefix(fmt.Sprintf("%s", types.SendKey))
136+
store := prefix.NewStore(ctx.KVStore(k.storeKey), p)
137+
138+
iterator := sdk.KVStorePrefixIterator(store, []byte{})
139+
140+
defer iterator.Close()
141+
cctxList := make([]types.CrossChainTx, 0)
142+
for ; iterator.Valid(); iterator.Next() {
143+
var val types.CrossChainTx
144+
k.cdc.MustUnmarshal(iterator.Value(), &val)
145+
if val.CctxStatus.Status == req.Status {
146+
cctxList = append(cctxList, val)
147+
}
148+
}
149+
150+
return &types.QueryCctxByStatusResponse{CrossChainTx: cctxList}, nil
151+
}
152+
130153
func (k Keeper) Cctx(c context.Context, req *types.QueryGetCctxRequest) (*types.QueryGetCctxResponse, error) {
131154
if req == nil {
132155
return nil, status.Error(codes.InvalidArgument, "invalid request")

0 commit comments

Comments
 (0)