Documentation ¶
Index ¶
- Constants
- Variables
- func DBGetBlockIdByHash(dbTx database.Tx, h *hash.Hash) (uint32, error)
- func DBGetBlockIdByOrder(dbTx database.Tx, order uint) (uint32, error)
- func DBGetDAGBlock(dbTx database.Tx, block IBlock) error
- func DBHasMainChainBlock(dbTx database.Tx, id uint) bool
- func DBPutBlockIdByOrder(dbTx database.Tx, order uint, id uint) error
- func DBPutDAGBlock(dbTx database.Tx, block IBlock) error
- func DBPutDAGBlockIdByHash(dbTx database.Tx, block IBlock) error
- func DBPutDAGInfo(dbTx database.Tx, bd *BlockDAG) error
- func DBPutMainChainBlock(dbTx database.Tx, id uint) error
- func DBRemoveMainChainBlock(dbTx database.Tx, id uint) error
- func GetDAGTypeByIndex(dagType byte) string
- func GetDAGTypeIndex(dagType string) byte
- func GetMaxLenHashSet(bsm map[hash.Hash]*HashSet) *hash.Hash
- func GetOrderLogStr(order uint) string
- func GetRisk(N int, alpha float64, lambda float64, delay float64, waitingTime uint, ...) float64
- func UseLogger(logger l.Logger)
- type Block
- func (b *Block) AddChild(child IBlock)
- func (b *Block) Decode(r io.Reader) error
- func (b *Block) Encode(w io.Writer) error
- func (b *Block) GetBackParent() *Block
- func (b *Block) GetChildren() *IdSet
- func (b *Block) GetData() IBlockData
- func (b *Block) GetForwardParent() *Block
- func (b *Block) GetHash() *hash.Hash
- func (b *Block) GetHeight() uint
- func (b *Block) GetID() uint
- func (b *Block) GetLayer() uint
- func (b *Block) GetMainParent() uint
- func (b *Block) GetOrder() uint
- func (b *Block) GetParents() *IdSet
- func (b *Block) GetStatus() BlockStatus
- func (b *Block) GetWeight() uint64
- func (b *Block) HasChildren() bool
- func (b *Block) HasParents() bool
- func (b *Block) Invalid()
- func (b *Block) IsOrdered() bool
- func (b *Block) RemoveChild(child uint)
- func (b *Block) SetHeight(h uint)
- func (b *Block) SetID(id uint)
- func (b *Block) SetLayer(layer uint)
- func (b *Block) SetOrder(o uint)
- func (b *Block) SetStatus(status BlockStatus)
- func (b *Block) SetStatusFlags(flags BlockStatus)
- func (b *Block) SetWeight(weight uint64)
- func (b *Block) UnsetStatusFlags(flags BlockStatus)
- func (b *Block) Valid()
- type BlockDAG
- func (bd *BlockDAG) AddBlock(b IBlockData) (*list.List, *list.List, IBlock, bool)
- func (bd *BlockDAG) BuildMerkleTreeStoreFromTips() []*hash.Hash
- func (bd *BlockDAG) CheckBlueAndMature(targets []uint, views []uint, max uint) error
- func (bd *BlockDAG) CheckBlueAndMatureMT(targets []uint, views []uint, max uint) error
- func (bd *BlockDAG) CheckSubMainChainTip(parents []uint) (uint, bool)
- func (bd *BlockDAG) Commit() error
- func (bd *BlockDAG) CreateVirtualBlock(data IBlockData) IBlock
- func (bd *BlockDAG) Decode(r io.Reader) error
- func (bd *BlockDAG) Encode(w io.Writer) error
- func (bd *BlockDAG) GetBlock(h *hash.Hash) IBlock
- func (bd *BlockDAG) GetBlockById(id uint) IBlock
- func (bd *BlockDAG) GetBlockByOrder(order uint) IBlock
- func (bd *BlockDAG) GetBlockByOrderWithTx(dbTx database.Tx, order uint) *hash.Hash
- func (bd *BlockDAG) GetBlockConcurrency(h *hash.Hash) (uint, error)
- func (bd *BlockDAG) GetBlockHash(id uint) *hash.Hash
- func (bd *BlockDAG) GetBlockHashByOrder(order uint) *hash.Hash
- func (bd *BlockDAG) GetBlockId(h *hash.Hash) uint
- func (bd *BlockDAG) GetBlockTotal() uint
- func (bd *BlockDAG) GetBlues(parents *IdSet) uint
- func (bd *BlockDAG) GetConfirmations(id uint) uint
- func (bd *BlockDAG) GetGenesisHash() *hash.Hash
- func (bd *BlockDAG) GetGraphState() *GraphState
- func (bd *BlockDAG) GetIdSet(hs []*hash.Hash) *IdSet
- func (bd *BlockDAG) GetInstance() IBlockDAG
- func (bd *BlockDAG) GetLastBlock() IBlock
- func (bd *BlockDAG) GetLastTime() *time.Time
- func (bd *BlockDAG) GetLayer(id uint) uint
- func (bd *BlockDAG) GetMainAncestor(block IBlock, height int64) IBlock
- func (bd *BlockDAG) GetMainChainTip() IBlock
- func (bd *BlockDAG) GetMainParent(parents *IdSet) IBlock
- func (bd *BlockDAG) GetMainParentByHashs(parents []*hash.Hash) IBlock
- func (bd *BlockDAG) GetMainParentConcurrency(b IBlock) int
- func (bd *BlockDAG) GetMaturity(target uint, views []uint) uint
- func (bd *BlockDAG) GetName() string
- func (bd *BlockDAG) GetParentsMaxLayer(parents *IdSet) (uint, bool)
- func (bd *BlockDAG) GetPrevious(id uint) (uint, error)
- func (bd *BlockDAG) GetTips() *HashSet
- func (bd *BlockDAG) GetTipsList() []IBlock
- func (bd *BlockDAG) GetValidTips() []*hash.Hash
- func (bd *BlockDAG) HasBlock(h *hash.Hash) bool
- func (bd *BlockDAG) HasBlockById(id uint) bool
- func (bd *BlockDAG) Init(dagType string, calcWeight CalcWeight, blockRate float64, db database.DB, ...) IBlockDAG
- func (bd *BlockDAG) InvalidBlock(block IBlock)
- func (bd *BlockDAG) IsBlue(id uint) bool
- func (bd *BlockDAG) IsHourglass(id uint) bool
- func (bd *BlockDAG) IsOnMainChain(id uint) bool
- func (bd *BlockDAG) Load(dbTx database.Tx, blockTotal uint, genesis *hash.Hash) error
- func (bd *BlockDAG) RelativeMainAncestor(block IBlock, distance int64) IBlock
- func (bd *BlockDAG) SortBlock(src []*hash.Hash) []*hash.Hash
- func (bd *BlockDAG) UpdateWeight(ib IBlock)
- func (bd *BlockDAG) UpgradeDB(dbTx database.Tx) error
- func (bd *BlockDAG) ValidBlock(block IBlock)
- type BlockHashSlice
- type BlockOrderHelp
- type BlockOrderSlice
- type BlockSlice
- type BlockStatus
- type CalcWeight
- type Conflux
- func (con *Conflux) AddBlock(b IBlock) (*list.List, *list.List)
- func (con *Conflux) CreateBlock(b *Block) IBlock
- func (con *Conflux) Decode(r io.Reader) error
- func (con *Conflux) Encode(w io.Writer) error
- func (con *Conflux) GetBlues(parents *IdSet) uint
- func (con *Conflux) GetMainChain() []uint
- func (con *Conflux) GetMainChainTip() IBlock
- func (con *Conflux) GetMainChainTipId() uint
- func (con *Conflux) GetMainParent(parents *IdSet) IBlock
- func (con *Conflux) GetMainParentConcurrency(b IBlock) int
- func (con *Conflux) GetName() string
- func (con *Conflux) GetTipsList() []IBlock
- func (con *Conflux) Init(bd *BlockDAG) bool
- func (con *Conflux) IsBlue(id uint) bool
- func (con *Conflux) IsDAG(parents []IBlock) bool
- func (con *Conflux) IsOnMainChain(b IBlock) bool
- func (con *Conflux) Load(dbTx database.Tx) error
- type DAGSnapshot
- type DAGSync
- type Empty
- type Epoch
- type GetBlockData
- type GraphState
- func (gs *GraphState) Clone() *GraphState
- func (gs *GraphState) Decode(r io.Reader, pver uint32) error
- func (gs *GraphState) Encode(w io.Writer, pver uint32) error
- func (gs *GraphState) Equal(other *GraphState)
- func (gs *GraphState) GetLayer() uint
- func (gs *GraphState) GetMainChainTip() *hash.Hash
- func (gs *GraphState) GetMainHeight() uint
- func (gs *GraphState) GetMainOrder() uint
- func (gs *GraphState) GetTips() *HashSet
- func (gs *GraphState) GetTotal() uint
- func (gs *GraphState) IsEqual(other *GraphState) bool
- func (gs *GraphState) IsExcellent(other *GraphState) bool
- func (gs *GraphState) IsGenesis() bool
- func (gs *GraphState) MaxPayloadLength() uint32
- func (gs *GraphState) SetLayer(layer uint)
- func (gs *GraphState) SetMainHeight(mainHeight uint)
- func (gs *GraphState) SetMainOrder(order uint)
- func (gs *GraphState) SetTips(tips *HashSet)
- func (gs *GraphState) SetTotal(total uint)
- func (gs *GraphState) String() string
- type HashSet
- func (s *HashSet) Add(elem *hash.Hash)
- func (s *HashSet) AddList(list []*hash.Hash)
- func (s *HashSet) AddPair(elem *hash.Hash, data interface{})
- func (s *HashSet) AddSet(other *HashSet)
- func (s *HashSet) Clean()
- func (s *HashSet) Clone() *HashSet
- func (s *HashSet) Contain(other *HashSet) bool
- func (s *HashSet) Exclude(other *HashSet)
- func (s *HashSet) Get(elem *hash.Hash) interface{}
- func (s *HashSet) GetMap() map[hash.Hash]interface{}
- func (s *HashSet) Has(elem *hash.Hash) bool
- func (s *HashSet) HasOnly(elem *hash.Hash) bool
- func (s *HashSet) Intersection(other *HashSet) *HashSet
- func (s *HashSet) IsEmpty() bool
- func (s *HashSet) IsEqual(other *HashSet) bool
- func (s *HashSet) List() []*hash.Hash
- func (s *HashSet) Remove(elem *hash.Hash)
- func (s *HashSet) RemoveSet(other *HashSet)
- func (s *HashSet) Size() int
- func (s *HashSet) SortList(reverse bool) []*hash.Hash
- func (s *HashSet) Union(other *HashSet) *HashSet
- type HashSlice
- type IBlock
- type IBlockDAG
- type IBlockData
- type ISpectre
- type IdSet
- func (s *IdSet) Add(elem uint)
- func (s *IdSet) AddList(list []uint)
- func (s *IdSet) AddPair(elem uint, data interface{})
- func (s *IdSet) AddSet(other *IdSet)
- func (s *IdSet) Clean()
- func (s *IdSet) Clone() *IdSet
- func (s *IdSet) Contain(other *IdSet) bool
- func (s *IdSet) Exclude(other *IdSet)
- func (s *IdSet) Get(elem uint) interface{}
- func (s *IdSet) GetMap() map[uint]interface{}
- func (s *IdSet) Has(elem uint) bool
- func (s *IdSet) HasOnly(elem uint) bool
- func (s *IdSet) Intersection(other *IdSet) *IdSet
- func (s *IdSet) IsEmpty() bool
- func (s *IdSet) IsEqual(other *IdSet) bool
- func (s *IdSet) List() []uint
- func (s *IdSet) Remove(elem uint)
- func (s *IdSet) RemoveSet(other *IdSet)
- func (s *IdSet) Size() int
- func (s *IdSet) SortHashList(reverse bool) []uint
- func (s *IdSet) SortList(reverse bool) []uint
- func (s *IdSet) Union(other *IdSet) *IdSet
- type IdSlice
- type KChain
- type LazySet
- type MainChain
- type Phantom
- func (ph *Phantom) AddBlock(ib IBlock) (*list.List, *list.List)
- func (ph *Phantom) CheckMainChainDB(dbTx database.Tx) error
- func (ph *Phantom) CreateBlock(b *Block) IBlock
- func (ph *Phantom) Decode(r io.Reader) error
- func (ph *Phantom) Encode(w io.Writer) error
- func (ph *Phantom) GetBlues(parents *IdSet) uint
- func (ph *Phantom) GetDiffAnticone() *IdSet
- func (ph *Phantom) GetDiffBlueSet() *IdSet
- func (ph *Phantom) GetMainChainTip() IBlock
- func (ph *Phantom) GetMainChainTipId() uint
- func (ph *Phantom) GetMainParent(parents *IdSet) IBlock
- func (ph *Phantom) GetMainParentConcurrency(b IBlock) int
- func (ph *Phantom) GetName() string
- func (ph *Phantom) GetTipsList() []IBlock
- func (ph *Phantom) Init(bd *BlockDAG) bool
- func (ph *Phantom) IsBlue(id uint) bool
- func (ph *Phantom) IsDAG(parents []IBlock) bool
- func (ph *Phantom) IsOnMainChain(b IBlock) bool
- func (ph *Phantom) Load(dbTx database.Tx) error
- func (ph *Phantom) UpdateVirtualBlockOrder() *PhantomBlock
- func (ph *Phantom) UpdateWeight(ib IBlock)
- type PhantomBlock
- func (pb *PhantomBlock) Decode(r io.Reader) error
- func (pb *PhantomBlock) Encode(w io.Writer) error
- func (pb *PhantomBlock) GetBlueDiffAnticone() *IdSet
- func (pb *PhantomBlock) GetBlueNum() uint
- func (pb *PhantomBlock) GetRedDiffAnticone() *IdSet
- func (pb *PhantomBlock) IsBluer(other *PhantomBlock) bool
- type Phantom_v2
- func (ph *Phantom_v2) AddBlock(b IBlock) (*list.List, *list.List)
- func (ph *Phantom_v2) CreateBlock(b *Block) IBlock
- func (ph *Phantom_v2) Decode(r io.Reader) error
- func (ph *Phantom_v2) Encode(w io.Writer) error
- func (ph *Phantom_v2) GetBlues(parents *IdSet) uint
- func (ph *Phantom_v2) GetMainChainTip() IBlock
- func (ph *Phantom_v2) GetMainChainTipId() uint
- func (ph *Phantom_v2) GetMainParent(parents *IdSet) IBlock
- func (ph *Phantom_v2) GetMainParentConcurrency(b IBlock) int
- func (ph *Phantom_v2) GetName() string
- func (ph *Phantom_v2) GetTipsList() []IBlock
- func (ph *Phantom_v2) Init(bd *BlockDAG) bool
- func (ph *Phantom_v2) IsBlue(id uint) bool
- func (ph *Phantom_v2) IsDAG(parents []IBlock) bool
- func (ph *Phantom_v2) IsOnMainChain(b IBlock) bool
- func (ph *Phantom_v2) Load(dbTx database.Tx) error
- type Spectre
- func (sp *Spectre) AddBlock(b IBlock) (*list.List, *list.List)
- func (sp *Spectre) CreateBlock(b *Block) IBlock
- func (sp *Spectre) Decode(r io.Reader) error
- func (sp *Spectre) Encode(w io.Writer) error
- func (sp *Spectre) GetBlues(parents *IdSet) uint
- func (sp *Spectre) GetMainChainTip() IBlock
- func (sp *Spectre) GetMainChainTipId() uint
- func (sp *Spectre) GetMainParent(parents *IdSet) IBlock
- func (sp *Spectre) GetMainParentConcurrency(b IBlock) int
- func (sp *Spectre) GetName() string
- func (sp *Spectre) GetTipsList() []IBlock
- func (sp *Spectre) Init(bd *BlockDAG) bool
- func (sp *Spectre) InitVote(b1 IBlock, b2 IBlock) (bool, error)
- func (sp *Spectre) IsBlue(id uint) bool
- func (sp *Spectre) IsDAG(parents []IBlock) bool
- func (sp *Spectre) IsInPastOf(b1 IBlock, b2 IBlock) bool
- func (sp *Spectre) IsOnMainChain(b IBlock) bool
- func (sp *Spectre) Load(dbTx database.Tx) error
- func (sp *Spectre) Vote(b1 IBlock, b2 IBlock) (bool, error)
- func (sp *Spectre) VoteByBlock(virtualBlock IBlock) (bool, error)
- func (sp *Spectre) Votes() map[hash.Hash]bool
- type SpectreBlock
- type SpectreBlockData
- type SyncMode
Constants ¶
const ( VMK_KEY = 1 RET_KEY = 2 )
const GenesisId = uint(0)
Genesis id of the DAG block
const MaxBlockOrder = uint(^uint32(0))
Maximum order of the DAG block
const MaxId = uint(math.MaxUint32)
Maximum id of the DAG block
const MaxMainLocatorNum = 32
This parameter can be set according to the size of TCP package(1500) to ensure the transmission stability of the network
const MaxTipLayerGap = 10
MaxTipLayerGap
const MaxTips = 100
Maximum number of the DAG tip
const StableConfirmations = 10
StableConfirmations
Variables ¶
var (
BlockRate = anticone.DefaultBlockRate
)
Functions ¶
func DBGetBlockIdByHash ¶ added in v0.10.1
func DBGetBlockIdByOrder ¶ added in v0.10.1
func DBGetDAGBlock ¶
DBGetDAGBlock get dag block data by resouce ID
func DBHasMainChainBlock ¶ added in v0.10.1
func DBPutBlockIdByOrder ¶ added in v0.10.1
func DBPutDAGBlock ¶
DBPutDAGBlock stores the information needed to reconstruct the provided block in the block index according to the format described above.
func DBPutDAGBlockIdByHash ¶ added in v0.10.1
func DBPutMainChainBlock ¶ added in v0.10.1
func DBRemoveMainChainBlock ¶ added in v0.10.1
func GetDAGTypeByIndex ¶
func GetDAGTypeIndex ¶
func GetOrderLogStr ¶
func GetRisk ¶
func GetRisk(N int, alpha float64, lambda float64, delay float64, waitingTime uint, antiPast int) float64
parameters N: just pick a value much greater than 1. alpha: the attacker’s relative computational power. lambda: blocks per second. delay: the upper bound on the recent delay diameter in the network. waitingTime: wait time. antiPast: min(|future(x')|), where x' is x or any block in anticone(x) and x is the block we want to confirm, ideally this should be about waitingTime * lambda.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
It is the element of a DAG. It is the most basic data unit.
func (*Block) GetData ¶ added in v0.10.1
func (b *Block) GetData() IBlockData
func (*Block) GetForwardParent ¶
Parent with order in front.
func (*Block) GetMainParent ¶
func (*Block) GetParents ¶
Get all parents set,the dag block has more than one parent
func (*Block) GetStatus ¶
func (b *Block) GetStatus() BlockStatus
func (*Block) HasChildren ¶
Detecting the presence of child nodes
func (*Block) RemoveChild ¶ added in v0.10.1
func (*Block) SetStatusFlags ¶
func (b *Block) SetStatusFlags(flags BlockStatus)
func (*Block) UnsetStatusFlags ¶
func (b *Block) UnsetStatusFlags(flags BlockStatus)
type BlockDAG ¶
type BlockDAG struct {
// contains filtered or unexported fields
}
The general foundation framework of DAG
func (*BlockDAG) AddBlock ¶
This is an entry for update the block dag,you need pass in a block parameter, If add block have failure,it will return false.
func (*BlockDAG) BuildMerkleTreeStoreFromTips ¶
build merkle tree form current DAG tips
func (*BlockDAG) CheckBlueAndMature ¶ added in v0.10.1
Batch check the blue and mature properties of blocks in views perspective. targets: Need check blocks views: Block DAG perspective when calculate the result max: Max maturity
func (*BlockDAG) CheckBlueAndMatureMT ¶ added in v0.10.1
Batch check the blue and mature properties of blocks in views perspective, and enable multithreading mode. targets: Need check blocks views: Block DAG perspective when calculate the result max: Max maturity
func (*BlockDAG) CheckSubMainChainTip ¶
Checking the sub main chain for the parents of tip
func (*BlockDAG) Commit ¶ added in v0.10.1
Commit the consensus content to the database for persistence
func (*BlockDAG) CreateVirtualBlock ¶ added in v0.10.1
func (bd *BlockDAG) CreateVirtualBlock(data IBlockData) IBlock
Just for custom Virtual block
func (*BlockDAG) GetBlockById ¶ added in v0.10.1
Acquire one block by hash
func (*BlockDAG) GetBlockByOrder ¶
func (*BlockDAG) GetBlockByOrderWithTx ¶ added in v0.10.1
func (*BlockDAG) GetBlockConcurrency ¶ added in v0.10.1
GetBlockConcurrency : Temporarily use blue set of the past blocks as the criterion
func (*BlockDAG) GetBlockHashByOrder ¶ added in v0.10.1
Obtain block hash by global order
func (*BlockDAG) GetConfirmations ¶
GetConfirmations
func (*BlockDAG) GetGenesisHash ¶
Acquire the genesis block hash of chain
func (*BlockDAG) GetGraphState ¶
func (bd *BlockDAG) GetGraphState() *GraphState
Return current general description of the whole state of DAG
func (*BlockDAG) GetLastBlock ¶
Return the last order block
func (*BlockDAG) GetLastTime ¶
The last time is when add one block to DAG.
func (*BlockDAG) GetLayer ¶
Return the layer of block,it is stable. You can imagine that this is the main chain.
func (*BlockDAG) GetMainAncestor ¶ added in v0.10.1
func (*BlockDAG) GetMainChainTip ¶
return the tip of main chain
func (*BlockDAG) GetMainParent ¶
return the main parent in the parents
func (*BlockDAG) GetMainParentByHashs ¶ added in v0.10.1
return the main parent in the parents
func (*BlockDAG) GetMainParentConcurrency ¶ added in v0.10.1
The main parent concurrency of block
func (*BlockDAG) GetMaturity ¶
GetMaturity
func (*BlockDAG) GetParentsMaxLayer ¶
func (*BlockDAG) GetPrevious ¶
This function need a stable sequence,so call it before sorting the DAG. If the h is invalid,the function will become a little inefficient.
func (*BlockDAG) GetTips ¶
return the terminal blocks, because there maybe more than one, so this is a set.
func (*BlockDAG) GetTipsList ¶
Acquire the tips array of DAG
func (*BlockDAG) GetValidTips ¶
func (*BlockDAG) HasBlockById ¶ added in v0.10.1
Is there a block in DAG?
func (*BlockDAG) Init ¶
func (bd *BlockDAG) Init(dagType string, calcWeight CalcWeight, blockRate float64, db database.DB, getBlockData GetBlockData) IBlockDAG
Initialize self, the function to be invoked at the beginning
func (*BlockDAG) InvalidBlock ¶ added in v0.10.1
func (*BlockDAG) IsHourglass ¶
func (*BlockDAG) IsOnMainChain ¶
Query whether a given block is on the main chain. Note that some DAG protocols may not support this feature.
func (*BlockDAG) RelativeMainAncestor ¶ added in v0.10.1
func (*BlockDAG) UpdateWeight ¶ added in v0.10.1
func (*BlockDAG) ValidBlock ¶ added in v0.10.1
type BlockHashSlice ¶ added in v0.10.1
type BlockHashSlice []IBlock
BlockSlice is used to sort dag block Just for inside
func (BlockHashSlice) Len ¶ added in v0.10.1
func (bn BlockHashSlice) Len() int
func (BlockHashSlice) Less ¶ added in v0.10.1
func (bn BlockHashSlice) Less(i, j int) bool
func (BlockHashSlice) Swap ¶ added in v0.10.1
func (bn BlockHashSlice) Swap(i, j int)
type BlockOrderHelp ¶ added in v0.10.1
BlockOrderHelp is used to help reorganize block order
type BlockOrderSlice ¶ added in v0.10.1
type BlockOrderSlice []IBlock
BlockOrderSlice is used to sort dag block by order
func (BlockOrderSlice) Len ¶ added in v0.10.1
func (bs BlockOrderSlice) Len() int
func (BlockOrderSlice) Less ¶ added in v0.10.1
func (bs BlockOrderSlice) Less(i, j int) bool
func (BlockOrderSlice) Swap ¶ added in v0.10.1
func (bs BlockOrderSlice) Swap(i, j int)
type BlockSlice ¶
type BlockSlice []IBlock
BlockSlice is used to sort dag block Just for outside
func (BlockSlice) Len ¶
func (bn BlockSlice) Len() int
func (BlockSlice) Less ¶
func (bn BlockSlice) Less(i, j int) bool
func (BlockSlice) Swap ¶
func (bn BlockSlice) Swap(i, j int)
type BlockStatus ¶
type BlockStatus byte
BlockStatus
const ( // StatusNone StatusNone BlockStatus = 0 // StatusBadSide StatusBadSide BlockStatus = 1 << 0 // StatusInvalid indicates that the block data has failed validation. StatusInvalid BlockStatus = 1 << 2 )
func (BlockStatus) IsBadSide ¶
func (status BlockStatus) IsBadSide() bool
func (BlockStatus) KnownInvalid ¶ added in v0.10.1
func (status BlockStatus) KnownInvalid() bool
type Conflux ¶
type Conflux struct {
// contains filtered or unexported fields
}
func (*Conflux) GetMainChain ¶
func (*Conflux) GetMainChainTip ¶
return the tip of main chain
func (*Conflux) GetMainChainTipId ¶ added in v0.10.1
return the tip of main chain id
func (*Conflux) GetMainParent ¶
return the main parent in the parents
func (*Conflux) GetMainParentConcurrency ¶ added in v0.10.1
The main parent concurrency of block
func (*Conflux) GetTipsList ¶
func (*Conflux) IsOnMainChain ¶
Query whether a given block is on the main chain.
type DAGSnapshot ¶ added in v0.10.1
type DAGSnapshot struct {
// contains filtered or unexported fields
}
func NewDAGSnapshot ¶ added in v0.10.1
func NewDAGSnapshot() *DAGSnapshot
func (*DAGSnapshot) AddOrder ¶ added in v0.10.1
func (d *DAGSnapshot) AddOrder(ib IBlock)
func (*DAGSnapshot) Clean ¶ added in v0.10.1
func (d *DAGSnapshot) Clean()
func (*DAGSnapshot) IsValid ¶ added in v0.10.1
func (d *DAGSnapshot) IsValid() bool
type DAGSync ¶
type DAGSync struct {
// contains filtered or unexported fields
}
func (*DAGSync) CalcSyncBlocks ¶
func (ds *DAGSync) CalcSyncBlocks(gs *GraphState, locator []*hash.Hash, mode SyncMode, maxHashes uint) ([]*hash.Hash, *hash.Hash)
CalcSyncBlocks
func (*DAGSync) GetMainLocator ¶
GetMainLocator
func (*DAGSync) SetGraphState ¶ added in v0.10.1
func (ds *DAGSync) SetGraphState(gs *GraphState)
type Epoch ¶
type Epoch struct {
// contains filtered or unexported fields
}
func (*Epoch) GetSequence ¶
func (*Epoch) HasDepends ¶
type GetBlockData ¶ added in v0.10.1
type GetBlockData func(*hash.Hash) IBlockData
type GraphState ¶
type GraphState struct {
// contains filtered or unexported fields
}
A general description of the whole state of DAG
func (*GraphState) Decode ¶
func (gs *GraphState) Decode(r io.Reader, pver uint32) error
Decode itself from bytes buff
func (*GraphState) Encode ¶
func (gs *GraphState) Encode(w io.Writer, pver uint32) error
Encode itself to bytes buff
func (*GraphState) GetMainChainTip ¶
func (gs *GraphState) GetMainChainTip() *hash.Hash
func (*GraphState) GetMainHeight ¶
func (gs *GraphState) GetMainHeight() uint
Return the height of main chain
func (*GraphState) GetMainOrder ¶
func (gs *GraphState) GetMainOrder() uint
func (*GraphState) IsEqual ¶
func (gs *GraphState) IsEqual(other *GraphState) bool
Judging whether it is equal to other
func (*GraphState) IsExcellent ¶
func (gs *GraphState) IsExcellent(other *GraphState) bool
Judging whether it is better than other
func (*GraphState) IsGenesis ¶ added in v0.10.1
func (gs *GraphState) IsGenesis() bool
func (*GraphState) MaxPayloadLength ¶
func (gs *GraphState) MaxPayloadLength() uint32
func (*GraphState) SetLayer ¶
func (gs *GraphState) SetLayer(layer uint)
func (*GraphState) SetMainHeight ¶
func (gs *GraphState) SetMainHeight(mainHeight uint)
func (*GraphState) SetMainOrder ¶
func (gs *GraphState) SetMainOrder(order uint)
func (*GraphState) SetTips ¶
func (gs *GraphState) SetTips(tips *HashSet)
func (*GraphState) SetTotal ¶
func (gs *GraphState) SetTotal(total uint)
type HashSet ¶
type HashSet struct {
// contains filtered or unexported fields
}
On the Set of hash, and the saved data can be of any type
func (*HashSet) Intersection ¶
This function returns a new open memory (HashSet) The intersection of a set
type IBlock ¶
type IBlock interface { // Return block ID GetID() uint // Return the hash of block. It will be a pointer. GetHash() *hash.Hash // Acquire the layer of block GetLayer() uint // Setting the order of block SetOrder(o uint) // Acquire the order of block GetOrder() uint // IsOrdered IsOrdered() bool // Get all parents set,the dag block has more than one parent GetParents() *IdSet // Testing whether it has parents HasParents() bool // Add child nodes to block AddChild(child IBlock) // Get all the children of block GetChildren() *IdSet // Detecting the presence of child nodes HasChildren() bool RemoveChild(child uint) // GetMainParent GetMainParent() uint // Setting the weight of block SetWeight(weight uint64) // Acquire the weight of block GetWeight() uint64 // Acquire the height of block in main chain GetHeight() uint // SetStatus SetStatus(status BlockStatus) // GetStatus GetStatus() BlockStatus // encode Encode(w io.Writer) error // decode Decode(r io.Reader) error // block data GetData() IBlockData // valid block data Valid() // invalid block data Invalid() }
The interface of block
type IBlockDAG ¶
type IBlockDAG interface { // Return the name GetName() string // This instance is initialized and will be executed first. Init(bd *BlockDAG) bool // Add a block AddBlock(ib IBlock) (*list.List, *list.List) // Build self block CreateBlock(b *Block) IBlock // If the successor return nil, the underlying layer will use the default tips list. GetTipsList() []IBlock // Query whether a given block is on the main chain. IsOnMainChain(ib IBlock) bool // return the tip of main chain GetMainChainTip() IBlock // return the tip of main chain id GetMainChainTipId() uint // return the main parent in the parents GetMainParent(parents *IdSet) IBlock // encode Encode(w io.Writer) error // decode Decode(r io.Reader) error // load Load(dbTx database.Tx) error // IsDAG IsDAG(parents []IBlock) bool // The main parent concurrency of block GetMainParentConcurrency(b IBlock) int // GetBlues GetBlues(parents *IdSet) uint // IsBlue IsBlue(id uint) bool // contains filtered or unexported methods }
The abstract inferface is used to build and manager DAG
func NewBlockDAG ¶
It will create different BlockDAG instances
type IBlockData ¶
type IBlockData interface { // Get hash of block GetHash() *hash.Hash // Get all parents set,the dag block has more than one parent GetParents() []*hash.Hash // Timestamp GetTimestamp() int64 }
The abstract inferface is used to dag block
type IdSet ¶ added in v0.10.1
type IdSet struct {
// contains filtered or unexported fields
}
On the Set of hash, and the saved data can be of any type
func (*IdSet) Intersection ¶ added in v0.10.1
This function returns a new open memory (IdSet) The intersection of a set
func (*IdSet) SortHashList ¶ added in v0.10.1
Value must be ensured
type LazySet ¶
type LazySet struct {
// contains filtered or unexported fields
}
A collection that tries to imitate "lazy" operations
func (*LazySet) Intersection ¶
A collection consisting of all elements belonging to set self and other.
type MainChain ¶
type MainChain struct {
// contains filtered or unexported fields
}
The main chain of DAG is support incremental expansion
type Phantom ¶
type Phantom struct {
// contains filtered or unexported fields
}
func (*Phantom) CheckMainChainDB ¶ added in v0.10.1
func (*Phantom) GetDiffAnticone ¶
func (*Phantom) GetDiffBlueSet ¶
func (*Phantom) GetMainChainTip ¶
return the tip of main chain
func (*Phantom) GetMainChainTipId ¶ added in v0.10.1
func (*Phantom) GetMainParent ¶
return the main parent in the parents
func (*Phantom) GetMainParentConcurrency ¶ added in v0.10.1
The main parent concurrency of block
func (*Phantom) GetTipsList ¶
If the successor return nil, the underlying layer will use the default tips list.
func (*Phantom) IsOnMainChain ¶
Query whether a given block is on the main chain.
func (*Phantom) UpdateVirtualBlockOrder ¶
func (ph *Phantom) UpdateVirtualBlockOrder() *PhantomBlock
func (*Phantom) UpdateWeight ¶ added in v0.10.1
type PhantomBlock ¶
type PhantomBlock struct { *Block // contains filtered or unexported fields }
func (*PhantomBlock) GetBlueDiffAnticone ¶ added in v0.10.1
func (pb *PhantomBlock) GetBlueDiffAnticone() *IdSet
func (*PhantomBlock) GetRedDiffAnticone ¶ added in v0.10.1
func (pb *PhantomBlock) GetRedDiffAnticone() *IdSet
func (*PhantomBlock) IsBluer ¶
func (pb *PhantomBlock) IsBluer(other *PhantomBlock) bool
type Phantom_v2 ¶
type Phantom_v2 struct {
// contains filtered or unexported fields
}
func (*Phantom_v2) CreateBlock ¶
func (ph *Phantom_v2) CreateBlock(b *Block) IBlock
Build self block
func (*Phantom_v2) GetBlues ¶ added in v0.10.1
func (ph *Phantom_v2) GetBlues(parents *IdSet) uint
GetBlues
func (*Phantom_v2) GetMainChainTip ¶
func (ph *Phantom_v2) GetMainChainTip() IBlock
return the tip of main chain
func (*Phantom_v2) GetMainChainTipId ¶ added in v0.10.1
func (ph *Phantom_v2) GetMainChainTipId() uint
return the tip of main chain id
func (*Phantom_v2) GetMainParent ¶
func (ph *Phantom_v2) GetMainParent(parents *IdSet) IBlock
return the main parent in the parents
func (*Phantom_v2) GetMainParentConcurrency ¶ added in v0.10.1
func (ph *Phantom_v2) GetMainParentConcurrency(b IBlock) int
The main parent concurrency of block
func (*Phantom_v2) GetName ¶
func (ph *Phantom_v2) GetName() string
func (*Phantom_v2) GetTipsList ¶
func (ph *Phantom_v2) GetTipsList() []IBlock
If the successor return nil, the underlying layer will use the default tips list.
func (*Phantom_v2) Init ¶
func (ph *Phantom_v2) Init(bd *BlockDAG) bool
func (*Phantom_v2) IsOnMainChain ¶
func (ph *Phantom_v2) IsOnMainChain(b IBlock) bool
Query whether a given block is on the main chain.
type Spectre ¶
type Spectre struct {
// contains filtered or unexported fields
}
func (*Spectre) GetMainChainTip ¶
return the tip of main chain
func (*Spectre) GetMainChainTipId ¶ added in v0.10.1
func (*Spectre) GetMainParent ¶
return the main parent in the parents
func (*Spectre) GetMainParentConcurrency ¶ added in v0.10.1
The main parent concurrency of block
func (*Spectre) GetTipsList ¶
func (*Spectre) IsInPastOf ¶
TODO: test if there is ancestor-descendant relationship between b1 and b2
func (*Spectre) IsOnMainChain ¶
Currently not supported
func (*Spectre) VoteByBlock ¶
If virtual block is nil, it is like an imaginary recent coming node which references all the tips and the whole graph is its past set, otherwise it means that some real block is the virtual block of its own past set
type SpectreBlock ¶
type SpectreBlock struct {
Votes1, Votes2 int // votes in future set, -1 means not voted yet
// contains filtered or unexported fields
}
func (*SpectreBlock) GetHash ¶
func (sb *SpectreBlock) GetHash() *hash.Hash
type SpectreBlockData ¶
type SpectreBlockData struct {
// contains filtered or unexported fields
}
func (*SpectreBlockData) GetHash ¶
func (sd *SpectreBlockData) GetHash() *hash.Hash
func (*SpectreBlockData) GetParents ¶
func (sd *SpectreBlockData) GetParents() []*hash.Hash
func (*SpectreBlockData) GetTimestamp ¶
func (sd *SpectreBlockData) GetTimestamp() int64
func (*SpectreBlockData) GetWeight ¶
func (sd *SpectreBlockData) GetWeight() uint64
Acquire the weight of block