bstore

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeBlockID

func ComputeBlockID(block *protocol.Block) []byte

ComputeBlockID computes the block ID according to cryptographic constraints

func GetEmptyBlockID

func GetEmptyBlockID() []byte

GetEmptyBlockID computes the zero block ID (i.e. Previous of first block applied to genesis state)

Types

type BadgerBackend

type BadgerBackend struct {
	DB *badger.DB
}

BadgerBackend Badger backend implementation

func NewBadgerBackend

func NewBadgerBackend(opts badger.Options) (*BadgerBackend, error)

NewBadgerBackend BadgerBackend constructor

func (*BadgerBackend) Close

func (backend *BadgerBackend) Close()

Close cleans backend resources

func (*BadgerBackend) Delete added in v1.0.0

func (backend *BadgerBackend) Delete(key []byte) error

Delete an item from the database

func (*BadgerBackend) Get

func (backend *BadgerBackend) Get(key []byte) ([]byte, error)

Get backend getter

func (*BadgerBackend) Put

func (backend *BadgerBackend) Put(key, value []byte) error

Put backend setter

func (*BadgerBackend) Reset

func (backend *BadgerBackend) Reset() error

Reset resets the database

type BlockHeightMismatch

type BlockHeightMismatch struct {
}

BlockHeightMismatch is an error type thrown when querying ancestor of block B at height H where H >= B.height.

func (*BlockHeightMismatch) Error

func (e *BlockHeightMismatch) Error() string

type BlockNotPresent

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

BlockNotPresent is an error type thrown when asking for a block that is not contained in the blockstore

func (*BlockNotPresent) Error

func (e *BlockNotPresent) Error() string

type BlockStoreBackend

type BlockStoreBackend interface {
	/**
	 * Store the given value in the given key.
	 */
	Put(key []byte, value []byte) error

	/**
	 * Deletes the value at the given key.
	 */
	Delete(key []byte) error

	/**
	 * Get a previously stored value.
	 *
	 * If the key is not found, returns (nil, nil).
	 */
	Get(key []byte) ([]byte, error)

	// Resets the entire database
	Reset() error
}

BlockStoreBackend interface defines an abstract key-value store

type BlockTree

type BlockTree struct {
	// Block indexed by number
	ByNum map[uint64]*protocol.Block

	// Receipt indexed by number
	ReceiptByNum map[uint64][]byte

	// MockBlock by number
	Numbers []uint64
}

BlockTree tracks blocks by number.

func ToBlockTree

func ToBlockTree(mbt *MockBlockTree) *BlockTree

ToBlockTree converts a MockBlockTree to a BlockTree

type DeserializeError

type DeserializeError struct {
}

DeserializeError is an error type for errors during deserialization

func (*DeserializeError) Error

func (e *DeserializeError) Error() string

type InternalError

type InternalError struct {
}

InternalError is an error type that is thrown when an internal constraint is violated

func (*InternalError) Error

func (e *InternalError) Error() string

type KoinosBadgerLogger

type KoinosBadgerLogger struct {
}

KoinosBadgerLogger implements the badger.Logger interface in roder to pass badger logs the the koinos logger

func (KoinosBadgerLogger) Debugf

func (kbl KoinosBadgerLogger) Debugf(msg string, args ...interface{})

Debugf implements formatted debug message handling for badger

func (KoinosBadgerLogger) Errorf

func (kbl KoinosBadgerLogger) Errorf(msg string, args ...interface{})

Errorf implements formatted error message handling for badger

func (KoinosBadgerLogger) Infof

func (kbl KoinosBadgerLogger) Infof(msg string, args ...interface{})

Infof implements formatted info message handling for badger

func (KoinosBadgerLogger) Warningf

func (kbl KoinosBadgerLogger) Warningf(msg string, args ...interface{})

Warningf implements formatted warning message handling for badger

type MapBackend

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

MapBackend implements a key-value store backed by a simple map

func NewMapBackend

func NewMapBackend() *MapBackend

NewMapBackend creates and returns a reference to a map backend instance

func (*MapBackend) Delete added in v1.0.0

func (backend *MapBackend) Delete(key []byte) error

Delete an item from the database

func (*MapBackend) Get

func (backend *MapBackend) Get(key []byte) ([]byte, error)

Get fetches the requested value from the database

func (*MapBackend) Put

func (backend *MapBackend) Put(key []byte, value []byte) error

Put adds the requested value to the database

func (*MapBackend) Reset

func (backend *MapBackend) Reset() error

Reset resets the database

type MockBlock

type MockBlock struct {
	Num      uint64
	Previous uint64

	ActiveData    []byte
	PassiveData   []byte
	SignatureData []byte

	Transactions []*protocol.Transaction

	Receipt []byte
}

MockBlock is similar to a Block.

MockBlock is referred to by a number. For example, we might represent a forked blockchain like this:

101 -> 102 -> 103 -> 104

\
 ---> 203 -> 204

The numbers 101, 102, 103, 104, 203, 204, etc. are used to explain how the blocks relate to each other topologically.

For example, if we're constructing block 203 in some variable mb, we would say mb.Previous = 102. These MockBlocks would be contained in a MockBlockTree, and the number-based Previous is translated to an actual block ID that obeys proper cryptographic constraints by ToBlockTree().

func NewMockBlock

func NewMockBlock() *MockBlock

NewMockBlock creates a new MockBlock object.

type MockBlockTree

type MockBlockTree struct {
	// MockBlock indexed by number
	ByNum map[uint64]*MockBlock
}

MockBlockTree tracks mock blocks by number.

func NewMockBlockTree

func NewMockBlockTree(tree [][]uint64) *MockBlockTree

NewMockBlockTree creates a MockBlockTree from a tree specification

type NotImplemented

type NotImplemented struct {
}

NotImplemented is an error type for unimplemented types

func (*NotImplemented) Error

func (e *NotImplemented) Error() string

type RequestHandler

type RequestHandler struct {
	Backend BlockStoreBackend
	// contains filtered or unexported fields
}

RequestHandler contains a backend object and handles requests

func (*RequestHandler) AddBlock

AddBlock adds a block to the block store

func (*RequestHandler) GetBlocksByHeight

GetBlocksByHeight retuns blocks by block height

func (*RequestHandler) GetBlocksByID

GetBlocksByID returns blocks by block ID

func (*RequestHandler) GetHighestBlock

GetHighestBlock returns the highest block seen by the block store

func (*RequestHandler) HandleRequest

HandleRequest handles and routes blockstore requests

func (*RequestHandler) UpdateHighestBlock

func (handler *RequestHandler) UpdateHighestBlock(topology *koinos.BlockTopology) error

UpdateHighestBlock Updates the database metadata with the highest blocks ID

type ReservedReqError

type ReservedReqError struct {
}

ReservedReqError is an error type that is thrown when a reserved request is passed to the request handler

func (*ReservedReqError) Error

func (e *ReservedReqError) Error() string

type TraverseBeforeGenesisError

type TraverseBeforeGenesisError struct {
}

TraverseBeforeGenesisError is an error type when the blockchain attempts to traverse before genesis

func (*TraverseBeforeGenesisError) Error

type UnexpectedHeightError

type UnexpectedHeightError struct {
}

UnexpectedHeightError is an error type for bad block heights

func (*UnexpectedHeightError) Error

func (e *UnexpectedHeightError) Error() string

type UnknownReqError

type UnknownReqError struct {
}

UnknownReqError is an error that is thrown when an unknown request is given to the request handler

func (*UnknownReqError) Error

func (e *UnknownReqError) Error() string

Jump to

Keyboard shortcuts

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