Skip to content

Commit

Permalink
Merge branch 'develop' into fix/address-compare
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 authored Oct 10, 2023
2 parents 1099923 + 23d7724 commit 6fb9ed6
Show file tree
Hide file tree
Showing 27 changed files with 508 additions and 194 deletions.
14 changes: 13 additions & 1 deletion cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {

customAppTemplate, customAppConfig := initAppConfig()

return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, tmcfg.DefaultConfig())
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, initTmConfig())
},
}

Expand All @@ -107,6 +107,18 @@ func initAppConfig() (string, interface{}) {
return servercfg.AppConfig(zetacoredconfig.BaseDenom)
}

// initTmConfig overrides the default Tendermint config
func initTmConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()

// use mempool version 1 to enable tx priority
if cfg.Mempool != nil {
cfg.Mempool.Version = tmcfg.MempoolV1
}

return cfg
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig) {
rootCmd.AddCommand(
ethermintclient.ValidateChainID(
Expand Down
5 changes: 5 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50449,6 +50449,11 @@ definitions:
type: object
crosschainMsgWhitelistERC20Response:
type: object
properties:
zrc20_address:
type: string
cctx_index:
type: string
crosschainOutTxTracker:
type: object
properties:
Expand Down
3 changes: 3 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ message MsgVoteOnObservedInboundTx {

## MsgWhitelistERC20

WhitelistERC20 deploys a new zrc20, create a foreign coin object for the ERC20
and emit a crosschain tx to whitelist the ERC20 on the external chain

```proto
message MsgWhitelistERC20 {
string creator = 1;
Expand Down
5 changes: 4 additions & 1 deletion proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ message MsgWhitelistERC20 {
int64 gas_limit = 7;
}

message MsgWhitelistERC20Response {}
message MsgWhitelistERC20Response {
string zrc20_address = 1;
string cctx_index = 2;
}

message MsgAddToOutTxTracker {
string creator = 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.

10 changes: 5 additions & 5 deletions x/crosschain/keeper/cctx_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"errors"
"fmt"

cosmoserrors "cosmossdk.io/errors"
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
Expand All @@ -24,24 +24,24 @@ func (k Keeper) UpdateNonce(ctx sdk.Context, receiveChainID int64, cctx *types.C

nonce, found := k.GetChainNonces(ctx, chain.ChainName.String())
if !found {
return sdkerrors.Wrap(types.ErrCannotFindReceiverNonce, fmt.Sprintf("Chain(%s) | Identifiers : %s ", chain.ChainName.String(), cctx.LogIdentifierForCCTX()))
return cosmoserrors.Wrap(types.ErrCannotFindReceiverNonce, fmt.Sprintf("Chain(%s) | Identifiers : %s ", chain.ChainName.String(), cctx.LogIdentifierForCCTX()))
}

// SET nonce
cctx.GetCurrentOutTxParam().OutboundTxTssNonce = nonce.Nonce
tss, found := k.GetTSS(ctx)
if !found {
return sdkerrors.Wrap(types.ErrCannotFindTSSKeys, fmt.Sprintf("Chain(%s) | Identifiers : %s ", chain.ChainName.String(), cctx.LogIdentifierForCCTX()))
return cosmoserrors.Wrap(types.ErrCannotFindTSSKeys, fmt.Sprintf("Chain(%s) | Identifiers : %s ", chain.ChainName.String(), cctx.LogIdentifierForCCTX()))
}

p, found := k.GetPendingNonces(ctx, tss.TssPubkey, receiveChainID)
if !found {
return sdkerrors.Wrap(types.ErrCannotFindPendingNonces, fmt.Sprintf("chain_id %d, nonce %d", receiveChainID, nonce.Nonce))
return cosmoserrors.Wrap(types.ErrCannotFindPendingNonces, fmt.Sprintf("chain_id %d, nonce %d", receiveChainID, nonce.Nonce))
}

// #nosec G701 always in range
if p.NonceHigh != int64(nonce.Nonce) {
return sdkerrors.Wrap(types.ErrNonceMismatch, fmt.Sprintf("chain_id %d, high nonce %d, current nonce %d", receiveChainID, p.NonceHigh, nonce.Nonce))
return cosmoserrors.Wrap(types.ErrNonceMismatch, fmt.Sprintf("chain_id %d, high nonce %d, current nonce %d", receiveChainID, p.NonceHigh, nonce.Nonce))
}

nonce.Nonce++
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
Loading

0 comments on commit 6fb9ed6

Please sign in to comment.