Skip to content

Commit

Permalink
Merge branch 'develop' into fix-btc-gasrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored Oct 11, 2023
2 parents 9d4850f + a1d7be0 commit 4427252
Show file tree
Hide file tree
Showing 48 changed files with 1,490 additions and 387 deletions.
3 changes: 2 additions & 1 deletion cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func keygenTss(cfg *config.Config, tss *mc.TSS, keygenLogger zerolog.Logger) err
if err != nil {
return err
}
zetaHash, err := tss.CoreBridge.PostBlameData(&res.Blame, common.ZetaChain().ChainId, digest)
index := fmt.Sprintf("keygen-%s-%d", digest, keyGen.BlockNumber)
zetaHash, err := tss.CoreBridge.PostBlameData(&res.Blame, common.ZetaChain().ChainId, index)
if err != nil {
keygenLogger.Error().Err(err).Msg("error sending blame data to core")
return err
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 @@ -27295,6 +27295,32 @@ paths:
type: string
tags:
- Query
/zeta-chain/observer/blame_by_chain_and_nonce/{chain_id}/{nonce}:
get:
summary: Queries a list of VoterByIdentifier items.
operationId: Query_BlamesByChainAndNonce
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/observerQueryBlameByChainAndNonceResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: chain_id
in: path
required: true
type: string
format: int64
- name: nonce
in: path
required: true
type: string
format: int64
tags:
- Query
/zeta-chain/observer/blame_by_identifier/{blame_identifier}:
get:
summary: Queries a list of VoterByIdentifier items.
Expand Down Expand Up @@ -51119,6 +51145,14 @@ definitions:
$ref: '#/definitions/observerObservationType'
ballot_status:
$ref: '#/definitions/observerBallotStatus'
observerQueryBlameByChainAndNonceResponse:
type: object
properties:
blame_info:
type: array
items:
type: object
$ref: '#/definitions/observerBlame'
observerQueryBlameByIdentifierResponse:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/fungible/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ message MsgUpdateZRC20WithdrawFee {
string creator = 1;
string zrc20_address = 2;
string new_withdraw_fee = 6;
string new_gas_limit = 7;
}
```

Expand Down
2 changes: 2 additions & 0 deletions proto/fungible/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ message EventZRC20WithdrawFeeUpdated {
string old_withdraw_fee = 5;
string new_withdraw_fee = 6;
string signer = 7;
string old_gas_limit = 8;
string new_gas_limit = 9;
}

message EventZRC20PausedStatusUpdated {
Expand Down
4 changes: 4 additions & 0 deletions proto/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ message MsgUpdateZRC20WithdrawFee {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
string new_gas_limit = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}

message MsgUpdateZRC20WithdrawFeeResponse {}
Expand Down
14 changes: 14 additions & 0 deletions proto/observer/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ service Query {
option (google.api.http).get = "/zeta-chain/observer/get_all_blame_records";
}

// Queries a list of VoterByIdentifier items.
rpc BlamesByChainAndNonce(QueryBlameByChainAndNonceRequest) returns (QueryBlameByChainAndNonceResponse) {
option (google.api.http).get = "/zeta-chain/observer/blame_by_chain_and_nonce/{chain_id}/{nonce}";
}

rpc GetAllBlockHeaders(QueryAllBlockHeaderRequest) returns (QueryAllBlockHeaderResponse) {
option (google.api.http).get = "/zeta-chain/observer/get_all_block_headers";
}
Expand Down Expand Up @@ -211,6 +216,15 @@ message QueryAllBlameRecordsResponse {
repeated Blame blame_info = 1;
}

message QueryBlameByChainAndNonceRequest {
int64 chain_id = 1;
int64 nonce = 2;
}

message QueryBlameByChainAndNonceResponse {
repeated Blame blame_info = 1;
}

message QueryAllBlockHeaderRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 3 additions & 13 deletions testutil/keeper/mocks/crosschain/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/evm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions x/crosschain/keeper/gas_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) {
zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) {
zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
gasZRC20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foo", "foo")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -551,7 +551,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down
10 changes: 4 additions & 6 deletions x/crosschain/keeper/keeper_chain_nonces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"fmt"

zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -108,12 +107,11 @@ func (k msgServer) NonceVoter(goCtx context.Context, msg *types.MsgNonceVoter) (
ctx := sdk.UnwrapSDKContext(goCtx)
chain := k.zetaObserverKeeper.GetParams(ctx).GetChainFromChainID(msg.ChainId)
if chain == nil {
return nil, zetaObserverTypes.ErrSupportedChains
return nil, observertypes.ErrSupportedChains
}

ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain); !ok {
return nil, observertypes.ErrNotAuthorizedPolicy
}
chainNonce, isFound := k.GetChainNonces(ctx, chain.ChainName.String())

Expand Down
5 changes: 2 additions & 3 deletions x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ func (k msgServer) VoteOnObservedInboundTx(goCtx context.Context, msg *types.Msg
tssPub = tss.TssPubkey
}
// IsAuthorized does various checks against the list of observer mappers
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain); !ok {
return nil, observerTypes.ErrNotAuthorizedPolicy
}

index := msg.Digest()
Expand Down
5 changes: 2 additions & 3 deletions x/crosschain/keeper/keeper_cross_chain_tx_vote_outbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func (k msgServer) VoteOnObservedOutboundTx(goCtx context.Context, msg *types.Ms
return nil, err
}
//Check is msg.Creator is authorized to vote
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain); !ok {
return nil, observerTypes.ErrNotAuthorizedPolicy
}

// Check if CCTX exists
Expand Down
9 changes: 4 additions & 5 deletions x/crosschain/keeper/keeper_gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/zeta-chain/zetacore/x/crosschain/types"
zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -127,11 +127,10 @@ func (k msgServer) GasPriceVoter(goCtx context.Context, msg *types.MsgGasPriceVo

chain := k.zetaObserverKeeper.GetParams(ctx).GetChainFromChainID(msg.ChainId)
if chain == nil {
return nil, zetaObserverTypes.ErrSupportedChains
return nil, observertypes.ErrSupportedChains
}
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain); !ok {
return nil, observertypes.ErrNotAuthorizedPolicy
}
if chain == nil {
return nil, sdkerrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID : %d ", msg.ChainId))
Expand Down
7 changes: 2 additions & 5 deletions x/crosschain/keeper/keeper_out_tx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,8 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO
adminPolicyAccount := k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1)
isAdmin := msg.Creator == adminPolicyAccount

isObserver, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if err != nil {
ctx.Logger().Error("Error while checking if the account is an observer", err)
return nil, cosmoserrors.Wrap(observertypes.ErrNotAuthorized, fmt.Sprintf("error IsAuthorized %s", msg.Creator))
}
isObserver := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)

// Sender needs to be either the admin policy account or an observer
if !(isAdmin || isObserver) {
return nil, cosmoserrors.Wrap(observertypes.ErrNotAuthorized, fmt.Sprintf("Creator %s", msg.Creator))
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var (
ErrNotEnoughZetaBurnt = errorsmod.Register(ModuleName, 1109, "not enough zeta burnt")
ErrCannotFindReceiverNonce = errorsmod.Register(ModuleName, 1110, "cannot find receiver chain nonce")

ErrGasCoinNotFound = errorsmod.Register(ModuleName, 1113, "gas coin not found for SenderChain")
ErrGasCoinNotFound = errorsmod.Register(ModuleName, 1113, "gas coin not found for sender chain")
ErrUnableToParseAddress = errorsmod.Register(ModuleName, 1115, "cannot parse address and data")
ErrCannotProcessWithdrawal = errorsmod.Register(ModuleName, 1116, "cannot process withdrawal event")
ErrForeignCoinNotFound = errorsmod.Register(ModuleName, 1118, "gas coin not found for SenderChain")
ErrForeignCoinNotFound = errorsmod.Register(ModuleName, 1118, "foreign coin not found for sender chain")
ErrNotEnoughPermissions = errorsmod.Register(ModuleName, 1119, "not enough permissions for current actions")

ErrCannotFindPendingNonces = errorsmod.Register(ModuleName, 1121, "cannot find pending nonces")
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ZetaObserverKeeper interface {
SetLastObserverCount(ctx sdk.Context, lbc *zetaObserverTypes.LastObserverCount)
AddVoteToBallot(ctx sdk.Context, ballot zetaObserverTypes.Ballot, address string, observationType zetaObserverTypes.VoteType) (zetaObserverTypes.Ballot, error)
CheckIfFinalizingVote(ctx sdk.Context, ballot zetaObserverTypes.Ballot) (zetaObserverTypes.Ballot, bool)
IsAuthorized(ctx sdk.Context, address string, chain *common.Chain) (bool, error)
IsAuthorized(ctx sdk.Context, address string, chain *common.Chain) bool
FindBallot(ctx sdk.Context, index string, chain *common.Chain, observationType zetaObserverTypes.ObservationType) (ballot zetaObserverTypes.Ballot, isNew bool, err error)
AddBallotToList(ctx sdk.Context, ballot zetaObserverTypes.Ballot)
GetBlockHeader(ctx sdk.Context, hash []byte) (val common.BlockHeader, found bool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"math/big"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -146,7 +148,12 @@ func (k Keeper) TestUpdateZRC20WithdrawFee(goCtx context.Context) error {
creator := k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1)

for _, foreignCoin := range foreignCoins {
msg := types.NewMsgUpdateZRC20WithdrawFee(creator, foreignCoin.Zrc20ContractAddress, sdk.NewUint(uint64(foreignCoin.ForeignChainId)))
msg := types.NewMsgUpdateZRC20WithdrawFee(
creator,
foreignCoin.Zrc20ContractAddress,
sdk.NewUint(uint64(foreignCoin.ForeignChainId)),
math.Uint{},
)
_, err := k.UpdateZRC20WithdrawFee(ctx, msg)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 4427252

Please sign in to comment.