kernel

package
v0.0.0-...-4701ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: LGPL-3.0 Imports: 28 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTxInKey            = errors.New("invalid txin key")
	ErrInvalidChainCoord         = errors.New("invalid chain coord")
	ErrInvalidSignatureCount     = errors.New("invalid signature count")
	ErrKernelClosed              = errors.New("kernel closed")
	ErrStoreClosed               = errors.New("store closed")
	ErrDirtyContext              = errors.New("dirty context")
	ErrInvalidLevelRootHash      = errors.New("invalid level root hash")
	ErrNotExistConsensusSaveData = errors.New("invalid consensus save data")
	ErrNotExistRewardSaveData    = errors.New("invalid reward save data")
	ErrExpiredContextHeight      = errors.New("expired context height")
	ErrExpiredContextBlockHash   = errors.New("expired context block hash")
	ErrInvalidAppendBlockHeight  = errors.New("invalid append block height")
	ErrInvalidAppendBlockHash    = errors.New("invalid append block hash")
	ErrInvalidAppendContextHash  = errors.New("invalid append context hash")
	ErrInvalidTopSignature       = errors.New("invalid top signature")
	ErrInvalidUTXO               = errors.New("invalid utxo")
	ErrProcessingTransaction     = errors.New("processing transaction")
	ErrNotFormulator             = errors.New("not formulator")
	ErrPastSeq                   = errors.New("past seq")
	ErrTooFarSeq                 = errors.New("too far seq")
	ErrTxQueueOverflowed         = errors.New("tx queue overflowed")
)

store errors

Functions

This section is empty.

Types

type Config

type Config struct {
	ChainCoord              *common.Coordinate
	ObserverKeyMap          map[common.PublicHash]bool
	MaxBlocksPerFormulator  uint32
	MaxTransactionsPerBlock int
}

Config is the configuration of the kernel

type EventHandler

type EventHandler interface {
	// OnProcessBlock called when processing a block to the chain (error prevent processing block)
	OnProcessBlock(kn *Kernel, b *block.Block, s *block.ObserverSigned, ctx *data.Context) error
	// AfterProcessBlock called when processed block to the chain
	AfterProcessBlock(kn *Kernel, b *block.Block, s *block.ObserverSigned, ctx *data.Context)
	// OnPushTransaction called when pushing a transaction to the transaction pool (error prevent push transaction)
	OnPushTransaction(kn *Kernel, tx transaction.Transaction, sigs []common.Signature) error
	// AfterPushTransaction called when pushed a transaction to the transaction pool
	AfterPushTransaction(kn *Kernel, tx transaction.Transaction, sigs []common.Signature)
	// DoTransactionBroadcast called when a transaction need to be broadcast
	DoTransactionBroadcast(kn *Kernel, msg *message_def.TransactionMessage)
	// DebugLog TEMP
	DebugLog(kn *Kernel, args ...interface{})
}

EventHandler provides callback abilities to the kernel

type Kernel

type Kernel struct {
	sync.Mutex
	Config *Config
	// contains filtered or unexported fields
}

Kernel processes the block chain using its components and stores state of the block chain It based on Proof-of-Formulation and Account/UTXO hybrid model All kinds of accounts and transactions processed the out side of kernel

func NewKernel

func NewKernel(Config *Config, st *Store, rd reward.Rewarder, genesisContextData *data.ContextData) (*Kernel, error)

NewKernel returns a Kernel

func (*Kernel) Accounter

func (kn *Kernel) Accounter() *data.Accounter

Accounter returns the accounter of the target kernel

func (*Kernel) AddEventHandler

func (kn *Kernel) AddEventHandler(eh EventHandler)

AddEventHandler adds a event handler to the kernel

func (*Kernel) AddTransaction

func (kn *Kernel) AddTransaction(tx transaction.Transaction, sigs []common.Signature) error

AddTransaction validate the transaction and push it to the transaction pool

func (*Kernel) Block

func (kn *Kernel) Block(height uint32) (*block.Block, error)

Block returns the block of the height

func (*Kernel) BlocksFromSameFormulator

func (kn *Kernel) BlocksFromSameFormulator() uint32

BlocksFromSameFormulator returns a number of blocks made from same formulator

func (*Kernel) CandidateCount

func (kn *Kernel) CandidateCount() int

CandidateCount returns a count of the rank table

func (*Kernel) ChainCoord

func (kn *Kernel) ChainCoord() *common.Coordinate

ChainCoord returns the coordinate of the target kernel

func (*Kernel) CheckFork

func (kn *Kernel) CheckFork(ch chain.Header, sigs []common.Signature) error

CheckFork returns chain.ErrForkDetected if the given data is valid and collapse with stored one

func (*Kernel) Close

func (kn *Kernel) Close()

Close terminates and cleans the kernel

func (*Kernel) DebugLog

func (kn *Kernel) DebugLog(args ...interface{})

DebugLog TEMP

func (*Kernel) GenerateBlock

func (kn *Kernel) GenerateBlock(ctx *data.Context, TimeoutCount uint32, Timestamp uint64, Formulator common.Address) (*block.Block, error)

GenerateBlock generate a next block and its signature using transactions in the pool

func (*Kernel) HasTransaction

func (kn *Kernel) HasTransaction(TxHash hash.Hash256) bool

HasTransaction validate the transaction and push it to the transaction pool

func (*Kernel) IsFormulator

func (kn *Kernel) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool

IsFormulator returns the given information is correct or not

func (*Kernel) Loader

func (kn *Kernel) Loader() data.Loader

Loader returns the loader of the kernel

func (*Kernel) OnItemExpired

func (kn *Kernel) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool)

OnItemExpired is called when the item is expired

func (*Kernel) Process

func (kn *Kernel) Process(cd *chain.Data, UserData interface{}) error

Process resolves the chain data and updates the context

func (*Kernel) Provider

func (kn *Kernel) Provider() chain.Provider

Provider returns the provider of the kernel

func (*Kernel) RanksInMap

func (kn *Kernel) RanksInMap(FormulatorMap map[common.Address]bool, Limit int) ([]*consensus.Rank, error)

RanksInMap returns the ranks in the map

func (*Kernel) Screening

func (kn *Kernel) Screening(cd *chain.Data) error

Screening determines the acceptance of the chain data

func (*Kernel) TopRank

func (kn *Kernel) TopRank(TimeoutCount int) (*consensus.Rank, error)

TopRank returns the top rank by the given timeout count

func (*Kernel) TopRankInMap

func (kn *Kernel) TopRankInMap(FormulatorMap map[common.Address]bool) (*consensus.Rank, int, error)

TopRankInMap returns the top rank by the given timeout count in the given map

func (*Kernel) Transactor

func (kn *Kernel) Transactor() *data.Transactor

Transactor returns the transactor of the target kernel

func (*Kernel) Validate

func (kn *Kernel) Validate(b *block.Block, GeneratorSignature common.Signature) (*data.Context, error)

Validate validates the chain header and returns the context of it

func (*Kernel) Version

func (kn *Kernel) Version() uint16

Version returns the version of the target kernel

type Store

type Store struct {
	sync.Mutex

	SeqMapLock sync.Mutex
	SeqMap     map[common.Address]uint64
	// contains filtered or unexported fields
}

Store saves the target chain state All updates are executed in one transaction with FileSync option

func NewStore

func NewStore(path string, version uint16, act *data.Accounter, tran *data.Transactor, evt *data.Eventer, bRecover bool) (*Store, error)

NewStore returns a Store

func (*Store) Account

func (st *Store) Account(addr common.Address) (account.Account, error)

Account returns the account instance of the address from the store

func (*Store) AccountData

func (st *Store) AccountData(addr common.Address, name []byte) []byte

AccountData returns the account data from the store

func (*Store) AccountDataKeys

func (st *Store) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)

AccountDataKeys returns all data keys of the account in the store

func (*Store) Accounter

func (st *Store) Accounter() *data.Accounter

Accounter returns the accounter of the target chain

func (*Store) Accounts

func (st *Store) Accounts() ([]account.Account, error)

Accounts returns all accounts in the store

func (*Store) AddressByName

func (st *Store) AddressByName(Name string) (common.Address, error)

AddressByName returns the account instance of the name from the store

func (*Store) ChainCoord

func (st *Store) ChainCoord() *common.Coordinate

ChainCoord returns the coordinate of the target chain

func (*Store) Close

func (st *Store) Close()

Close terminate and clean store

func (*Store) CreateBody

func (st *Store) CreateBody() chain.Body

CreateBody returns a header that implements the chain header interface

func (*Store) CreateHeader

func (st *Store) CreateHeader() chain.Header

CreateHeader returns a header that implements the chain header interface

func (*Store) CustomData

func (st *Store) CustomData(key string) []byte

CustomData returns the custom data by the key from the store

func (*Store) Data

func (st *Store) Data(height uint32) (*chain.Data, error)

Data returns the data by height

func (*Store) DeleteCustomData

func (st *Store) DeleteCustomData(key string) error

DeleteCustomData deletes the custom data

func (*Store) Eventer

func (st *Store) Eventer() *data.Eventer

Eventer returns the eventer of the target chain

func (*Store) Events

func (st *Store) Events(From uint32, To uint32) ([]event.Event, error)

Events returns all events by conditions

func (*Store) Hash

func (st *Store) Hash(height uint32) (hash.Hash256, error)

Hash returns the hash of the data by height

func (*Store) Header

func (st *Store) Header(height uint32) (chain.Header, error)

Header returns the header of the data by height

func (*Store) Height

func (st *Store) Height() uint32

Height returns the current height of the target chain

func (*Store) IsExistAccount

func (st *Store) IsExistAccount(addr common.Address) (bool, error)

IsExistAccount checks that the account of the address is exist or not

func (*Store) IsExistAccountName

func (st *Store) IsExistAccountName(Name string) (bool, error)

IsExistAccountName checks that the account of the name is exist or not

func (*Store) IsExistUTXO

func (st *Store) IsExistUTXO(id uint64) (bool, error)

IsExistUTXO checks that the utxo of the id is exist or not

func (*Store) LastHash

func (st *Store) LastHash() hash.Hash256

LastHash returns the last hash of the chain

func (*Store) LockedBalances

func (st *Store) LockedBalances(addr common.Address) ([]*data.LockedBalance, error)

LockedBalances returns locked balances of the address

func (*Store) LockedBalancesByHeight

func (st *Store) LockedBalancesByHeight(Height uint32) ([]*data.LockedBalance, error)

LockedBalancesByHeight returns locked balances of the height

func (*Store) Provider

func (st *Store) Provider() chain.Provider

Provider returns the provider of the kernel

func (*Store) Seq

func (st *Store) Seq(addr common.Address) uint64

Seq returns the sequence of the transaction

func (*Store) SetCustomData

func (st *Store) SetCustomData(key string, value []byte) error

SetCustomData updates the custom data

func (*Store) StoreData

func (st *Store) StoreData(cd *chain.Data, ctd *data.ContextData, customHash map[string][]byte) error

StoreData stores the data

func (*Store) StoreGenesis

func (st *Store) StoreGenesis(genHash hash.Hash256, ctd *data.ContextData, customHash map[string][]byte) error

StoreGenesis stores the genesis data

func (*Store) TargetHeight

func (st *Store) TargetHeight() uint32

TargetHeight returns the target height of the target chain

func (*Store) Transactor

func (st *Store) Transactor() *data.Transactor

Transactor returns the transactor of the target chain

func (*Store) UTXO

func (st *Store) UTXO(id uint64) (*transaction.UTXO, error)

UTXO returns the UTXO from the top store

func (*Store) UTXOs

func (st *Store) UTXOs() ([]*transaction.UTXO, error)

UTXOs returns all UTXOs in the store

func (*Store) Version

func (st *Store) Version() uint16

Version returns the version of the target chain

Jump to

Keyboard shortcuts

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