Documentation ¶
Index ¶
- Variables
- type Config
- type EventHandler
- type Kernel
- func (kn *Kernel) Accounter() *data.Accounter
- func (kn *Kernel) AddEventHandler(eh EventHandler)
- func (kn *Kernel) AddTransaction(tx transaction.Transaction, sigs []common.Signature) error
- func (kn *Kernel) Block(height uint32) (*block.Block, error)
- func (kn *Kernel) BlocksFromSameFormulator() uint32
- func (kn *Kernel) CandidateCount() int
- func (kn *Kernel) ChainCoord() *common.Coordinate
- func (kn *Kernel) CheckFork(ch chain.Header, sigs []common.Signature) error
- func (kn *Kernel) Close()
- func (kn *Kernel) DebugLog(args ...interface{})
- func (kn *Kernel) GenerateBlock(ctx *data.Context, TimeoutCount uint32, Timestamp uint64, ...) (*block.Block, error)
- func (kn *Kernel) HasTransaction(TxHash hash.Hash256) bool
- func (kn *Kernel) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool
- func (kn *Kernel) Loader() data.Loader
- func (kn *Kernel) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool)
- func (kn *Kernel) Process(cd *chain.Data, UserData interface{}) error
- func (kn *Kernel) Provider() chain.Provider
- func (kn *Kernel) RanksInMap(FormulatorMap map[common.Address]bool, Limit int) ([]*consensus.Rank, error)
- func (kn *Kernel) Screening(cd *chain.Data) error
- func (kn *Kernel) TopRank(TimeoutCount int) (*consensus.Rank, error)
- func (kn *Kernel) TopRankInMap(FormulatorMap map[common.Address]bool) (*consensus.Rank, int, error)
- func (kn *Kernel) Transactor() *data.Transactor
- func (kn *Kernel) Validate(b *block.Block, GeneratorSignature common.Signature) (*data.Context, error)
- func (kn *Kernel) Version() uint16
- type Store
- func (st *Store) Account(addr common.Address) (account.Account, error)
- func (st *Store) AccountData(addr common.Address, name []byte) []byte
- func (st *Store) AccountDataKeys(addr common.Address, Prefix []byte) ([][]byte, error)
- func (st *Store) Accounter() *data.Accounter
- func (st *Store) Accounts() ([]account.Account, error)
- func (st *Store) AddressByName(Name string) (common.Address, error)
- func (st *Store) ChainCoord() *common.Coordinate
- func (st *Store) Close()
- func (st *Store) CreateBody() chain.Body
- func (st *Store) CreateHeader() chain.Header
- func (st *Store) CustomData(key string) []byte
- func (st *Store) Data(height uint32) (*chain.Data, error)
- func (st *Store) DeleteCustomData(key string) error
- func (st *Store) Eventer() *data.Eventer
- func (st *Store) Events(From uint32, To uint32) ([]event.Event, error)
- func (st *Store) Hash(height uint32) (hash.Hash256, error)
- func (st *Store) Header(height uint32) (chain.Header, error)
- func (st *Store) Height() uint32
- func (st *Store) IsExistAccount(addr common.Address) (bool, error)
- func (st *Store) IsExistAccountName(Name string) (bool, error)
- func (st *Store) IsExistUTXO(id uint64) (bool, error)
- func (st *Store) LastHash() hash.Hash256
- func (st *Store) LockedBalances(addr common.Address) ([]*data.LockedBalance, error)
- func (st *Store) LockedBalancesByHeight(Height uint32) ([]*data.LockedBalance, error)
- func (st *Store) Provider() chain.Provider
- func (st *Store) Seq(addr common.Address) uint64
- func (st *Store) SetCustomData(key string, value []byte) error
- func (st *Store) StoreData(cd *chain.Data, ctd *data.ContextData, customHash map[string][]byte) error
- func (st *Store) StoreGenesis(genHash hash.Hash256, ctd *data.ContextData, customHash map[string][]byte) error
- func (st *Store) TargetHeight() uint32
- func (st *Store) Transactor() *data.Transactor
- func (st *Store) UTXO(id uint64) (*transaction.UTXO, error)
- func (st *Store) UTXOs() ([]*transaction.UTXO, error)
- func (st *Store) Version() uint16
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) 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) BlocksFromSameFormulator ¶
BlocksFromSameFormulator returns a number of blocks made from same formulator
func (*Kernel) CandidateCount ¶
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 ¶
CheckFork returns chain.ErrForkDetected if the given data is valid and collapse with stored one
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 ¶
HasTransaction validate the transaction and push it to the transaction pool
func (*Kernel) IsFormulator ¶
IsFormulator returns the given information is correct or not
func (*Kernel) OnItemExpired ¶
OnItemExpired is called when the item is expired
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) TopRankInMap ¶
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
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) AccountData ¶
AccountData returns the account data from the store
func (*Store) AccountDataKeys ¶
AccountDataKeys returns all data keys of the account in the store
func (*Store) AddressByName ¶
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) CreateBody ¶
CreateBody returns a header that implements the chain header interface
func (*Store) CreateHeader ¶
CreateHeader returns a header that implements the chain header interface
func (*Store) CustomData ¶
CustomData returns the custom data by the key from the store
func (*Store) DeleteCustomData ¶
DeleteCustomData deletes the custom data
func (*Store) IsExistAccount ¶
IsExistAccount checks that the account of the address is exist or not
func (*Store) IsExistAccountName ¶
IsExistAccountName checks that the account of the name is exist or not
func (*Store) IsExistUTXO ¶
IsExistUTXO checks that the utxo of the id is exist or not
func (*Store) LockedBalances ¶
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) SetCustomData ¶
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 ¶
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