batch

package
v2.10.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorArrivedToMax means that the maximum capacity has been reached for the batch
	ErrorArrivedToMax = errors.New("arrived to max")
	// ErrorReference mean that the dependency item(account or snapshot block) does not exist in chain or batch
	ErrorReference = errors.New("refer not exist")
)

Functions

func NewGenesisBlock

func NewGenesisBlock(addr *types.Address) *mockItem

func NewMockReceiveBlcok

func NewMockReceiveBlcok(prev Item, sendHash types.Hash) *mockItem

mock receive item

func NewMockSendBlcok

func NewMockSendBlcok(prev Item) *mockItem

mock send item

func NewMockSnapshotBlock

func NewMockSnapshotBlock(prev Item, accBlocks []Item) *mockItem

mock snapshot item

Types

type AccountExistsFunc

type AccountExistsFunc func(hash types.Hash) error

return nil, if hash is exists

type Batch

type Batch interface {
	// AddAItem add account block to Batch
	AddAItem(item Item, sHash *types.Hash) error
	// AddAItem add snapshot block to Batch
	AddSItem(item Item) error
	// Levels returns all levels for the Batch
	Levels() []Level
	// Size returns the number of items
	Size() int
	// Info returns the basic info for the Batch
	Info() string
	// Version returns the version for the Batch
	Version() uint64
	// Exists returns whether or not the hash is in the Batch
	Exists(hash types.Hash) bool
	// Batch runs the Batch
	Batch(snapshotFn BucketExecutorFn, accountFn BucketExecutorFn) error
	// Id returns the id of the Batch
	Id() uint64
}

Batch is a batch for block insertion.

func NewBatch

func NewBatch(snapshotF SnapshotExistsFunc, accountF AccountExistsFunc, version uint64, max int) Batch

type Bucket

type Bucket interface {
	// Items returns all items
	Items() []Item
	// Owner mean the same address, it will return nil if all items are snapshot item.
	Owner() *types.Address
}

Bucket is a item(account and snapshot block) collection for same address

type BucketExecutorFn

type BucketExecutorFn func(p Batch, l Level, bucket Bucket, version uint64) error

BucketExecutorFn can insert a bucket

type Item

type Item interface {
	// keys, accounts, snapshot
	ReferHashes() ([]types.Hash, []types.Hash, *types.Hash)
	// Owner will return nil if the item is the snapshot item.
	Owner() *types.Address
	Hash() types.Hash
	Height() uint64
	PrevHash() types.Hash
}

Item means a account block or a snapshot block

type Level

type Level interface {
	// Buckets returns all buckets in the level.
	Buckets() []Bucket
	// Add will add the item to the level.
	Add(item Item) error
	// SHash is snapshot hash for the level, will return nil for snapshot level.
	SHash() *types.Hash
	// Snapshot mean whether it is a snapshot level(just snapshot item can be added).
	Snapshot() bool
	// Index means the index of the level
	Index() int
	// Close means not accepting any item
	Close()
	Closed() bool
	// Done mean all item have been added to chain
	Done()
	HasDone() bool

	// The count of Items
	Size() int
}

Level is a bucket collection, and it cannot be inserted concurrently between level

type SnapshotExistsFunc

type SnapshotExistsFunc func(hash types.Hash) error

return nil, if hash is exists

Jump to

Keyboard shortcuts

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