Skip to content

Commit

Permalink
allow authz msgupdateoracle to systemlane (#126)
Browse files Browse the repository at this point in the history
* allow authz msgupdateoracle to systemlane

* allow fee granter to free lane
  • Loading branch information
sh-cha authored Nov 18, 2024
1 parent 7fa2bce commit f0c2a63
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
10 changes: 9 additions & 1 deletion x/opchild/lanes/free.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
22 changes: 19 additions & 3 deletions x/opchild/lanes/free_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -82,5 +98,5 @@ func (tx MockTx) FeePayer() []byte {
return tx.feePayer
}
func (tx MockTx) FeeGranter() []byte {
return nil
return tx.feeGranter
}
10 changes: 9 additions & 1 deletion x/opchild/lanes/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions x/opchild/lanes/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
}))
}

0 comments on commit f0c2a63

Please sign in to comment.