Skip to content

Commit

Permalink
rename Abortedamout to ZetaqAccounting
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Nov 15, 2023
1 parent 4eef2fe commit cbc4d18
Show file tree
Hide file tree
Showing 25 changed files with 518 additions and 521 deletions.
3 changes: 1 addition & 2 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const releaseVersion = "v10.1.0"
Expand All @@ -18,7 +17,7 @@ func SetupHandlers(app *App) {
for m, mb := range app.mm.Modules {
vm[m] = mb.ConsensusVersion()
}
vm[observertypes.ModuleName] = vm[crosschaintypes.ModuleName] - 1
vm[crosschaintypes.ModuleName] = vm[crosschaintypes.ModuleName] - 1
return app.mm.RunMigrations(ctx, app.configurator, vm)
})

Expand Down
4 changes: 2 additions & 2 deletions proto/crosschain/cross_chain_tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ message InboundTxParams {
uint64 inbound_tx_finalized_zeta_height = 10;
}

message AbortedZetaAmount {
string amount = 6 [
message ZetaAccounting {
string aborted_zeta_amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
Expand Down
2 changes: 1 addition & 1 deletion proto/crosschain/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ message GenesisState {
repeated InTxHashToCctx inTxHashToCctxList = 9 [(gogoproto.nullable) = false];
repeated TSS tss_history = 10 [(gogoproto.nullable) = false];
repeated InTxTracker in_tx_tracker_list = 11 [(gogoproto.nullable) = false];
AbortedZetaAmount aborted_zeta_amount = 12 [(gogoproto.nullable) = false];
ZetaAccounting zeta_accounting = 12 [(gogoproto.nullable) = false];
}
8 changes: 4 additions & 4 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ service Query {
option (google.api.http).get = "/zeta-chain/crosschain/cctxbyStatus/{status}";
}

rpc AbortedZetaAmount(QueryAbortedZetaAmountRequest) returns (QueryAbortedZetaAmountResponse) {
rpc ZetaAccounting(QueryZetaAccountingRequest) returns (QueryZetaAccountingResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/abortedZetaAmount";
}
}

message QueryAbortedZetaAmountRequest {}
message QueryZetaAccountingRequest {}

message QueryAbortedZetaAmountResponse {
string amount = 6 [
message QueryZetaAccountingResponse {
string aborted_zeta_amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
Expand Down
20 changes: 10 additions & 10 deletions typescript/crosschain/cross_chain_tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,27 @@ export declare class InboundTxParams extends Message<InboundTxParams> {
}

/**
* @generated from message zetachain.zetacore.crosschain.AbortedZetaAmount
* @generated from message zetachain.zetacore.crosschain.ZetaAccounting
*/
export declare class AbortedZetaAmount extends Message<AbortedZetaAmount> {
export declare class ZetaAccounting extends Message<ZetaAccounting> {
/**
* @generated from field: string amount = 6;
* @generated from field: string aborted_zeta_amount = 1;
*/
amount: string;
abortedZetaAmount: string;

constructor(data?: PartialMessage<AbortedZetaAmount>);
constructor(data?: PartialMessage<ZetaAccounting>);

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

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

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

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

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

/**
Expand Down
6 changes: 3 additions & 3 deletions typescript/crosschain/genesis_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { OutTxTracker } from "./out_tx_tracker_pb.js";
import type { TSS } from "./tss_pb.js";
import type { GasPrice } from "./gas_price_pb.js";
import type { ChainNonces } from "./chain_nonces_pb.js";
import type { AbortedZetaAmount, CrossChainTx } from "./cross_chain_tx_pb.js";
import type { CrossChainTx, ZetaAccounting } from "./cross_chain_tx_pb.js";
import type { LastBlockHeight } from "./last_block_height_pb.js";
import type { InTxHashToCctx } from "./in_tx_hash_to_cctx_pb.js";
import type { InTxTracker } from "./in_tx_tracker_pb.js";
Expand Down Expand Up @@ -72,9 +72,9 @@ export declare class GenesisState extends Message<GenesisState> {
inTxTrackerList: InTxTracker[];

/**
* @generated from field: zetachain.zetacore.crosschain.AbortedZetaAmount aborted_zeta_amount = 12;
* @generated from field: zetachain.zetacore.crosschain.ZetaAccounting zeta_accounting = 12;
*/
abortedZetaAmount?: AbortedZetaAmount;
zetaAccounting?: ZetaAccounting;

constructor(data?: PartialMessage<GenesisState>);

Expand Down
2 changes: 1 addition & 1 deletion typescript/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export declare class QueryAbortedZetaAmountRequest extends Message<QueryAbortedZ
*/
export declare class QueryAbortedZetaAmountResponse extends Message<QueryAbortedZetaAmountResponse> {
/**
* @generated from field: string amount = 6;
* @generated from field: string amount = 1;
*/
amount: string;

Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetQueryCmd(_ string) *cobra.Command {
CmdPendingCctx(),
CmdListInTxTrackerByChain(),
CmdListInTxTrackers(),
CmdGetAbortedZetaAmount(),
CmdGetZetaAccounting(),
)

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func CmdGetAbortedZetaAmount() *cobra.Command {
func CmdGetZetaAccounting() *cobra.Command {
cmd := &cobra.Command{
Use: "get-aborted-zeta-amount",
Short: "Query current tss address",
Expand All @@ -18,8 +18,8 @@ func CmdGetAbortedZetaAmount() *cobra.Command {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryAbortedZetaAmountRequest{}
res, err := queryClient.AbortedZetaAmount(cmd.Context(), params)
params := &types.QueryZetaAccountingRequest{}
res, err := queryClient.ZetaAccounting(cmd.Context(), params)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
// Params
k.SetParams(ctx, genState.Params)

k.SetAbortedZetaAmount(ctx, genState.AbortedZetaAmount)
k.SetZetaAccounting(ctx, genState.ZetaAccounting)
// Set all the outTxTracker
for _, elem := range genState.OutTxTrackerList {
k.SetOutTxTracker(ctx, elem)
Expand Down Expand Up @@ -118,9 +118,9 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
}

genesis.TssHistory = k.GetAllTSS(ctx)
amount, found := k.GetAbortedZetaAmount(ctx)
amount, found := k.GetZetaAccounting(ctx)
if found {
genesis.AbortedZetaAmount = amount
genesis.ZetaAccounting = amount
}

return &genesis
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
AbortedZetaAmount: types.AbortedZetaAmount{
Amount: sdkmath.OneUint(),
ZetaAccounting: types.ZetaAccounting{
AbortedZetaAmount: sdkmath.OneUint(),
},
OutTxTrackerList: []types.OutTxTracker{
sample.OutTxTracker(t, "0"),
Expand Down
35 changes: 0 additions & 35 deletions x/crosschain/keeper/aborted_zeta_amount.go

This file was deleted.

6 changes: 3 additions & 3 deletions x/crosschain/keeper/grpc_query_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"google.golang.org/grpc/status"
)

func (k Keeper) AbortedZetaAmount(c context.Context, _ *types.QueryAbortedZetaAmountRequest) (*types.QueryAbortedZetaAmountResponse, error) {
func (k Keeper) ZetaAccounting(c context.Context, _ *types.QueryZetaAccountingRequest) (*types.QueryZetaAccountingResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
amount, found := k.GetAbortedZetaAmount(ctx)
amount, found := k.GetZetaAccounting(ctx)
if !found {
return nil, status.Error(codes.Internal, "aborted zeta amount not found")
}
return &types.QueryAbortedZetaAmountResponse{Amount: amount.Amount}, nil
return &types.QueryZetaAccountingResponse{AbortedZetaAmount: amount.AbortedZetaAmount}, nil
}

func (k Keeper) CctxAll(c context.Context, req *types.QueryAllCctxRequest) (*types.QueryAllCctxResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/keeper_cross_chain_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (k Keeper) SetCctxAndNonceToCctxAndInTxHashToCctx(ctx sdk.Context, send typ
})
}
if send.CctxStatus.Status == types.CctxStatus_Aborted {
k.AddAbortedZetaAmount(ctx, send.GetCurrentOutTxParam().Amount)
k.AddZetaAccounting(ctx, send.GetCurrentOutTxParam().Amount)
}
}

Expand Down
35 changes: 35 additions & 0 deletions x/crosschain/keeper/zeta_accountin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package keeper

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func (k Keeper) SetZetaAccounting(ctx sdk.Context, abortedZetaAmount types.ZetaAccounting) {
store := ctx.KVStore(k.storeKey)
b := k.cdc.MustMarshal(&abortedZetaAmount)
store.Set([]byte(types.ZetaAccountingKey), b)
}

func (k Keeper) GetZetaAccounting(ctx sdk.Context) (val types.ZetaAccounting, found bool) {
store := ctx.KVStore(k.storeKey)
b := store.Get([]byte(types.ZetaAccountingKey))
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}

func (k Keeper) AddZetaAccounting(ctx sdk.Context, amount sdkmath.Uint) {
zetaAccounting, found := k.GetZetaAccounting(ctx)
if !found {
zetaAccounting = types.ZetaAccounting{
AbortedZetaAmount: amount,
}
} else {
zetaAccounting.AbortedZetaAmount = zetaAccounting.AbortedZetaAmount.Add(amount)
}
k.SetZetaAccounting(ctx, zetaAccounting)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestKeeper_AddAbortedZetaAmount(t *testing.T) {
func TestKeeper_AddZetaAccounting(t *testing.T) {

t.Run("should add aborted zeta amount", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
originalAmount := sdkmath.NewUint(rand.Uint64())
k.SetAbortedZetaAmount(ctx, types.AbortedZetaAmount{
k.SetZetaAccounting(ctx, types.ZetaAccounting{
originalAmount,
})
val, found := k.GetAbortedZetaAmount(ctx)
val, found := k.GetZetaAccounting(ctx)
require.True(t, found)
require.Equal(t, originalAmount, val.Amount)
require.Equal(t, originalAmount, val.AbortedZetaAmount)
addAmount := sdkmath.NewUint(rand.Uint64())
k.AddAbortedZetaAmount(ctx, addAmount)
val, found = k.GetAbortedZetaAmount(ctx)
k.AddZetaAccounting(ctx, addAmount)
val, found = k.GetZetaAccounting(ctx)
require.True(t, found)
require.Equal(t, originalAmount.Add(addAmount), val.Amount)
require.Equal(t, originalAmount.Add(addAmount), val.AbortedZetaAmount)
})

t.Run("cant find aborted amount", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
val, found := k.GetAbortedZetaAmount(ctx)
val, found := k.GetZetaAccounting(ctx)
require.False(t, found)
require.Equal(t, types.AbortedZetaAmount{}, val)
require.Equal(t, types.ZetaAccounting{}, val)
})

t.Run("add very high zeta amount", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
highAmount := sdkmath.NewUintFromString("100000000000000000000000000000000000000000000000")
k.SetAbortedZetaAmount(ctx, types.AbortedZetaAmount{
k.SetZetaAccounting(ctx, types.ZetaAccounting{
highAmount,
})
val, found := k.GetAbortedZetaAmount(ctx)
val, found := k.GetZetaAccounting(ctx)
require.True(t, found)
require.Equal(t, highAmount, val.Amount)
require.Equal(t, highAmount, val.AbortedZetaAmount)
})

}
4 changes: 2 additions & 2 deletions x/crosschain/migrations/v4/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func MigrateStore(
abortedAmount = abortedAmount.Add(val.GetCurrentOutTxParam().Amount)
}
}
b := cdc.MustMarshal(&types.AbortedZetaAmount{Amount: abortedAmount})
b := cdc.MustMarshal(&types.ZetaAccounting{AbortedZetaAmount: abortedAmount})
store := ctx.KVStore(crossChainStoreKey)
store.Set([]byte(types.AbortedZetaAmountKey), b)
store.Set([]byte(types.ZetaAccountingKey), b)
return nil
}
4 changes: 2 additions & 2 deletions x/crosschain/migrations/v4/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func TestMigrateStore(t *testing.T) {
amount := SetCrossRandomTx(10, ctx, *k)
err := v4.MigrateStore(ctx, k.GetStoreKey(), k.GetCodec())
assert.NoError(t, err)
abortedZetaAmount, found := k.GetAbortedZetaAmount(ctx)
abortedZetaAmount, found := k.GetZetaAccounting(ctx)
assert.True(t, found)
assert.Equal(t, amount, abortedZetaAmount.Amount)
assert.Equal(t, amount, abortedZetaAmount.AbortedZetaAmount)

}

Expand Down
Loading

0 comments on commit cbc4d18

Please sign in to comment.