Skip to content

Commit

Permalink
Merge branch 'develop' into fix/evmhook-check-log-len
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Jan 11, 2024
2 parents 02e6c74 + b2fbd84 commit 6acffac
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 52 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

### Fixes

* [1554](https://github.com/zeta-chain/node/pull/1554) - Screen out unconfirmed UTXOs that are not created by TSS itself
* [1560](https://github.com/zeta-chain/node/issues/1560) - Zetaclient post evm-chain outtx hashes only when receipt is available
* [1516](https://github.com/zeta-chain/node/issues/1516) - Unprivileged outtx tracker removal
* [1537](https://github.com/zeta-chain/node/issues/1537) - Sanity check events of ZetaSent/ZetaReceived/ZetaRevertedWithdrawn/Deposited
* [1530](https://github.com/zeta-chain/node/pull/1530) - Outbound tx confirmation/inclusion enhancement
* [1496](https://github.com/zeta-chain/node/issues/1496) - post block header for enabled EVM chains only
Expand All @@ -36,9 +39,11 @@
* [1522](https://github.com/zeta-chain/node/pull/1522/files) - block `distribution` module account from receiving zeta
* [1528](https://github.com/zeta-chain/node/pull/1528) - fix panic caused on decoding malformed BTC addresses
* [1556](https://github.com/zeta-chain/node/pull/1556) - add emptiness check for topic array in event parsing
* [1555](https://github.com/zeta-chain/node/pull/1555) - Reduce websocket message limit to 10MB

### Refactoring

* [1552](https://github.com/zeta-chain/node/pull/1552) - requires group2 to enable header verification
* [1211](https://github.com/zeta-chain/node/issues/1211) - use `grpc` and `msg` for query and message files
* refactor cctx scheduler - decouple evm cctx scheduler from btc cctx scheduler
* move tss state from crosschain to observer
Expand All @@ -52,6 +57,8 @@
* Remove chain id from the index for observer mapper and rename it to observer set.
* Add logger to smoke tests
* [1521](https://github.com/zeta-chain/node/pull/1521) - replace go-tss lib version with one that reverts back to thorchain tss-lib
* [1558](https://github.com/zeta-chain/node/pull/1558) - change log level for gas stability pool iteration error
* Update --ledger flag hint

### Chores
* [1446](https://github.com/zeta-chain/node/pull/1446) - renamed file `zetaclientd/aux.go` to `zetaclientd/utils.go` to avoid complaints from go package resolver.
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetacored/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func processError(err error) {
if strings.Contains(err.Error(), "cannot set custom bip32 path with ledger") {
printNotice([]string{
"note: --ledger flag can't be used with Ethereum HD path (used by default)",
"use --hd-path=\"\" in the command to use Cosmos HD path",
"Please set a blank path with --hd-path=\"\" to use Cosmos HD path instead.",
})
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
)

const (
messageSizeLimit = 32 * 1024 * 1024 // 32MB
messageSizeLimit = 10 * 1024 * 1024 // 10MB

)

Expand Down
30 changes: 18 additions & 12 deletions x/crosschain/keeper/msg_server_add_to_outtx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO
return nil, observertypes.ErrSupportedChains
}

// the cctx must exist
cctx, err := k.CctxByNonce(ctx, &types.QueryGetCctxByNonceRequest{
ChainID: msg.ChainId,
Nonce: msg.Nonce,
})
if err != nil {
return nil, cosmoserrors.Wrap(err, "CcxtByNonce failed")
}
if cctx == nil || cctx.CrossChainTx == nil {
return nil, cosmoserrors.Wrapf(types.ErrCannotFindCctx, "no corresponding cctx found for chain %d, nonce %d", msg.ChainId, msg.Nonce)
}
// tracker submission is only allowed when the cctx is pending
if !IsPending(*cctx.CrossChainTx) {
// garbage tracker (for any reason) is harmful to outTx observation and should be removed
k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce)
return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil
}

if msg.Proof == nil { // without proof, only certain accounts can send this message
adminPolicyAccount := k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1)
isAdmin := msg.Creator == adminPolicyAccount
Expand All @@ -53,18 +71,6 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO
isProven = true
}

cctx, err := k.CctxByNonce(ctx, &types.QueryGetCctxByNonceRequest{
ChainID: msg.ChainId,
Nonce: msg.Nonce,
})
if err != nil || cctx == nil || cctx.CrossChainTx == nil {
return nil, cosmoserrors.Wrap(types.ErrCannotFindCctx, "cannot add out tx: no corresponding cctx found")
}
if !IsPending(*cctx.CrossChainTx) {
k.RemoveOutTxTracker(ctx, msg.ChainId, msg.Nonce)
return &types.MsgAddToOutTxTrackerResponse{IsRemoved: true}, nil
}

tracker, found := k.GetOutTxTracker(ctx, msg.ChainId, msg.Nonce)
hash := types.TxHashList{
TxHash: msg.TxHash,
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (AppModule) ConsensusVersion() uint64 { return 4 }
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
err := am.keeper.IterateAndUpdateCctxGasPrice(ctx)
if err != nil {
ctx.Logger().Error("Error iterating and updating pending cctx gas price", "err", err.Error())
ctx.Logger().Info("Error iterating and updating pending cctx gas price", "err", err.Error())
}
}

Expand Down
7 changes: 1 addition & 6 deletions x/observer/keeper/msg_server_update_crosschain_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import (
func (k msgServer) UpdateCrosschainFlags(goCtx context.Context, msg *types.MsgUpdateCrosschainFlags) (*types.MsgUpdateCrosschainFlagsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

requiredGroup := types.Policy_Type_group1
if msg.IsInboundEnabled || msg.IsOutboundEnabled || msg.GasPriceIncreaseFlags != nil {
requiredGroup = types.Policy_Type_group2
}

// check permission
if msg.Creator != k.GetParams(ctx).GetAdminPolicyAccount(requiredGroup) {
if msg.Creator != k.GetParams(ctx).GetAdminPolicyAccount(msg.GetRequiredGroup()) {
return &types.MsgUpdateCrosschainFlagsResponse{}, types.ErrNotAuthorizedPolicy
}

Expand Down
33 changes: 31 additions & 2 deletions x/observer/keeper/msg_server_update_crosschain_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2)

// can update flags again
Expand All @@ -71,7 +72,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
},
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
IsBtcTypeChainEnabled: true,
},
})
require.NoError(t, err)
Expand All @@ -84,7 +85,8 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)
require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// group 1 should be able to disable inbound and outbound
setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1)

Expand All @@ -103,6 +105,33 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength)
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// group 1 should be able to disable header verification
setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1)

// if gas price increase flags is nil, it should not be updated
_, err = srv.UpdateCrosschainFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateCrosschainFlags{
Creator: admin,
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
})
require.NoError(t, err)

flags, found = k.GetCrosschainFlags(ctx)
require.True(t, found)
require.False(t, flags.IsInboundEnabled)
require.False(t, flags.IsOutboundEnabled)
require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength)
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// if flags are not defined, default should be used
k.RemoveCrosschainFlags(ctx)
Expand Down
18 changes: 18 additions & 0 deletions x/observer/types/message_crosschain_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ func (gpf GasPriceIncreaseFlags) Validate() error {
}
return nil
}

// GetRequiredGroup returns the required group policy for the message to execute the message
// Group 1 should only be able to stop or disable functiunalities in case of emergency
// this concerns disabling inbound and outbound txs or block header verification
// every other action requires group 2
func (msg *MsgUpdateCrosschainFlags) GetRequiredGroup() Policy_Type {
if msg.IsInboundEnabled || msg.IsOutboundEnabled {
return Policy_Type_group2
}
if msg.GasPriceIncreaseFlags != nil {
return Policy_Type_group2
}
if msg.BlockHeaderVerificationFlags != nil && (msg.BlockHeaderVerificationFlags.IsEthTypeChainEnabled || msg.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) {
return Policy_Type_group2

}
return Policy_Type_group1
}
115 changes: 115 additions & 0 deletions x/observer/types/message_crosschain_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,118 @@ func TestGasPriceIncreaseFlags_Validate(t *testing.T) {
})
}
}

func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) {
tests := []struct {
name string
msg types.MsgUpdateCrosschainFlags
want types.Policy_Type
}{
{
name: "disabling outbound and inbound allows group 1",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: nil,
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group1,
},
{
name: "disabling outbound and inbound and block header verification allows group 1",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group1,
},
{
name: "updating gas price increase flags requires group 2",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
GasPriceIncreaseFlags: &types.GasPriceIncreaseFlags{
EpochLength: 1,
RetryInterval: 1,
GasPriceIncreasePercent: 1,
MaxPendingCctxs: 100,
},
},
want: types.Policy_Type_group2,
},
{
name: "enabling inbound requires group 2",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: true,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group2,
},
{
name: "enabling outbound requires group 2",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: true,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group2,
},
{
name: "enabling eth header verification requires group 2",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: true,
IsBtcTypeChainEnabled: false,
},
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group2,
},
{
name: "enabling btc header verification requires group 2",
msg: types.MsgUpdateCrosschainFlags{
Creator: sample.AccAddress(),
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: true,
},
GasPriceIncreaseFlags: nil,
},
want: types.Policy_Type_group2,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, tt.msg.GetRequiredGroup())
})
}
}
Loading

0 comments on commit 6acffac

Please sign in to comment.