heavy

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 19 Imported by: 0

README

General concept

For general concept explanation one can refer to /pkg/core/database/README.md. This document must focus on decisions made with regard to goleveldb specifics

K/V storage schema to store a single pkg/core/block.Block into blockchain

Prefix KEY VALUE Count Used by
0x01 HeaderHash Header.Encode() 1 per block
0x02 HeaderHash + TxID TxIndex + Tx.Encode() block txs count
0x04 TxID HeaderHash block txs count FetchBlockTxByHash
0x05 KeyImage TxID sum of block txs inputs FetchKeyImageExists
0x03 Height HeaderHash 1 per block FetchBlockHashByHeight
0x07 State Chain tip hash 1 per chain FetchState

K/V storage schema to store a candidate pkg/core/block.Block

Prefix KEY VALUE Count Used by
0x06 HeaderHash + Height Block.Encode() Many per blockchain Store/Fetch/Delete CandidateBlock

Table notation

  • HeaderHash - a calculated hash of block header
  • TxID - a calculated hash of transaction
  • '+' operation - denotes concatenation of byte arrays
  • Tx.Encode() - Encoded binary form of all Tx fields without TxID

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderPrefix    = []byte{0x01}
	TxPrefix        = []byte{0x02}
	HeightPrefix    = []byte{0x03}
	TxIDPrefix      = []byte{0x04}
	KeyImagePrefix  = []byte{0x05}
	StatePrefix     = []byte{0x06}
	OutputKeyPrefix = []byte{0x07}
	BidValuesPrefix = []byte{0x08}
)
View Source
var (
	// DriverName is the unique identifier for the heavy driver
	DriverName = "heavy_v0.1.0"
)

Functions

func CreateDBConnection

func CreateDBConnection() (database.Driver, database.DB)

func NewDatabase

func NewDatabase(path string, network protocol.Magic, readonly bool) (database.DB, error)

NewDatabase create or open backend storage (goleveldb) located at the specified path. Readonly option is pseudo read-only mode implemented by heavy.Database. Not to be confused with read-only goleveldb mode

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB on top of underlying storage syndtr/goleveldb/leveldb

func (DB) Begin

func (db DB) Begin(writable bool) (database.Transaction, error)

Begin builds read-only or read-write Transaction

func (DB) Close

func (db DB) Close() error

Close does not close the underlying storage as we need to reuse it within another DB instances. Note that we rely on the Finalizer that goleveldb is setting at the point of leveldb.DB.openDB to call leveldb.DB.Close() when the process is terminating

func (DB) GetSnapshot

func (db DB) GetSnapshot() (*leveldb.Snapshot, error)

GetSnapshot returns current storage snapshot. To be used only by database/testing pkg

func (DB) Update

func (db DB) Update(fn func(database.Transaction) error) error

func (DB) View

func (db DB) View(fn func(database.Transaction) error) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL