Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions badgerdb-analyzer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Makefile for badgerdb-analyzer

.PHONY: all build-all build-v2 build-v3 build-v4 clean tidy-all

# Default target
all: build-all

# Build all versions
build-all: build-v2 build-v3 build-v4

# Build BadgerDB v2 version
build-v2:
@echo "Building badgerdb-analyzer-v2..."
go build -modfile=go_v2.mod -tags badgerv2 -o bin/badgerdb-analyzer-v2
@echo "✓ Built: bin/badgerdb-analyzer-v2"

# Build BadgerDB v3 version
build-v3:
@echo "Building badgerdb-analyzer-v3..."
go build -modfile=go_v3.mod -tags badgerv3 -o bin/badgerdb-analyzer-v3
@echo "✓ Built: bin/badgerdb-analyzer-v3"

# Build BadgerDB v4 version
build-v4:
@echo "Building badgerdb-analyzer-v4..."
go build -modfile=go_v4.mod -tags badgerv4 -o bin/badgerdb-analyzer-v4
@echo "✓ Built: bin/badgerdb-analyzer-v4"

# Clean build artifacts
clean:
@echo "Cleaning bin/..."
rm -f bin/badgerdb-sampler-v2 bin/badgerdb-sampler-v3 bin/badgerdb-sampler-v4
@echo "Cleaning outputs/..."
rm -rf outputs/*
@echo "✓ Cleaned"

# Tidy all module files
tidy-all:
@echo "Tidying all module files..."
GOFLAGS="-tags=badgerv2" go mod tidy -modfile=go_v2.mod
GOFLAGS="-tags=badgerv3" go mod tidy -modfile=go_v3.mod
GOFLAGS="-tags=badgerv4" go mod tidy -modfile=go_v4.mod
@echo "✓ All module files tidied"
75 changes: 75 additions & 0 deletions badgerdb-analyzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# BadgerDB Analyzer

This **badgerdb-analyzer** tool is for analyzing and checking the consistency of BadgerDB databases from Oasis node snapshots. It performs a full database scan, analysis with statistics, consistency validation, and integrity checks. It handles multiple BadgerDB versions (v2-v4) and data representations use by Oasis nodes (v20.x-v25.x). The decoding logic is from the **badgerdb-sampler** tool.

**Warning:** For experimental purposes only. Decoded data might be incorrect.

## Features

- Full database analysis in single pass
- Comprehensive statistics (key/value sizes, block ranges, transaction counts)
- Consistency checks (block sequences, timestamp validation, referential integrity)
- Multi-version support (BadgerDB v2, v3, v4)
- Six database types (consensus-blockstore, consensus-evidence, consensus-mkvs, consensus-state, runtime-history, runtime-mkvs)
- JSON output for programmatic analysis

## Supported Database Types

| Database Type | Description | Key Statistics |
|------------------------|-------------------------------------|----------------|
| `consensus-blockstore` | Block metadata and commit info | Consensus block sequences, timestamps, transactions, events |
| `consensus-evidence` | Byzantine validator evidence | Evidence heights, gap detection |
| `consensus-mkvs` | Consensus state Merkle tree | Node types, write log versions |
| `consensus-state` | Tendermint/CometBFT consensus state | ABCI responses completeness |
| `runtime-history` | Runtime block history | Runtime/consensus heights, timestamps, intervals |
| `runtime-mkvs` | Runtime state Merkle tree | Node types, module distribution, write log versions |

## Installation

```bash
make build-all
```

This builds three binaries:
- `./bin/badgerdb-analyzer-v2` - For BadgerDB v2 databases
- `./bin/badgerdb-analyzer-v3` - For BadgerDB v3 databases
- `./bin/badgerdb-analyzer-v4` - For BadgerDB v4 databases

## Usage

```bash
badgerdb-analyzer-vX <database-type> <database-path> [output-json]
```

**Arguments:**
- `database-type`: One of: `consensus-blockstore`, `consensus-evidence`, `consensus-mkvs`, `consensus-state`, `runtime-mkvs`, `runtime-history`
- `database-path`: Path to the BadgerDB directory
- `output-json`: (Optional) Path to JSON output file. If omitted, outputs to stdout

### Examples

**Analyze consensus blockstore:**
```bash
./bin/badgerdb-analyzer-v3 consensus-blockstore \
/snapshots/mainnet/consensus/tendermint/data/blockstore.badger.db \
blockstore-analysis.json
```

**Analyze runtime history:**
```bash
./bin/badgerdb-analyzer-v3 runtime-history \
/snapshots/mainnet/runtimes/<runtime-id>/history.db \
runtime-history-analysis.json
```

## Exit Codes

- `0` - Success, all checks passed
- `1` - Issues found (checks failed)
- `2` - Database open failed
- `3` - Invalid arguments
- `4` - Analysis error

## Related Tools

- **badgerdb-sampler**: Sample-based database exploration
Loading