Skip to content

Commit

Permalink
feat: zeta supply checks (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Nov 10, 2023
1 parent 4841dfd commit aaadff9
Show file tree
Hide file tree
Showing 13 changed files with 1,229 additions and 262 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
* chore: increment handler version by @kingpinXD in https://github.com/zeta-chain/node/pull/1307
* fix: begin blocker for mock mainnet by @kingpinXD in https://github.com/zeta-chain/node/pull/1308

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



9 changes: 9 additions & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func start(_ *cobra.Command, _ []string) error {
go zetaBridge.ConfigUpdater(cfg)

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

zetaSupplyChecker, err := mc.NewZetaSupplyChecker(cfg, zetaBridge, masterLogger)
if err != nil {
startLogger.Err(err).Msg("NewZetaSupplyChecker")
}
if err == nil {
zetaSupplyChecker.Start()
defer zetaSupplyChecker.Stop()
}
startLogger.Info().Msgf("awaiting the os.Interrupt, syscall.SIGTERM signals...")
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
Expand Down
34 changes: 34 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26646,6 +26646,32 @@ paths:
type: boolean
tags:
- Query
/zeta-chain/crosschain/cctxbyStatus/{status}:
get:
operationId: Query_CctxByStatus
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryCctxByStatusResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: status
in: path
required: true
type: string
enum:
- PendingInbound
- PendingOutbound
- OutboundMined
- PendingRevert
- Reverted
- Aborted
tags:
- Query
/zeta-chain/crosschain/chainNonces:
get:
summary: Queries a list of chainNonces items.
Expand Down Expand Up @@ -50834,6 +50860,14 @@ definitions:
items:
type: object
$ref: '#/definitions/crosschainPendingNonces'
crosschainQueryCctxByStatusResponse:
type: object
properties:
CrossChainTx:
type: array
items:
type: object
$ref: '#/definitions/crosschainCrossChainTx'
crosschainQueryConvertGasToZetaResponse:
type: object
properties:
Expand Down
11 changes: 11 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ service Query {
rpc TssHistory(QueryTssHistoryRequest) returns (QueryTssHistoryResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/tssHistory";
}

rpc CctxByStatus(QueryCctxByStatusRequest) returns (QueryCctxByStatusResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/cctxbyStatus/{status}";
}
}

message QueryCctxByStatusRequest {
CctxStatus status = 1;
}
message QueryCctxByStatusResponse {
repeated CrossChainTx CrossChainTx = 1 [(gogoproto.nullable) = false];
}

message QueryTssHistoryRequest {}
Expand Down
50 changes: 49 additions & 1 deletion typescript/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,66 @@

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";
import type { CctxStatus, CrossChainTx } from "./cross_chain_tx_pb.js";
import type { TSS } from "./tss_pb.js";
import type { Params } from "./params_pb.js";
import type { OutTxTracker } from "./out_tx_tracker_pb.js";
import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js";
import type { InTxTracker } from "./in_tx_tracker_pb.js";
import type { InTxHashToCctx } from "./in_tx_hash_to_cctx_pb.js";
import type { CrossChainTx } from "./cross_chain_tx_pb.js";
import type { GasPrice } from "./gas_price_pb.js";
import type { ChainNonces } from "./chain_nonces_pb.js";
import type { PendingNonces } from "./nonce_to_cctx_pb.js";
import type { LastBlockHeight } from "./last_block_height_pb.js";

/**
* @generated from message zetachain.zetacore.crosschain.QueryCctxByStatusRequest
*/
export declare class QueryCctxByStatusRequest extends Message<QueryCctxByStatusRequest> {
/**
* @generated from field: zetachain.zetacore.crosschain.CctxStatus status = 1;
*/
status: CctxStatus;

constructor(data?: PartialMessage<QueryCctxByStatusRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryCctxByStatusRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryCctxByStatusRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryCctxByStatusRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryCctxByStatusRequest;

static equals(a: QueryCctxByStatusRequest | PlainMessage<QueryCctxByStatusRequest> | undefined, b: QueryCctxByStatusRequest | PlainMessage<QueryCctxByStatusRequest> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryCctxByStatusResponse
*/
export declare class QueryCctxByStatusResponse extends Message<QueryCctxByStatusResponse> {
/**
* @generated from field: repeated zetachain.zetacore.crosschain.CrossChainTx CrossChainTx = 1;
*/
CrossChainTx: CrossChainTx[];

constructor(data?: PartialMessage<QueryCctxByStatusResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryCctxByStatusResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryCctxByStatusResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryCctxByStatusResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryCctxByStatusResponse;

static equals(a: QueryCctxByStatusResponse | PlainMessage<QueryCctxByStatusResponse> | undefined, b: QueryCctxByStatusResponse | PlainMessage<QueryCctxByStatusResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryTssHistoryRequest
*/
Expand Down
23 changes: 23 additions & 0 deletions x/crosschain/keeper/keeper_cross_chain_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ func (k Keeper) CctxAll(c context.Context, req *types.QueryAllCctxRequest) (*typ
return &types.QueryAllCctxResponse{CrossChainTx: sends, Pagination: pageRes}, nil
}

func (k Keeper) CctxByStatus(c context.Context, req *types.QueryCctxByStatusRequest) (*types.QueryCctxByStatusResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
p := types.KeyPrefix(fmt.Sprintf("%s", types.SendKey))
store := prefix.NewStore(ctx.KVStore(k.storeKey), p)

iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()
cctxList := make([]types.CrossChainTx, 0)
for ; iterator.Valid(); iterator.Next() {
var val types.CrossChainTx
k.cdc.MustUnmarshal(iterator.Value(), &val)
if val.CctxStatus.Status == req.Status {
cctxList = append(cctxList, val)
}
}

return &types.QueryCctxByStatusResponse{CrossChainTx: cctxList}, nil
}

func (k Keeper) Cctx(c context.Context, req *types.QueryGetCctxRequest) (*types.QueryGetCctxResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
Expand Down
Loading

0 comments on commit aaadff9

Please sign in to comment.