Skip to content

Commit

Permalink
add feegrant msg to grant-oracle cmd (#49)
Browse files Browse the repository at this point in the history
* add feegrant msg to grant-oracle cmd

* add disable delete future withdrawals flag (#50)

* add disable delete future withdrawals flag

* format
  • Loading branch information
sh-cha authored Nov 20, 2024
1 parent 88491e9 commit dcae51a
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 18 deletions.
19 changes: 17 additions & 2 deletions challenger/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 13 additions & 1 deletion cmd/opinitd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
6 changes: 5 additions & 1 deletion executor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
```

Expand Down
11 changes: 10 additions & 1 deletion executor/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 12 additions & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions executor/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions node/broadcaster/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions node/broadcaster/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 10 additions & 7 deletions provider/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (b *BaseChild) Initialize(
bridgeInfo ophosttypes.QueryBridgeResponse,
keyringConfig *btypes.KeyringConfig,
oracleKeyringConfig *btypes.KeyringConfig,
disableDeleteFutureWithdrawals bool,
) (uint64, error) {
b.SetBridgeInfo(bridgeInfo)

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions types/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ const (
DACelestiaName = "da_celestia"

MsgUpdateOracleTypeUrl = "/opinit.opchild.v1.MsgUpdateOracle"
MsgAuthzExecTypeUrl = "/cosmos.authz.v1beta1.MsgExec"
)

0 comments on commit dcae51a

Please sign in to comment.