isaacblock

package
v0.0.0-...-8c25bd3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package isaacblock handles data of block.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLastBlockMapOnlyInDatabase = util.NewIDError("last blockmap found in database, but not in local fs")
	ErrLastBlockMapOnlyInLocalFS  = util.NewIDError("last blockmap found in local fs, but not in database")
)
View Source
var BlockMapHint = hint.MustNewHint("blockmap-v0.0.1")
View Source
var BlockTempDirectoryPrefix = "temp"
View Source
var LocalFSWriterHint = hint.MustNewHint("block-localfs-writer-v0.0.1")
View Source
var SuffrageProofHint = hint.MustNewHint("suffrage-proof-v0.0.1")

Functions

func BlockItemFileName

func BlockItemFileName(t base.BlockItemType, hinttype hint.Type, compressFormat string) (string, error)

func CleanBlockTempDirectory

func CleanBlockTempDirectory(root string) error

func DefaultBlockItemFileName

func DefaultBlockItemFileName(t base.BlockItemType, hinttype hint.Type) (string, error)

func FindHighestBlockItemFiles

func FindHighestBlockItemFiles(p string, depth int) (height int64, lastpath string, _ error)

func FindHighestDirectory

func FindHighestDirectory(root string) (_ base.Height, directory string, found bool, _ error)

func HeightFromDirectory

func HeightFromDirectory(s string) (base.Height, error)

func ImportBlocks

func ImportBlocks(
	ctx context.Context,
	from, to base.Height,
	batchlimit int64,
	readers *isaac.BlockItemReaders,
	blockMapf ImportBlocksBlockMapFunc,
	blockItemf ImportBlocksBlockItemFunc,
	newBlockImporter func(base.BlockMap) (isaac.BlockImporter, error),
	setLastVoteproofsFunc func([2]base.Voteproof, bool) error,
	mergeBlockWriterDatabasesf func(context.Context) error,
) error

func IsValidAllBlockMapsFromLocalFS

func IsValidAllBlockMapsFromLocalFS(
	readers *isaac.BlockItemReaders,
	last base.Height,
	networkID base.NetworkID,
) error

func IsValidBlockFromLocalFS

func IsValidBlockFromLocalFS(
	itemf isaac.BlockItemReadersItemFunc,
	height base.Height,
	networkID base.NetworkID,
	validateBlockMapf func(base.BlockMap) error,
	validateOperationf func(base.Operation) error,
	validateStatef func(base.State) error,
) error

func IsValidBlocksFromStorage

func IsValidBlocksFromStorage(
	itemf isaac.BlockItemReadersItemFunc,
	fromHeight, toHeight base.Height,
	networkID base.NetworkID,
	db isaac.Database,
	whenBlockDonef func(base.BlockMap, error) error,
) error

func IsValidLastBlocks

func IsValidLastBlocks(
	readers *isaac.BlockItemReaders,
	remotes isaac.RemotesBlockItemReadFunc,
	db isaac.Database,
	networkID base.NetworkID,
) error

func IsValidOperationsOfBlock

func IsValidOperationsOfBlock(
	opstree fixedtree.Tree,
	ops []base.Operation,
	manifest base.Manifest,
	networkID base.NetworkID,
	validateOperationf func(base.Operation) error,
) error

func IsValidStatesOfBlock

func IsValidStatesOfBlock(
	ststree fixedtree.Tree,
	sts []base.State,
	manifest base.Manifest,
	networkID base.NetworkID,
	validateStatef func(base.State) error,
) error

func NewDefaultItemReaderFunc

func NewDefaultItemReaderFunc(workerSize uint64) isaac.NewBlockItemReaderFunc

func NewItemReader

func NewItemReader(
	t base.BlockItemType,
	enc encoder.Encoder,
	r *util.CompressedReader,
	workerSize uint64,
) (isaac.BlockItemReader, error)

func RemoveBlockFromLocalFS

func RemoveBlockFromLocalFS(root string, height base.Height) (bool, error)

func RemoveBlocksFromLocalFS

func RemoveBlocksFromLocalFS(root string, height base.Height) (bool, error)

Types

type BlockImporter

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

func NewBlockImporter

func NewBlockImporter(
	root string,
	encs *encoder.Encoders,
	m base.BlockMap,
	bwdb isaac.BlockWriteDatabase,
	mergeBlockWriteDatabasef func(context.Context) error,
	networkID base.NetworkID,
) (*BlockImporter, error)

func (*BlockImporter) CancelImport

func (im *BlockImporter) CancelImport(context.Context) error

func (*BlockImporter) Save

func (im *BlockImporter) Save(context.Context) (func(context.Context) error, error)

func (*BlockImporter) WriteItem

func (*BlockImporter) WriteMap

func (im *BlockImporter) WriteMap(m base.BlockMap) error

type BlockMap

type BlockMap struct {
	base.BaseNodeSign
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBlockMap

func NewBlockMap() BlockMap

func (BlockMap) Bytes

func (BlockMap) Bytes() []byte

func (*BlockMap) DecodeJSON

func (m *BlockMap) DecodeJSON(b []byte, enc encoder.Encoder) error

func (BlockMap) IsValid

func (m BlockMap) IsValid(b []byte) error

func (BlockMap) Item

func (BlockMap) Items

func (m BlockMap) Items(f func(base.BlockMapItem) bool)

func (BlockMap) Manifest

func (m BlockMap) Manifest() base.Manifest

func (BlockMap) MarshalJSON

func (m BlockMap) MarshalJSON() ([]byte, error)

func (*BlockMap) SetItem

func (m *BlockMap) SetItem(item base.BlockMapItem) error

func (*BlockMap) SetManifest

func (m *BlockMap) SetManifest(manifest base.Manifest)

func (*BlockMap) Sign

func (m *BlockMap) Sign(node base.Address, priv base.Privatekey, networkID base.NetworkID) error

type BlockMapItem

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

func NewBlockMapItem

func NewBlockMapItem(t base.BlockItemType, checksum string) BlockMapItem

func (BlockMapItem) Checksum

func (item BlockMapItem) Checksum() string

func (BlockMapItem) IsValid

func (item BlockMapItem) IsValid([]byte) error

func (BlockMapItem) MarshalJSON

func (item BlockMapItem) MarshalJSON() ([]byte, error)

func (BlockMapItem) Type

func (item BlockMapItem) Type() base.BlockItemType

func (*BlockMapItem) UnmarshalJSON

func (item *BlockMapItem) UnmarshalJSON(b []byte) error

type DefaultStatesMerger

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

func NewDefaultStatesMerger

func NewDefaultStatesMerger(
	height base.Height,
	getStateFunc base.GetStateFunc,
	workersize int64,
) *DefaultStatesMerger

func (*DefaultStatesMerger) Close

func (sm *DefaultStatesMerger) Close() error

func (*DefaultStatesMerger) CloseStates

func (sm *DefaultStatesMerger) CloseStates(
	ctx context.Context,
	beforeClose func(keyscount uint64) error,
	oneState func(newState base.State, total, index uint64) error,
) error

func (*DefaultStatesMerger) Len

func (sm *DefaultStatesMerger) Len() int

func (*DefaultStatesMerger) SetStates

func (sm *DefaultStatesMerger) SetStates(
	ctx context.Context,
	index uint64,
	stvms []base.StateMergeValue,
	operation util.Hash,
) error

type ErrValidatedDifferentHeightBlockMaps

type ErrValidatedDifferentHeightBlockMaps struct {
	*util.IDError
	// contains filtered or unexported fields
}

func (*ErrValidatedDifferentHeightBlockMaps) DatabaseHeight

func (er *ErrValidatedDifferentHeightBlockMaps) DatabaseHeight() base.Height

func (*ErrValidatedDifferentHeightBlockMaps) Errorf

func (er *ErrValidatedDifferentHeightBlockMaps) Errorf(
	format string, args ...interface{},
) *ErrValidatedDifferentHeightBlockMaps

func (*ErrValidatedDifferentHeightBlockMaps) LocalFSHeight

func (er *ErrValidatedDifferentHeightBlockMaps) LocalFSHeight() base.Height

func (*ErrValidatedDifferentHeightBlockMaps) WithMessage

func (er *ErrValidatedDifferentHeightBlockMaps) WithMessage(err error, format string, args ...interface{}) error

func (*ErrValidatedDifferentHeightBlockMaps) WithStack

func (*ErrValidatedDifferentHeightBlockMaps) Wrap

type FSWriter

type FSWriter interface {
	SetProposal(context.Context, base.ProposalSignFact) error
	SetOperation(_ context.Context, total, index uint64, _ base.Operation) error
	SetOperationsTree(context.Context, fixedtree.Tree) error
	SetState(_ context.Context, total, index uint64, _ base.State) error
	SetStatesTree(context.Context, fixedtree.Tree) error
	SetManifest(context.Context, base.Manifest) error
	SetINITVoteproof(context.Context, base.INITVoteproof) error
	SetACCEPTVoteproof(context.Context, base.ACCEPTVoteproof) error
	Save(context.Context) (base.BlockMap, error)
	Cancel() error
}

type ImportBlocksBlockItemFunc

type ImportBlocksBlockItemFunc func(
	context.Context, base.Height, base.BlockItemType, func(_ io.Reader, found bool, compressFormat string) error,
) error

type ImportBlocksBlockMapFunc

type ImportBlocksBlockMapFunc func(context.Context, base.Height) (base.BlockMap, bool, error)

type ItemReader

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

func (*ItemReader) Decode

func (r *ItemReader) Decode() (interface{}, error)

func (*ItemReader) DecodeItems

func (r *ItemReader) DecodeItems(f func(uint64, uint64, interface{}) error) (uint64, error)

func (*ItemReader) Encoder

func (r *ItemReader) Encoder() encoder.Encoder

func (*ItemReader) Reader

func (r *ItemReader) Reader() *util.CompressedReader

func (*ItemReader) Type

func (r *ItemReader) Type() base.BlockItemType

type LocalFSImporter

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

func NewLocalFSImporter

func NewLocalFSImporter(root string, jsonenc, enc encoder.Encoder, m base.BlockMap) (*LocalFSImporter, error)

func (*LocalFSImporter) Cancel

func (l *LocalFSImporter) Cancel() error

func (*LocalFSImporter) Save

func (l *LocalFSImporter) Save() error

func (*LocalFSImporter) WriteItem

func (l *LocalFSImporter) WriteItem(
	t base.BlockItemType,
	enc hint.Hint,
	compressFormat string,
) (io.WriteCloser, error)

func (*LocalFSImporter) WriteMap

func (l *LocalFSImporter) WriteMap(m base.BlockMap) error

WriteMap writes BlockMap; BlockMap should be already sign.

type LocalFSWriter

type LocalFSWriter struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewLocalFSWriter

func NewLocalFSWriter(
	root string,
	height base.Height,
	jsonenc, enc encoder.Encoder,
	local base.LocalNode,
	networkID base.NetworkID,
) (*LocalFSWriter, error)

func (*LocalFSWriter) Cancel

func (w *LocalFSWriter) Cancel() error

func (*LocalFSWriter) Save

func (w *LocalFSWriter) Save(ctx context.Context) (base.BlockMap, error)

func (*LocalFSWriter) SetACCEPTVoteproof

func (w *LocalFSWriter) SetACCEPTVoteproof(_ context.Context, vp base.ACCEPTVoteproof) error

func (*LocalFSWriter) SetINITVoteproof

func (w *LocalFSWriter) SetINITVoteproof(_ context.Context, vp base.INITVoteproof) error

func (*LocalFSWriter) SetManifest

func (w *LocalFSWriter) SetManifest(_ context.Context, m base.Manifest) error

func (*LocalFSWriter) SetOperation

func (w *LocalFSWriter) SetOperation(_ context.Context, total, _ uint64, op base.Operation) error

func (*LocalFSWriter) SetOperationsTree

func (w *LocalFSWriter) SetOperationsTree(ctx context.Context, tr fixedtree.Tree) error

func (*LocalFSWriter) SetProposal

func (w *LocalFSWriter) SetProposal(_ context.Context, pr base.ProposalSignFact) error

func (*LocalFSWriter) SetState

func (w *LocalFSWriter) SetState(_ context.Context, total, _ uint64, st base.State) error

func (*LocalFSWriter) SetStatesTree

func (w *LocalFSWriter) SetStatesTree(ctx context.Context, tr fixedtree.Tree) error

type StatesMerger

type StatesMerger interface {
	SetStates(_ context.Context, opindex uint64, _ []base.StateMergeValue, operationfacthash util.Hash) error
	CloseStates(
		_ context.Context,
		beforeClose func(keyscount uint64) error,
		oneState func(newState base.State, total, index uint64) error,
	) error
	Len() int
	Close() error
}

type SuffrageProof

type SuffrageProof struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewSuffrageProof

func NewSuffrageProof(
	m base.BlockMap,
	st base.State,
	proof fixedtree.Proof,
) SuffrageProof

func (*SuffrageProof) DecodeJSON

func (s *SuffrageProof) DecodeJSON(b []byte, enc encoder.Encoder) error

func (SuffrageProof) IsValid

func (s SuffrageProof) IsValid(b []byte) error

func (SuffrageProof) Map

func (s SuffrageProof) Map() base.BlockMap

func (SuffrageProof) MarshalJSON

func (s SuffrageProof) MarshalJSON() ([]byte, error)

func (SuffrageProof) Proof

func (s SuffrageProof) Proof() fixedtree.Proof

func (SuffrageProof) Prove

func (s SuffrageProof) Prove(previousState base.State) error

Prove should be called after IsValid().

func (SuffrageProof) State

func (s SuffrageProof) State() base.State

func (SuffrageProof) Suffrage

func (s SuffrageProof) Suffrage() (base.Suffrage, error)

func (SuffrageProof) SuffrageHeight

func (s SuffrageProof) SuffrageHeight() base.Height

type SuffrageProofJSONMarshaler

type SuffrageProofJSONMarshaler struct {
	Map   base.BlockMap   `json:"map"`
	State base.State      `json:"state"`
	Proof fixedtree.Proof `json:"proof"`
	hint.BaseHinter
}

type SuffrageProofJSONUnmarshaler

type SuffrageProofJSONUnmarshaler struct {
	Map   json.RawMessage `json:"map"`
	State json.RawMessage `json:"state"`
	Proof fixedtree.Proof `json:"proof"`
}

type Writer

type Writer struct {
	*logging.Logging
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(
	proposal base.ProposalSignFact,
	getStateFunc base.GetStateFunc,
	db isaac.BlockWriteDatabase,
	mergeDatabase func(isaac.BlockWriteDatabase) error,
	fswriter FSWriter,
	workersize int64,
) *Writer

func (*Writer) Cancel

func (w *Writer) Cancel() error

func (*Writer) Manifest

func (w *Writer) Manifest(ctx context.Context, previous base.Manifest) (base.Manifest, error)

func (*Writer) Save

func (w *Writer) Save(ctx context.Context) (base.BlockMap, error)

func (*Writer) SetACCEPTVoteproof

func (w *Writer) SetACCEPTVoteproof(_ context.Context, vp base.ACCEPTVoteproof) error

func (*Writer) SetINITVoteproof

func (w *Writer) SetINITVoteproof(_ context.Context, vp base.INITVoteproof) error

func (*Writer) SetOperationsSize

func (w *Writer) SetOperationsSize(n uint64)

func (*Writer) SetProcessResult

func (w *Writer) SetProcessResult(
	_ context.Context,
	index uint64,
	op, facthash util.Hash,
	instate bool,
	errorreason base.OperationProcessReasonError,
) error

func (*Writer) SetStates

func (w *Writer) SetStates(
	ctx context.Context, index uint64, states []base.StateMergeValue, operation base.Operation,
) error

Jump to

Keyboard shortcuts

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