Skip to main content

Data Storage Formats

KalyChain offers two formats for storing blockchain state: Forest of Tries and Bonsai Tries. Each has different performance characteristics and storage requirements.

Overview

The world state is a mapping of all accounts and their storage. How this data is organized affects:

  • Storage size — Disk space requirements
  • Read performance — Speed of data access
  • Write performance — Speed of state updates
  • Sync time — Initial synchronization duration

Forest of Tries

Forest of Tries (forest mode) is the traditional storage format.

How It Works

  • Each trie node is stored by its hash in a key-value store.
  • For each block, new nodes are added for changed state.
  • Old nodes remain in storage (no automatic cleanup).
  • Data is accessed by traversing the trie structure.
Block N State Root

┌───┴───┐
▼ ▼
Branch Branch
│ │
▼ ▼
Leaf Leaf

Characteristics

AspectForest Mode
Storage GrowthLinear with chain growth
Read SpeedModerate (hash-based lookup)
Historical AccessAll history available
PruningOptional, reduces size

Pruning

Enable pruning to remove unreachable state trie nodes:

kaly --pruning-enabled
note

Pruning is being deprecated in favor of Bonsai Tries and may not receive updates.

Bonsai Tries

Bonsai Tries is a newer storage format designed for efficiency.

How It Works

  • Leaf values stored in a trie log, separate from branches.
  • Nodes stored by location, not hash.
  • Account data accessed directly via account key.
  • Orphaned nodes automatically pruned.
Account Key → Direct Lookup → Leaf Value

Trie Log (history)

Configuration

Enable Bonsai mode:

kaly --data-storage-format=BONSAI

Characteristics

AspectBonsai Mode
Storage SizeSignificantly smaller
Read SpeedFast (direct key access)
Historical AccessLimited (configurable)
PruningAutomatic

Historical Data Limits

Bonsai limits how far back it can reconstruct historical state:

kaly --bonsai-maximum-back-layers-to-load=512
SettingEffect
Default (512)~17 minutes of history at 2s blocks
Higher valuesMore history, slower performance
Lower valuesLess history, faster performance
Resource Usage

Accessing very old state in Bonsai mode becomes increasingly resource-intensive. Set appropriate limits for your use case.

Comparison

FeatureForestBonsai
Disk UsageHighLow
Recent State ReadModerateFast
Historical State ReadConsistentDegrades with age
Memory UsageHigherLower
Automatic PruningNoYes
Good ForFull archivesMost use cases

Choosing a Format

Use Bonsai When:

  • Running a validator or RPC node
  • Disk space is limited
  • Mostly accessing recent state
  • Performance is a priority

Use Forest When:

  • Running an archive node
  • Need full historical state access
  • Running analytics on historical data
  • Debugging historical transactions

Migration

warning

Switching storage formats requires a full resync. There is no in-place migration.

To switch formats:

  1. Stop the node.
  2. Delete (or move) the data directory.
  3. Start with the new format option.
  4. Wait for full synchronization.

Client Configuration

Bonsai Configuration Options

OptionDescriptionDefault
--data-storage-format=BONSAIEnable Bonsai modeFOREST
--bonsai-maximum-back-layers-to-loadHistorical depth512

Forest Configuration Options

OptionDescriptionDefault
--data-storage-format=FORESTEnable Forest modeFOREST
--pruning-enabledEnable state pruningfalse

Further Reading