diem/diem · error

Unable to get txn iter

Error message

Unable to get txn iter

What it means

Panic from `.expect()` on `BackupHandler::get_transaction_iter(0, version)`, which opens a RocksDB iterator over raw transactions from version 0 to the latest version. The underlying Result carries the storage error (I/O failure, invalid version range, or DB handle problem) and turning it into an expect aborts the process.

Source

Thrown at storage/inspector/src/main.rs:113

                info!(
                    "Account {} exists, but have no AccountResource: {}.",
                    addr, e
                );
            }
        }
    } else {
        info!("Account {} doesn't exists", addr);
    }
}

fn list_txns(db: &DiemDB) {
    let version = db
        .get_latest_version()
        .expect("Unable to get latest version");
    let backup = db.get_backup_handler();
    let iter = backup
        .get_transaction_iter(0, version as usize)
        .expect("Unable to get txn iter");
    for (v, tx) in iter.enumerate() {
        println!(
            "TXN {}: {}",
            v,
            tx.expect("Unable to read TX")
                .0
                .format_for_client(|bytes| name_for_script(bytes).unwrap())
        );
    }
}

fn list_accounts(db: &DiemDB) {
    let version = db
        .get_latest_version()
        .expect("Unable to get latest version");
    let backup = db.get_backup_handler();
    let iter = backup
        .get_account_iter(version)

View on GitHub (pinned to fc4714a8ea)

Solutions

  1. Retry with a smaller end version within the DB's actual transaction range
  2. Check RocksDB logs in the DB directory for corruption and run a repair or restore from backup
  3. Ensure the DB was not pruned below version 0 unexpectedly; use the pruner-aware range
  4. Rebuild the inspector against the same DB schema version

Example fix

// before
let iter = backup
    .get_transaction_iter(0, version as usize)
    .expect("Unable to get txn iter");
// after
let iter = match backup.get_transaction_iter(0, version as usize) {
    Ok(it) => it,
    Err(e) => { eprintln!("Cannot open txn iter: {:?}", e); return; }
};
Defensive patterns

Strategy: try-catch

Validate before calling

// Bound the range to what the DB actually holds:
// if version == 0 or history was pruned, do not request from 0..version
// check RocksDB logs for corruption before iterating

Try / catch

let iter = match backup.get_transaction_iter(0, version as usize) {
    Ok(it) => it,
    Err(e) => { eprintln!("Unable to get txn iter: {:?}", e); return; }
};

Prevention

When it happens

Trigger: `list_txns` where version is huge/invalid relative to actual DB contents, the transaction column family is missing or corrupted, or RocksDB fails to create the iterator (I/O error, corrupt SST file).

Common situations: Running on a DB restored partially from backup (transaction history truncated below `version`), corrupted RocksDB data files after a crash, or requesting a range that no longer exists after pruning.

Related errors


AI-assisted analysis of diem/diem@fc4714a8ea (2026-09-04). Data as JSON: /api/errors/3baff2ab8ce10aba. Report an issue: GitHub.