Documentation ¶
Index ¶
- Constants
- Variables
- func AddrAllTokenUtxoKey(addr string, tid txlogic.TokenID) []byte
- func AddrAllUtxoKey(addr string) []byte
- func AddrBalanceKey(addr string) []byte
- func AddrTokenBalanceKey(addr string, token types.OutPoint) []byte
- func AddrTokenUtxoKey(addr string, tid txlogic.TokenID, op types.OutPoint) []byte
- func AddrUtxoKey(addr string, op types.OutPoint) []byte
- func BlockHashKey(height uint32) []byte
- func BlockHeightFromBlockHashKey(k []byte) uint32
- func BlockHeightPrefix() []byte
- func BlockKey(h *crypto.HashType) []byte
- func CalcBlockSubsidy(height uint32) uint64
- func CalcCandidatePledgeHeight(tailHeight int64) int64
- func CalcTxsHash(txs []*types.Transaction) *crypto.HashType
- func CandidatesKey(h *crypto.HashType) []byte
- func CreateCoinbaseTx(addr []byte, blockHeight uint32) (*types.Transaction, error)
- func DeserializeUtxoWrap(serialized []byte) (*types.UtxoWrap, error)
- func FilterHeightHashFromKey(k []byte) (uint32, string)
- func FilterKey(height uint32, hash crypto.HashType) []byte
- func FilterKeyPrefix() []byte
- func IsCoinBase(tx *types.Transaction) bool
- func IsTxFinalized(tx *types.Transaction, blockHeight uint32, blockTime int64) bool
- func MarshalMissData(height, miss uint32, ts int64) (data []byte, err error)
- func MarshalTxIndex(height, index uint32) (data []byte, err error)
- func SerializeUtxoWrap(utxoWrap *types.UtxoWrap) ([]byte, error)
- func SplitAddrKey(hash []byte) []byte
- func TokenPreAllocation() ([]*types.Transaction, error)
- func TxIndexKey(h *crypto.HashType) []byte
- func TxKey(h *crypto.HashType) []byte
- func UnmarshalMissData(data []byte) (height uint32, miss uint32, ts int64, err error)
- func UnmarshalTxIndex(data []byte) (height uint32, index uint32, err error)
- func ValidateTransactionPreliminary(tx *types.Transaction) error
- func ValidateTxInputs(utxoSet *UtxoSet, tx *types.Transaction, txHeight uint32) (uint64, error)
- func VerifyBlockTimeOut(block *types.Block) error
- type BlockChain
- func (chain *BlockChain) Bus() eventbus.Bus
- func (chain *BlockChain) CalcRootHashForNBlocks(hash crypto.HashType, num uint32) (*crypto.HashType, error)
- func (chain *BlockChain) ChangeNewTail(tail *types.Block)
- func (chain *BlockChain) Consensus() types.Consensus
- func (chain *BlockChain) DB() storage.Table
- func (chain *BlockChain) DelSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error
- func (chain *BlockChain) DelTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error
- func (chain *BlockChain) DeleteSplitAddrIndex(block *types.Block, batch storage.Batch) error
- func (chain *BlockChain) EternalBlock() *types.Block
- func (chain *BlockChain) FetchNBlockAfterSpecificHash(hash crypto.HashType, num uint32) ([]*types.Block, error)
- func (chain *BlockChain) Genesis() *types.Block
- func (chain *BlockChain) GetBlockHash(blockHeight uint32) (*crypto.HashType, error)
- func (chain *BlockChain) GetBlockHeight() uint32
- func (chain *BlockChain) GetDataFromDB(key []byte) ([]byte, error)
- func (chain *BlockChain) GetParentBlock(block *types.Block) *types.Block
- func (chain *BlockChain) IsBusy() bool
- func (chain *BlockChain) IsCoinBase(tx *types.Transaction) bool
- func (chain *BlockChain) LoadBlockByHash(hash crypto.HashType) (*types.Block, error)
- func (chain *BlockChain) LoadBlockByHeight(height uint32) (*types.Block, error)
- func (chain *BlockChain) LoadBlockInfoByTxHash(hash crypto.HashType) (*types.Block, *types.Transaction, error)
- func (chain *BlockChain) LoadEternalBlock() (*types.Block, error)
- func (chain *BlockChain) LocateForkPointAndFetchHeaders(hashes []*crypto.HashType) ([]*crypto.HashType, error)
- func (chain *BlockChain) Proc() goprocess.Process
- func (chain *BlockChain) ProcessBlock(block *types.Block, transferMode core.TransferMode, fastConfirm bool, ...) error
- func (chain *BlockChain) ReadBlockFromDB(hash *crypto.HashType) (*types.Block, int, error)
- func (chain *BlockChain) RemoveBlock(block *types.Block)
- func (chain *BlockChain) Run() error
- func (chain *BlockChain) SetEternal(block *types.Block) error
- func (chain *BlockChain) Setup(consensus types.Consensus, syncManager types.SyncManager)
- func (chain *BlockChain) Stop()
- func (chain *BlockChain) StoreBlock(block *types.Block) error
- func (chain *BlockChain) StoreBlockInBatch(block *types.Block, batch storage.Batch) error
- func (chain *BlockChain) StoreEternalBlock(block *types.Block) error
- func (chain *BlockChain) StoreSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error
- func (chain *BlockChain) StoreTailBlock(block *types.Block, batch storage.Batch) error
- func (chain *BlockChain) TailBlock() *types.Block
- func (chain *BlockChain) WriteSplitAddrIndex(block *types.Block, batch storage.Batch) error
- func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error
- type BloomFilterHolder
- type DummyDpos
- func (dpos *DummyDpos) BroadcastEternalMsgToMiners(block *types.Block) error
- func (dpos *DummyDpos) IsCandidateExist(addr types.AddressHash) bool
- func (dpos *DummyDpos) RecoverMint()
- func (dpos *DummyDpos) Run() error
- func (dpos *DummyDpos) Stop()
- func (dpos *DummyDpos) StopMint()
- func (dpos *DummyDpos) StoreCandidateContext(*types.Block, storage.Batch) error
- func (dpos *DummyDpos) TryToUpdateEternalBlock(src *types.Block)
- func (dpos *DummyDpos) UpdateCandidateContext(block *types.Block) error
- func (dpos *DummyDpos) ValidateMiner() bool
- func (dpos *DummyDpos) VerifyCandidates(block *types.Block) error
- func (dpos *DummyDpos) VerifyMinerEpoch(*types.Block) error
- func (dpos *DummyDpos) VerifySign(*types.Block) (bool, error)
- type DummySyncManager
- type FilterEntry
- type LockTime
- type MemoryBloomFilterHolder
- func (holder *MemoryBloomFilterHolder) AddFilter(height uint32, hash crypto.HashType, db storage.Table, batch storage.Batch, ...) error
- func (holder *MemoryBloomFilterHolder) ListMatchedBlockHashes(word []byte) []crypto.HashType
- func (holder *MemoryBloomFilterHolder) ResetFilters(height uint32) error
- type ScriptItem
- type UpdateMsg
- type UtxoSet
- func (u *UtxoSet) AddUtxo(tx *types.Transaction, txOutIdx uint32, blockHeight uint32) error
- func (u *UtxoSet) All() types.UtxoMap
- func (u *UtxoSet) ApplyBlock(block *types.Block) error
- func (u *UtxoSet) ApplyBlockWithScriptFilter(block *types.Block, targetScript []byte) error
- func (u *UtxoSet) ApplyTx(tx *types.Transaction, blockHeight uint32) error
- func (u *UtxoSet) ApplyTxWithScriptFilter(tx *types.Transaction, blockHeight uint32, targetScript []byte) error
- func (u *UtxoSet) FindUtxo(outPoint types.OutPoint) *types.UtxoWrap
- func (u *UtxoSet) GetUtxos() types.UtxoMap
- func (u *UtxoSet) LoadBlockAllUtxos(block *types.Block, db storage.Table) error
- func (u *UtxoSet) LoadBlockUtxos(block *types.Block, db storage.Table) error
- func (u *UtxoSet) LoadTxUtxos(tx *types.Transaction, db storage.Table) error
- func (u *UtxoSet) RevertBlock(block *types.Block, chain *BlockChain) error
- func (u *UtxoSet) RevertTx(tx *types.Transaction, chain *BlockChain) error
- func (u *UtxoSet) SpendUtxo(outPoint types.OutPoint)
- func (u *UtxoSet) TxInputAmount(tx *types.Transaction) uint64
- func (u *UtxoSet) WriteUtxoSetToDB(batch storage.Batch) error
Constants ¶
const ( BlockMsgChBufferSize = 1024 EternalBlockMsgChBufferSize = 65536 MaxTimeOffsetSeconds = 2 * 60 * 60 MaxBlockSize = 32000000 CoinbaseLib = 100 PeriodDuration = 21 * 5 * 10000 MaxBlocksPerSync = 1024 Threshold = 32 )
const defines constants
const ( // BlockTableName is the table name of db to store block chain data BlockTableName = "core" // WalletTableName is the table name of db to store wallet data WalletTableName = "wl" // Tail is the db key name of tail block Tail = "/tail" // Genesis is the db key name of genesis block Genesis = "/genesis" // Eternal is the db key name of eternal block Eternal = "/eternal" // Period is the db key name of current period Period = "/period/current" // MissCount is the db key name of minuer's block miss rate data // value: 4 bytes height + 4 bytes miss count + 10 bytes ts MissCount = "/missrate" // BlockPrefix is the key prefix of database key to store block content // /bk/{hex encoded block hash} // e.g. // key: /bk/005973c44c4879b137c3723c96d2e341eeaf83fe58845b2975556c9f3bd640bb // value: block binary BlockPrefix = "/bk" // TxPrefix is the key prefix of database key to store tx content TxPrefix = "/tx" // BlockHashPrefix is the key prefix of database key to store block hash of specified height // /bh/{hex encoded height} //e.g. // key: /bh/3e2d // value: block hash binary BlockHashPrefix = "/bh" // TxIndexPrefix is the key prefix of database key to store tx index // /ti/{hex encoded tx hash} // e.g. // key: /ti/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757 // value: 4 bytes height + 4 bytes index in txs TxIndexPrefix = "/ti" // UtxoPrefix is the key prefix of database key to store utxo content // /ut/{hex encoded tx hash}/{vout index} // e.g. // key: /ut/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757/2 // value: utxo wrapper UtxoPrefix = "/ut" // CandidatesPrefix is the key prefix of database key to store candidates CandidatesPrefix = "/candidates" // FilterPrefix is the key prefix of block bloom filter to store a filter bytes // /bf/{hex encoded block hash} // e.g. // key: /bf/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757 // value: crypto hash FilterPrefix = "/bf" // SplitAddressPrefix is the key prefix of split address SplitAddressPrefix = "/sap" // AddressUtxoPrefix is the key prefix of database key to store address related utxo AddressUtxoPrefix = "/aut" // AddressTokenUtxoPrefix is the key prefix of database key to store address related token utxo AddressTokenUtxoPrefix = "/atut" // AddrBalancePrefix is the key prefix of database key to store address box balance AddrBalancePrefix = "/bal" // AddrTokenBalancePrefix is the key prefix of database key to store address token balance AddrTokenBalancePrefix = "/tbal" )
Variables ¶
var ( // TotalSupply is the total supply of box: 3 billion TotalSupply = (uint64)(3e9 * core.DuPerBox) // CoinbaseMaturity coinbase only spendable after this many blocks CoinbaseMaturity = (uint32)(0) // BaseSubsidy is the starting subsidy amount for mined blocks. // This value is halved every SubsidyReductionInterval blocks. BaseSubsidy = (uint64)(50 * core.DuPerBox) // CandidatePledge is pledge for candidate to mint. CandidatePledge = (uint64)(1e6 * core.DuPerBox) // MinNumOfVotes is Minimum number of votes MinNumOfVotes = (uint64)(100) )
var EternalKey = []byte(Eternal)
EternalKey is the db key to store eternal block content
var GenesisBlock = types.Block{ Header: &types.BlockHeader{ Version: 1, PrevBlockHash: crypto.HashType{}, TimeStamp: time.Date(2018, 1, 31, 0, 0, 0, 0, time.UTC).Unix(), }, Height: 0, }
GenesisBlock represents genesis block.
var GenesisKey = []byte(Genesis)
GenesisKey is the db key to store genesis block content
var GenesisPeriod = []map[string]string{
{
"addr": "b1YaxM6pR9vWejxbEJ8cmHhebPcLHyKZn2F",
"peerID": "12D3KooWPWfagC42R1DjpB8VMaQbwdqNLWtXwzhS1UuVuYHVjGc8",
},
{
"addr": "b1hE3LghriqzGnuuFtSNWNKRiwEGZACQwyx",
"peerID": "12D3KooWSTL8TCZpRc6WjTZYtmzbAiDCbEUDuw9VzXCokSFER1v7",
},
{
"addr": "b1VGrGhmraZ1A96S9qj5FaWWgGgi7bsjY9P",
"peerID": "12D3KooWPpJsKMsCgu9UpU2KH9PU1un37HZo81mhiMYs7Zkem8qC",
},
{
"addr": "b1aFeMqvL9AzWoxPi1ojPDM9veTrgBC9fg8",
"peerID": "12D3KooWHWVZpXoXQqM5F6kLzdxdD2mStRn34UiKccdmtLTyU8iN",
},
{
"addr": "b1f3WDbds2vypDx1vzHiRnhX1mCEAdUYPFP",
"peerID": "12D3KooWPXieg5ZEUzbHaKNFMsL3DxxUxoHytuojrKJk74G7weRg",
},
{
"addr": "b1qLJXfr3xcAL85LKGZbkpvDcfRFiUbg75g",
"peerID": "12D3KooWEf6zh21ATMAF3JGhyCNJPreJUmUYiB4uchMoqKgjDjCi",
},
{
"addr": "b1qW9wwyd1VDN75Mao9e8k7nVVVmcc6mJ7w",
"peerID": "12D3KooWGHyrGhQkPY6nUSnstYwuNFs5CmytofQfdkiR8DLygbrB",
},
{
"addr": "b1iGd3kcZKnT7zPf6k48j8juv8pRMe8Fw65",
"peerID": "12D3KooWGUK3nyQwm7Wew3HWu6jX8vB1CyqUqQ7u9wNYUcF3FCXC",
},
{
"addr": "b1nyv68asDNhCUudpF2bvELyBPzEEoQU5KC",
"peerID": "12D3KooWPkoxuH9sfmfBwBHxn7YgxFSfQAPBms9p1eWPd5BGh2T6",
},
{
"addr": "b1mDDEWqQnX4yPLq6UDCfXX8LVGhTYHDMB7",
"peerID": "12D3KooWCy9vMmStynZJuqJ8Yj1r6XaVADtqBAfNWe4De4WDaHR7",
},
{
"addr": "b1mpGAYQjwSWoDzuXnZqCW9RaRBjKHMCVEx",
"peerID": "12D3KooWEUHqAhaaSZrG9R8p85XnVJC4e3iz4dM26Z1LQfZsMu7F",
},
{
"addr": "b1g8TPMT4mFZEcDZWomPJWXit4suGHs1eoq",
"peerID": "12D3KooWS9afhAEkmT437oNkPBGkNLHJ9EkL5r4h2aXc6bsZgaTD",
},
{
"addr": "b1UTAV44cCeCF1SZc23szgHxFiMMbma4PHB",
"peerID": "12D3KooWNANjisCyouVwekviY7hodpyBJrT5YWsi1xSMYbtDAWhN",
},
{
"addr": "b1mr7Rk5fQkS3avFDtQpKhzPak87fzZu6ta",
"peerID": "12D3KooWAMTzTN4DuJck63sfQvRjp4jT1hjoYF2ucbGEvwoy2pRK",
},
{
"addr": "b1k9dMK6xrsXYCBuJfjTN9eTsMCiRb18Hnt",
"peerID": "12D3KooWCZVcNiuADTbzQwjNgj5hzbCpQJPo3JkBXwafXSggx4AG",
},
}
GenesisPeriod genesis period
var MissrateKey = []byte(MissCount)
MissrateKey is the db key to store miner's blocks miss rate
var PeriodKey = []byte(Period)
PeriodKey is the db key to store current period contex content
var TailKey = []byte(Tail)
TailKey is the db key to store tail block content
Functions ¶
func AddrAllTokenUtxoKey ¶ added in v0.3.0
AddrAllTokenUtxoKey is the key prefix to explore all token utxos of an address
func AddrAllUtxoKey ¶ added in v0.3.0
AddrAllUtxoKey is the key prefix to explore all utxos of an address
func AddrBalanceKey ¶ added in v0.3.0
AddrBalanceKey is the key to store an address's balance
func AddrTokenBalanceKey ¶ added in v0.3.0
AddrTokenBalanceKey is the key to store an address's token balance
func AddrTokenUtxoKey ¶ added in v0.3.0
AddrTokenUtxoKey is the key to store an token utxo which belongs to the input param address
func AddrUtxoKey ¶ added in v0.3.0
AddrUtxoKey is the key to store an utxo which belongs to the input param address
func BlockHashKey ¶
BlockHashKey returns the db key to store block hash content of the height
func BlockHeightFromBlockHashKey ¶ added in v0.3.0
BlockHeightFromBlockHashKey parse height info from a BlockHashKey
func BlockHeightPrefix ¶ added in v0.3.0
func BlockHeightPrefix() []byte
BlockHeightPrefix returns the db key prefix to store hash content of the height
func CalcBlockSubsidy ¶
CalcBlockSubsidy returns the subsidy amount a block at the provided height should have.
func CalcCandidatePledgeHeight ¶ added in v0.3.0
CalcCandidatePledgeHeight calc current candidate pledge height
func CalcTxsHash ¶
func CalcTxsHash(txs []*types.Transaction) *crypto.HashType
CalcTxsHash calculate txsHash in block.
func CandidatesKey ¶
CandidatesKey returns the db key to store candidates.
func CreateCoinbaseTx ¶
func CreateCoinbaseTx(addr []byte, blockHeight uint32) (*types.Transaction, error)
CreateCoinbaseTx creates a coinbase give miner address and block height
func DeserializeUtxoWrap ¶ added in v0.3.0
DeserializeUtxoWrap returns UtxoWrap form serialized bytes.
func FilterHeightHashFromKey ¶ added in v0.3.0
FilterHeightHashFromKey parse height and hash info from a FilterKey
func FilterKeyPrefix ¶ added in v0.3.0
func FilterKeyPrefix() []byte
FilterKeyPrefix returns the db key prefix to store bloom filter of block
func IsCoinBase ¶
func IsCoinBase(tx *types.Transaction) bool
IsCoinBase determines whether or not a transaction is a coinbase.
func IsTxFinalized ¶
func IsTxFinalized(tx *types.Transaction, blockHeight uint32, blockTime int64) bool
IsTxFinalized checks if a transaction is finalized.
func MarshalMissData ¶ added in v0.3.0
MarshalMissData writes miss rate data to bytes
func MarshalTxIndex ¶
MarshalTxIndex writes Tx height and index to bytes
func SerializeUtxoWrap ¶ added in v0.3.0
SerializeUtxoWrap returns the utxoWrap serialized to a format that is suitable for long-term storage.
func SplitAddrKey ¶ added in v0.3.0
SplitAddrKey returns the db key to store split address
func TokenPreAllocation ¶ added in v0.3.0
func TokenPreAllocation() ([]*types.Transaction, error)
TokenPreAllocation is for token preallocation
func TxIndexKey ¶
TxIndexKey returns the db key to store tx index of the hash
func UnmarshalMissData ¶ added in v0.3.0
UnmarshalMissData return tx index from bytes
func UnmarshalTxIndex ¶
UnmarshalTxIndex return tx index from bytes
func ValidateTransactionPreliminary ¶
func ValidateTransactionPreliminary(tx *types.Transaction) error
ValidateTransactionPreliminary performs some preliminary checks on a transaction to ensure it is sane. These checks are context free.
func ValidateTxInputs ¶
ValidateTxInputs validates the inputs of a tx. Returns the total tx fee.
func VerifyBlockTimeOut ¶
VerifyBlockTimeOut refuse to accept a block with wrong timestamp.
Types ¶
type BlockChain ¶
type BlockChain struct { LongestChainHeight uint32 // contains filtered or unexported fields }
BlockChain define chain struct
func NewBlockChain ¶
func NewBlockChain(parent goprocess.Process, notifiee p2p.Net, db storage.Storage, bus eventbus.Bus) (*BlockChain, error)
NewBlockChain return a blockchain.
func NewTestBlockChain ¶
func NewTestBlockChain() *BlockChain
NewTestBlockChain generate a chain for testing
func (*BlockChain) Bus ¶
func (chain *BlockChain) Bus() eventbus.Bus
Bus returns the goprocess of the BlockChain
func (*BlockChain) CalcRootHashForNBlocks ¶
func (chain *BlockChain) CalcRootHashForNBlocks(hash crypto.HashType, num uint32) (*crypto.HashType, error)
CalcRootHashForNBlocks return root hash for N blocks.
func (*BlockChain) ChangeNewTail ¶ added in v0.3.0
func (chain *BlockChain) ChangeNewTail(tail *types.Block)
ChangeNewTail change chain tail block.
func (*BlockChain) Consensus ¶ added in v0.3.0
func (chain *BlockChain) Consensus() types.Consensus
Consensus return chain consensus.
func (*BlockChain) DelSplitTxs ¶ added in v0.3.0
func (chain *BlockChain) DelSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error
DelSplitTxs del split txs.
func (*BlockChain) DelTxIndex ¶
func (chain *BlockChain) DelTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error
DelTxIndex deletes tx index in block Delete split transaction copies saved earlier, both before and after split
func (*BlockChain) DeleteSplitAddrIndex ¶ added in v0.3.0
DeleteSplitAddrIndex remove split address index from both db and cache
func (*BlockChain) EternalBlock ¶
func (chain *BlockChain) EternalBlock() *types.Block
EternalBlock return chain eternal block.
func (*BlockChain) FetchNBlockAfterSpecificHash ¶
func (chain *BlockChain) FetchNBlockAfterSpecificHash(hash crypto.HashType, num uint32) ([]*types.Block, error)
FetchNBlockAfterSpecificHash get N block after specific hash.
func (*BlockChain) Genesis ¶ added in v0.3.0
func (chain *BlockChain) Genesis() *types.Block
Genesis return chain tail block.
func (*BlockChain) GetBlockHash ¶
func (chain *BlockChain) GetBlockHash(blockHeight uint32) (*crypto.HashType, error)
GetBlockHash finds the block in target height of main chain and returns it's hash
func (*BlockChain) GetBlockHeight ¶
func (chain *BlockChain) GetBlockHeight() uint32
GetBlockHeight returns current height of main chain
func (*BlockChain) GetDataFromDB ¶ added in v0.3.0
func (chain *BlockChain) GetDataFromDB(key []byte) ([]byte, error)
GetDataFromDB get data from db
func (*BlockChain) GetParentBlock ¶ added in v0.3.0
func (chain *BlockChain) GetParentBlock(block *types.Block) *types.Block
GetParentBlock Finds the parent of a block. Return nil if nonexistent
func (*BlockChain) IsBusy ¶ added in v0.3.0
func (chain *BlockChain) IsBusy() bool
IsBusy return if the chain is processing a block
func (*BlockChain) IsCoinBase ¶ added in v0.3.0
func (chain *BlockChain) IsCoinBase(tx *types.Transaction) bool
IsCoinBase checks if an transaction is coinbase transaction
func (*BlockChain) LoadBlockByHash ¶
LoadBlockByHash load block by hash from db.
func (*BlockChain) LoadBlockByHeight ¶
func (chain *BlockChain) LoadBlockByHeight(height uint32) (*types.Block, error)
LoadBlockByHeight load block by height from db.
func (*BlockChain) LoadBlockInfoByTxHash ¶ added in v0.3.0
func (chain *BlockChain) LoadBlockInfoByTxHash(hash crypto.HashType) (*types.Block, *types.Transaction, error)
LoadBlockInfoByTxHash returns block and txIndex of transaction with the input param hash
func (*BlockChain) LoadEternalBlock ¶ added in v0.3.0
func (chain *BlockChain) LoadEternalBlock() (*types.Block, error)
LoadEternalBlock returns the current highest eternal block
func (*BlockChain) LocateForkPointAndFetchHeaders ¶
func (chain *BlockChain) LocateForkPointAndFetchHeaders(hashes []*crypto.HashType) ([]*crypto.HashType, error)
LocateForkPointAndFetchHeaders return block headers when get locate fork point request for sync service.
func (*BlockChain) Proc ¶
func (chain *BlockChain) Proc() goprocess.Process
Proc returns the goprocess of the BlockChain
func (*BlockChain) ProcessBlock ¶
func (chain *BlockChain) ProcessBlock(block *types.Block, transferMode core.TransferMode, fastConfirm bool, messageFrom peer.ID) error
ProcessBlock is used to handle new blocks.
func (*BlockChain) ReadBlockFromDB ¶ added in v0.3.0
ReadBlockFromDB reads a block from db by hash and returns block and it's size
func (*BlockChain) RemoveBlock ¶ added in v0.3.0
func (chain *BlockChain) RemoveBlock(block *types.Block)
RemoveBlock store block to db.
func (*BlockChain) SetEternal ¶
func (chain *BlockChain) SetEternal(block *types.Block) error
SetEternal set block eternal status.
func (*BlockChain) Setup ¶
func (chain *BlockChain) Setup(consensus types.Consensus, syncManager types.SyncManager)
Setup prepare blockchain.
func (*BlockChain) StoreBlock ¶ added in v0.3.0
func (chain *BlockChain) StoreBlock(block *types.Block) error
StoreBlock store block to db.
func (*BlockChain) StoreBlockInBatch ¶ added in v0.3.0
StoreBlockInBatch store block to db in batch mod.
func (*BlockChain) StoreEternalBlock ¶
func (chain *BlockChain) StoreEternalBlock(block *types.Block) error
StoreEternalBlock store eternal block to db.
func (*BlockChain) StoreSplitTxs ¶ added in v0.3.0
func (chain *BlockChain) StoreSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error
StoreSplitTxs store split txs.
func (*BlockChain) StoreTailBlock ¶
StoreTailBlock store tail block to db.
func (*BlockChain) TailBlock ¶
func (chain *BlockChain) TailBlock() *types.Block
TailBlock return chain tail block.
func (*BlockChain) WriteSplitAddrIndex ¶ added in v0.3.0
WriteSplitAddrIndex writes split addr info index
func (*BlockChain) WriteTxIndex ¶
func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error
WriteTxIndex builds tx index in block Save split transaction copies before and after split. The latter is needed when reverting a transaction during reorg, spending from utxo/coin received at a split address
type BloomFilterHolder ¶
type BloomFilterHolder interface { ResetFilters(uint32) error ListMatchedBlockHashes([]byte) []crypto.HashType AddFilter(uint32, crypto.HashType, storage.Table, storage.Batch, func() bloom.Filter) error }
BloomFilterHolder holds all bloom filters in main chain
func NewFilterHolder ¶
func NewFilterHolder() BloomFilterHolder
NewFilterHolder creates an holder instance
type DummyDpos ¶
type DummyDpos struct{}
DummyDpos dummy dpos
func (*DummyDpos) BroadcastEternalMsgToMiners ¶
BroadcastEternalMsgToMiners broadcast etrnalmsg to miners
func (*DummyDpos) IsCandidateExist ¶ added in v0.3.0
func (dpos *DummyDpos) IsCandidateExist(addr types.AddressHash) bool
IsCandidateExist check candidate is exist.
func (*DummyDpos) StoreCandidateContext ¶
StoreCandidateContext store candidate context
func (*DummyDpos) TryToUpdateEternalBlock ¶ added in v0.3.0
TryToUpdateEternalBlock try to update eternal block.
func (*DummyDpos) UpdateCandidateContext ¶ added in v0.3.0
UpdateCandidateContext update candidate context in memory.
func (*DummyDpos) ValidateMiner ¶
ValidateMiner validate miner
func (*DummyDpos) VerifyCandidates ¶ added in v0.3.0
VerifyCandidates vefiry if the block candidates hash is right.
func (*DummyDpos) VerifyMinerEpoch ¶
VerifyMinerEpoch verify miner epoch
type DummySyncManager ¶
type DummySyncManager struct{}
DummySyncManager is only used to test
func NewDummySyncManager ¶
func NewDummySyncManager() *DummySyncManager
NewDummySyncManager returns a new DummySyncManager
func (*DummySyncManager) ActiveLightSync ¶
func (dm *DummySyncManager) ActiveLightSync(pid peer.ID) error
ActiveLightSync active light sync from remote peer.
type FilterEntry ¶
FilterEntry represents a bloom filter for the block of the given hash
type MemoryBloomFilterHolder ¶
type MemoryBloomFilterHolder struct {
// contains filtered or unexported fields
}
MemoryBloomFilterHolder holds all bloom filters in main chain in an array format in memory
func (*MemoryBloomFilterHolder) AddFilter ¶
func (holder *MemoryBloomFilterHolder) AddFilter( height uint32, hash crypto.HashType, db storage.Table, batch storage.Batch, onCacheMiss func() bloom.Filter) error
AddFilter adds a filter of block at height. Filter is loaded from db instance if it is stored, otherwise, it's calculated using onCacheMiss function
func (*MemoryBloomFilterHolder) ListMatchedBlockHashes ¶
func (holder *MemoryBloomFilterHolder) ListMatchedBlockHashes(word []byte) []crypto.HashType
ListMatchedBlockHashes search all blocks' bloom filter, and returns block hashes that might contain a certain word
func (*MemoryBloomFilterHolder) ResetFilters ¶
func (holder *MemoryBloomFilterHolder) ResetFilters(height uint32) error
ResetFilters resets filterEntry array to a height
type ScriptItem ¶ added in v0.3.0
type ScriptItem struct {
// contains filtered or unexported fields
}
ScriptItem saves scripts for parallel validation
func CheckTxScripts ¶ added in v0.3.0
func CheckTxScripts(utxoSet *UtxoSet, tx *types.Transaction, skipValidation bool) ([]*ScriptItem, error)
CheckTxScripts verifies unlocking script for each input to ensure it is authorized to spend the utxo Coinbase tx will not reach here
type UpdateMsg ¶
type UpdateMsg struct { // block connected/disconnected from main chain AttachBlocks []*types.Block DetachBlocks []*types.Block }
UpdateMsg sent from blockchain to, e.g., mempool
type UtxoSet ¶
type UtxoSet struct {
// contains filtered or unexported fields
}
UtxoSet contains all utxos
func GetExtendedTxUtxoSet ¶
func GetExtendedTxUtxoSet(tx *types.Transaction, db storage.Table, spendableTxs *sync.Map) (*UtxoSet, error)
GetExtendedTxUtxoSet returns tx's utxo set from both db & txs in spendableTxs
func NewUtxoSetFromMap ¶
NewUtxoSetFromMap returns the underlying utxos as a map
func (*UtxoSet) ApplyBlock ¶
ApplyBlock updates utxos with all transactions in the passed block
func (*UtxoSet) ApplyBlockWithScriptFilter ¶
ApplyBlockWithScriptFilter adds or remove all utxos that transactions use or generate with the specified script bytes
func (*UtxoSet) ApplyTx ¶
func (u *UtxoSet) ApplyTx(tx *types.Transaction, blockHeight uint32) error
ApplyTx updates utxos with the passed tx: adds all utxos in outputs and delete all utxos in inputs.
func (*UtxoSet) ApplyTxWithScriptFilter ¶
func (u *UtxoSet) ApplyTxWithScriptFilter(tx *types.Transaction, blockHeight uint32, targetScript []byte) error
ApplyTxWithScriptFilter adds or remove an utxo if the transaction uses or generates an utxo with the specified script bytes
func (*UtxoSet) LoadBlockAllUtxos ¶ added in v0.3.0
LoadBlockAllUtxos loads all UTXOs txs in the block
func (*UtxoSet) LoadBlockUtxos ¶
LoadBlockUtxos loads UTXOs txs in the block spend
func (*UtxoSet) LoadTxUtxos ¶
LoadTxUtxos loads the unspent transaction outputs related to tx
func (*UtxoSet) RevertBlock ¶
func (u *UtxoSet) RevertBlock(block *types.Block, chain *BlockChain) error
RevertBlock undoes utxo changes made with all the transactions in the passed block It undoes the effect of ApplyBlock on utxo set
func (*UtxoSet) RevertTx ¶
func (u *UtxoSet) RevertTx(tx *types.Transaction, chain *BlockChain) error
RevertTx updates utxos with the passed tx: delete all utxos in outputs and add all utxos in inputs. It undoes the effect of ApplyTx on utxo set
func (*UtxoSet) TxInputAmount ¶ added in v0.3.0
func (u *UtxoSet) TxInputAmount(tx *types.Transaction) uint64
TxInputAmount returns total amount from tx's inputs Return 0 if a tx is not fully funded, i.e., if not all of its spending utxos exist