diff --git a/challenger/db.go b/challenger/db.go index 72fdf70..aab51a8 100644 --- a/challenger/db.go +++ b/challenger/db.go @@ -39,7 +39,7 @@ func (c *Challenger) deletePendingChallenge(challenge challengertypes.Challenge) } func (c *Challenger) loadPendingChallenges() (challenges []challengertypes.Challenge, err error) { - iterErr := c.db.PrefixedIterate(challengertypes.PendingChallengeKey, func(_, value []byte) (stop bool, err error) { + iterErr := c.db.PrefixedIterate(challengertypes.PendingChallengeKey, nil, func(_, value []byte) (stop bool, err error) { challenge := challengertypes.Challenge{} err = challenge.Unmarshal(value) if err != nil { @@ -66,7 +66,7 @@ func (c *Challenger) saveChallenge(challenge challengertypes.Challenge) (types.R } func (c *Challenger) loadChallenges() (challenges []challengertypes.Challenge, err error) { - iterErr := c.db.PrefixedReverseIterate(challengertypes.ChallengeKey, func(_, value []byte) (stop bool, err error) { + iterErr := c.db.PrefixedReverseIterate(challengertypes.ChallengeKey, nil, func(_, value []byte) (stop bool, err error) { challenge := challengertypes.Challenge{} err = challenge.Unmarshal(value) if err != nil { @@ -87,7 +87,7 @@ func (c *Challenger) loadChallenges() (challenges []challengertypes.Challenge, e func (c *Challenger) DeleteFutureChallenges(initialBlockTime time.Time) error { deletingKeys := make([][]byte, 0) - iterErr := c.db.PrefixedReverseIterate(challengertypes.ChallengeKey, func(key []byte, _ []byte) (stop bool, err error) { + iterErr := c.db.PrefixedReverseIterate(challengertypes.ChallengeKey, nil, func(key []byte, _ []byte) (stop bool, err error) { ts, _, err := challengertypes.ParseChallenge(key) if err != nil { return true, err @@ -150,7 +150,7 @@ func ResetHeight(db types.DB, nodeName string) error { func DeletePendingEvents(db types.DB) error { deletingKeys := make([][]byte, 0) - iterErr := db.PrefixedIterate(challengertypes.PendingEventKey, func(key []byte, _ []byte) (stop bool, err error) { + iterErr := db.PrefixedIterate(challengertypes.PendingEventKey, nil, func(key []byte, _ []byte) (stop bool, err error) { deletingKeys = append(deletingKeys, key) return false, nil }) @@ -169,7 +169,7 @@ func DeletePendingEvents(db types.DB) error { func DeletePendingChallenges(db types.DB) error { deletingKeys := make([][]byte, 0) - iterErr := db.PrefixedIterate(challengertypes.PendingChallengeKey, func(key []byte, _ []byte) (stop bool, err error) { + iterErr := db.PrefixedIterate(challengertypes.PendingChallengeKey, nil, func(key []byte, _ []byte) (stop bool, err error) { deletingKeys = append(deletingKeys, key) return false, nil }) diff --git a/challenger/eventhandler/pending_events.go b/challenger/eventhandler/pending_events.go index e912a85..c849bf0 100644 --- a/challenger/eventhandler/pending_events.go +++ b/challenger/eventhandler/pending_events.go @@ -96,7 +96,7 @@ func (ch *ChallengeEventHandler) SetPendingEvents(events []challengertypes.Chall } func (ch *ChallengeEventHandler) loadPendingEvents() (events []challengertypes.ChallengeEvent, err error) { - iterErr := ch.db.PrefixedIterate(challengertypes.PendingEventKey, func(key, value []byte) (stop bool, err error) { + iterErr := ch.db.PrefixedIterate(challengertypes.PendingEventKey, nil, func(key, value []byte) (stop bool, err error) { id, err := challengertypes.ParsePendingEvent(key) if err != nil { return true, err diff --git a/challenger/query.go b/challenger/query.go index 4ad11d0..4c42c39 100644 --- a/challenger/query.go +++ b/challenger/query.go @@ -4,7 +4,7 @@ import challengertypes "github.com/initia-labs/opinit-bots/challenger/types" func (c *Challenger) QueryChallenges(page uint64) (challenges []challengertypes.Challenge, err error) { i := uint64(0) - iterErr := c.db.PrefixedIterate(challengertypes.ChallengeKey, func(_, value []byte) (stop bool, err error) { + iterErr := c.db.PrefixedIterate(challengertypes.ChallengeKey, nil, func(_, value []byte) (stop bool, err error) { i++ if i >= (page+1)*100 { return true, nil diff --git a/cmd/opinitd/db.go b/cmd/opinitd/db.go new file mode 100644 index 0000000..e7c51ab --- /dev/null +++ b/cmd/opinitd/db.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + + "github.com/initia-labs/opinit-bots/bot" + bottypes "github.com/initia-labs/opinit-bots/bot/types" + "github.com/initia-labs/opinit-bots/db" + "github.com/initia-labs/opinit-bots/executor" + "github.com/spf13/cobra" +) + +// migration015Cmd handles the one-time migration of withdrawal data for v0.1.5 +// TODO: Remove this command in the future +func migration015Cmd(ctx *cmdContext) *cobra.Command { + cmd := &cobra.Command{ + Use: "migrate", + Args: cobra.ExactArgs(1), + Short: "Run database migrations", + Long: `Run database migrations +v0.1.5: Store the sequence number so that it can be accessed by address +`, + RunE: func(cmd *cobra.Command, args []string) error { + version := args[0] + switch version { + case "v0.1.5": + // Run migration for v0.1.5 + db, err := db.NewDB(bot.GetDBPath(ctx.homePath, bottypes.BotTypeExecutor)) + if err != nil { + return err + } + return executor.Migration015(db) + default: + return fmt.Errorf("unknown migration version: %s", version) + } + }, + } + return cmd +} diff --git a/cmd/opinitd/root.go b/cmd/opinitd/root.go index faf17a5..50f892a 100644 --- a/cmd/opinitd/root.go +++ b/cmd/opinitd/root.go @@ -48,6 +48,7 @@ func NewRootCmd() *cobra.Command { resetDBCmd(ctx), resetHeightsCmd(ctx), resetHeightCmd(ctx), + migration015Cmd(ctx), version.NewVersionCommand(), ) return rootCmd diff --git a/db/db.go b/db/db.go index bdc9a7a..309ef8b 100644 --- a/db/db.go +++ b/db/db.go @@ -87,36 +87,45 @@ func (db *LevelDB) Close() error { // PrefixedIterate iterates over the key-value pairs in the database with prefixing the keys. // // @dev: `LevelDB.prefix + prefix` is used as the prefix for the iteration. -func (db *LevelDB) PrefixedIterate(prefix []byte, cb func(key, value []byte) (stop bool, err error)) error { +func (db *LevelDB) PrefixedIterate(prefix []byte, start []byte, cb func(key, value []byte) (stop bool, err error)) error { iter := db.db.NewIterator(util.BytesPrefix(db.PrefixedKey(prefix)), nil) defer iter.Release() - for iter.Next() { + if start != nil { + iter.Seek(db.PrefixedKey(start)) + } else { + iter.First() + } + + for iter.Valid() { key := db.UnprefixedKey(bytes.Clone(iter.Key())) if stop, err := cb(key, bytes.Clone(iter.Value())); err != nil { return err } else if stop { break } + iter.Next() } return iter.Error() } -func (db *LevelDB) PrefixedReverseIterate(prefix []byte, cb func(key, value []byte) (stop bool, err error)) error { +func (db *LevelDB) PrefixedReverseIterate(prefix []byte, start []byte, cb func(key, value []byte) (stop bool, err error)) error { iter := db.db.NewIterator(util.BytesPrefix(db.PrefixedKey(prefix)), nil) defer iter.Release() - if iter.Last() { - for { - key := db.UnprefixedKey(bytes.Clone(iter.Key())) - if stop, err := cb(key, bytes.Clone(iter.Value())); err != nil { - return err - } else if stop { - break - } - - if !iter.Prev() { - break - } + if start != nil { + iter.Seek(db.PrefixedKey(start)) + } else { + iter.Last() + } + + for iter.Valid() { + key := db.UnprefixedKey(bytes.Clone(iter.Key())) + if stop, err := cb(key, bytes.Clone(iter.Value())); err != nil { + return err + } else if stop { + break } + + iter.Prev() } return iter.Error() } @@ -127,7 +136,13 @@ func (db *LevelDB) PrefixedReverseIterate(prefix []byte, cb func(key, value []by func (db *LevelDB) SeekPrevInclusiveKey(prefix []byte, key []byte) (k []byte, v []byte, err error) { iter := db.db.NewIterator(util.BytesPrefix(db.PrefixedKey(prefix)), nil) defer iter.Release() - if iter.Seek(db.PrefixedKey(key)) || iter.Valid() && iter.Prev() || iter.Last() && iter.Valid() { + if ok := iter.Seek(db.PrefixedKey(key)); ok || iter.Last() { + // if the valid key is not found, the iterator will be at the last key + // if the key is found, the iterator will be at the key + // or the previous key if the key is not found + if ok && !bytes.Equal(db.PrefixedKey(key), iter.Key()) { + iter.Prev() + } k = db.UnprefixedKey(bytes.Clone(iter.Key())) v = bytes.Clone(iter.Value()) } else { diff --git a/executor/child/child.go b/executor/child/child.go index fc146b8..845c1c2 100644 --- a/executor/child/child.go +++ b/executor/child/child.go @@ -42,6 +42,9 @@ type Child struct { lastFinalizedDepositL1BlockHeight int64 lastFinalizedDepositL1Sequence uint64 lastOutputTime time.Time + + batchKVs []types.RawKV + addressIndexMap map[string]uint64 } func NewChildV1( @@ -49,7 +52,9 @@ func NewChildV1( db types.DB, logger *zap.Logger, ) *Child { return &Child{ - BaseChild: childprovider.NewBaseChildV1(cfg, db, logger), + BaseChild: childprovider.NewBaseChildV1(cfg, db, logger), + batchKVs: make([]types.RawKV, 0), + addressIndexMap: make(map[string]uint64), } } diff --git a/executor/child/handler.go b/executor/child/handler.go index 97648a3..0846305 100644 --- a/executor/child/handler.go +++ b/executor/child/handler.go @@ -8,13 +8,15 @@ import ( btypes "github.com/initia-labs/opinit-bots/node/broadcaster/types" nodetypes "github.com/initia-labs/opinit-bots/node/types" - "github.com/initia-labs/opinit-bots/types" + "golang.org/x/exp/maps" ) func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBlockArgs) (err error) { blockHeight := args.Block.Header.Height ch.EmptyMsgQueue() ch.EmptyProcessedMsgs() + ch.batchKVs = ch.batchKVs[:0] + maps.Clear(ch.addressIndexMap) if ch.Merkle() == nil { return errors.New("merkle is not initialized") @@ -34,13 +36,12 @@ func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBloc func (ch *Child) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) error { blockHeight := args.Block.Header.Height - batchKVs := make([]types.RawKV, 0) treeKVs, storageRoot, err := ch.handleTree(blockHeight, args.LatestHeight, args.BlockID, args.Block.Header) if err != nil { return err } - batchKVs = append(batchKVs, treeKVs...) + ch.batchKVs = append(ch.batchKVs, treeKVs...) if storageRoot != nil { workingTreeIndex, err := ch.GetWorkingTreeIndex() if err != nil { @@ -53,7 +54,7 @@ func (ch *Child) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) } // update the sync info - batchKVs = append(batchKVs, ch.Node().SyncInfoToRawKV(blockHeight)) + ch.batchKVs = append(ch.batchKVs, ch.Node().SyncInfoToRawKV(blockHeight)) // if has key, then process the messages if ch.host.HasKey() { @@ -76,10 +77,10 @@ func (ch *Child) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) if err != nil { return err } - batchKVs = append(batchKVs, msgKVs...) + ch.batchKVs = append(ch.batchKVs, msgKVs...) } - err = ch.DB().RawBatchSet(batchKVs...) + err = ch.DB().RawBatchSet(ch.batchKVs...) if err != nil { return err } diff --git a/executor/child/query.go b/executor/child/query.go index 601c23e..9520669 100644 --- a/executor/child/query.go +++ b/executor/child/query.go @@ -33,14 +33,36 @@ func (ch Child) QueryWithdrawal(sequence uint64) (executortypes.QueryWithdrawalR BridgeId: ch.BridgeId(), OutputIndex: outputIndex, WithdrawalProofs: proofs, - Sender: withdrawal.From, + From: withdrawal.From, + To: withdrawal.To, Sequence: sequence, - Amount: amount.String(), + Amount: amount, Version: []byte{ch.Version()}, StorageRoot: outputRoot, - LatestBlockHash: treeExtraData.BlockHash, - BlockNumber: treeExtraData.BlockNumber, - Receiver: withdrawal.To, - WithdrawalHash: withdrawal.WithdrawalHash, + LastBlockHash: treeExtraData.BlockHash, + // BlockNumber: treeExtraData.BlockNumber, + // WithdrawalHash: withdrawal.WithdrawalHash, }, nil } + +func (ch Child) QueryWithdrawals(address string, offset uint64, limit uint64, descOrder bool) (executortypes.QueryWithdrawalsResponse, error) { + sequences, next, total, err := ch.GetSequencesByAddress(address, offset, limit, descOrder) + if err != nil { + return executortypes.QueryWithdrawalsResponse{}, err + } + withdrawals := make([]executortypes.QueryWithdrawalResponse, 0) + for _, sequence := range sequences { + withdrawal, err := ch.QueryWithdrawal(sequence) + if err != nil { + return executortypes.QueryWithdrawalsResponse{}, err + } + withdrawals = append(withdrawals, withdrawal) + } + + res := executortypes.QueryWithdrawalsResponse{ + Withdrawals: withdrawals, + Next: next, + Total: total, + } + return res, nil +} diff --git a/executor/child/withdraw.go b/executor/child/withdraw.go index 2f46d1e..45fe609 100644 --- a/executor/child/withdraw.go +++ b/executor/child/withdraw.go @@ -38,10 +38,11 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str } // store to database - err := ch.SetWithdrawal(l2Sequence, data) + kvs, err := ch.WithdrawalToRawKVs(l2Sequence, data) if err != nil { return err } + ch.batchKVs = append(ch.batchKVs, kvs...) // generate merkle tree err = ch.Merkle().InsertLeaf(withdrawalHash[:]) @@ -143,9 +144,15 @@ func (ch *Child) handleTree(blockHeight int64, latestHeight int64, blockId []byt return nil, nil, err } + startLeafIndex, err := ch.GetStartLeafIndex() + if err != nil { + return nil, nil, err + } + ch.Logger().Info("finalize working tree", zap.Uint64("tree_index", workingTreeIndex), zap.Int64("height", blockHeight), + zap.Uint64("start_leaf_index", startLeafIndex), zap.Uint64("num_leaves", workingTreeLeafCount), zap.String("storage_root", base64.StdEncoding.EncodeToString(storageRoot)), ) @@ -196,18 +203,103 @@ func (ch *Child) GetWithdrawal(sequence uint64) (executortypes.WithdrawalData, e return data, err } +func (ch *Child) GetSequencesByAddress(address string, offset uint64, limit uint64, descOrder bool) (sequences []uint64, next, total uint64, err error) { + if limit == 0 { + return nil, 0, 0, nil + } + + count := uint64(0) + fetchFn := func(key, value []byte) (bool, error) { + sequence, err := dbtypes.ToUint64(value) + if err != nil { + return true, err + } + sequences = append(sequences, sequence) + count++ + if count >= limit { + return true, nil + } + return false, nil + } + total, err = ch.GetLastAddressIndex(address) + if err != nil { + return nil, 0, 0, err + } + + if descOrder { + if offset > total || offset == 0 { + offset = total + } + startKey := executortypes.PrefixedWithdrawalKeyAddressIndex(address, offset) + err = ch.DB().PrefixedReverseIterate(executortypes.PrefixedWithdrawalKeyAddress(address), startKey, fetchFn) + if err != nil { + return nil, 0, 0, err + } + + next = offset - count + } else { + if offset == 0 { + offset = 1 + } + startKey := executortypes.PrefixedWithdrawalKeyAddressIndex(address, offset) + err := ch.DB().PrefixedIterate(executortypes.PrefixedWithdrawalKeyAddress(address), startKey, fetchFn) + if err != nil { + return nil, 0, 0, err + } + + next = offset + count + } + + return sequences, next, total, nil +} + // SetWithdrawal store the withdrawal data for the given sequence to the database -func (ch *Child) SetWithdrawal(sequence uint64, data executortypes.WithdrawalData) error { +func (ch *Child) WithdrawalToRawKVs(sequence uint64, data executortypes.WithdrawalData) ([]types.RawKV, error) { dataBytes, err := json.Marshal(&data) if err != nil { - return err + return nil, err } - return ch.DB().Set(executortypes.PrefixedWithdrawalKey(sequence), dataBytes) + kvs := make([]types.RawKV, 0) + kvs = append(kvs, types.RawKV{ + Key: ch.DB().PrefixedKey(executortypes.PrefixedWithdrawalKey(sequence)), + Value: dataBytes, + }) + + addressIndex, err := ch.GetAddressIndex(data.To) + if err != nil { + return nil, err + } + ch.addressIndexMap[data.To] = addressIndex + 1 + kvs = append(kvs, types.RawKV{ + Key: ch.DB().PrefixedKey(executortypes.PrefixedWithdrawalKeyAddressIndex(data.To, ch.addressIndexMap[data.To])), + Value: dbtypes.FromUint64(sequence), + }) + return kvs, nil +} + +func (ch *Child) GetAddressIndex(address string) (uint64, error) { + if index, ok := ch.addressIndexMap[address]; !ok { + lastIndex, err := ch.GetLastAddressIndex(address) + if err != nil { + return 0, err + } + return lastIndex, nil + } else { + return index, nil + } +} + +func (ch *Child) GetLastAddressIndex(address string) (lastIndex uint64, err error) { + err = ch.DB().PrefixedReverseIterate(executortypes.PrefixedWithdrawalKeyAddress(address), nil, func(key, _ []byte) (bool, error) { + lastIndex = dbtypes.ToUint64Key(key[len(key)-8:]) + return true, nil + }) + return lastIndex, err } func (ch *Child) DeleteFutureWithdrawals(fromSequence uint64) error { - return ch.DB().PrefixedIterate(executortypes.WithdrawalKey, func(key, _ []byte) (bool, error) { + return ch.DB().PrefixedIterate(executortypes.WithdrawalKey, nil, func(key, _ []byte) (bool, error) { sequence := dbtypes.ToUint64Key(key[len(key)-8:]) if sequence >= fromSequence { err := ch.DB().Delete(key) diff --git a/executor/db.go b/executor/db.go index bbb62bf..8de0202 100644 --- a/executor/db.go +++ b/executor/db.go @@ -1,8 +1,11 @@ package executor import ( + "encoding/json" "fmt" + dbtypes "github.com/initia-labs/opinit-bots/db/types" + executortypes "github.com/initia-labs/opinit-bots/executor/types" "github.com/initia-labs/opinit-bots/node" "github.com/initia-labs/opinit-bots/types" "github.com/pkg/errors" @@ -46,3 +49,26 @@ func ResetHeight(db types.DB, nodeName string) error { fmt.Printf("reset height to 0 for node %s\n", string(nodeDB.GetPrefix())) return nil } + +func Migration015(db types.DB) error { + nodeDB := db.WithPrefix([]byte(types.ChildName)) + addressIndexMap := make(map[string]uint64) + return nodeDB.PrefixedIterate(executortypes.WithdrawalKey, nil, func(key, value []byte) (bool, error) { + if len(key) != len(executortypes.WithdrawalKey)+1+8 { + return false, nil + } + + sequence := dbtypes.ToUint64Key(key[len(key)-8:]) + var data executortypes.WithdrawalData + err := json.Unmarshal(value, &data) + if err != nil { + return true, err + } + addressIndexMap[data.To]++ + err = nodeDB.Set(executortypes.PrefixedWithdrawalKeyAddressIndex(data.To, addressIndexMap[data.To]), dbtypes.FromUint64(sequence)) + if err != nil { + return true, err + } + return false, nil + }) +} diff --git a/executor/executor.go b/executor/executor.go index b1841be..ecb2c0a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -166,6 +166,40 @@ func (ex *Executor) RegisterQuerier() { return c.JSON(res) }) + ex.server.RegisterQuerier("/withdrawals/:address", func(c *fiber.Ctx) error { + address := c.Params("address") + if address == "" { + return errors.New("address is required") + } + + offset := c.QueryInt("offset", 0) + uoffset, err := types.SafeInt64ToUint64(int64(offset)) + if err != nil { + return err + } + + limit := c.QueryInt("limit", 10) + if limit > 100 { + limit = 100 + } + + ulimit, err := types.SafeInt64ToUint64(int64(limit)) + if err != nil { + return err + } + + descOrder := true + orderStr := c.Query("order", "desc") + if orderStr == "asc" { + descOrder = false + } + res, err := ex.child.QueryWithdrawals(address, uoffset, ulimit, descOrder) + if err != nil { + return err + } + return c.JSON(res) + }) + ex.server.RegisterQuerier("/status", func(c *fiber.Ctx) error { status, err := ex.GetStatus() if err != nil { diff --git a/executor/types/key.go b/executor/types/key.go index 7ffa3bd..deae983 100644 --- a/executor/types/key.go +++ b/executor/types/key.go @@ -11,3 +11,11 @@ var ( func PrefixedWithdrawalKey(sequence uint64) []byte { return append(append(WithdrawalKey, dbtypes.Splitter), dbtypes.FromUint64Key(sequence)...) } + +func PrefixedWithdrawalKeyAddress(address string) []byte { + return append(append(append(WithdrawalKey, dbtypes.Splitter), []byte(address)...), dbtypes.Splitter) +} + +func PrefixedWithdrawalKeyAddressIndex(address string, index uint64) []byte { + return append(PrefixedWithdrawalKeyAddress(address), dbtypes.FromUint64Key(index)...) +} diff --git a/executor/types/query.go b/executor/types/query.go index ebe1505..98f1c21 100644 --- a/executor/types/query.go +++ b/executor/types/query.go @@ -1,19 +1,27 @@ package types +import "github.com/cosmos/cosmos-sdk/types" + type QueryWithdrawalResponse struct { // fields required to withdraw funds - BridgeId uint64 `json:"bridge_id"` - OutputIndex uint64 `json:"output_index"` - WithdrawalProofs [][]byte `json:"withdrawal_proofs"` - Sender string `json:"sender"` - Sequence uint64 `json:"sequence"` - Amount string `json:"amount"` - Version []byte `json:"version"` - StorageRoot []byte `json:"storage_root"` - LatestBlockHash []byte `json:"latest_block_hash"` + Sequence uint64 `json:"sequence"` + To string `json:"to"` + From string `json:"from"` + Amount types.Coin `json:"amount"` + OutputIndex uint64 `json:"output_index"` + BridgeId uint64 `json:"bridge_id"` + WithdrawalProofs [][]byte `json:"withdrawal_proofs"` + Version []byte `json:"version"` + StorageRoot []byte `json:"storage_root"` + LastBlockHash []byte `json:"last_block_hash"` // extra info - BlockNumber int64 `json:"block_number"` - Receiver string `json:"receiver"` - WithdrawalHash []byte `json:"withdrawal_hash"` + // BlockNumber int64 `json:"block_number"` + // WithdrawalHash []byte `json:"withdrawal_hash"` +} + +type QueryWithdrawalsResponse struct { + Withdrawals []QueryWithdrawalResponse `json:"withdrawals"` + Next uint64 `json:"next"` + Total uint64 `json:"total"` } diff --git a/go.mod b/go.mod index 3a5c931..aa9bdb8 100644 --- a/go.mod +++ b/go.mod @@ -3,81 +3,51 @@ module github.com/initia-labs/opinit-bots go 1.22.5 require ( + cosmossdk.io/core v0.11.1 + cosmossdk.io/errors v1.0.1 + cosmossdk.io/math v1.3.0 + cosmossdk.io/x/tx v0.13.4 github.com/celestiaorg/go-square/v2 v2.0.0 github.com/cometbft/cometbft v0.38.12 github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/go-bip39 v1.0.0 + github.com/cosmos/gogoproto v1.7.0 github.com/gofiber/fiber/v2 v2.52.5 github.com/initia-labs/OPinit v0.5.2 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 + github.com/stretchr/testify v1.9.0 + github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d + go.uber.org/zap v1.27.0 + golang.org/x/crypto v0.27.0 + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 + golang.org/x/sync v0.8.0 + google.golang.org/grpc v1.66.2 gopkg.in/yaml.v2 v2.4.0 ) -require ( - cosmossdk.io/x/upgrade v0.1.4 // indirect - github.com/DataDog/datadog-go v3.2.0+incompatible // indirect - github.com/andybalholm/brotli v1.0.5 // indirect - github.com/celestiaorg/nmt v0.22.1 // indirect - github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect - github.com/cosmos/gogogateway v1.2.0 // indirect - github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect - github.com/cosmos/ibc-go/v8 v8.5.0 // indirect - github.com/cosmos/interchain-security/v6 v6.0.0 // indirect - github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect - github.com/dgraph-io/badger/v4 v4.2.0 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/gogo/googleapis v1.4.1 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/google/flatbuffers v2.0.8+incompatible // indirect - github.com/google/orderedcode v0.0.1 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect - github.com/hashicorp/go-hclog v1.5.0 // indirect - github.com/hashicorp/go-plugin v1.5.2 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/hashicorp/yamux v0.1.1 // indirect - github.com/huandu/skiplist v1.2.0 // indirect - github.com/improbable-eng/grpc-web v0.15.0 // indirect - github.com/initia-labs/OPinit/api v0.5.1 // indirect - github.com/leodido/go-urn v1.4.0 // indirect - github.com/lib/pq v1.10.9 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/minio/highwayhash v1.0.2 // indirect - github.com/mitchellh/go-testing-interface v1.14.1 // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/oklog/run v1.1.0 // indirect - github.com/rivo/uniseg v0.4.4 // indirect - github.com/rs/cors v1.11.1 // indirect - github.com/skip-mev/connect/v2 v2.0.1 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.51.0 // indirect - github.com/valyala/tcplisten v1.0.0 // indirect - go.opencensus.io v0.24.0 // indirect - nhooyr.io/websocket v1.8.6 // indirect -) - require ( cosmossdk.io/api v0.7.5 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/core v0.11.1 cosmossdk.io/depinject v1.0.0 // indirect - cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1 // indirect - cosmossdk.io/x/tx v0.13.4 + cosmossdk.io/x/upgrade v0.1.4 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect + github.com/DataDog/datadog-go v3.2.0+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect + github.com/andybalholm/brotli v1.0.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect + github.com/celestiaorg/nmt v0.22.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect @@ -86,14 +56,18 @@ require ( github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.2 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect - github.com/cosmos/go-bip39 v1.0.0 - github.com/cosmos/gogoproto v1.7.0 + github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v1.2.0 // indirect + github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect + github.com/cosmos/ibc-go/v8 v8.5.0 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect + github.com/cosmos/interchain-security/v6 v6.0.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/danieljoos/wincred v1.1.2 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect + github.com/dgraph-io/badger/v4 v4.2.0 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect @@ -105,36 +79,58 @@ require ( github.com/go-kit/kit v0.13.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect + github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.3 // indirect github.com/golang/glog v1.2.1 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/btree v1.1.2 // indirect + github.com/google/flatbuffers v2.0.8+incompatible // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/orderedcode v0.0.1 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect + github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-metrics v0.5.3 // indirect + github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.1.0 // indirect + github.com/huandu/skiplist v1.2.0 // indirect github.com/iancoleman/strcase v0.3.0 // indirect + github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/initia-labs/OPinit/api v0.5.1 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/lib/pq v1.10.9 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/minio/highwayhash v1.0.2 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect + github.com/oklog/run v1.1.0 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -143,40 +139,41 @@ require ( github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/rs/cors v1.11.1 // indirect github.com/rs/zerolog v1.33.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect + github.com/skip-mev/connect/v2 v2.0.1 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/stretchr/testify v1.9.0 github.com/subosito/gotenv v1.6.0 // indirect - github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.51.0 // indirect + github.com/valyala/tcplisten v1.0.0 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect + go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.27.0 - golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/sync v0.8.0 golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect golang.org/x/text v0.18.0 // indirect google.golang.org/genproto v0.0.0-20240722135656-d784300faade // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect - google.golang.org/grpc v1.66.2 google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect + nhooyr.io/websocket v1.8.6 // indirect pgregory.net/rapid v1.1.0 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/merkle/merkle.go b/merkle/merkle.go index 37a5311..66e368f 100644 --- a/merkle/merkle.go +++ b/merkle/merkle.go @@ -123,7 +123,7 @@ func (m *Merkle) FinalizeWorkingTree(extraData []byte) ([]types.RawKV, []byte /* } func (m *Merkle) DeleteFutureFinalizedTrees(fromSequence uint64) error { - return m.db.PrefixedIterate(merkletypes.FinalizedTreeKey, func(key, _ []byte) (bool, error) { + return m.db.PrefixedIterate(merkletypes.FinalizedTreeKey, nil, func(key, _ []byte) (bool, error) { sequence := dbtypes.ToUint64Key(key[len(key)-8:]) if sequence >= fromSequence { err := m.db.Delete(key) @@ -136,7 +136,7 @@ func (m *Merkle) DeleteFutureFinalizedTrees(fromSequence uint64) error { } func (m *Merkle) DeleteFutureWorkingTrees(fromVersion uint64) error { - return m.db.PrefixedIterate(merkletypes.WorkingTreeKey, func(key, _ []byte) (bool, error) { + return m.db.PrefixedIterate(merkletypes.WorkingTreeKey, nil, func(key, _ []byte) (bool, error) { version := dbtypes.ToUint64Key(key[len(key)-8:]) if version >= fromVersion { err := m.db.Delete(key) diff --git a/node/broadcaster/db.go b/node/broadcaster/db.go index 7eb6018..3c501de 100644 --- a/node/broadcaster/db.go +++ b/node/broadcaster/db.go @@ -24,7 +24,7 @@ func (b Broadcaster) deletePendingTx(sequence uint64) error { } func (b Broadcaster) loadPendingTxs() (txs []btypes.PendingTxInfo, err error) { - iterErr := b.db.PrefixedIterate(btypes.PendingTxsKey, func(_, value []byte) (stop bool, err error) { + iterErr := b.db.PrefixedIterate(btypes.PendingTxsKey, nil, func(_, value []byte) (stop bool, err error) { txInfo := btypes.PendingTxInfo{} err = txInfo.Unmarshal(value) if err != nil { @@ -99,7 +99,7 @@ func (b Broadcaster) ProcessedMsgsToRawKV(ProcessedMsgs []btypes.ProcessedMsgs, // } func (b Broadcaster) loadProcessedMsgs() (ProcessedMsgs []btypes.ProcessedMsgs, err error) { - iterErr := b.db.PrefixedIterate(btypes.ProcessedMsgsKey, func(_, value []byte) (stop bool, err error) { + iterErr := b.db.PrefixedIterate(btypes.ProcessedMsgsKey, nil, func(_, value []byte) (stop bool, err error) { var processedMsgs btypes.ProcessedMsgs err = processedMsgs.UnmarshalInterfaceJSON(b.cdc, value) if err != nil { diff --git a/node/db.go b/node/db.go index cee9fe9..c7fcaff 100644 --- a/node/db.go +++ b/node/db.go @@ -57,7 +57,7 @@ func DeleteSyncInfo(db types.DB) error { } func DeleteProcessedMsgs(db types.DB) error { - return db.PrefixedIterate(btypes.ProcessedMsgsKey, func(key, _ []byte) (stop bool, err error) { + return db.PrefixedIterate(btypes.ProcessedMsgsKey, nil, func(key, _ []byte) (stop bool, err error) { err = db.Delete(key) if err != nil { return stop, err @@ -67,7 +67,7 @@ func DeleteProcessedMsgs(db types.DB) error { } func DeletePendingTxs(db types.DB) error { - return db.PrefixedIterate(btypes.PendingTxsKey, func(key, _ []byte) (stop bool, err error) { + return db.PrefixedIterate(btypes.PendingTxsKey, nil, func(key, _ []byte) (stop bool, err error) { err = db.Delete(key) if err != nil { return stop, err diff --git a/types/db.go b/types/db.go index 7259a7e..39d3537 100644 --- a/types/db.go +++ b/types/db.go @@ -19,8 +19,8 @@ type DB interface { BatchSet(...KV) error Delete([]byte) error Close() error - PrefixedIterate([]byte, func([]byte, []byte) (bool, error)) error - PrefixedReverseIterate([]byte, func([]byte, []byte) (bool, error)) error + PrefixedIterate([]byte, []byte, func([]byte, []byte) (bool, error)) error + PrefixedReverseIterate([]byte, []byte, func([]byte, []byte) (bool, error)) error SeekPrevInclusiveKey([]byte, []byte) ([]byte, []byte, error) WithPrefix([]byte) DB PrefixedKey([]byte) []byte