db

package
v0.0.0-...-02f1fe4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockExists is the error when block eixsts.
	ErrBlockExists = errors.New("block exists")
	// ErrBlockDoesNotExist is the error when block does not eixst.
	ErrBlockDoesNotExist = errors.New("block does not exist")
	// ErrIterationFinished is the error to check if the iteration is finished.
	ErrIterationFinished = errors.New("iteration finished")
	// ErrEmptyPath is the error when the required path is empty.
	ErrEmptyPath = fmt.Errorf("empty path")
	// ErrClosed is the error when using DB after it's closed.
	ErrClosed = fmt.Errorf("db closed")
	// ErrNotImplemented is the error that some interface is not implemented.
	ErrNotImplemented = fmt.Errorf("not implemented")
	// ErrInvalidCompactionChainTipHeight means the newly updated height of
	// the tip of compaction chain is invalid, usually means it's smaller than
	// current cached one.
	ErrInvalidCompactionChainTipHeight = fmt.Errorf(
		"invalid compaction chain tip height")
	// ErrDKGPrivateKeyExists raised when attempting to save DKG private key
	// that already saved.
	ErrDKGPrivateKeyExists = errors.New("dkg private key exists")
	// ErrDKGPrivateKeyDoesNotExist raised when the DKG private key of the
	// requested round does not exists.
	ErrDKGPrivateKeyDoesNotExist = errors.New("dkg private key does not exists")
	// ErrDKGProtocolExists raised when attempting to save DKG protocol
	// that already saved.
	ErrDKGProtocolExists = errors.New("dkg protocol exists")
	// ErrDKGProtocolDoesNotExist raised when the DKG protocol of the
	// requested round does not exists.
	ErrDKGProtocolDoesNotExist = errors.New("dkg protocol does not exists")
)

Functions

This section is empty.

Types

type BlockIterator

type BlockIterator interface {
	NextBlock() (types.Block, error)
}

BlockIterator defines an iterator on blocks hold in a DB.

type DKGProtocolInfo

type DKGProtocolInfo struct {
	ID                        types.NodeID
	Round                     uint64
	Threshold                 uint64
	IDMap                     NodeIDToDKGID
	MpkMap                    NodeIDToPubShares
	MasterPrivateShare        dkg.PrivateKeyShares
	IsMasterPrivateShareEmpty bool
	PrvShares                 dkg.PrivateKeyShares
	IsPrvSharesEmpty          bool
	PrvSharesReceived         NodeID
	NodeComplained            NodeID
	AntiComplaintReceived     NodeIDToNodeIDs
	Step                      uint64
	Reset                     uint64
}

DKGProtocolInfo DKG protocol info.

func (*DKGProtocolInfo) Equal

func (info *DKGProtocolInfo) Equal(target *DKGProtocolInfo) bool

Equal compare with target DKGProtocolInfo.

type Database

type Database interface {
	Reader
	Writer

	// Close allows database implementation able to
	// release resource when finishing.
	Close() error
}

Database is the interface for a Database.

type LevelDBBackedDB

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

LevelDBBackedDB is a leveldb backed DB implementation.

func NewLevelDBBackedDB

func NewLevelDBBackedDB(
	path string) (lvl *LevelDBBackedDB, err error)

NewLevelDBBackedDB initialize a leveldb-backed database.

func (*LevelDBBackedDB) Close

func (lvl *LevelDBBackedDB) Close() error

Close implement Closer interface, which would release allocated resource.

func (*LevelDBBackedDB) GetAllBlocks

func (lvl *LevelDBBackedDB) GetAllBlocks() (BlockIterator, error)

GetAllBlocks implements Reader.GetAllBlocks method, which allows callers to retrieve all blocks in DB.

func (*LevelDBBackedDB) GetBlock

func (lvl *LevelDBBackedDB) GetBlock(
	hash common.Hash) (block types.Block, err error)

GetBlock implements the Reader.GetBlock method.

func (*LevelDBBackedDB) GetCompactionChainTipInfo

func (lvl *LevelDBBackedDB) GetCompactionChainTipInfo() (
	hash common.Hash, height uint64)

GetCompactionChainTipInfo get the tip info of compaction chain into the database.

func (*LevelDBBackedDB) GetDKGPrivateKey

func (lvl *LevelDBBackedDB) GetDKGPrivateKey(round, reset uint64) (
	prv dkg.PrivateKey, err error)

GetDKGPrivateKey get DKG private key of one round.

func (*LevelDBBackedDB) GetDKGProtocol

func (lvl *LevelDBBackedDB) GetDKGProtocol() (
	info DKGProtocolInfo, err error)

GetDKGProtocol get DKG protocol.

func (*LevelDBBackedDB) HasBlock

func (lvl *LevelDBBackedDB) HasBlock(hash common.Hash) bool

HasBlock implements the Reader.Has method.

func (*LevelDBBackedDB) PutBlock

func (lvl *LevelDBBackedDB) PutBlock(block types.Block) (err error)

PutBlock implements the Writer.PutBlock method.

func (*LevelDBBackedDB) PutCompactionChainTipInfo

func (lvl *LevelDBBackedDB) PutCompactionChainTipInfo(
	blockHash common.Hash, height uint64) error

PutCompactionChainTipInfo saves tip of compaction chain into the database.

func (*LevelDBBackedDB) PutDKGPrivateKey

func (lvl *LevelDBBackedDB) PutDKGPrivateKey(
	round, reset uint64, prv dkg.PrivateKey) error

PutDKGPrivateKey save DKG private key of one round.

func (*LevelDBBackedDB) PutOrUpdateDKGProtocol

func (lvl *LevelDBBackedDB) PutOrUpdateDKGProtocol(info DKGProtocolInfo) error

PutOrUpdateDKGProtocol save DKG protocol.

func (*LevelDBBackedDB) UpdateBlock

func (lvl *LevelDBBackedDB) UpdateBlock(block types.Block) (err error)

UpdateBlock implements the Writer.UpdateBlock method.

type MemBackedDB

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

MemBackedDB is a memory backed DB implementation.

func NewMemBackedDB

func NewMemBackedDB(persistantFilePath ...string) (
	dbInst *MemBackedDB, err error)

NewMemBackedDB initialize a memory-backed database.

func (*MemBackedDB) Close

func (m *MemBackedDB) Close() (err error)

Close implement Closer interface, which would release allocated resource.

func (*MemBackedDB) GetAllBlocks

func (m *MemBackedDB) GetAllBlocks() (BlockIterator, error)

GetAllBlocks implement Reader.GetAllBlocks method, which allows caller to retrieve all blocks in DB.

func (*MemBackedDB) GetBlock

func (m *MemBackedDB) GetBlock(hash common.Hash) (types.Block, error)

GetBlock returns a block given a hash.

func (*MemBackedDB) GetCompactionChainTipInfo

func (m *MemBackedDB) GetCompactionChainTipInfo() (
	hash common.Hash, height uint64)

GetCompactionChainTipInfo get the tip info of compaction chain into the database.

func (*MemBackedDB) GetDKGPrivateKey

func (m *MemBackedDB) GetDKGPrivateKey(round, reset uint64) (
	dkg.PrivateKey, error)

GetDKGPrivateKey get DKG private key of one round.

func (*MemBackedDB) GetDKGProtocol

func (m *MemBackedDB) GetDKGProtocol() (
	DKGProtocolInfo, error)

GetDKGProtocol get DKG protocol.

func (*MemBackedDB) HasBlock

func (m *MemBackedDB) HasBlock(hash common.Hash) bool

HasBlock returns wheter or not the DB has a block identified with the hash.

func (*MemBackedDB) PutBlock

func (m *MemBackedDB) PutBlock(block types.Block) error

PutBlock inserts a new block into the database.

func (*MemBackedDB) PutCompactionChainTipInfo

func (m *MemBackedDB) PutCompactionChainTipInfo(
	blockHash common.Hash, height uint64) error

PutCompactionChainTipInfo saves tip of compaction chain into the database.

func (*MemBackedDB) PutDKGPrivateKey

func (m *MemBackedDB) PutDKGPrivateKey(
	round, reset uint64, prv dkg.PrivateKey) error

PutDKGPrivateKey save DKG private key of one round.

func (*MemBackedDB) PutOrUpdateDKGProtocol

func (m *MemBackedDB) PutOrUpdateDKGProtocol(dkgProtocol DKGProtocolInfo) error

PutOrUpdateDKGProtocol save DKG protocol.

func (*MemBackedDB) UpdateBlock

func (m *MemBackedDB) UpdateBlock(block types.Block) error

UpdateBlock updates a block in the database.

type NodeID

type NodeID map[types.NodeID]struct{}

NodeID the map with NodeID.

func (*NodeID) DecodeRLP

func (m *NodeID) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Encoder

func (NodeID) EncodeRLP

func (m NodeID) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

type NodeIDToDKGID

type NodeIDToDKGID map[types.NodeID]dkg.ID

NodeIDToDKGID the map with NodeID to DKGID.

func (*NodeIDToDKGID) DecodeRLP

func (m *NodeIDToDKGID) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Encoder

func (NodeIDToDKGID) EncodeRLP

func (m NodeIDToDKGID) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

type NodeIDToNodeIDs

type NodeIDToNodeIDs map[types.NodeID]map[types.NodeID]struct{}

NodeIDToNodeIDs the map with NodeID to NodeIDs.

func (*NodeIDToNodeIDs) DecodeRLP

func (m *NodeIDToNodeIDs) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Encoder

func (NodeIDToNodeIDs) EncodeRLP

func (m NodeIDToNodeIDs) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

type NodeIDToPubShares

type NodeIDToPubShares map[types.NodeID]*dkg.PublicKeyShares

NodeIDToPubShares the map with NodeID to PublicKeyShares.

func (*NodeIDToPubShares) DecodeRLP

func (m *NodeIDToPubShares) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Encoder

func (NodeIDToPubShares) EncodeRLP

func (m NodeIDToPubShares) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

type Reader

type Reader interface {
	HasBlock(hash common.Hash) bool
	GetBlock(hash common.Hash) (types.Block, error)
	GetAllBlocks() (BlockIterator, error)

	// GetCompactionChainTipInfo returns the block hash and finalization height
	// of the tip block of compaction chain. Empty hash and zero height means
	// the compaction chain is empty.
	GetCompactionChainTipInfo() (common.Hash, uint64)

	// DKG Private Key related methods.
	GetDKGPrivateKey(round, reset uint64) (dkg.PrivateKey, error)
	GetDKGProtocol() (dkgProtocol DKGProtocolInfo, err error)
}

Reader defines the interface for reading blocks into DB.

type Writer

type Writer interface {
	UpdateBlock(block types.Block) error
	PutBlock(block types.Block) error
	PutCompactionChainTipInfo(common.Hash, uint64) error
	PutDKGPrivateKey(round, reset uint64, pk dkg.PrivateKey) error
	PutOrUpdateDKGProtocol(dkgProtocol DKGProtocolInfo) error
}

Writer defines the interface for writing blocks into DB.

Jump to

Keyboard shortcuts

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