diff --git a/challenger/child/child.go b/challenger/child/child.go index 1199ae6..ce64e03 100644 --- a/challenger/child/child.go +++ b/challenger/child/child.go @@ -56,8 +56,23 @@ func NewChildV1( } } -func (ch *Child) Initialize(ctx context.Context, processedHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo ophosttypes.QueryBridgeResponse, challenger challenger) (time.Time, error) { - _, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil, nil) +func (ch *Child) Initialize( + ctx context.Context, + processedHeight int64, + startOutputIndex uint64, + host hostNode, + bridgeInfo ophosttypes.QueryBridgeResponse, + challenger challenger, +) (time.Time, error) { + _, err := ch.BaseChild.Initialize( + ctx, + processedHeight, + startOutputIndex, + bridgeInfo, + nil, + nil, + true, + ) if err != nil { return time.Time{}, err } diff --git a/cmd/opinitd/tx.go b/cmd/opinitd/tx.go index 33d5163..ebca4cc 100644 --- a/cmd/opinitd/tx.go +++ b/cmd/opinitd/tx.go @@ -9,6 +9,8 @@ import ( "github.com/spf13/cobra" "golang.org/x/sync/errgroup" + "cosmossdk.io/x/feegrant" + "github.com/cosmos/cosmos-sdk/x/authz" "github.com/initia-labs/opinit-bots/bot" @@ -69,7 +71,17 @@ func txGrantOracleCmd(baseCtx *cmdContext) *cobra.Command { return err } - txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg}) + msgAllowance, err := feegrant.NewAllowedMsgAllowance(&feegrant.BasicAllowance{}, []string{types.MsgUpdateOracleTypeUrl, types.MsgAuthzExecTypeUrl}) + if err != nil { + return err + } + + feegrantMsg, err := feegrant.NewMsgGrantAllowance(msgAllowance, account.GetAddress(), oracleAddress) + if err != nil { + return err + } + + txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg, feegrantMsg}) if err != nil { return errors.Wrapf(err, "simulation failed") } diff --git a/executor/README.md b/executor/README.md index 848f4b5..7dbac0f 100644 --- a/executor/README.md +++ b/executor/README.md @@ -86,7 +86,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f "l2_start_height": 0, // StartBatchHeight is the height to start the batch. If it is 0, it will start from the latest height. // If the latest height stored in the db is not 0, this config is ignored. - "batch_start_height": 0 + "batch_start_height": 0, + // DisableDeleteFutureWithdrawal is the flag to disable the deletion of future withdrawal. + // when the bot is rolled back, it will delete the future withdrawals from DB. + // If it is true, it will not delete the future withdrawals. + "disable_delete_future_withdrawal": false, } ``` diff --git a/executor/child/child.go b/executor/child/child.go index f0775af..a9ddb07 100644 --- a/executor/child/child.go +++ b/executor/child/child.go @@ -66,8 +66,17 @@ func (ch *Child) Initialize( bridgeInfo ophosttypes.QueryBridgeResponse, keyringConfig *btypes.KeyringConfig, oracleKeyringConfig *btypes.KeyringConfig, + disableDeleteFutureWithdrawals bool, ) error { - l2Sequence, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, keyringConfig, oracleKeyringConfig) + l2Sequence, err := ch.BaseChild.Initialize( + ctx, + processedHeight, + startOutputIndex, + bridgeInfo, + keyringConfig, + oracleKeyringConfig, + disableDeleteFutureWithdrawals, + ) if err != nil { return err } diff --git a/executor/executor.go b/executor/executor.go index 22a98e5..2f99d13 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -104,7 +104,16 @@ func (ex *Executor) Initialize(ctx context.Context) error { if err != nil { return err } - err = ex.child.Initialize(ctx, childProcessedHeight, processedOutputIndex+1, ex.host, *bridgeInfo, childKeyringConfig, childOracleKeyringConfig) + err = ex.child.Initialize( + ctx, + childProcessedHeight, + processedOutputIndex+1, + ex.host, + *bridgeInfo, + childKeyringConfig, + childOracleKeyringConfig, + ex.cfg.DisableDeleteFutureWithdrawal, + ) if err != nil { return err } @@ -327,7 +336,8 @@ func (ex *Executor) getKeyringConfigs(bridgeInfo ophosttypes.QueryBridgeResponse if bridgeInfo.BridgeConfig.OracleEnabled && ex.cfg.OracleBridgeExecutor != "" { childOracleKeyringConfig = &btypes.KeyringConfig{ - Name: ex.cfg.OracleBridgeExecutor, + Name: ex.cfg.OracleBridgeExecutor, + FeeGranter: childKeyringConfig, } } } diff --git a/executor/types/config.go b/executor/types/config.go index bc3a2ec..53ccf68 100644 --- a/executor/types/config.go +++ b/executor/types/config.go @@ -88,6 +88,11 @@ type Config struct { // BatchStartHeight is the height to start the batch. If it is 0, it will start from the latest height. // If the latest height stored in the db is not 0, this config is ignored. BatchStartHeight int64 `json:"batch_start_height"` + + // DisableDeleteFutureWithdrawal is the flag to disable the deletion of future withdrawal. + // when the bot is rolled back, it will delete the future withdrawals from DB. + // If it is true, it will not delete the future withdrawals. + DisableDeleteFutureWithdrawal bool `json:"disable_delete_future_withdrawal"` } func DefaultConfig() *Config { @@ -137,10 +142,11 @@ func DefaultConfig() *Config { MaxChunkSize: 300000, // 300KB MaxSubmissionTime: 60 * 60, // 1 hour - DisableAutoSetL1Height: false, - L1StartHeight: 0, - L2StartHeight: 0, - BatchStartHeight: 0, + DisableAutoSetL1Height: false, + L1StartHeight: 0, + L2StartHeight: 0, + BatchStartHeight: 0, + DisableDeleteFutureWithdrawal: false, } } diff --git a/go.mod b/go.mod index 5e8696b..1204c64 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( cosmossdk.io/core v0.11.1 cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 + cosmossdk.io/x/feegrant v0.1.1 cosmossdk.io/x/tx v0.13.5 github.com/celestiaorg/go-square/v2 v2.0.0 github.com/cometbft/cometbft v0.38.12 diff --git a/node/broadcaster/account.go b/node/broadcaster/account.go index c1908d9..38f356f 100644 --- a/node/broadcaster/account.go +++ b/node/broadcaster/account.go @@ -95,6 +95,19 @@ func NewBroadcasterAccount(cfg btypes.BroadcasterConfig, cdc codec.Codec, txConf WithKeybase(keyBase). WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) + if keyringConfig.FeeGranter != nil { + // setup keyring + _, feeGranterKeyringRecord, err := cfg.GetKeyringRecord(cdc, keyringConfig.FeeGranter) + if err != nil { + return nil, err + } + + feeGranter, err := feeGranterKeyringRecord.GetAddress() + if err != nil { + return nil, err + } + b.txf = b.txf.WithFeeGranter(feeGranter) + } return b, nil } diff --git a/node/broadcaster/types/config.go b/node/broadcaster/types/config.go index 899810e..ff8fe3e 100644 --- a/node/broadcaster/types/config.go +++ b/node/broadcaster/types/config.go @@ -89,6 +89,9 @@ type KeyringConfig struct { // Address of key in keyring Address string `json:"address"` + // FeeGranter is the fee granter. + FeeGranter *KeyringConfig + // BuildTxWithMessages is the function to build a transaction with messages. BuildTxWithMessages BuildTxWithMessagesFn diff --git a/provider/child/child.go b/provider/child/child.go index 8e99bb2..1399ce0 100644 --- a/provider/child/child.go +++ b/provider/child/child.go @@ -107,6 +107,7 @@ func (b *BaseChild) Initialize( bridgeInfo ophosttypes.QueryBridgeResponse, keyringConfig *btypes.KeyringConfig, oracleKeyringConfig *btypes.KeyringConfig, + disableDeleteFutureWithdrawals bool, ) (uint64, error) { b.SetBridgeInfo(bridgeInfo) @@ -117,14 +118,16 @@ func (b *BaseChild) Initialize( var l2Sequence uint64 if b.node.HeightInitialized() { - l2Sequence, err = b.QueryNextL2Sequence(ctx, processedHeight) - if err != nil { - return 0, err - } + if !disableDeleteFutureWithdrawals { + l2Sequence, err = b.QueryNextL2Sequence(ctx, processedHeight) + if err != nil { + return 0, err + } - err = b.mk.DeleteFutureFinalizedTrees(l2Sequence) - if err != nil { - return 0, err + err = b.mk.DeleteFutureFinalizedTrees(l2Sequence) + if err != nil { + return 0, err + } } version := types.MustInt64ToUint64(processedHeight) diff --git a/types/const.go b/types/const.go index eacbcc8..96a8ea5 100644 --- a/types/const.go +++ b/types/const.go @@ -10,4 +10,5 @@ const ( DACelestiaName = "da_celestia" MsgUpdateOracleTypeUrl = "/opinit.opchild.v1.MsgUpdateOracle" + MsgAuthzExecTypeUrl = "/cosmos.authz.v1beta1.MsgExec" )