storage

package
v0.0.0-...-a5ce5ae Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBlockTxCount = 1000
	MaxSetSize      = 100
	Version         = 1
)
View Source
const (
	BlockStateUnvalidated = iota
	BlockStateValidated
	BlockStateAccepted
)
View Source
const (
	CIDEncodingTx    = 0x87
	CIDEncodingBlock = 0x88
	CIDEncodingSet   = 0x89
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")

	ErrDIDAlreadyExists    = errors.New("DID already exists")
	ErrDIDInvalid          = errors.New("DID is invalid")
	ErrDIDInvalidSignature = errors.New("tx signature not signed by key in DID")

	ErrOpNotSupported = errors.New("operation not supported on tx type")

	ErrTxVersionNotSupported = errors.New("tx version not supported")
	ErrTxMissingTimestamp    = errors.New("tx missing timestamp")
	ErrTxMissingFrom         = errors.New("tx missing from did")
	ErrTxUnsupportedType     = errors.New("unsupported tx type")
	ErrTxMissingData         = errors.New("tx missing data")
)

Functions

func BloomContains

func BloomContains(b []byte, tx cid.Cid) (bool, error)

BloomContains checks if the given bloom filter contains the CID

func MakeBloom

func MakeBloom(tx []cid.Cid) ([]byte, error)

MakeBloom constructs a new bloom byte array from a given set of CIDs with a bloom estimation of the total number of CIDs in the set

Types

type Block

type Block struct {
	Version   uint32   `msgpack:"v"`
	ID        BlockID  `magpack:"i"`
	Parent    BlockID  `msgpack:"p"`
	Height    uint64   `msgpack:"h"`
	CreatedAt int64    `msgpack:"t"`
	Proposer  string   `msgpack:"w"`
	Signature []byte   `msgpack:"s"`
	Nonce     [32]byte `msgpack:"n"`
	Bloom     []byte   `msgpack:"b"`
	TxRoot    cid.Cid  `msgpack:"x"`
}

func NewBlock

func NewBlock(ctx context.Context, s Store, parent BlockID, txs []cid.Cid) (*Block, error)

type BlockID

type BlockID cid.Cid

func (BlockID) Bytes

func (b BlockID) Bytes() []byte

func (BlockID) String

func (b BlockID) String() string

type BlockState

type BlockState int

type GenesisInfo

type GenesisInfo struct {
	ChainID string   `msgpack:"chain"`
	Block   Block    `magpack:"block"`
	Txs     []*tx.Tx `msgpack:"txs"`
}

GenesisInfo provides enough information to be used as the genesis block of the block chain. It does not provide a TxSet assuming that the block definition stores the root of the CID Merkle Tree and the storage engine needs to check if the TXs aligns with the TxSet root when applying the TXs with a metadata store. A ChainID is also provided

type MemStore

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

MemStore implements an in-memory store and metadata store primarily used for testing

func NewMemStore

func NewMemStore() *MemStore

NewMemStore constructs a new blank MemStore

func (*MemStore) AllTx

func (m *MemStore) AllTx(ctx context.Context, b *Block) (map[tx.TxID]*tx.Tx, error)

func (*MemStore) ApplyGenesis

func (m *MemStore) ApplyGenesis(gen *GenesisInfo) error

func (*MemStore) ApplyTx

func (m *MemStore) ApplyTx(ctx context.Context, id tx.TxID, t *tx.Tx) error

func (*MemStore) Claims

func (m *MemStore) Claims(_ context.Context, id string) ([]*tx.Tx, error)

func (*MemStore) CompleteTest

func (m *MemStore) CompleteTest(context.Context) error

func (*MemStore) DIDHistory

func (m *MemStore) DIDHistory(_ context.Context, id string) ([]*tx.Tx, error)

func (*MemStore) GetBlock

func (m *MemStore) GetBlock(ctx context.Context, id BlockID) (*Block, error)

func (*MemStore) GetLastApplied

func (m *MemStore) GetLastApplied(ctx context.Context) (*Block, error)

func (*MemStore) GetSet

func (m *MemStore) GetSet(ctx context.Context, id cid.Cid) (*TxSet, error)

func (*MemStore) GetTx

func (m *MemStore) GetTx(ctx context.Context, id tx.TxID) (*tx.Tx, error)

func (*MemStore) GetTxBlock

func (m *MemStore) GetTxBlock(ctx context.Context, id tx.TxID) (*Block, error)

func (*MemStore) HasGenesisApplied

func (m *MemStore) HasGenesisApplied() bool

func (*MemStore) LookupDID

func (m *MemStore) LookupDID(_ context.Context, id string) (*w3cdid.Document, error)

func (*MemStore) MarkBlock

func (m *MemStore) MarkBlock(ctx context.Context, b BlockID, s BlockState) error

func (*MemStore) Node

func (m *MemStore) Node(ctx context.Context, id string) (*tx.Node, error)

func (*MemStore) Nodes

func (m *MemStore) Nodes() ([]string, error)

func (*MemStore) PutBlock

func (m *MemStore) PutBlock(ctx context.Context, b *Block) (cid.Cid, error)

func (*MemStore) PutSet

func (m *MemStore) PutSet(ctx context.Context, txt *TxSet) (cid.Cid, error)

func (*MemStore) PutTx

func (m *MemStore) PutTx(ctx context.Context, tx *tx.Tx) (cid.Cid, error)

func (*MemStore) StartTest

func (m *MemStore) StartTest(context.Context) (Store, error)

func (*MemStore) Stop

func (m *MemStore) Stop() error

func (*MemStore) UpdateLastApplied

func (m *MemStore) UpdateLastApplied(_ context.Context, id BlockID) error

type MetadataProvider

type MetadataProvider interface {
	LookupDID(context.Context, string) (*w3cdid.Document, error)
	DIDHistory(context.Context, string) ([]*tx.Tx, error)

	Claims(context.Context, string) ([]*tx.Tx, error) //TODO(tcfw): vc type

	Nodes() ([]string, error)
	Node(context.Context, string) (*tx.Node, error)

	HasGenesisApplied() bool
	ApplyGenesis(*GenesisInfo) error

	ApplyTx(context.Context, tx.TxID, *tx.Tx) error

	StartTest(context.Context) (Store, error)
	CompleteTest(context.Context) error
}

MetadataProvider provides indexes and metadata for TXs that have been successfully validates and applied in the block chain The information should be maintainable and rebuildable without a metadata store and should be used as a performance measure for reading blockchain records

type Store

type Store interface {
	MetadataProvider

	PutTx(context.Context, *tx.Tx) (cid.Cid, error)
	GetTx(context.Context, tx.TxID) (*tx.Tx, error)

	PutBlock(context.Context, *Block) (cid.Cid, error)
	GetBlock(context.Context, BlockID) (*Block, error)

	AllTx(context.Context, *Block) (map[tx.TxID]*tx.Tx, error)

	PutSet(context.Context, *TxSet) (cid.Cid, error)
	GetSet(context.Context, cid.Cid) (*TxSet, error)

	GetTxBlock(context.Context, tx.TxID) (*Block, error)
	MarkBlock(context.Context, BlockID, BlockState) error

	UpdateLastApplied(context.Context, BlockID) error
	GetLastApplied(context.Context) (*Block, error)

	Stop() error
}

Store provides a means of storing individual components in the blockchain such as blocks, tx, txsets and the like as well as storing the consensus state for persistance between node restarts

type TxSet

type TxSet struct {
	Children []cid.Cid `msgpack:"c"`
	Tx       *cid.Cid  `msgpack:"t"`
	// contains filtered or unexported fields
}

func NewTxSet

func NewTxSet(s Store, txs []cid.Cid) (*TxSet, error)

NewTxSet constructs a new Merkle tree of TX CIDs and stores the TxSet in the provided store as the Merkle tree reduces to its root node

func (*TxSet) Cid

func (txs *TxSet) Cid() cid.Cid

type TxValidator

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

func NewTxValidator

func NewTxValidator(s Store) *TxValidator

func (*TxValidator) ApplyFromTip

func (v *TxValidator) ApplyFromTip(ctx context.Context, id BlockID) error

func (*TxValidator) IsBlockValid

func (v *TxValidator) IsBlockValid(ctx context.Context, b *Block, isNewBlock bool) error

func (*TxValidator) IsTxValid

func (v *TxValidator) IsTxValid(ctx context.Context, t *tx.Tx) error

type Validator

type Validator interface {
	IsBlockValid(context.Context, *Block, bool) error
	IsTxValid(context.Context, *tx.Tx) error
	ApplyFromTip(context.Context, BlockID) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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