Skip to content

Conversation

@coderabbitai
Copy link
Contributor

@coderabbitai coderabbitai bot commented Nov 12, 2025

Docstrings generation was requested by @JayT106.

The following files were modified:

  • cmd/cronosd/cmd/database.go
  • cmd/cronosd/cmd/migrate_db.go
  • cmd/cronosd/cmd/patch_db.go
  • cmd/cronosd/cmd/root.go
  • cmd/cronosd/dbmigrate/height_filter.go
  • cmd/cronosd/dbmigrate/migrate.go
  • cmd/cronosd/dbmigrate/migrate_no_rocksdb.go
  • cmd/cronosd/dbmigrate/migrate_rocksdb.go
  • cmd/cronosd/dbmigrate/patch.go
  • cmd/cronosd/dbmigrate/swap-migrated-db.sh
  • x/e2ee/client/cli/encrypt.go
These files were ignored
  • cmd/cronosd/cmd/migrate_db_test.go
  • cmd/cronosd/dbmigrate/height_filter_test.go
  • cmd/cronosd/dbmigrate/height_parse_test.go
  • cmd/cronosd/dbmigrate/migrate_basic_test.go
  • cmd/cronosd/dbmigrate/migrate_dbname_test.go
  • cmd/cronosd/dbmigrate/migrate_rocksdb_test.go
  • cmd/cronosd/dbmigrate/migrate_test.go
  • cmd/cronosd/dbmigrate/patch_test.go
These file types are not supported
  • CHANGELOG.md
  • Makefile
  • cmd/cronosd/dbmigrate/QUICKSTART.md
  • cmd/cronosd/dbmigrate/README.md
ℹ️ Note

CodeRabbit cannot perform edits on its own pull requests yet.

Docstrings generation was requested by @JayT106.

* #1908 (comment)

The following files were modified:

* `cmd/cronosd/cmd/database.go`
* `cmd/cronosd/cmd/migrate_db.go`
* `cmd/cronosd/cmd/patch_db.go`
* `cmd/cronosd/cmd/root.go`
* `cmd/cronosd/dbmigrate/height_filter.go`
* `cmd/cronosd/dbmigrate/migrate.go`
* `cmd/cronosd/dbmigrate/migrate_no_rocksdb.go`
* `cmd/cronosd/dbmigrate/migrate_rocksdb.go`
* `cmd/cronosd/dbmigrate/patch.go`
* `cmd/cronosd/dbmigrate/swap-migrated-db.sh`
* `x/e2ee/client/cli/encrypt.go`
@coderabbitai coderabbitai bot requested a review from a team as a code owner November 12, 2025 20:25
@coderabbitai coderabbitai bot requested review from a team, JayT106, XinyuCRO and calvinaco and removed request for a team and XinyuCRO November 12, 2025 20:25
@coderabbitai
Copy link
Contributor Author

coderabbitai bot commented Nov 12, 2025

Important

Review skipped

CodeRabbit bot authored PR detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "📝 Add docstrings to `jt/dbmigrate`". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

"target_keys_checked", targetKeys,
"mismatches", mismatchCount,
)
lastProgressReport = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism

logger := opts.Logger
stats := &MigrationStats{
StartTime: time.Now(),

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
}
}

stats.EndTime = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
Comment on lines +737 to +870
for ethTxHash, info := range ethTxInfos {
// Create specific prefix for this transaction to minimize iteration range
// Format: ethereum_tx.ethereumTxHash/0x<eth_txhash>/<height>/<txindex>
// This will match both keys with and without "$es$<eventseq>" suffix
// Note: ethTxHash already includes the 0x prefix
prefix := fmt.Sprintf("ethereum_tx.ethereumTxHash/%s/%d/%d", ethTxHash, info.Height, info.TxIndex)
prefixBytes := []byte(prefix)

// Create end boundary by incrementing the prefix (exclusive upper bound)
endBytes := incrementBytes(prefixBytes)

// Create bounded iterator with [start, end)
it, err := sourceDB.Iterator(prefixBytes, endBytes)
if err != nil {
logger.Error("Failed to create iterator for ethereum event keys", "error", err, "eth_txhash", ethTxHash)
stats.ErrorCount.Add(1)
continue
}

eventKeysFound := 0
for it.Valid() {
key := it.Key()
value := it.Value()

// Stop if we're past the prefix
if !bytes.HasPrefix(key, prefixBytes) {
break
}

eventKeysFound++
keyStr := string(key)

logger.Debug("Found ethereum event key in source",
"event_key", keyStr,
"eth_txhash", ethTxHash,
"height", info.Height,
"tx_index", info.TxIndex,
)

// Check for conflicts
shouldWrite := true
if !opts.SkipConflictChecks {
existingValue, err := targetDB.Get(key)
if err != nil {
stats.ErrorCount.Add(1)
logger.Error("Failed to check existing ethereum event key", "error", err)
it.Next()
continue
}

if existingValue != nil {
switch currentStrategy {
case ConflictSkip:
shouldWrite = false
skippedCount++
logger.Debug("Skipping existing ethereum event key",
"event_key", keyStr,
)

case ConflictReplace, ConflictReplaceAll:
shouldWrite = true
logger.Debug("Replacing existing ethereum event key",
"event_key", keyStr,
)

case ConflictAsk:
// Use replace strategy for event keys to avoid excessive prompting
shouldWrite = true
logger.Debug("Patching ethereum event key (using current strategy)",
"event_key", keyStr,
)
}
}
}

if shouldWrite {
// Make a copy of the value since iterator reuses memory
valueCopy := make([]byte, len(value))
copy(valueCopy, value)

if opts.DryRun {
logger.Debug("[DRY RUN] Would patch ethereum event key",
"event_key", keyStr,
"value_preview", formatKeyPrefix(valueCopy, 80),
)
} else {
if err := batch.Set(key, valueCopy); err != nil {
stats.ErrorCount.Add(1)
logger.Error("Failed to set ethereum event key in batch", "error", err)
it.Next()
continue
}
logger.Debug("Patched ethereum event key",
"event_key", keyStr,
"value_preview", formatKeyPrefix(valueCopy, 80),
)
}

batchCount++
processedCount++

// Write batch when full
if batchCount >= opts.BatchSize {
if !opts.DryRun {
if err := batch.Write(); err != nil {
it.Close()
return fmt.Errorf("failed to write ethereum event batch: %w", err)
}
logger.Debug("Wrote ethereum event batch", "batch_size", batchCount)
batch.Close()
batch = targetDB.NewBatch()
}
stats.ProcessedKeys.Add(int64(batchCount))
batchCount = 0
}
}

it.Next()
}

if err := it.Error(); err != nil {
it.Close()
return fmt.Errorf("iterator error for eth_txhash %s: %w", ethTxHash, err)
}

it.Close()

if eventKeysFound > 0 {
logger.Debug("Processed event keys for transaction",
"eth_txhash", ethTxHash,
"event_keys_found", eventKeysFound,
)
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

batchCount := 0
skippedCount := int64(0)
lastLogTime := time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
"progress", fmt.Sprintf("%.2f%%", progress),
"errors", stats.ErrorCount.Load(),
)
lastLogTime = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
}

// If more than 80% is printable, treat as text
if float64(printableCount)/float64(len(value)) > 0.8 {

Check notice

Code scanning / CodeQL

Floating point arithmetic Note

Floating point arithmetic operations are not associative and a possible source of non-determinism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants