Skip to content

Commit

Permalink
Merge branch 'develop' into fix-inbound-index
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Jan 11, 2024
2 parents 43d0091 + fde9cab commit 4470f50
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 39 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

### 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
Expand All @@ -37,9 +39,12 @@
* [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
* [1536](https://github.com/zeta-chain/node/pull/1536) - add index to check previously finalized inbounds
* [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 @@ -53,6 +58,7 @@
* 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
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
6 changes: 6 additions & 0 deletions x/crosschain/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ func (k Keeper) ParseZRC20WithdrawalEvent(ctx sdk.Context, log ethtypes.Log) (*z
if err != nil {
return nil, err
}
if len(log.Topics) == 0 {
return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: invalid log - no topics")
}
event, err := zrc20ZEVM.ParseWithdrawal(log)
if err != nil {
return nil, err
Expand Down Expand Up @@ -306,6 +309,9 @@ func ParseZetaSentEvent(log ethtypes.Log, connectorZEVM ethcommon.Address) (*con
if err != nil {
return nil, err
}
if len(log.Topics) == 0 {
return nil, fmt.Errorf("ParseZetaSentEvent: invalid log - no topics")
}
event, err := zetaConnectorZEVM.ParseZetaSent(log)
if err != nil {
return nil, err
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 4470f50

Please sign in to comment.