db

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB is a wrapper around the badger database to provide functions for storing blocks and attestations.

func NewBadgerDB

func NewBadgerDB(databaseDir string) *BadgerDB

NewBadgerDB initializes the badger database with the supplied directories.

func (*BadgerDB) Close

func (b *BadgerDB) Close() error

Close closes the database.

func (*BadgerDB) Flush

func (b *BadgerDB) Flush() error

Flush flushes all block data.

func (*BadgerDB) GarbageCollect

func (b *BadgerDB) GarbageCollect()

GarbageCollect runs badger garbage collection.

func (*BadgerDB) GetBlockForHash

func (b *BadgerDB) GetBlockForHash(h chainhash.Hash, transaction ...interface{}) (*primitives.Block, error)

GetBlockForHash gets a block for a certain block hash.

func (*BadgerDB) GetBlockNode

func (b *BadgerDB) GetBlockNode(h chainhash.Hash, transaction ...interface{}) (*BlockNodeDisk, error)

GetBlockNode gets a block node from the database.

func (*BadgerDB) GetFinalizedHead

func (b *BadgerDB) GetFinalizedHead(transaction ...interface{}) (*chainhash.Hash, error)

GetFinalizedHead gets the finalized head block hash for the chain.

func (*BadgerDB) GetFinalizedState

func (b *BadgerDB) GetFinalizedState(transaction ...interface{}) (*primitives.State, error)

GetFinalizedState gets the finalized state from the database.

func (*BadgerDB) GetGenesisTime

func (b *BadgerDB) GetGenesisTime(transaction ...interface{}) (uint64, error)

GetGenesisTime gets the genesis time of the blockchain.

func (*BadgerDB) GetHeadBlock

func (b *BadgerDB) GetHeadBlock(transaction ...interface{}) (*chainhash.Hash, error)

GetHeadBlock gets the head block for the chain.

func (*BadgerDB) GetHostKey

func (b *BadgerDB) GetHostKey(transaction ...interface{}) (crypto.PrivKey, error)

GetHostKey gets the key used by the P2P interface for identity.

func (*BadgerDB) GetJustifiedHead

func (b *BadgerDB) GetJustifiedHead(transaction ...interface{}) (*chainhash.Hash, error)

GetJustifiedHead gets the justified head block hash for the chain.

func (*BadgerDB) GetJustifiedState

func (b *BadgerDB) GetJustifiedState(transaction ...interface{}) (*primitives.State, error)

GetJustifiedState gets the justified state from the database.

func (*BadgerDB) GetLatestAttestation

func (b *BadgerDB) GetLatestAttestation(validator uint32, transaction ...interface{}) (*primitives.Attestation, error)

GetLatestAttestation gets the latest attestation from a validator.

func (*BadgerDB) SetBlock

func (b *BadgerDB) SetBlock(block primitives.Block, transaction ...interface{}) error

SetBlock sets a block for a certain block hash.

func (*BadgerDB) SetBlockNode

func (b *BadgerDB) SetBlockNode(node BlockNodeDisk, transaction ...interface{}) error

SetBlockNode sets a block node in the database.

func (*BadgerDB) SetFinalizedHead

func (b *BadgerDB) SetFinalizedHead(h chainhash.Hash, transaction ...interface{}) error

SetFinalizedHead sets the finalized head block hash for the chain.

func (*BadgerDB) SetFinalizedState

func (b *BadgerDB) SetFinalizedState(state primitives.State, transaction ...interface{}) error

SetFinalizedState sets the finalized state.

func (*BadgerDB) SetGenesisTime

func (b *BadgerDB) SetGenesisTime(time uint64, transaction ...interface{}) error

SetGenesisTime sets the head block for the chain.

func (*BadgerDB) SetHeadBlock

func (b *BadgerDB) SetHeadBlock(h chainhash.Hash, transaction ...interface{}) error

SetHeadBlock sets the head block for the chain.

func (*BadgerDB) SetHostKey

func (b *BadgerDB) SetHostKey(key crypto.PrivKey, transaction ...interface{}) error

SetHostKey sets the key used by the P2P interface for identity.

func (*BadgerDB) SetJustifiedHead

func (b *BadgerDB) SetJustifiedHead(h chainhash.Hash, transaction ...interface{}) error

SetJustifiedHead sets the justified head block hash for the chain.

func (*BadgerDB) SetJustifiedState

func (b *BadgerDB) SetJustifiedState(state primitives.State, transaction ...interface{}) error

SetJustifiedState sets the justified state.

func (*BadgerDB) SetLatestAttestationsIfNeeded

func (b *BadgerDB) SetLatestAttestationsIfNeeded(validators []uint32, attestation primitives.Attestation, transaction ...interface{}) error

SetLatestAttestationsIfNeeded sets the latest attestation from a validator.

func (*BadgerDB) TransactionalUpdate added in v0.1.1

func (b *BadgerDB) TransactionalUpdate(cb func(transaction interface{}) error) error

TransactionalUpdate executes cb in an update transaction

type BlockNodeDisk

type BlockNodeDisk struct {
	Hash      chainhash.Hash
	Height    uint64
	Slot      uint64
	Parent    chainhash.Hash
	StateRoot chainhash.Hash
	Children  []chainhash.Hash
}

BlockNodeDisk is a block node stored on the disk.

type BlockNodeDiskWithoutChildren

type BlockNodeDiskWithoutChildren struct {
	Hash      chainhash.Hash
	Height    uint64
	Slot      uint64
	Parent    chainhash.Hash
	StateRoot chainhash.Hash
}

BlockNodeDiskWithoutChildren is a block node stored on the disk.

type Database

type Database interface {
	GetBlockForHash(h chainhash.Hash, transaction ...interface{}) (*primitives.Block, error)
	SetBlock(b primitives.Block, transaction ...interface{}) error
	GetLatestAttestation(validator uint32, transaction ...interface{}) (*primitives.Attestation, error)
	SetLatestAttestationsIfNeeded(validators []uint32, attestation primitives.Attestation, transaction ...interface{}) error
	SetHeadBlock(block chainhash.Hash, transaction ...interface{}) error
	GetHeadBlock(transaction ...interface{}) (*chainhash.Hash, error)
	SetFinalizedState(state primitives.State, transaction ...interface{}) error
	GetFinalizedState(transaction ...interface{}) (*primitives.State, error)
	SetJustifiedState(state primitives.State, transaction ...interface{}) error
	GetJustifiedState(transaction ...interface{}) (*primitives.State, error)
	SetBlockNode(node BlockNodeDisk, transaction ...interface{}) error
	GetBlockNode(h chainhash.Hash, transaction ...interface{}) (*BlockNodeDisk, error)
	SetJustifiedHead(h chainhash.Hash, transaction ...interface{}) error
	SetFinalizedHead(h chainhash.Hash, transaction ...interface{}) error
	GetJustifiedHead(transaction ...interface{}) (*chainhash.Hash, error)
	GetFinalizedHead(transaction ...interface{}) (*chainhash.Hash, error)
	GetGenesisTime(transaction ...interface{}) (uint64, error)
	SetGenesisTime(t uint64, transaction ...interface{}) error
	GetHostKey(transaction ...interface{}) (crypto.PrivKey, error)
	SetHostKey(key crypto.PrivKey, transaction ...interface{}) error
	Close() error
	TransactionalUpdate(cb func(transaction interface{}) error) error
}

Database is a very basic interface for pluggable databases.

type InMemoryDB

type InMemoryDB struct {
	DB            map[chainhash.Hash]primitives.Block
	AttestationDB map[uint32]primitives.Attestation
	// contains filtered or unexported fields
}

InMemoryDB is a very basic block database.

func NewInMemoryDB

func NewInMemoryDB() *InMemoryDB

NewInMemoryDB initializes a new in-memory DB

func (*InMemoryDB) Close

func (db *InMemoryDB) Close() error

Close closes the database.

func (*InMemoryDB) GetBlockForHash

func (db *InMemoryDB) GetBlockForHash(h chainhash.Hash, transaction ...interface{}) (*primitives.Block, error)

GetBlockForHash is a database lookup function

func (*InMemoryDB) GetBlockNode

func (db *InMemoryDB) GetBlockNode(h chainhash.Hash, transaction ...interface{}) (*BlockNodeDisk, error)

GetBlockNode gets the block node with slot.

func (*InMemoryDB) GetFinalizedHead

func (db *InMemoryDB) GetFinalizedHead(transaction ...interface{}) (*chainhash.Hash, error)

GetFinalizedHead gets the finalized head block for a chain.

func (*InMemoryDB) GetFinalizedState

func (db *InMemoryDB) GetFinalizedState(transaction ...interface{}) (*primitives.State, error)

GetFinalizedState gets the finalized state from the database.

func (*InMemoryDB) GetGenesisTime

func (db *InMemoryDB) GetGenesisTime(transaction ...interface{}) (uint64, error)

GetGenesisTime gets the genesis time for the chain represented by this database.

func (*InMemoryDB) GetHeadBlock

func (db *InMemoryDB) GetHeadBlock(transaction ...interface{}) (*chainhash.Hash, error)

GetHeadBlock gets the head block.

func (*InMemoryDB) GetHostKey

func (db *InMemoryDB) GetHostKey(transaction ...interface{}) (crypto.PrivKey, error)

GetHostKey gets the host key

func (*InMemoryDB) GetJustifiedHead

func (db *InMemoryDB) GetJustifiedHead(transaction ...interface{}) (*chainhash.Hash, error)

GetJustifiedHead gets the justified head block for a chain.

func (*InMemoryDB) GetJustifiedState

func (db *InMemoryDB) GetJustifiedState(transaction ...interface{}) (*primitives.State, error)

GetJustifiedState gets the justified state from the database.

func (*InMemoryDB) GetLatestAttestation

func (db *InMemoryDB) GetLatestAttestation(validator uint32, transaction ...interface{}) (*primitives.Attestation, error)

GetLatestAttestation gets the latest attestation from a validator.

func (*InMemoryDB) SetBlock

func (db *InMemoryDB) SetBlock(b primitives.Block, transaction ...interface{}) error

SetBlock adds the block to storage

func (*InMemoryDB) SetBlockNode

func (db *InMemoryDB) SetBlockNode(node BlockNodeDisk, transaction ...interface{}) error

SetBlockNode sets the block node in the database.

func (*InMemoryDB) SetBlockState

func (db *InMemoryDB) SetBlockState(chainhash.Hash, primitives.State) error

SetBlockState sets the block state in the database.

func (*InMemoryDB) SetFinalizedHead

func (db *InMemoryDB) SetFinalizedHead(h chainhash.Hash, transaction ...interface{}) error

SetFinalizedHead sets the finalized head for the chain in the database.

func (*InMemoryDB) SetFinalizedState

func (db *InMemoryDB) SetFinalizedState(state primitives.State, transaction ...interface{}) error

SetFinalizedState sets the finalized state

func (*InMemoryDB) SetGenesisTime

func (db *InMemoryDB) SetGenesisTime(t uint64, transaction ...interface{}) error

SetGenesisTime sets the genesis time for the chain represented by this database.

func (*InMemoryDB) SetHeadBlock

func (db *InMemoryDB) SetHeadBlock(h chainhash.Hash, transaction ...interface{}) error

SetHeadBlock sets the head block.

func (*InMemoryDB) SetHostKey

func (db *InMemoryDB) SetHostKey(key crypto.PrivKey, transaction ...interface{}) error

SetHostKey sets the host key

func (*InMemoryDB) SetJustifiedHead

func (db *InMemoryDB) SetJustifiedHead(h chainhash.Hash, transaction ...interface{}) error

SetJustifiedHead sets the justified head for the chain in the database.

func (*InMemoryDB) SetJustifiedState

func (db *InMemoryDB) SetJustifiedState(state primitives.State, transaction ...interface{}) error

SetJustifiedState sets the justified state

func (*InMemoryDB) SetLatestAttestationsIfNeeded

func (db *InMemoryDB) SetLatestAttestationsIfNeeded(validators []uint32, att primitives.Attestation, transaction ...interface{}) error

SetLatestAttestationsIfNeeded sets the latest attestation received from a validator.

func (*InMemoryDB) TransactionalUpdate added in v0.1.1

func (db *InMemoryDB) TransactionalUpdate(cb func(transaction interface{}) error) error

TransactionalUpdate executes cb in an update transaction

Jump to

Keyboard shortcuts

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