Go to file
Ian Norden 4a52acb0bb
Merge pull request #50 from cerc-io/ian/v5
v0 blockstore compatible version
2023-03-30 15:51:59 -05:00
postgres update postgres v0 subpkg and tests to work with cid keys 2023-02-20 12:44:45 -06:00
.gitignore init repo 2020-05-30 11:53:27 -05:00
batch_test.go cerc github refactor 2022-09-14 01:03:07 -04:00
batch.go Exchange.Interface no longer IsOnline and other updates for blockservice version update 2022-08-01 17:05:18 -04:00
database_test.go cerc github refactor 2022-09-14 01:03:07 -04:00
database.go Exchange.Interface no longer IsOnline and other updates for blockservice version update 2022-08-01 17:05:18 -04:00
go.mod dependency updates for 1.10.26 geth release 2022-11-07 10:25:21 -05:00
go.sum dependency updates for 1.10.26 geth release 2022-11-07 10:25:21 -05:00
iterator.go updates to satisfy the v1.10.14 ethdb.Database interface 2021-12-29 00:17:09 -06:00
LICENSE license 2020-05-30 11:59:16 -05:00
mock_blockservice.go Exchange.Interface no longer IsOnline and other updates for blockservice version update 2022-08-01 17:05:18 -04:00
README.md Update module path for v4 2022-05-09 16:29:09 +05:30
suite_test.go remove unnecessary dep; gofmt 2020-07-12 18:18:25 -05:00
util.go updates to satisfy the v1.10.14 ethdb.Database interface 2021-12-29 00:17:09 -06:00

ipfs-ethdb

Go Report Card

go-ethereum ethdb interfaces for Ethereum state data stored in IPFS

Background

Go-ethereum defines a number of interfaces in the ethdb package for interfacing with a state database. These interfaces are used to build higher-level types such as the trie.Database which are used to perform the bulk of state related needs.

Ethereum data can be stored on IPFS, standard codecs for Etheruem data are defined in the go-cid library. Using our statediffing geth client it is feasible to extract every single state and storage node and publish it to IPFS.

Geth stores state data in leveldb as key-value pairs between the keccak256 hash of the rlp-encoded object and the rlp-encoded object. Ethereum data on IPFS is also stored as key-value pairs with the value being the rlp-encoded byte value for the object, but the key is a derivative of the keccak256 hash rather than the hash itself. This library provides ethdb interfaces for Ethereum data on IPFS by handling the conversion of a keccak256 hash to its multihash-derived key.

Usage

To use this module import it and build an ethdb interface around an instance of a go ipfs blockservice, you can then employ it as you would the usual leveldb or memorydb ethdbs with some exceptions: the AncientReader, AncientWriter, Compacter, and Iteratee/Iterator interfaces are not functionally complete.

Ancient data does not currently have a representation on IPFS, and recapitulation of the database key iterator and compacter is complicated since go-ethereum types that use this interface expect the iterator and compacter to operate over keccak256 hash key ranges, whereas the keys for Ethereum data on IPFS are derived from that hash but not the hash itself.

Iteratee interface is used in Geth for various tests, in trie/sync_bloom.go (for fast sync), rawdb.InspectDatabase, and the new (1.9.15) core/state/snapshot features; Ancient interfaces are used for Ancient/frozen data operations (e.g. rawdb/table.go); and Compacter is used in core/state/snapshot, rawdb/table.go, chaincmd.go, and the private debug api.

Outside of these primarily auxiliary capabilities, this package satisfies the interfaces required for many state operations using Ethereum data on IPFS.

e.g.

go-ethereum trie.NodeIterator and state.NodeIterator can be constructed from the ethdb.KeyValueStore and ethdb.Database interfaces, respectively:

package main

import (
    "context"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/core/state"
    "github.com/ethereum/go-ethereum/trie"
    "github.com/ipfs/go-blockservice"
    "github.com/ipfs/go-ipfs/core"
    "github.com/ipfs/go-ipfs/repo/fsrepo"
    "github.com/jmoiron/sqlx"
    "github.com/vulcanize/ipfs-ethdb/v4"
)

func main() {
    // errors are ignored for brevity
    ipfsPath := "~/.ipfs"
    r, _ := fsrepo.Open(ipfsPath)
    ctx := context.Background()
    cfg := &core.BuildCfg{
        Online: false,
        Repo:   r,
    }
    ipfsNode, _ := core.NewNode(ctx, cfg)
    kvs := ipfsethdb.NewKeyValueStore(ipfsNode.Blocks)
    trieDB := trie.NewDatabase(kvs)
    t, _ := trie.New(common.Hash{}, trieDB)
    trieNodeIterator := t.NodeIterator([]byte{})
    // do stuff with trie node iterator

    database := ipfsethdb.NewDatabase(ipfsNode.Blocks)
    stateDatabase := state.NewDatabase(database)
    stateDB, _ := state.New(common.Hash{}, stateDatabase, nil)
    stateDBNodeIterator := state.NewNodeIterator(stateDB)
    // do stuff with the statedb node iterator
}

Types are also available for interfacing directly with the data stored in an IPFS-backing Postgres database

Maintainers

@vulcanize @AFDudley @i-norden

Contributing

Contributions are welcome!

VulcanizeDB follows the Contributor Covenant Code of Conduct.

License

AGPL-3.0 © Vulcanize Inc