From f0c2a63ff55c573a42991ba97bf59f906d7550aa Mon Sep 17 00:00:00 2001 From: Hoon <48665813+sh-cha@users.noreply.github.com> Date: Mon, 18 Nov 2024 22:31:14 +0900 Subject: [PATCH] allow authz msgupdateoracle to systemlane (#126) * allow authz msgupdateoracle to systemlane * allow fee granter to free lane --- x/opchild/lanes/free.go | 10 +++++++++- x/opchild/lanes/free_test.go | 22 +++++++++++++++++++--- x/opchild/lanes/system.go | 10 +++++++++- x/opchild/lanes/system_test.go | 23 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/x/opchild/lanes/free.go b/x/opchild/lanes/free.go index 344ec450..da6cab73 100644 --- a/x/opchild/lanes/free.go +++ b/x/opchild/lanes/free.go @@ -39,8 +39,16 @@ func (h FreeLaneMatchHandler) MatchHandler() base.MatchHandler { } else if payer, err := h.ac.BytesToString(feeTx.FeePayer()); err != nil { return false } else { + var granter string + if feeTx.FeeGranter() != nil { + granter, err = h.ac.BytesToString(feeTx.FeeGranter()) + if err != nil { + return false + } + } + for _, addr := range whitelist { - if addr == payer { + if addr == payer || addr == granter { return true } } diff --git a/x/opchild/lanes/free_test.go b/x/opchild/lanes/free_test.go index c18fcdf9..a35d4c8b 100644 --- a/x/opchild/lanes/free_test.go +++ b/x/opchild/lanes/free_test.go @@ -52,14 +52,30 @@ func Test_FreeLaneMatchHandler(t *testing.T) { require.True(t, handler(ctx, MockTx{ feePayer: []byte{3, 4, 5, 6}, })) + + require.True(t, handler(ctx, MockTx{ + feePayer: []byte{2, 3, 4, 5}, + feeGranter: []byte{0, 1, 2, 3}, + })) + + require.True(t, handler(ctx, MockTx{ + feePayer: []byte{2, 3, 4, 5}, + feeGranter: []byte{3, 4, 5, 6}, + })) + + require.False(t, handler(ctx, MockTx{ + feePayer: []byte{2, 3, 4, 5}, + feeGranter: []byte{2, 3, 5, 6}, + })) } var _ sdk.Tx = MockTx{} var _ sdk.FeeTx = &MockTx{} type MockTx struct { - msgs []sdk.Msg - feePayer []byte + msgs []sdk.Msg + feePayer []byte + feeGranter []byte } func (tx MockTx) GetMsgsV2() ([]protov2.Message, error) { @@ -82,5 +98,5 @@ func (tx MockTx) FeePayer() []byte { return tx.feePayer } func (tx MockTx) FeeGranter() []byte { - return nil + return tx.feeGranter } diff --git a/x/opchild/lanes/system.go b/x/opchild/lanes/system.go index 5e5ea1e7..627582c3 100644 --- a/x/opchild/lanes/system.go +++ b/x/opchild/lanes/system.go @@ -5,6 +5,7 @@ import ( blockbase "github.com/skip-mev/block-sdk/v2/block/base" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/initia-labs/OPinit/x/opchild/types" ) @@ -16,8 +17,15 @@ func SystemLaneMatchHandler() blockbase.MatchHandler { } for _, msg := range tx.GetMsgs() { - switch msg.(type) { + switch msg := msg.(type) { case *types.MsgUpdateOracle: + case *authz.MsgExec: + msgs, err := msg.GetMessages() + if err != nil || len(msgs) != 1 { + return false + } else if _, ok := msgs[0].(*types.MsgUpdateOracle); !ok { + return false + } default: return false } diff --git a/x/opchild/lanes/system_test.go b/x/opchild/lanes/system_test.go index c6b24570..2380cefe 100644 --- a/x/opchild/lanes/system_test.go +++ b/x/opchild/lanes/system_test.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/log" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cometbft/cometbft/proto/tendermint/types" @@ -41,4 +42,26 @@ func Test_SystemLaneMatchHandler(t *testing.T) { &banktypes.MsgSend{}, }, })) + + authzMsg := authz.NewMsgExec(nil, []sdk.Msg{ + &opchildtypes.MsgUpdateOracle{}, + }) + + // 1 system message and authz.MsgExec + require.True(t, handler(ctx, MockTx{ + msgs: []sdk.Msg{ + &authzMsg, + }, + })) + + authzMsg = authz.NewMsgExec(nil, []sdk.Msg{ + &banktypes.MsgSend{}, + }) + + // authz.MsgExec with non-system message + require.False(t, handler(ctx, MockTx{ + msgs: []sdk.Msg{ + &authzMsg, + }, + })) }