Skip to content

Commit dcae51a

Browse files
authored
add feegrant msg to grant-oracle cmd (#49)
* add feegrant msg to grant-oracle cmd * add disable delete future withdrawals flag (#50) * add disable delete future withdrawals flag * format
1 parent 88491e9 commit dcae51a

File tree

11 files changed

+95
-18
lines changed

11 files changed

+95
-18
lines changed

challenger/child/child.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ func NewChildV1(
5656
}
5757
}
5858

59-
func (ch *Child) Initialize(ctx context.Context, processedHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo ophosttypes.QueryBridgeResponse, challenger challenger) (time.Time, error) {
60-
_, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil, nil)
59+
func (ch *Child) Initialize(
60+
ctx context.Context,
61+
processedHeight int64,
62+
startOutputIndex uint64,
63+
host hostNode,
64+
bridgeInfo ophosttypes.QueryBridgeResponse,
65+
challenger challenger,
66+
) (time.Time, error) {
67+
_, err := ch.BaseChild.Initialize(
68+
ctx,
69+
processedHeight,
70+
startOutputIndex,
71+
bridgeInfo,
72+
nil,
73+
nil,
74+
true,
75+
)
6176
if err != nil {
6277
return time.Time{}, err
6378
}

cmd/opinitd/tx.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/spf13/cobra"
1010
"golang.org/x/sync/errgroup"
1111

12+
"cosmossdk.io/x/feegrant"
13+
1214
"github.com/cosmos/cosmos-sdk/x/authz"
1315

1416
"github.com/initia-labs/opinit-bots/bot"
@@ -69,7 +71,17 @@ func txGrantOracleCmd(baseCtx *cmdContext) *cobra.Command {
6971
return err
7072
}
7173

72-
txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg})
74+
msgAllowance, err := feegrant.NewAllowedMsgAllowance(&feegrant.BasicAllowance{}, []string{types.MsgUpdateOracleTypeUrl, types.MsgAuthzExecTypeUrl})
75+
if err != nil {
76+
return err
77+
}
78+
79+
feegrantMsg, err := feegrant.NewMsgGrantAllowance(msgAllowance, account.GetAddress(), oracleAddress)
80+
if err != nil {
81+
return err
82+
}
83+
84+
txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg, feegrantMsg})
7385
if err != nil {
7486
return errors.Wrapf(err, "simulation failed")
7587
}

executor/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
8686
"l2_start_height": 0,
8787
// StartBatchHeight is the height to start the batch. If it is 0, it will start from the latest height.
8888
// If the latest height stored in the db is not 0, this config is ignored.
89-
"batch_start_height": 0
89+
"batch_start_height": 0,
90+
// DisableDeleteFutureWithdrawal is the flag to disable the deletion of future withdrawal.
91+
// when the bot is rolled back, it will delete the future withdrawals from DB.
92+
// If it is true, it will not delete the future withdrawals.
93+
"disable_delete_future_withdrawal": false,
9094
}
9195
```
9296

executor/child/child.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,17 @@ func (ch *Child) Initialize(
6666
bridgeInfo ophosttypes.QueryBridgeResponse,
6767
keyringConfig *btypes.KeyringConfig,
6868
oracleKeyringConfig *btypes.KeyringConfig,
69+
disableDeleteFutureWithdrawals bool,
6970
) error {
70-
l2Sequence, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, keyringConfig, oracleKeyringConfig)
71+
l2Sequence, err := ch.BaseChild.Initialize(
72+
ctx,
73+
processedHeight,
74+
startOutputIndex,
75+
bridgeInfo,
76+
keyringConfig,
77+
oracleKeyringConfig,
78+
disableDeleteFutureWithdrawals,
79+
)
7180
if err != nil {
7281
return err
7382
}

executor/executor.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,16 @@ func (ex *Executor) Initialize(ctx context.Context) error {
104104
if err != nil {
105105
return err
106106
}
107-
err = ex.child.Initialize(ctx, childProcessedHeight, processedOutputIndex+1, ex.host, *bridgeInfo, childKeyringConfig, childOracleKeyringConfig)
107+
err = ex.child.Initialize(
108+
ctx,
109+
childProcessedHeight,
110+
processedOutputIndex+1,
111+
ex.host,
112+
*bridgeInfo,
113+
childKeyringConfig,
114+
childOracleKeyringConfig,
115+
ex.cfg.DisableDeleteFutureWithdrawal,
116+
)
108117
if err != nil {
109118
return err
110119
}
@@ -327,7 +336,8 @@ func (ex *Executor) getKeyringConfigs(bridgeInfo ophosttypes.QueryBridgeResponse
327336

328337
if bridgeInfo.BridgeConfig.OracleEnabled && ex.cfg.OracleBridgeExecutor != "" {
329338
childOracleKeyringConfig = &btypes.KeyringConfig{
330-
Name: ex.cfg.OracleBridgeExecutor,
339+
Name: ex.cfg.OracleBridgeExecutor,
340+
FeeGranter: childKeyringConfig,
331341
}
332342
}
333343
}

executor/types/config.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ type Config struct {
8888
// BatchStartHeight is the height to start the batch. If it is 0, it will start from the latest height.
8989
// If the latest height stored in the db is not 0, this config is ignored.
9090
BatchStartHeight int64 `json:"batch_start_height"`
91+
92+
// DisableDeleteFutureWithdrawal is the flag to disable the deletion of future withdrawal.
93+
// when the bot is rolled back, it will delete the future withdrawals from DB.
94+
// If it is true, it will not delete the future withdrawals.
95+
DisableDeleteFutureWithdrawal bool `json:"disable_delete_future_withdrawal"`
9196
}
9297

9398
func DefaultConfig() *Config {
@@ -137,10 +142,11 @@ func DefaultConfig() *Config {
137142
MaxChunkSize: 300000, // 300KB
138143
MaxSubmissionTime: 60 * 60, // 1 hour
139144

140-
DisableAutoSetL1Height: false,
141-
L1StartHeight: 0,
142-
L2StartHeight: 0,
143-
BatchStartHeight: 0,
145+
DisableAutoSetL1Height: false,
146+
L1StartHeight: 0,
147+
L2StartHeight: 0,
148+
BatchStartHeight: 0,
149+
DisableDeleteFutureWithdrawal: false,
144150
}
145151
}
146152

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
cosmossdk.io/core v0.11.1
77
cosmossdk.io/errors v1.0.1
88
cosmossdk.io/math v1.3.0
9+
cosmossdk.io/x/feegrant v0.1.1
910
cosmossdk.io/x/tx v0.13.5
1011
github.com/celestiaorg/go-square/v2 v2.0.0
1112
github.com/cometbft/cometbft v0.38.12

node/broadcaster/account.go

+13
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ func NewBroadcasterAccount(cfg btypes.BroadcasterConfig, cdc codec.Codec, txConf
9595
WithKeybase(keyBase).
9696
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
9797

98+
if keyringConfig.FeeGranter != nil {
99+
// setup keyring
100+
_, feeGranterKeyringRecord, err := cfg.GetKeyringRecord(cdc, keyringConfig.FeeGranter)
101+
if err != nil {
102+
return nil, err
103+
}
104+
105+
feeGranter, err := feeGranterKeyringRecord.GetAddress()
106+
if err != nil {
107+
return nil, err
108+
}
109+
b.txf = b.txf.WithFeeGranter(feeGranter)
110+
}
98111
return b, nil
99112
}
100113

node/broadcaster/types/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ type KeyringConfig struct {
8989
// Address of key in keyring
9090
Address string `json:"address"`
9191

92+
// FeeGranter is the fee granter.
93+
FeeGranter *KeyringConfig
94+
9295
// BuildTxWithMessages is the function to build a transaction with messages.
9396
BuildTxWithMessages BuildTxWithMessagesFn
9497

provider/child/child.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (b *BaseChild) Initialize(
107107
bridgeInfo ophosttypes.QueryBridgeResponse,
108108
keyringConfig *btypes.KeyringConfig,
109109
oracleKeyringConfig *btypes.KeyringConfig,
110+
disableDeleteFutureWithdrawals bool,
110111
) (uint64, error) {
111112
b.SetBridgeInfo(bridgeInfo)
112113

@@ -117,14 +118,16 @@ func (b *BaseChild) Initialize(
117118

118119
var l2Sequence uint64
119120
if b.node.HeightInitialized() {
120-
l2Sequence, err = b.QueryNextL2Sequence(ctx, processedHeight)
121-
if err != nil {
122-
return 0, err
123-
}
121+
if !disableDeleteFutureWithdrawals {
122+
l2Sequence, err = b.QueryNextL2Sequence(ctx, processedHeight)
123+
if err != nil {
124+
return 0, err
125+
}
124126

125-
err = b.mk.DeleteFutureFinalizedTrees(l2Sequence)
126-
if err != nil {
127-
return 0, err
127+
err = b.mk.DeleteFutureFinalizedTrees(l2Sequence)
128+
if err != nil {
129+
return 0, err
130+
}
128131
}
129132

130133
version := types.MustInt64ToUint64(processedHeight)

types/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ const (
1010
DACelestiaName = "da_celestia"
1111

1212
MsgUpdateOracleTypeUrl = "/opinit.opchild.v1.MsgUpdateOracle"
13+
MsgAuthzExecTypeUrl = "/cosmos.authz.v1beta1.MsgExec"
1314
)

0 commit comments

Comments
 (0)