Documentation ¶
Index ¶
- Constants
- Variables
- func AddChildrenWork(node *BlockNode, work *big.Int)
- func BigToCompact(n *big.Int) uint32
- func CalcPastMedianTime(node *BlockNode) time.Time
- func CalcWork(bits uint32) *big.Int
- func CalculateTxsFee(block *Block)
- func CheckDPOSIllegalBlocks(d *payload.DPOSIllegalBlocks) error
- func CheckDPOSIllegalProposals(d *payload.DPOSIllegalProposals) error
- func CheckDPOSIllegalVotes(d *payload.DPOSIllegalVotes) error
- func CheckInactiveArbitrators(txn *Transaction) error
- func CheckProofOfWork(header *Header, powLimit *big.Int) error
- func CheckSideChainPowConsensus(txn *Transaction, arbitrator []byte) error
- func CheckSidechainIllegalEvidence(p *payload.SidechainIllegalData) error
- func CompactToBig(compact uint32) *big.Int
- func ConfirmContextCheck(confirm *payload.Confirm) error
- func ConfirmSanityCheck(confirm *payload.Confirm) error
- func DBRemoveBlockIndex(dbTx database.Tx, hash *common.Uint256, height uint32) error
- func DBRemoveBlockNode(dbTx database.Tx, header *types.Header) error
- func DBStoreBlockNode(dbTx database.Tx, header *types.Header, status blockStatus) error
- func DeserializeBlockRow(blockRow []byte) (*types.Header, blockStatus, error)
- func GetBlockWeight(blk *types.Block) int64
- func GetTransactionWeight(tx *types.Transaction) int64
- func GetTxFee(tx *Transaction, assetId Uint256, references map[*Input]Output) Fixed64
- func GetTxFeeMap(tx *Transaction, references map[*Input]Output) (map[Uint256]Fixed64, error)
- func GetTxProgramHashes(tx *Transaction, references map[*Input]Output) ([]common.Uint168, error)
- func HashToBig(hash *Uint256) *big.Int
- func IsFinalizedTransaction(msgTx *Transaction, blockHeight uint32) bool
- func LoadBlockDB(dataPath string, dbName string) (database.DB, error)
- func PreProcessSpecialTx(block *Block) error
- func ProposalCheck(proposal *payload.DPOSProposal) error
- func ProposalCheckByHeight(proposal *payload.DPOSProposal, height uint32) error
- func ProposalContextCheck(proposal *payload.DPOSProposal) error
- func ProposalContextCheckByHeight(proposal *payload.DPOSProposal, height uint32) error
- func ProposalSanityCheck(proposal *payload.DPOSProposal) error
- func RunPrograms(data []byte, programHashes []common.Uint168, programs []*Program) error
- func SortPrograms(programs []*Program)
- func VoteCheck(vote *payload.DPOSProposalVote) error
- func VoteCheckByHeight(vote *payload.DPOSProposalVote, height uint32) error
- func VoteContextCheck(vote *payload.DPOSProposalVote) error
- func VoteContextCheckByHeight(vote *payload.DPOSProposalVote, height uint32) error
- func VoteSanityCheck(vote *payload.DPOSProposalVote) error
- type BestState
- type BlockChain
- func (b *BlockChain) AddOrphanBlock(block *Block)
- func (b *BlockChain) AddOrphanConfirm(confirm *payload.Confirm)
- func (b *BlockChain) BlockExists(hash *Uint256) bool
- func (b *BlockChain) BlockLocatorFromHash(inhash *Uint256) []*Uint256
- func (b *BlockChain) CalcCurrentDifficulty(currentBits uint32) string
- func (b *BlockChain) CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)
- func (b *BlockChain) CheckBlockContext(block *Block, prevNode *BlockNode) error
- func (b *BlockChain) CheckBlockSanity(block *Block) error
- func (b *BlockChain) CheckTransactionContext(blockHeight uint32, txn *Transaction, references map[*Input]Output, ...) elaerr.ELAError
- func (b *BlockChain) CheckTransactionSanity(blockHeight uint32, txn *Transaction) elaerr.ELAError
- func (b *BlockChain) ContainsTransaction(hash Uint256) bool
- func (b *BlockChain) CreateCRCAppropriationTransaction() (*Transaction, error)
- func (b *BlockChain) GetBlockByHash(hash Uint256) (*Block, error)
- func (b *BlockChain) GetBlockByHeight(height uint32) (*Block, error)
- func (b *BlockChain) GetBlockHash(height uint32) (Uint256, error)
- func (b *BlockChain) GetBlockNode(height uint32) *BlockNode
- func (b *BlockChain) GetCRCommittee() *crstate.Committee
- func (b *BlockChain) GetCurrentBlockHash() Uint256
- func (b *BlockChain) GetDB() IChainStore
- func (b *BlockChain) GetDposBlockByHash(hash Uint256) (*DposBlock, error)
- func (b *BlockChain) GetHeader(hash Uint256) (*Header, error)
- func (b *BlockChain) GetHeight() uint32
- func (b *BlockChain) GetNetworkHashPS() *big.Int
- func (b *BlockChain) GetOrphan(hash *Uint256) *OrphanBlock
- func (b *BlockChain) GetOrphanConfirm(hash *Uint256) (*payload.Confirm, bool)
- func (b *BlockChain) GetOrphanRoot(hash *Uint256) *Uint256
- func (b *BlockChain) GetState() *state.State
- func (b *BlockChain) HaveBlock(hash *Uint256) (bool, error)
- func (b *BlockChain) Init(interrupt <-chan struct{}) error
- func (b *BlockChain) InitCheckpoint(interrupt <-chan struct{}, barStart func(total uint32), increase func()) (err error)
- func (b *BlockChain) IsKnownOrphan(hash *Uint256) bool
- func (b *BlockChain) LatestBlockLocator() ([]*Uint256, error)
- func (b *BlockChain) LoadBlockNode(blockHeader *Header, hash *Uint256) (*BlockNode, error)
- func (b *BlockChain) LocateBlocks(locator []*Uint256, hashStop *Uint256, maxHashes uint32) []*Uint256
- func (b *BlockChain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)
- func (b *BlockChain) MainChainHasBlock(height uint32, hash *Uint256) bool
- func (b *BlockChain) MedianAdjustedTime() time.Time
- func (b *BlockChain) MigrateOldDB(interrupt <-chan struct{}, barStart func(total uint32), increase func(), ...) (err error)
- func (b *BlockChain) ProcessBlock(block *Block, confirm *payload.Confirm) (bool, bool, error)
- func (b *BlockChain) ProcessIllegalBlock(payload *payload.DPOSIllegalBlocks)
- func (b *BlockChain) ProcessInactiveArbiter(payload *payload.InactiveArbitrators)
- func (b *BlockChain) ProcessOrphans(hash *Uint256) error
- func (b *BlockChain) RemoveOrphanBlock(orphan *OrphanBlock)
- func (b *BlockChain) ReorganizeChain(block *Block) error
- func (b *BlockChain) SetTip(node *BlockNode)
- type BlockNode
- type ChainStore
- func (c *ChainStore) Close()
- func (c *ChainStore) CloseLeveldb()
- func (c *ChainStore) GetConfirm(hash Uint256) (*payload.Confirm, error)
- func (c *ChainStore) GetFFLDB() IFFLDBChainStore
- func (c *ChainStore) GetHeight() uint32
- func (c *ChainStore) GetTransaction(txID Uint256) (*Transaction, uint32, error)
- func (c *ChainStore) GetTxReference(tx *Transaction) (map[*Input]*Output, error)
- func (c *ChainStore) IsDoubleSpend(txn *Transaction) bool
- func (c *ChainStore) IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool
- func (c *ChainStore) IsTxHashDuplicate(txID Uint256) bool
- func (c *ChainStore) RollbackBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error
- func (c *ChainStore) SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error
- func (c *ChainStore) SetHeight(height uint32)
- type ChainStoreFFLDB
- func (c *ChainStoreFFLDB) Begin(writable bool) (database.Tx, error)
- func (c *ChainStoreFFLDB) BlockExists(hash *Uint256) (bool, uint32, error)
- func (c *ChainStoreFFLDB) Close() error
- func (c *ChainStoreFFLDB) GetBlock(hash Uint256) (*DposBlock, error)
- func (c *ChainStoreFFLDB) GetHeader(hash Uint256) (*Header, error)
- func (c *ChainStoreFFLDB) GetOldBlock(hash Uint256) (*Block, error)
- func (c *ChainStoreFFLDB) GetTransaction(txID Uint256) (*Transaction, uint32, error)
- func (c *ChainStoreFFLDB) GetUTXO(programHash *Uint168) ([]*UTXO, error)
- func (c *ChainStoreFFLDB) GetUnspent(txID Uint256) ([]uint16, error)
- func (c *ChainStoreFFLDB) InitIndex(chain indexers.IChain, interrupt <-chan struct{}) error
- func (c *ChainStoreFFLDB) IsBlockInStore(hash *Uint256) bool
- func (c *ChainStoreFFLDB) IsTx3Exist(txHash *Uint256) bool
- func (c *ChainStoreFFLDB) RollbackBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error
- func (c *ChainStoreFFLDB) SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error
- func (c *ChainStoreFFLDB) Type() string
- func (c *ChainStoreFFLDB) Update(fn func(tx database.Tx) error) error
- func (c *ChainStoreFFLDB) View(fn func(tx database.Tx) error) error
- type DataEntryPrefix
- type IChainStore
- type IFFLDBChainStore
- type IIterator
- type IStore
- type IUTXOCacheStore
- type Iterator
- type Ledger
- func (l *Ledger) AppendDposBlocks(confirms []*DposBlock) error
- func (l *Ledger) GetBlockWithHash(hash Uint256) (*Block, error)
- func (l *Ledger) GetBlockWithHeight(height uint32) (*Block, error)
- func (l *Ledger) GetDposBlocks(start, end uint32) ([]*DposBlock, error)
- func (l *Ledger) GetLocalBlockChainHeight() uint32
- func (l *Ledger) GetTransactionWithHash(hash Uint256) (*Transaction, error)
- func (l *Ledger) IsDoubleSpend(Tx *Transaction) bool
- type LevelDB
- func (ldb *LevelDB) BatchCommit() error
- func (ldb *LevelDB) BatchDelete(key []byte)
- func (ldb *LevelDB) BatchPut(key []byte, value []byte)
- func (ldb *LevelDB) Close() error
- func (ldb *LevelDB) Delete(key []byte) error
- func (ldb *LevelDB) Get(key []byte) ([]byte, error)
- func (ldb *LevelDB) NewBatch()
- func (ldb *LevelDB) NewIterator(prefix []byte) IIterator
- func (ldb *LevelDB) Put(key []byte, value []byte) error
- type MedianTimeSource
- type OrphanBlock
- type OutputInfo
- type ProducerInfo
- type ProducerState
- type UTXOCache
Constants ¶
const ( // MaxStringLength is the maximum length of a string field. MaxStringLength = 100 // Category Data length limit not exceeding 4096 characters MaxCategoryDataStringLength = 4096 // MaxBudgetsCount indicates max budgets count of one proposal. MaxBudgetsCount = 128 // ELIPBudgetsCount indicates budgets count of ELIP. ELIPBudgetsCount = 2 // CRCProposalBudgetsPercentage indicates the percentage of the CRC member // address balance available for a single proposal budget. CRCProposalBudgetsPercentage = 10 )
const ( // MaxBlockWeight defines the maximum block weight, where "block // weight" is interpreted as defined in BIP0141. A block's weight is // calculated as the sum of the of bytes in the existing transactions // and header, plus the weight of each byte within a transaction. The // weight of a "base" byte is 4, while the weight of a witness byte is // 1. As a result, for a block to be valid, the BlockWeight MUST be // less than, or equal to MaxBlockWeight. MaxBlockWeight = 4000000 // MaxBlockBaseSize is the maximum number of bytes within a block // which can be allocated to non-witness data. MaxBlockBaseSize = 1000000 // MaxBlockSigOpsCost is the maximum number of signature operations // allowed for a block. It is calculated via a weighted algorithm which // weights segregated witness sig ops lower than regular sig ops. MaxBlockSigOpsCost = 80000 // WitnessScaleFactor determines the level of "discount" witness data // receives compared to "base" data. A scale factor of 4, denotes that // witness data is 1/4 as cheap as regular non-witness data. WitnessScaleFactor = 4 // MinTxOutputWeight is the minimum possible weight for a transaction // output. MinTxOutputWeight = WitnessScaleFactor * wire.MinTxOutPayload // MaxOutputsPerBlock is the maximum number of transaction outputs there // can be in a block of max weight size. MaxOutputsPerBlock = MaxBlockWeight / MinTxOutputWeight )
const BITSPERKEY = 10
used to compute the size of bloom filter bits array . too small will lead to high false positive rate.
const (
BlocksCacheSize = 2
)
const (
// HashSize of array used to store hashes. See Hash.
HashSize = 32
)
const (
MaxTimeOffsetSeconds = 2 * 60 * 60
)
Variables ¶
var ( FoundationAddress Uint168 DefaultLedger *Ledger )
Functions ¶
func AddChildrenWork ¶
func BigToCompact ¶
func CalcPastMedianTime ¶
func CalculateTxsFee ¶ added in v0.3.3
func CalculateTxsFee(block *Block)
func CheckDPOSIllegalBlocks ¶ added in v0.3.0
func CheckDPOSIllegalBlocks(d *payload.DPOSIllegalBlocks) error
func CheckDPOSIllegalProposals ¶ added in v0.3.0
func CheckDPOSIllegalProposals(d *payload.DPOSIllegalProposals) error
func CheckDPOSIllegalVotes ¶ added in v0.3.0
func CheckDPOSIllegalVotes(d *payload.DPOSIllegalVotes) error
func CheckInactiveArbitrators ¶ added in v0.3.0
func CheckInactiveArbitrators(txn *Transaction) error
func CheckProofOfWork ¶
func CheckSideChainPowConsensus ¶ added in v0.1.1
func CheckSidechainIllegalEvidence ¶ added in v0.3.0
func CheckSidechainIllegalEvidence(p *payload.SidechainIllegalData) error
func CompactToBig ¶
func ConfirmContextCheck ¶ added in v0.3.0
func ConfirmSanityCheck ¶ added in v0.3.0
func DBRemoveBlockIndex ¶ added in v0.5.0
DBRemoveBlockIndex uses an existing database transaction remove block index entries from the hash to height and height to hash mappings for the provided values.
func DBRemoveBlockNode ¶ added in v0.5.0
DBRemoveBlockNode stores the block header to the block index bucket. This overwrites the current entry if there exists one.
func DBStoreBlockNode ¶ added in v0.5.0
DBStoreBlockNode stores the block header to the block index bucket. This overwrites the current entry if there exists one.
func DeserializeBlockRow ¶ added in v0.5.0
DeserializeBlockRow parses a value in the block index bucket into a block header and block Status bitfield.
func GetBlockWeight ¶ added in v0.5.0
GetBlockWeight computes the value of the weight metric for a given block. Currently the weight metric is simply the sum of the block's serialized size without any witness data scaled proportionally by the WitnessScaleFactor, and the block's serialized size including any witness data.
func GetTransactionWeight ¶ added in v0.5.0
func GetTransactionWeight(tx *types.Transaction) int64
GetTransactionWeight computes the value of the weight metric for a given transaction. Currently the weight metric is simply the sum of the transactions's serialized size without any witness data scaled proportionally by the WitnessScaleFactor, and the transaction's serialized size including any witness data.
func GetTxFee ¶
func GetTxFee(tx *Transaction, assetId Uint256, references map[*Input]Output) Fixed64
func GetTxFeeMap ¶
func GetTxFeeMap(tx *Transaction, references map[*Input]Output) (map[Uint256]Fixed64, error)
func GetTxProgramHashes ¶
func IsFinalizedTransaction ¶
func LoadBlockDB ¶ added in v0.5.0
loadBlockDB loads (or creates when needed) the block database taking into account the selected database backend and returns a handle to it. It also contains additional logic such warning the user if there are multiple databases which consume space on the file system and ensuring the regression test database is clean when in regression test mode.
func PreProcessSpecialTx ¶ added in v0.3.2
func PreProcessSpecialTx(block *Block) error
func ProposalCheck ¶ added in v0.3.2
func ProposalCheck(proposal *payload.DPOSProposal) error
func ProposalCheckByHeight ¶ added in v0.3.2
func ProposalCheckByHeight(proposal *payload.DPOSProposal, height uint32) error
func ProposalContextCheck ¶ added in v0.3.0
func ProposalContextCheck(proposal *payload.DPOSProposal) error
func ProposalContextCheckByHeight ¶ added in v0.3.2
func ProposalContextCheckByHeight(proposal *payload.DPOSProposal, height uint32) error
func ProposalSanityCheck ¶ added in v0.3.0
func ProposalSanityCheck(proposal *payload.DPOSProposal) error
func RunPrograms ¶
func SortPrograms ¶ added in v0.1.1
func SortPrograms(programs []*Program)
func VoteCheck ¶ added in v0.3.2
func VoteCheck(vote *payload.DPOSProposalVote) error
func VoteCheckByHeight ¶ added in v0.3.2
func VoteCheckByHeight(vote *payload.DPOSProposalVote, height uint32) error
func VoteContextCheck ¶ added in v0.3.0
func VoteContextCheck(vote *payload.DPOSProposalVote) error
func VoteContextCheckByHeight ¶ added in v0.3.2
func VoteContextCheckByHeight(vote *payload.DPOSProposalVote, height uint32) error
func VoteSanityCheck ¶ added in v0.3.0
func VoteSanityCheck(vote *payload.DPOSProposalVote) error
Types ¶
type BestState ¶ added in v0.5.0
type BestState struct { Hash common.Uint256 // The hash of the block. Height uint32 // The height of the block. Bits uint32 // The difficulty bits of the block. BlockSize uint64 // The size of the block. BlockWeight uint64 // The weight of the block. NumTxns uint64 // The number of txns in the block. MedianTime time.Time // Median time as per CalcPastMedianTime. }
BestState houses information about the current best block and other info related to the state of the main chain as it exists from the point of view of the current best block.
The BestSnapshot method can be used to obtain access to this information in a concurrent safe manner and the data will not be changed out from under the caller when chain state changes occur as the function name implies. However, the returned snapshot must be treated as immutable since it is shared by all callers.
type BlockChain ¶ added in v0.3.0
type BlockChain struct { UTXOCache *UTXOCache GenesisHash Uint256 BestChain *BlockNode Root *BlockNode IndexLock sync.RWMutex Nodes []*BlockNode DepNodes map[Uint256][]*BlockNode TimeSource MedianTimeSource MedianTimePast time.Time // contains filtered or unexported fields }
func New ¶ added in v0.3.0
func New(db IChainStore, chainParams *config.Params, state *state.State, committee *crstate.Committee) (*BlockChain, error)
func (*BlockChain) AddOrphanBlock ¶ added in v0.3.0
func (b *BlockChain) AddOrphanBlock(block *Block)
func (*BlockChain) AddOrphanConfirm ¶ added in v0.3.0
func (b *BlockChain) AddOrphanConfirm(confirm *payload.Confirm)
func (*BlockChain) BlockExists ¶ added in v0.3.0
func (b *BlockChain) BlockExists(hash *Uint256) bool
func (*BlockChain) BlockLocatorFromHash ¶ added in v0.3.0
func (b *BlockChain) BlockLocatorFromHash(inhash *Uint256) []*Uint256
func (*BlockChain) CalcCurrentDifficulty ¶ added in v0.3.0
func (b *BlockChain) CalcCurrentDifficulty(currentBits uint32) string
func (*BlockChain) CalcNextRequiredDifficulty ¶ added in v0.3.0
func (*BlockChain) CheckBlockContext ¶ added in v0.3.4
func (b *BlockChain) CheckBlockContext(block *Block, prevNode *BlockNode) error
func (*BlockChain) CheckBlockSanity ¶ added in v0.3.0
func (b *BlockChain) CheckBlockSanity(block *Block) error
func (*BlockChain) CheckTransactionContext ¶ added in v0.3.0
func (b *BlockChain) CheckTransactionContext(blockHeight uint32, txn *Transaction, references map[*Input]Output, proposalsUsedAmount common.Fixed64) elaerr.ELAError
CheckTransactionContext verifies a transaction with history transaction in ledger
func (*BlockChain) CheckTransactionSanity ¶ added in v0.3.0
func (b *BlockChain) CheckTransactionSanity(blockHeight uint32, txn *Transaction) elaerr.ELAError
CheckTransactionSanity verifies received single transaction
func (*BlockChain) ContainsTransaction ¶ added in v0.3.0
func (b *BlockChain) ContainsTransaction(hash Uint256) bool
func (*BlockChain) CreateCRCAppropriationTransaction ¶ added in v0.5.0
func (b *BlockChain) CreateCRCAppropriationTransaction() (*Transaction, error)
func (*BlockChain) GetBlockByHash ¶ added in v0.3.0
func (b *BlockChain) GetBlockByHash(hash Uint256) (*Block, error)
Get block with block hash.
func (*BlockChain) GetBlockByHeight ¶ added in v0.5.0
func (b *BlockChain) GetBlockByHeight(height uint32) (*Block, error)
Get block by height
func (*BlockChain) GetBlockHash ¶ added in v0.5.0
func (b *BlockChain) GetBlockHash(height uint32) (Uint256, error)
Get block with block hash.
func (*BlockChain) GetBlockNode ¶ added in v0.5.0
func (b *BlockChain) GetBlockNode(height uint32) *BlockNode
Get block with block hash.
func (*BlockChain) GetCRCommittee ¶ added in v0.5.0
func (b *BlockChain) GetCRCommittee() *crstate.Committee
func (*BlockChain) GetCurrentBlockHash ¶ added in v0.5.0
func (b *BlockChain) GetCurrentBlockHash() Uint256
func (*BlockChain) GetDB ¶ added in v0.5.0
func (b *BlockChain) GetDB() IChainStore
func (*BlockChain) GetDposBlockByHash ¶ added in v0.3.0
func (b *BlockChain) GetDposBlockByHash(hash Uint256) (*DposBlock, error)
Get DPOS block with block hash.
func (*BlockChain) GetHeader ¶ added in v0.3.0
func (b *BlockChain) GetHeader(hash Uint256) (*Header, error)
func (*BlockChain) GetHeight ¶ added in v0.3.0
func (b *BlockChain) GetHeight() uint32
func (*BlockChain) GetNetworkHashPS ¶ added in v0.3.4
func (b *BlockChain) GetNetworkHashPS() *big.Int
GetNetworkHashPS return average network hashes per second based on the last 'lookup' blocks.
func (*BlockChain) GetOrphan ¶ added in v0.3.2
func (b *BlockChain) GetOrphan(hash *Uint256) *OrphanBlock
func (*BlockChain) GetOrphanConfirm ¶ added in v0.3.0
func (b *BlockChain) GetOrphanConfirm(hash *Uint256) (*payload.Confirm, bool)
func (*BlockChain) GetOrphanRoot ¶ added in v0.3.0
func (b *BlockChain) GetOrphanRoot(hash *Uint256) *Uint256
func (*BlockChain) GetState ¶ added in v0.3.0
func (b *BlockChain) GetState() *state.State
GetState returns the DPOS state instance that stores producers and votes information.
func (*BlockChain) HaveBlock ¶ added in v0.3.0
func (b *BlockChain) HaveBlock(hash *Uint256) (bool, error)
func (*BlockChain) Init ¶ added in v0.5.0
func (b *BlockChain) Init(interrupt <-chan struct{}) error
func (*BlockChain) InitCheckpoint ¶ added in v0.5.0
func (b *BlockChain) InitCheckpoint(interrupt <-chan struct{}, barStart func(total uint32), increase func()) (err error)
InitCheckpoint go through all blocks since the genesis block to initialize all checkpoint.
func (*BlockChain) IsKnownOrphan ¶ added in v0.3.0
func (b *BlockChain) IsKnownOrphan(hash *Uint256) bool
func (*BlockChain) LatestBlockLocator ¶ added in v0.3.0
func (b *BlockChain) LatestBlockLocator() ([]*Uint256, error)
func (*BlockChain) LoadBlockNode ¶ added in v0.3.0
func (b *BlockChain) LoadBlockNode(blockHeader *Header, hash *Uint256) (*BlockNode, error)
func (*BlockChain) LocateBlocks ¶ added in v0.3.0
func (b *BlockChain) LocateBlocks(locator []*Uint256, hashStop *Uint256, maxHashes uint32) []*Uint256
LocateBlocks returns the hashes of the blocks after the first known block in the locator until the provided stop hash is reached, or up to the provided max number of block hashes.
In addition, there are two special cases:
- When no locators are provided, the stop hash is treated as a request for that block, so it will either return the stop hash itself if it is known, or nil if it is unknown
- When locators are provided, but none of them are known, hashes starting after the genesis block will be returned
This function is safe for concurrent access.
func (*BlockChain) LookupNodeInIndex ¶ added in v0.3.0
func (b *BlockChain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)
func (*BlockChain) MainChainHasBlock ¶ added in v0.5.0
func (b *BlockChain) MainChainHasBlock(height uint32, hash *Uint256) bool
MainChainHasBlock returns whether or not the block with the given hash is in the main chain.
func (*BlockChain) MedianAdjustedTime ¶ added in v0.3.0
func (b *BlockChain) MedianAdjustedTime() time.Time
func (*BlockChain) MigrateOldDB ¶ added in v0.5.0
func (*BlockChain) ProcessBlock ¶ added in v0.3.0
func (*BlockChain) ProcessIllegalBlock ¶ added in v0.3.0
func (b *BlockChain) ProcessIllegalBlock(payload *payload.DPOSIllegalBlocks)
func (*BlockChain) ProcessInactiveArbiter ¶ added in v0.3.2
func (b *BlockChain) ProcessInactiveArbiter(payload *payload.InactiveArbitrators)
func (*BlockChain) ProcessOrphans ¶ added in v0.3.0
func (b *BlockChain) ProcessOrphans(hash *Uint256) error
func (*BlockChain) RemoveOrphanBlock ¶ added in v0.3.0
func (b *BlockChain) RemoveOrphanBlock(orphan *OrphanBlock)
func (*BlockChain) ReorganizeChain ¶ added in v0.3.0
func (b *BlockChain) ReorganizeChain(block *Block) error
ReorganizeChain reorganize chain by specify a block, this method shall not be called normally because it can cause reorganizing without node work sum checking
func (*BlockChain) SetTip ¶ added in v0.5.0
func (b *BlockChain) SetTip(node *BlockNode)
SetTip sets the block chain to use the provided block node as the current tip and ensures the view is consistent by populating it with the nodes obtained by walking backwards all the way to genesis block as necessary. Further calls will only perform the minimum work needed, so switching between chain tips is efficient.
This function is safe for concurrent access.
type BlockNode ¶
type BlockNode struct { Hash *common.Uint256 ParentHash *common.Uint256 Height uint32 Version uint32 Bits uint32 Timestamp uint32 WorkSum *big.Int InMainChain bool Parent *BlockNode Children []*BlockNode // Status is a bitfield representing the validation state of the block. The // Status field, unlike the other fields, may be written to and so should // only be accessed using the concurrent-safe NodeStatus method on // blockIndex once the node has been added to the global index. Status blockStatus }
BlockNode represents a block within the block chain and is primarily used to aid in selecting the best chain to be the main chain. The main chain is stored into the block database.
func NewBlockNode ¶
NewBlockNode returns a new block node for the given block header and block hash, calculating the height and workSum from the respective fields.
func RemoveChildNode ¶
type ChainStore ¶
type ChainStore struct {
// contains filtered or unexported fields
}
func (*ChainStore) Close ¶
func (c *ChainStore) Close()
func (*ChainStore) CloseLeveldb ¶ added in v0.5.0
func (c *ChainStore) CloseLeveldb()
func (*ChainStore) GetConfirm ¶ added in v0.2.2
func (c *ChainStore) GetConfirm(hash Uint256) (*payload.Confirm, error)
func (*ChainStore) GetFFLDB ¶ added in v0.5.0
func (c *ChainStore) GetFFLDB() IFFLDBChainStore
func (*ChainStore) GetHeight ¶
func (c *ChainStore) GetHeight() uint32
func (*ChainStore) GetTransaction ¶
func (c *ChainStore) GetTransaction(txID Uint256) (*Transaction, uint32, error)
func (*ChainStore) GetTxReference ¶
func (c *ChainStore) GetTxReference(tx *Transaction) (map[*Input]*Output, error)
func (*ChainStore) IsDoubleSpend ¶
func (c *ChainStore) IsDoubleSpend(txn *Transaction) bool
func (*ChainStore) IsSidechainTxHashDuplicate ¶ added in v0.1.1
func (c *ChainStore) IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool
func (*ChainStore) IsTxHashDuplicate ¶
func (c *ChainStore) IsTxHashDuplicate(txID Uint256) bool
func (*ChainStore) RollbackBlock ¶
func (*ChainStore) SetHeight ¶ added in v0.5.0
func (c *ChainStore) SetHeight(height uint32)
type ChainStoreFFLDB ¶ added in v0.5.0
type ChainStoreFFLDB struct {
// contains filtered or unexported fields
}
func (*ChainStoreFFLDB) Begin ¶ added in v0.5.0
func (c *ChainStoreFFLDB) Begin(writable bool) (database.Tx, error)
func (*ChainStoreFFLDB) BlockExists ¶ added in v0.5.0
func (c *ChainStoreFFLDB) BlockExists(hash *Uint256) (bool, uint32, error)
blockExists determines whether a block with the given hash exists either in the main chain or any side chains.
This function is safe for concurrent access.
func (*ChainStoreFFLDB) Close ¶ added in v0.5.0
func (c *ChainStoreFFLDB) Close() error
func (*ChainStoreFFLDB) GetBlock ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetBlock(hash Uint256) (*DposBlock, error)
func (*ChainStoreFFLDB) GetHeader ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetHeader(hash Uint256) (*Header, error)
func (*ChainStoreFFLDB) GetOldBlock ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetOldBlock(hash Uint256) (*Block, error)
func (*ChainStoreFFLDB) GetTransaction ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetTransaction(txID Uint256) (*Transaction, uint32, error)
func (*ChainStoreFFLDB) GetUTXO ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetUTXO(programHash *Uint168) ([]*UTXO, error)
func (*ChainStoreFFLDB) GetUnspent ¶ added in v0.5.0
func (c *ChainStoreFFLDB) GetUnspent(txID Uint256) ([]uint16, error)
func (*ChainStoreFFLDB) InitIndex ¶ added in v0.5.0
func (c *ChainStoreFFLDB) InitIndex(chain indexers.IChain, interrupt <-chan struct{}) error
func (*ChainStoreFFLDB) IsBlockInStore ¶ added in v0.5.0
func (c *ChainStoreFFLDB) IsBlockInStore(hash *Uint256) bool
func (*ChainStoreFFLDB) IsTx3Exist ¶ added in v0.5.0
func (c *ChainStoreFFLDB) IsTx3Exist(txHash *Uint256) bool
func (*ChainStoreFFLDB) RollbackBlock ¶ added in v0.5.0
func (*ChainStoreFFLDB) Type ¶ added in v0.5.0
func (c *ChainStoreFFLDB) Type() string
type DataEntryPrefix ¶
type DataEntryPrefix byte
DataEntryPrefix
const ( // DATA DATABlockHash DataEntryPrefix = 0x00 DATAHeader DataEntryPrefix = 0x01 DATATransaction DataEntryPrefix = 0x02 DATAConfirm DataEntryPrefix = 0x03 //SYSTEM SYSCurrentBlock DataEntryPrefix = 0x40 SYSCurrentBookKeeper DataEntryPrefix = 0x42 // INDEX IXHeaderHashList DataEntryPrefix = 0x80 IXUnspent DataEntryPrefix = 0x90 IXUnspentUTXO DataEntryPrefix = 0x91 IXSideChainTx DataEntryPrefix = 0x92 // ASSET STInfo DataEntryPrefix = 0xc0 // DPOS DPOSIllegalProducer DataEntryPrefix = 0xd1 //CONFIG CFGVersion DataEntryPrefix = 0xf0 )
type IChainStore ¶
type IChainStore interface { GetFFLDB() IFFLDBChainStore SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error IsDoubleSpend(tx *Transaction) bool GetConfirm(hash Uint256) (*payload.Confirm, error) RollbackBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error GetTransaction(txID Uint256) (*Transaction, uint32, error) GetTxReference(tx *Transaction) (map[*Input]*Output, error) SetHeight(height uint32) GetHeight() uint32 IsTxHashDuplicate(txhash Uint256) bool IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool Close() CloseLeveldb() }
IChainStore provides func with store package.
func NewChainStore ¶
func NewChainStore(dataDir string, params *config.Params) (IChainStore, error)
type IFFLDBChainStore ¶ added in v0.5.0
type IFFLDBChainStore interface { database.DB // SaveBlock will write block into file db. SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error // RollbackBlock only remove block state and block index. RollbackBlock(b *Block, node *BlockNode, confirm *payload.Confirm, medianTimePast time.Time) error // Get block from file db. GetBlock(hash Uint256) (*DposBlock, error) // Get block from file db. GetOldBlock(hash Uint256) (*Block, error) // Get block header from file db. GetHeader(hash Uint256) (*Header, error) // If already exist in main chain(exist in file db and exist block index), // will return true. BlockExists(hash *Uint256) (bool, uint32, error) // If already exist in file db (rollback will not remove from file db), will // return true. IsBlockInStore(hash *Uint256) bool // Get a transaction by transaction hash GetTransaction(txID Uint256) (*Transaction, uint32, error) // InitIndex use to initialize the index manager InitIndex(chain indexers.IChain, interrupt <-chan struct{}) error // Get unspent by transaction hash GetUnspent(txID Uint256) ([]uint16, error) // Get utxo by program hash GetUTXO(programHash *Uint168) ([]*UTXO, error) // IsTx3Exist use to find if tx3 exist in db IsTx3Exist(txHash *Uint256) bool }
IChainStore provides func with store package.
func NewChainStoreFFLDB ¶ added in v0.5.0
func NewChainStoreFFLDB(dataDir string, params *config.Params) (IFFLDBChainStore, error)
type IUTXOCacheStore ¶ added in v0.5.0
type Ledger ¶
type Ledger struct { Blockchain *BlockChain Store IChainStore Arbitrators state.Arbitrators Committee *crstate.Committee }
Ledger - the struct for ledger
func (*Ledger) AppendDposBlocks ¶ added in v0.2.2
Append blocks and confirms directly
func (*Ledger) GetBlockWithHash ¶
Get block with block hash.
func (*Ledger) GetBlockWithHeight ¶
Get Block With Height.
func (*Ledger) GetDposBlocks ¶ added in v0.2.2
Get blocks and confirms by given height range, if end equals zero will be treat as current highest block height
func (*Ledger) GetLocalBlockChainHeight ¶
Get local block chain height.
func (*Ledger) GetTransactionWithHash ¶
Get transaction with hash.
func (*Ledger) IsDoubleSpend ¶
check weather the transaction contains the doubleSpend.
type LevelDB ¶
type LevelDB struct {
// contains filtered or unexported fields
}
func NewLevelDB ¶
func (*LevelDB) BatchCommit ¶
func (*LevelDB) BatchDelete ¶
func (*LevelDB) NewIterator ¶
type MedianTimeSource ¶
type MedianTimeSource interface { // AdjustedTime returns the current time adjusted by the median time // offset as calculated from the time samples added by AddTimeSample. AdjustedTime() time.Time // AddTimeSample adds a time sample that is used when determining the // median time of the added samples. AddTimeSample(id string, timeVal time.Time) // Offset returns the number of seconds to adjust the local clock based // upon the median of the time samples added by AddTimeData. Offset() time.Duration // Reset the median time. Reset() }
MedianTimeSource provides a mechanism to add several time samples which are used to determine a median time which is then used as an offset to the local clock.
func NewMedianTime ¶
func NewMedianTime() MedianTimeSource
NewMedianTime returns a new instance of concurrency-safe implementation of the MedianTimeSource interface. The returned implementation contains the rules necessary for proper time handling in the chain consensus rules and expects the time samples to be added from the timestamp field of the version message received from remote peers that successfully connect and negotiate.
type OrphanBlock ¶
type OutputInfo ¶ added in v0.5.0
type OutputInfo struct { Recipient Uint168 Amount *Fixed64 }
type ProducerInfo ¶ added in v0.2.2
type ProducerInfo struct { Payload *payload.ProducerInfo RegHeight uint32 Vote Fixed64 }
type ProducerState ¶ added in v0.2.2
type ProducerState byte
type UTXOCache ¶ added in v0.5.0
func NewUTXOCache ¶ added in v0.5.0
func NewUTXOCache(db IUTXOCacheStore, params *config.Params) *UTXOCache
func (*UTXOCache) CleanCache ¶ added in v0.5.0
func (up *UTXOCache) CleanCache()
func (*UTXOCache) CleanTxCache ¶ added in v0.5.0
func (up *UTXOCache) CleanTxCache()