meerdag

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: ISC Imports: 43 Imported by: 0

Documentation

Overview

Package dbnamespace contains constants that define the database namespaces for the purpose of the blockdag, so that external callers may easily access this data.

Index

Constants

View Source
const (
	VMK_KEY = 1
	RET_KEY = 2
)
View Source
const (
	DAGErrorEmpty = "empty"
)
View Source
const (

	// GHOSTDAG is an greedy algorithm implementation based on PHANTOM protocol
	GHOSTDAG = "ghostdag"
)

Some available DAG algorithm types

View Source
const GenesisId = uint(0)

Genesis id of the DAG block

View Source
const MaxBlockOrder = uint(^uint32(0))

Maximum order of the DAG block

View Source
const MaxId = uint(math.MaxUint32)

Maximum id of the DAG block

View Source
const MaxMainLocatorNum = 32

This parameter can be set according to the size of TCP package(1500) to ensure the transmission stability of the network

View Source
const MaxPriority = int(math.MaxInt32)

Max Priority

View Source
const MaxTipLayerGap = 10

MaxTipLayerGap

View Source
const MaxTips = 100

Maximum number of the DAG tip

View Source
const MinBlockDataCache = 2000

block data

View Source
const MinBlockPruneSize = 2000
View Source
const StableConfirmations = 10

StableConfirmations

Variables

View Source
var (
	// ByteOrder is the preferred byte order used for serializing numeric
	// fields for storage in the database.
	ByteOrder = binary.LittleEndian

	// BlockIndexBucketName is the name of the db bucket used to house the
	// block which consists of metadata for all known blocks in DAG.
	BlockIndexBucketName = []byte("blockidx")

	// DagInfoBucketName is the name of the db bucket used to house the
	// dag information
	DagInfoBucketName = []byte("daginfo")

	// DAG Main Chain Blocks
	DagMainChainBucketName = []byte("dagmainchain")

	// OrderIdBucketName is the name of the db bucket used to house to
	// the block order -> block DAG Id.
	OrderIdBucketName = []byte("orderid")

	// BlockIdBucketName is the name of the db bucket used to house to
	// the block hash -> block DAG Id.
	BlockIdBucketName = []byte("blockid")

	// DAGTipsBucketName is the name of the db bucket used to house to
	// the block id -> is main chain
	DAGTipsBucketName = []byte("dagtips")

	// DiffAnticoneBucketName is the name of the db bucket used to house to
	// the block id
	DiffAnticoneBucketName = []byte("diffanticone")
)
View Source
var (
	BlockRate = anticone.DefaultBlockRate
)

Functions

func DBDelBlockIdByHash

func DBDelBlockIdByHash(dbTx database.Tx, h *hash.Hash) error

func DBDelDAGBlock

func DBDelDAGBlock(dbTx database.Tx, id uint) error

func DBDelDAGTip

func DBDelDAGTip(dbTx database.Tx, id uint) error

func DBDelDiffAnticone added in v1.0.18

func DBDelDiffAnticone(dbTx database.Tx, id uint) error

func DBGetBlockIdByHash

func DBGetBlockIdByHash(dbTx database.Tx, h *hash.Hash) (uint32, error)

func DBGetBlockIdByOrder

func DBGetBlockIdByOrder(dbTx database.Tx, order uint) (uint32, error)

func DBGetDAGBlock

func DBGetDAGBlock(dbTx database.Tx, block IBlock) error

DBGetDAGBlock get dag block data by resouce ID

func DBGetDAGBlockHashByID added in v1.0.19

func DBGetDAGBlockHashByID(dbTx database.Tx, id uint64) (*hash.Hash, error)

func DBGetDAGTips

func DBGetDAGTips(dbTx database.Tx) ([]uint, error)

func DBGetDiffAnticone added in v1.0.18

func DBGetDiffAnticone(dbTx database.Tx) ([]uint, error)

func DBHasMainChainBlock

func DBHasMainChainBlock(dbTx database.Tx, id uint) bool

func DBPutBlockIdByOrder

func DBPutBlockIdByOrder(dbTx database.Tx, order uint, id uint) error

func DBPutDAGBlock

func DBPutDAGBlock(dbTx database.Tx, block IBlock) error

DBPutDAGBlock stores the information needed to reconstruct the provided block in the block index according to the format described above.

func DBPutDAGBlockIdByHash

func DBPutDAGBlockIdByHash(dbTx database.Tx, block IBlock) error

func DBPutDAGInfo

func DBPutDAGInfo(dbTx database.Tx, bd *MeerDAG) error

func DBPutDAGTip

func DBPutDAGTip(dbTx database.Tx, id uint, isMain bool) error

tips

func DBPutDiffAnticone added in v1.0.18

func DBPutDiffAnticone(dbTx database.Tx, id uint) error

diffAnticone

func DBPutMainChainBlock

func DBPutMainChainBlock(dbTx database.Tx, id uint) error

func DBRemoveMainChainBlock

func DBRemoveMainChainBlock(dbTx database.Tx, id uint) error

func GetDAGTypeByIndex

func GetDAGTypeByIndex(dagType byte) string

func GetDAGTypeIndex

func GetDAGTypeIndex(dagType string) byte

func GetMaxLenHashSet

func GetMaxLenHashSet(bsm map[hash.Hash]*HashSet) *hash.Hash

func GetOrderLogStr

func GetOrderLogStr(order uint) string

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.

func NewDAGError

func NewDAGError(e error) error

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

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) AddChild

func (b *Block) AddChild(child IBlock)

Add child nodes to block

func (*Block) AddParent added in v1.0.18

func (b *Block) AddParent(parent IBlock)

func (*Block) AttachChild added in v1.0.18

func (b *Block) AttachChild(ib IBlock)

func (*Block) AttachParent added in v1.0.18

func (b *Block) AttachParent(ib IBlock)

func (*Block) Bytes added in v1.0.21

func (b *Block) Bytes() []byte

func (*Block) Decode

func (b *Block) Decode(r io.Reader) error

decode

func (*Block) DetachChild added in v1.0.18

func (b *Block) DetachChild(ib IBlock)

func (*Block) DetachParent added in v1.0.18

func (b *Block) DetachParent(ib IBlock)

func (*Block) Encode

func (b *Block) Encode(w io.Writer) error

encode

func (*Block) GetChildren

func (b *Block) GetChildren() *IdSet

Get all the children of block

func (*Block) GetData

func (b *Block) GetData() IBlockData

func (*Block) GetHash

func (b *Block) GetHash() *hash.Hash

Return the hash of block. It will be a pointer.

func (*Block) GetHeight

func (b *Block) GetHeight() uint

Acquire the height of block in main chain

func (*Block) GetID

func (b *Block) GetID() uint

Return block ID

func (*Block) GetLayer

func (b *Block) GetLayer() uint

Acquire the layer of block

func (*Block) GetMainParent

func (b *Block) GetMainParent() uint

func (*Block) GetOrder

func (b *Block) GetOrder() uint

Acquire the order of block

func (*Block) GetParents

func (b *Block) GetParents() *IdSet

Get all parents set,the dag block has more than one parent

func (*Block) GetState added in v1.0.21

func (b *Block) GetState() model.BlockState

GetState

func (*Block) HasChildren

func (b *Block) HasChildren() bool

Detecting the presence of child nodes

func (*Block) HasParents

func (b *Block) HasParents() bool

Testing whether it has parents

func (*Block) IsLoaded added in v1.0.18

func (b *Block) IsLoaded() bool

func (*Block) IsOrdered

func (b *Block) IsOrdered() bool

IsOrdered

func (*Block) RemoveChild

func (b *Block) RemoveChild(child uint)

func (*Block) RemoveParent added in v1.0.18

func (b *Block) RemoveParent(id uint)

func (*Block) SetData added in v1.0.18

func (b *Block) SetData(data IBlockData)

func (*Block) SetHeight

func (b *Block) SetHeight(h uint)

Setting the height of block in main chain

func (*Block) SetID

func (b *Block) SetID(id uint)

func (*Block) SetLayer

func (b *Block) SetLayer(layer uint)

Setting the layer of block

func (*Block) SetOrder

func (b *Block) SetOrder(o uint)

Setting the order of block

type BlockHashSlice

type BlockHashSlice []IBlock

BlockSlice is used to sort dag block Just for inside

func (BlockHashSlice) Len

func (bn BlockHashSlice) Len() int

func (BlockHashSlice) Less

func (bn BlockHashSlice) Less(i, j int) bool

func (BlockHashSlice) Swap

func (bn BlockHashSlice) Swap(i, j int)

type BlockHeightSlice

type BlockHeightSlice []IBlock

func (BlockHeightSlice) Len

func (bs BlockHeightSlice) Len() int

func (BlockHeightSlice) Less

func (bs BlockHeightSlice) Less(i, j int) bool

func (BlockHeightSlice) Swap

func (bs BlockHeightSlice) Swap(i, j int)

type BlockOrderHelp

type BlockOrderHelp struct {
	OldOrder uint
	Block    IBlock
}

BlockOrderHelp is used to help reorganize block order

type BlockOrderSlice

type BlockOrderSlice []IBlock

BlockOrderSlice is used to sort dag block by order

func (BlockOrderSlice) Len

func (bs BlockOrderSlice) Len() int

func (BlockOrderSlice) Less

func (bs BlockOrderSlice) Less(i, j int) bool

func (BlockOrderSlice) Swap

func (bs BlockOrderSlice) Swap(i, j int)

type BlockPrioritySlice

type BlockPrioritySlice []IBlock

BlockPrioritySlice is used to sort dag block Just for inside

func (BlockPrioritySlice) Len

func (bn BlockPrioritySlice) Len() int

func (BlockPrioritySlice) Less

func (bn BlockPrioritySlice) Less(i, j int) bool

func (BlockPrioritySlice) Swap

func (bn BlockPrioritySlice) 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 BlueInfo

type BlueInfo struct {
	// contains filtered or unexported fields
}

func NewBlueInfo

func NewBlueInfo(num uint, rate int64, weight int64, height int64) *BlueInfo

func (*BlueInfo) GetHeight

func (bi *BlueInfo) GetHeight() int64

func (*BlueInfo) GetNum

func (bi *BlueInfo) GetNum() uint

func (*BlueInfo) GetRate

func (bi *BlueInfo) GetRate() int64

func (*BlueInfo) GetWeight

func (bi *BlueInfo) GetWeight() int64

func (*BlueInfo) String

func (bi *BlueInfo) String() string

type CalcWeight

type CalcWeight func(ib IBlock, bi *BlueInfo) int64

CalcWeight

type Conflux

type Conflux struct {
	// contains filtered or unexported fields
}

func (*Conflux) AddBlock

func (con *Conflux) AddBlock(b IBlock) (*list.List, *list.List)

func (*Conflux) CreateBlock

func (con *Conflux) CreateBlock(b *Block) IBlock

Build self block

func (*Conflux) Decode

func (con *Conflux) Decode(r io.Reader) error

decode

func (*Conflux) Encode

func (con *Conflux) Encode(w io.Writer) error

encode

func (*Conflux) GetBlues

func (con *Conflux) GetBlues(parents *IdSet) uint

GetBlues

func (*Conflux) GetMainChain

func (con *Conflux) GetMainChain() []uint

func (*Conflux) GetMainChainTip

func (con *Conflux) GetMainChainTip() IBlock

return the tip of main chain

func (*Conflux) GetMainChainTipId

func (con *Conflux) GetMainChainTipId() uint

return the tip of main chain id

func (*Conflux) GetMainParent

func (con *Conflux) GetMainParent(parents *IdSet) IBlock

return the main parent in the parents

func (*Conflux) GetMainParentConcurrency

func (con *Conflux) GetMainParentConcurrency(b IBlock) int

The main parent concurrency of block

func (*Conflux) GetName

func (con *Conflux) GetName() string

func (*Conflux) GetTipsList

func (con *Conflux) GetTipsList() []IBlock

func (*Conflux) Init

func (con *Conflux) Init(bd *MeerDAG) bool

func (*Conflux) IsBlue

func (con *Conflux) IsBlue(id uint) bool

IsBlue

func (*Conflux) IsDAG

func (con *Conflux) IsDAG(parents []IBlock) bool

IsDAG

func (*Conflux) Load

func (con *Conflux) Load() error

type ConsensusAlgorithm

type ConsensusAlgorithm interface {
	// Return the name
	GetName() string

	// This instance is initialized and will be executed first.
	Init(bd *MeerDAG) 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

	// 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() 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 consensus algorithm

func NewBlockDAG

func NewBlockDAG(dagType string) ConsensusAlgorithm

It will create different BlockDAG instances

type CreateBlockState added in v1.0.21

type CreateBlockState func(id uint64) model.BlockState

type CreateBlockStateFromBytes added in v1.0.21

type CreateBlockStateFromBytes func(data []byte) (model.BlockState, error)

type DAGError

type DAGError struct {
	// contains filtered or unexported fields
}

func (*DAGError) Error

func (e *DAGError) Error() string

func (*DAGError) IsEmpty

func (e *DAGError) IsEmpty() bool

type DAGSnapshot

type DAGSnapshot struct {
	// contains filtered or unexported fields
}

func NewDAGSnapshot

func NewDAGSnapshot() *DAGSnapshot

func (*DAGSnapshot) AddOrder

func (d *DAGSnapshot) AddOrder(ib IBlock)

func (*DAGSnapshot) Clean

func (d *DAGSnapshot) Clean()

func (*DAGSnapshot) IsValid

func (d *DAGSnapshot) IsValid() bool

type DAGSync

type DAGSync struct {
	// contains filtered or unexported fields
}

func NewDAGSync

func NewDAGSync(bd *MeerDAG) *DAGSync

NewDAGSync

func (*DAGSync) CalcSyncBlocks

func (ds *DAGSync) CalcSyncBlocks(gs *GraphState, locator []*hash.Hash, mode SyncMode, maxHashes uint) ([]*hash.Hash, *hash.Hash)

CalcSyncBlocks

func (*DAGSync) GetMainLocator

func (ds *DAGSync) GetMainLocator(point *hash.Hash) []*hash.Hash

GetMainLocator

func (*DAGSync) SetGraphState

func (ds *DAGSync) SetGraphState(gs *GraphState)

type Empty

type Empty struct{}

This struct is empty

type Epoch

type Epoch struct {
	// contains filtered or unexported fields
}

func (*Epoch) GetSequence

func (e *Epoch) GetSequence() []IBlock

func (*Epoch) HasBlock

func (e *Epoch) HasBlock(h *hash.Hash) bool

func (*Epoch) HasDepends

func (e *Epoch) HasDepends() bool

type GetBlockData

type GetBlockData func(*hash.Hash) IBlockData

type GhostDAG added in v1.0.18

type GhostDAG struct {
	// contains filtered or unexported fields
}

func (*GhostDAG) AddBlock added in v1.0.18

func (gd *GhostDAG) AddBlock(ib IBlock) (*list.List, *list.List)

Add a block

func (*GhostDAG) BlockHeader added in v1.0.18

func (gd *GhostDAG) BlockHeader(dbContext model.DBReader, stagingArea *cmodel.StagingArea, blockHash *hash.Hash) (model.BlockHeader, error)

--------------- implementation

func (*GhostDAG) BlockHeaders added in v1.0.18

func (gd *GhostDAG) BlockHeaders(dbContext model.DBReader, stagingArea *cmodel.StagingArea, blockHashes []*hash.Hash) ([]model.BlockHeader, error)

func (*GhostDAG) ChildInSelectedParentChainOf added in v1.0.18

func (gd *GhostDAG) ChildInSelectedParentChainOf(stagingArea *cmodel.StagingArea, lowHash, highHash *hash.Hash) (*hash.Hash, error)

func (*GhostDAG) Children added in v1.0.18

func (gd *GhostDAG) Children(stagingArea *cmodel.StagingArea, blockHash *hash.Hash) ([]*hash.Hash, error)

func (*GhostDAG) Count added in v1.0.18

func (gd *GhostDAG) Count(stagingArea *cmodel.StagingArea) uint64

func (*GhostDAG) CreateBlock added in v1.0.18

func (gd *GhostDAG) CreateBlock(b *Block) IBlock

Build self block

func (*GhostDAG) Decode added in v1.0.18

func (gd *GhostDAG) Decode(r io.Reader) error

decode

func (*GhostDAG) Delete added in v1.0.18

func (gd *GhostDAG) Delete(stagingArea *cmodel.StagingArea, blockHash *hash.Hash)

func (*GhostDAG) Encode added in v1.0.18

func (gd *GhostDAG) Encode(w io.Writer) error

encode

func (*GhostDAG) Get added in v1.0.18

func (gd *GhostDAG) Get(dbContext model.DBReader, stagingArea *cmodel.StagingArea, blockHash *hash.Hash, isTrustedData bool) (*model.BlockGHOSTDAGData, error)

func (*GhostDAG) GetBlueSet added in v1.0.18

func (gd *GhostDAG) GetBlueSet() *IdSet

func (*GhostDAG) GetBlues added in v1.0.18

func (gd *GhostDAG) GetBlues(parents *IdSet) uint

func (*GhostDAG) GetMainChainTip added in v1.0.18

func (gd *GhostDAG) GetMainChainTip() IBlock

return the tip of main chain

func (*GhostDAG) GetMainChainTipId added in v1.0.18

func (gd *GhostDAG) GetMainChainTipId() uint

func (*GhostDAG) GetMainParent added in v1.0.18

func (gd *GhostDAG) GetMainParent(parents *IdSet) IBlock

return the main parent in the parents

func (*GhostDAG) GetMainParentConcurrency added in v1.0.18

func (gd *GhostDAG) GetMainParentConcurrency(b IBlock) int

The main parent concurrency of block

func (*GhostDAG) GetName added in v1.0.18

func (gd *GhostDAG) GetName() string

func (*GhostDAG) GetTipsList added in v1.0.18

func (gd *GhostDAG) GetTipsList() []IBlock

If the successor return nil, the underlying layer will use the default tips list.

func (*GhostDAG) HasBlockHeader added in v1.0.18

func (gd *GhostDAG) HasBlockHeader(dbContext model.DBReader, stagingArea *cmodel.StagingArea, blockHash *hash.Hash) (bool, error)

func (*GhostDAG) Init added in v1.0.18

func (gd *GhostDAG) Init(bd *MeerDAG) bool

func (*GhostDAG) IsAncestorOf added in v1.0.18

func (gd *GhostDAG) IsAncestorOf(stagingArea *cmodel.StagingArea, blockHashA *hash.Hash, blockHashB *hash.Hash) (bool, error)

func (*GhostDAG) IsAncestorOfAny added in v1.0.18

func (gd *GhostDAG) IsAncestorOfAny(stagingArea *cmodel.StagingArea, blockHash *hash.Hash, potentialDescendants []*hash.Hash) (bool, error)

func (*GhostDAG) IsAnyAncestorOf added in v1.0.18

func (gd *GhostDAG) IsAnyAncestorOf(stagingArea *cmodel.StagingArea, potentialAncestors []*hash.Hash, blockHash *hash.Hash) (bool, error)

func (*GhostDAG) IsBlue added in v1.0.18

func (gd *GhostDAG) IsBlue(id uint) bool

func (*GhostDAG) IsChildOf added in v1.0.18

func (gd *GhostDAG) IsChildOf(stagingArea *cmodel.StagingArea, blockHashA *hash.Hash, blockHashB *hash.Hash) (bool, error)

func (*GhostDAG) IsDAG added in v1.0.18

func (gd *GhostDAG) IsDAG(parents []IBlock) bool

IsDAG

func (*GhostDAG) IsInSelectedParentChainOf added in v1.0.18

func (gd *GhostDAG) IsInSelectedParentChainOf(stagingArea *cmodel.StagingArea, blockHashA *hash.Hash, blockHashB *hash.Hash) (bool, error)

func (*GhostDAG) IsParentOf added in v1.0.18

func (gd *GhostDAG) IsParentOf(stagingArea *cmodel.StagingArea, blockHashA *hash.Hash, blockHashB *hash.Hash) (bool, error)

func (*GhostDAG) IsStaged added in v1.0.18

func (gd *GhostDAG) IsStaged(stagingArea *cmodel.StagingArea) bool

func (*GhostDAG) Load added in v1.0.18

func (gd *GhostDAG) Load() error

load

func (*GhostDAG) Parents added in v1.0.18

func (gd *GhostDAG) Parents(stagingArea *cmodel.StagingArea, blockHash *hash.Hash) ([]*hash.Hash, error)

func (*GhostDAG) SetParents added in v1.0.18

func (gd *GhostDAG) SetParents(stagingArea *cmodel.StagingArea, blockHash *hash.Hash, parentHashes []*hash.Hash) error

func (*GhostDAG) Stage added in v1.0.18

func (gd *GhostDAG) Stage(stagingArea *cmodel.StagingArea, blockHash *hash.Hash, blockGHOSTDAGData *model.BlockGHOSTDAGData, isTrustedData bool)

func (*GhostDAG) UnstageAll added in v1.0.18

func (gd *GhostDAG) UnstageAll(stagingArea *cmodel.StagingArea)

func (*GhostDAG) UpdateOrders added in v1.0.18

func (gd *GhostDAG) UpdateOrders() error

It is only used to simulate the tags of all sequences, and the algorithm itself is very inefficient

type GraphState

type GraphState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A general description of the whole state of DAG

func NewGraphState

func NewGraphState() *GraphState

Create a new GraphState

func (*GraphState) Clone

func (gs *GraphState) Clone() *GraphState

Copy self and return

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) Equal

func (gs *GraphState) Equal(other *GraphState)

Setting vaules from other

func (*GraphState) GetLayer

func (gs *GraphState) GetLayer() uint

Return the DAG layer

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) GetTips

func (gs *GraphState) GetTips() *HashSet

func (*GraphState) GetTipsList

func (gs *GraphState) GetTipsList() []*hash.Hash

Return all tips of DAG

func (*GraphState) GetTotal

func (gs *GraphState) GetTotal() uint

Return the total of DAG

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

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 []*hash.Hash)

func (*GraphState) SetTotal

func (gs *GraphState) SetTotal(total uint)

func (*GraphState) String

func (gs *GraphState) String() string

Return one string contain info

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 NewHashSet

func NewHashSet() *HashSet

Create a new HashSet

func (*HashSet) Add

func (s *HashSet) Add(elem *hash.Hash)

Add the key of element

func (*HashSet) AddList

func (s *HashSet) AddList(list []*hash.Hash)

func (*HashSet) AddPair

func (s *HashSet) AddPair(elem *hash.Hash, data interface{})

Add one pair of data

func (*HashSet) AddSet

func (s *HashSet) AddSet(other *HashSet)

Add elements from set

func (*HashSet) Clean

func (s *HashSet) Clean()

func (*HashSet) Clone

func (s *HashSet) Clone() *HashSet

return a new copy

func (*HashSet) Contain

func (s *HashSet) Contain(other *HashSet) bool

func (*HashSet) Exclude

func (s *HashSet) Exclude(other *HashSet)

func (*HashSet) Get

func (s *HashSet) Get(elem *hash.Hash) interface{}

func (*HashSet) GetMap

func (s *HashSet) GetMap() map[hash.Hash]interface{}

Return the map

func (*HashSet) Has

func (s *HashSet) Has(elem *hash.Hash) bool

func (*HashSet) HasOnly

func (s *HashSet) HasOnly(elem *hash.Hash) bool

func (*HashSet) Intersection

func (s *HashSet) Intersection(other *HashSet) *HashSet

This function returns a new open memory (HashSet) The intersection of a set

func (*HashSet) IsEmpty

func (s *HashSet) IsEmpty() bool

func (*HashSet) IsEqual

func (s *HashSet) IsEqual(other *HashSet) bool

func (*HashSet) List

func (s *HashSet) List() []*hash.Hash

func (*HashSet) Remove

func (s *HashSet) Remove(elem *hash.Hash)

Remove the element

func (*HashSet) RemoveSet

func (s *HashSet) RemoveSet(other *HashSet)

func (*HashSet) Size

func (s *HashSet) Size() int

func (*HashSet) SortList

func (s *HashSet) SortList(reverse bool) []*hash.Hash

func (*HashSet) Union

func (s *HashSet) Union(other *HashSet) *HashSet

return union of a set

type HashSlice

type HashSlice []*hash.Hash

HashSlice is used to sort hash list

func (HashSlice) Has

func (sh HashSlice) Has(h *hash.Hash) bool

func (HashSlice) Len

func (sh HashSlice) Len() int

func (HashSlice) Less

func (sh HashSlice) Less(i, j int) bool

func (HashSlice) Swap

func (sh HashSlice) Swap(i, j int)

type IBlock

type IBlock interface {
	// Return block ID
	GetID() uint

	// Return the hash of block. It will be a pointer.
	GetHash() *hash.Hash

	AddParent(parent IBlock)

	// 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

	// Acquire the layer of block
	GetLayer() uint

	// Acquire the height of block in main chain
	GetHeight() uint

	// encode
	Encode(w io.Writer) error

	// decode
	Decode(r io.Reader) error

	// block data
	GetData() IBlockData
	SetData(data IBlockData)
	IsLoaded() bool

	AttachParent(ib IBlock)
	DetachParent(ib IBlock)

	AttachChild(ib IBlock)
	DetachChild(ib IBlock)

	// GetState
	GetState() model.BlockState

	// TODO:
	Bytes() []byte

	// Setting the order of block
	SetOrder(o uint)

	// Acquire the order of block
	GetOrder() uint

	// IsOrdered
	IsOrdered() bool
}

The interface of block

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

	GetMainParent() *hash.Hash

	// Timestamp
	GetTimestamp() int64

	// Priority
	GetPriority() int
}

The abstract inferface is used to dag block

type ISpectre

type ISpectre interface {
	Vote(x IBlock, y IBlock) int
}

type IdSet

type IdSet struct {
	// contains filtered or unexported fields
}

On the Set of hash, and the saved data can be of any type

func NewIdSet

func NewIdSet() *IdSet

Create a new IdSet

func (*IdSet) Add

func (s *IdSet) Add(elem uint)

Add the key of element

func (*IdSet) AddList

func (s *IdSet) AddList(list []uint)

func (*IdSet) AddPair

func (s *IdSet) AddPair(elem uint, data interface{})

Add one pair of data

func (*IdSet) AddSet

func (s *IdSet) AddSet(other *IdSet)

Add elements from set

func (*IdSet) Clean

func (s *IdSet) Clean()

func (*IdSet) Clone

func (s *IdSet) Clone() *IdSet

return a new copy

func (*IdSet) Contain

func (s *IdSet) Contain(other *IdSet) bool

func (*IdSet) Exclude

func (s *IdSet) Exclude(other *IdSet)

func (*IdSet) Get

func (s *IdSet) Get(elem uint) interface{}

func (*IdSet) GetMap

func (s *IdSet) GetMap() map[uint]interface{}

Return the map

func (*IdSet) Has

func (s *IdSet) Has(elem uint) bool

func (*IdSet) HasOnly

func (s *IdSet) HasOnly(elem uint) bool

func (*IdSet) Intersection

func (s *IdSet) Intersection(other *IdSet) *IdSet

This function returns a new open memory (IdSet) The intersection of a set

func (*IdSet) IsDataEmpty added in v1.0.18

func (s *IdSet) IsDataEmpty(elem uint) bool

func (*IdSet) IsEmpty

func (s *IdSet) IsEmpty() bool

func (*IdSet) IsEqual

func (s *IdSet) IsEqual(other *IdSet) bool

func (*IdSet) List

func (s *IdSet) List() []uint

func (*IdSet) Remove

func (s *IdSet) Remove(elem uint)

Remove the element

func (*IdSet) RemoveSet

func (s *IdSet) RemoveSet(other *IdSet)

func (*IdSet) Size

func (s *IdSet) Size() int

func (*IdSet) SortHashList

func (s *IdSet) SortHashList(reverse bool) []uint

Value must be ensured

func (*IdSet) SortHeightList

func (s *IdSet) SortHeightList(reverse bool) []uint

func (*IdSet) SortList

func (s *IdSet) SortList(reverse bool) []uint

func (*IdSet) SortPriorityList

func (s *IdSet) SortPriorityList(reverse bool) []uint

func (*IdSet) Union

func (s *IdSet) Union(other *IdSet) *IdSet

return union of a set

type IdSlice

type IdSlice []uint

IdSlice is used to sort id list

func (IdSlice) Has

func (sh IdSlice) Has(id uint) bool

func (IdSlice) Len

func (sh IdSlice) Len() int

func (IdSlice) Less

func (sh IdSlice) Less(i, j int) bool

func (IdSlice) Swap

func (sh IdSlice) Swap(i, j int)

type KChain

type KChain struct {
	// contains filtered or unexported fields
}

type LazySet

type LazySet struct {
	// contains filtered or unexported fields
}

A collection that tries to imitate "lazy" operations

func NewLazySet

func NewLazySet() *LazySet

Create a new LazySet

func (*LazySet) Add

func (ls *LazySet) Add(elem *hash.Hash)

func (*LazySet) Clear

func (ls *LazySet) Clear()

func (*LazySet) Clone

func (ls *LazySet) Clone() *LazySet

Return a new copy

func (*LazySet) Intersection

func (ls *LazySet) Intersection(other *HashSet) *LazySet

A collection consisting of all elements belonging to set self and other.

func (*LazySet) Remove

func (ls *LazySet) Remove(elem *hash.Hash)

func (*LazySet) Union

func (ls *LazySet) Union(other *HashSet) *LazySet

The set is composed of all self and other elements.

type MainChain

type MainChain struct {
	// contains filtered or unexported fields
}

The main chain of DAG is support incremental expansion

func (*MainChain) Add

func (mc *MainChain) Add(id uint) error

func (*MainChain) Has

func (mc *MainChain) Has(id uint) bool

func (*MainChain) Remove

func (mc *MainChain) Remove(id uint) error

type MeerDAG

type MeerDAG struct {
	service.Service
	// contains filtered or unexported fields
}

The general foundation framework of Block DAG implement

func New added in v1.0.18

func New(dagType string, calcWeight CalcWeight, blockRate float64, db database.DB, getBlockData GetBlockData, createBS CreateBlockState, createBSB CreateBlockStateFromBytes) *MeerDAG

func (*MeerDAG) AddBlock

func (bd *MeerDAG) AddBlock(b IBlockData) (*list.List, *list.List, IBlock, bool)

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 (*MeerDAG) AddToCommit added in v1.0.21

func (bd *MeerDAG) AddToCommit(block IBlock)

func (*MeerDAG) BuildMerkleTreeStoreFromTips

func (bd *MeerDAG) BuildMerkleTreeStoreFromTips() []*hash.Hash

build merkle tree form current DAG tips

func (*MeerDAG) CheckBlueAndMature

func (bd *MeerDAG) CheckBlueAndMature(targets []uint, views []uint, max uint) error

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 (*MeerDAG) CheckBlueAndMatureMT

func (bd *MeerDAG) CheckBlueAndMatureMT(targets []uint, views []uint, max uint) error

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 (*MeerDAG) CheckMainBlueAndMature

func (bd *MeerDAG) CheckMainBlueAndMature(target IBlock, targetMainFork IBlock, max uint) (bool, IBlock)

processMaturity

func (*MeerDAG) CheckSubMainChainTip

func (bd *MeerDAG) CheckSubMainChainTip(parents []*hash.Hash) error

Checking the sub main chain for the parents of tip

func (*MeerDAG) Commit

func (bd *MeerDAG) Commit() error

Commit the consensus content to the database for persistence

func (*MeerDAG) CreateVirtualBlock

func (bd *MeerDAG) CreateVirtualBlock(data IBlockData) IBlock

Just for custom Virtual block

func (*MeerDAG) Decode

func (bd *MeerDAG) Decode(r io.Reader) error

decode

func (*MeerDAG) Encode

func (bd *MeerDAG) Encode(w io.Writer) error

func (*MeerDAG) GetBlock

func (bd *MeerDAG) GetBlock(h *hash.Hash) IBlock

Acquire one block by hash

func (*MeerDAG) GetBlockById

func (bd *MeerDAG) GetBlockById(id uint) IBlock

Acquire one block by hash

func (*MeerDAG) GetBlockByOrder

func (bd *MeerDAG) GetBlockByOrder(order uint) IBlock

func (*MeerDAG) GetBlockCacheSize added in v1.0.18

func (bd *MeerDAG) GetBlockCacheSize() uint64

func (*MeerDAG) GetBlockConcurrency

func (bd *MeerDAG) GetBlockConcurrency(h *hash.Hash) (uint, error)

GetBlockConcurrency : Temporarily use blue set of the past blocks as the criterion

func (*MeerDAG) GetBlockData added in v1.0.18

func (bd *MeerDAG) GetBlockData(ib IBlock) IBlockData

func (*MeerDAG) GetBlockDataCacheSize added in v1.0.18

func (bd *MeerDAG) GetBlockDataCacheSize() uint64

func (*MeerDAG) GetBlockHash

func (bd *MeerDAG) GetBlockHash(id uint) *hash.Hash

func (*MeerDAG) GetBlockHashByOrder

func (bd *MeerDAG) GetBlockHashByOrder(order uint) *hash.Hash

Obtain block hash by global order

func (*MeerDAG) GetBlockId

func (bd *MeerDAG) GetBlockId(h *hash.Hash) uint

func (*MeerDAG) GetBlockTotal

func (bd *MeerDAG) GetBlockTotal() uint

Total number of blocks

func (*MeerDAG) GetBlueInfo

func (bd *MeerDAG) GetBlueInfo(ib IBlock) *BlueInfo

func (*MeerDAG) GetBlueInfoByHash

func (bd *MeerDAG) GetBlueInfoByHash(h *hash.Hash) *BlueInfo

func (*MeerDAG) GetBlues

func (bd *MeerDAG) GetBlues(parents *IdSet) uint

GetBlues

func (*MeerDAG) GetBluesByBlock

func (bd *MeerDAG) GetBluesByBlock(ib IBlock) uint

func (*MeerDAG) GetBluesByHash

func (bd *MeerDAG) GetBluesByHash(h *hash.Hash) uint

func (*MeerDAG) GetChildren added in v1.0.18

func (bd *MeerDAG) GetChildren(ib IBlock) *IdSet

func (*MeerDAG) GetConfirmations

func (bd *MeerDAG) GetConfirmations(id uint) uint

GetConfirmations

func (*MeerDAG) GetGenesisHash

func (bd *MeerDAG) GetGenesisHash() *hash.Hash

Acquire the genesis block hash of chain

func (*MeerDAG) GetGraphState

func (bd *MeerDAG) GetGraphState() *GraphState

Return current general description of the whole state of DAG

func (*MeerDAG) GetIdSet

func (bd *MeerDAG) GetIdSet(hs []*hash.Hash) *IdSet

GetIdSet

func (*MeerDAG) GetInstance

func (bd *MeerDAG) GetInstance() ConsensusAlgorithm

GetInstance

func (*MeerDAG) GetLastBlock

func (bd *MeerDAG) GetLastBlock() IBlock

Return the last order block

func (*MeerDAG) GetLastTime

func (bd *MeerDAG) GetLastTime() *time.Time

The last time is when add one block to DAG.

func (*MeerDAG) GetLayer

func (bd *MeerDAG) GetLayer(id uint) uint

Return the layer of block,it is stable. You can imagine that this is the main chain.

func (*MeerDAG) GetMainAncestor

func (bd *MeerDAG) GetMainAncestor(block IBlock, height int64) IBlock

func (*MeerDAG) GetMainChainTip

func (bd *MeerDAG) GetMainChainTip() IBlock

return the tip of main chain

func (*MeerDAG) GetMainParent

func (bd *MeerDAG) GetMainParent(parents *IdSet) IBlock

return the main parent in the parents

func (*MeerDAG) GetMainParentAndList

func (bd *MeerDAG) GetMainParentAndList(parents []*hash.Hash) (IBlock, []*hash.Hash)

func (*MeerDAG) GetMainParentByHashs

func (bd *MeerDAG) GetMainParentByHashs(parents []*hash.Hash) IBlock

return the main parent in the parents

func (*MeerDAG) GetMainParentConcurrency

func (bd *MeerDAG) GetMainParentConcurrency(b IBlock) int

The main parent concurrency of block

func (*MeerDAG) GetMaturity

func (bd *MeerDAG) GetMaturity(target uint, views []uint) uint

GetMaturity

func (*MeerDAG) GetMinBlockCacheSize added in v1.0.18

func (bd *MeerDAG) GetMinBlockCacheSize() uint64

func (*MeerDAG) GetMinBlockDataCacheSize added in v1.0.18

func (bd *MeerDAG) GetMinBlockDataCacheSize() uint64

func (*MeerDAG) GetName

func (bd *MeerDAG) GetName() string

Acquire the name of DAG instance

func (*MeerDAG) GetParents added in v1.0.18

func (bd *MeerDAG) GetParents(ib IBlock) *IdSet

func (*MeerDAG) GetParentsMaxLayer

func (bd *MeerDAG) GetParentsMaxLayer(parents *IdSet) (uint, bool)

func (*MeerDAG) GetPrevious

func (bd *MeerDAG) GetPrevious(id uint) (uint, error)

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 (*MeerDAG) GetTips

func (bd *MeerDAG) GetTips() *HashSet

return the terminal blocks, because there maybe more than one, so this is a set.

func (*MeerDAG) GetTipsList

func (bd *MeerDAG) GetTipsList() []IBlock

Acquire the tips array of DAG

func (*MeerDAG) GetValidTips

func (bd *MeerDAG) GetValidTips(expectPriority int) []*hash.Hash

func (*MeerDAG) HasBlock

func (bd *MeerDAG) HasBlock(h *hash.Hash) bool

Is there a block in DAG?

func (*MeerDAG) HasBlockById

func (bd *MeerDAG) HasBlockById(id uint) bool

Is there a block in DAG?

func (*MeerDAG) HasLoadedBlock added in v1.0.18

func (bd *MeerDAG) HasLoadedBlock(id uint) bool

func (*MeerDAG) InvalidBlock

func (bd *MeerDAG) InvalidBlock(block IBlock)

func (*MeerDAG) IsBlue

func (bd *MeerDAG) IsBlue(id uint) bool

IsBlue

func (*MeerDAG) IsHourglass

func (bd *MeerDAG) IsHourglass(id uint) bool

func (*MeerDAG) IsOnMainChain

func (bd *MeerDAG) IsOnMainChain(id uint) bool

Query whether a given block is on the main chain. Note that some DAG protocols may not support this feature.

func (*MeerDAG) Load

func (bd *MeerDAG) Load(blockTotal uint, genesis *hash.Hash) error

Load from database

func (*MeerDAG) LoadBlockDataSet added in v1.0.18

func (bd *MeerDAG) LoadBlockDataSet(sets *IdSet)

func (*MeerDAG) RelativeMainAncestor

func (bd *MeerDAG) RelativeMainAncestor(block IBlock, distance int64) IBlock

func (*MeerDAG) SetCacheSize added in v1.0.18

func (bd *MeerDAG) SetCacheSize(dag uint64, data uint64)

func (*MeerDAG) SetTipsDisLimit

func (bd *MeerDAG) SetTipsDisLimit(limit int64)

func (*MeerDAG) SortBlock

func (bd *MeerDAG) SortBlock(src []*hash.Hash) []*hash.Hash

Sort block by id

func (*MeerDAG) Start added in v1.0.18

func (bd *MeerDAG) Start() error

func (*MeerDAG) Stop added in v1.0.18

func (bd *MeerDAG) Stop() error

func (*MeerDAG) UpdateWeight

func (bd *MeerDAG) UpdateWeight(ib IBlock)

func (*MeerDAG) UpgradeDB

func (bd *MeerDAG) UpgradeDB(db database.DB, mainTip *hash.Hash, total uint64, genesis *hash.Hash, interrupt <-chan struct{}, dbFetchBlockByHash func(dbTx database.Tx, hash *hash.Hash) (*types.SerializedBlock, error), isDuplicateTx func(dbTx database.Tx, txid *hash.Hash, blockHash *hash.Hash) bool, evmbc *core.BlockChain, edb ethdb.Database) error

update db to new version

func (*MeerDAG) ValidBlock

func (bd *MeerDAG) ValidBlock(block IBlock)

type OldBlock added in v1.0.18

type OldBlock struct {
	// contains filtered or unexported fields
}

func (*OldBlock) AddChild added in v1.0.18

func (b *OldBlock) AddChild(child IBlock)

Add child nodes to block

func (*OldBlock) AddParent added in v1.0.18

func (b *OldBlock) AddParent(parent IBlock)

func (*OldBlock) AttachChild added in v1.0.18

func (b *OldBlock) AttachChild(ib IBlock)

func (*OldBlock) AttachParent added in v1.0.18

func (b *OldBlock) AttachParent(ib IBlock)

func (*OldBlock) Bytes added in v1.0.21

func (b *OldBlock) Bytes() []byte

func (*OldBlock) Decode added in v1.0.18

func (b *OldBlock) Decode(r io.Reader) error

decode

func (*OldBlock) DetachChild added in v1.0.18

func (b *OldBlock) DetachChild(ib IBlock)

func (*OldBlock) DetachParent added in v1.0.18

func (b *OldBlock) DetachParent(ib IBlock)

func (*OldBlock) Encode added in v1.0.18

func (b *OldBlock) Encode(w io.Writer) error

encode

func (*OldBlock) GetChildren added in v1.0.18

func (b *OldBlock) GetChildren() *IdSet

Get all the children of block

func (*OldBlock) GetData added in v1.0.18

func (b *OldBlock) GetData() IBlockData

func (*OldBlock) GetHash added in v1.0.18

func (b *OldBlock) GetHash() *hash.Hash

Return the hash of block. It will be a pointer.

func (*OldBlock) GetHeight added in v1.0.18

func (b *OldBlock) GetHeight() uint

Acquire the height of block in main chain

func (*OldBlock) GetID added in v1.0.18

func (b *OldBlock) GetID() uint

Return block ID

func (*OldBlock) GetLayer added in v1.0.18

func (b *OldBlock) GetLayer() uint

Acquire the layer of block

func (*OldBlock) GetMainParent added in v1.0.18

func (b *OldBlock) GetMainParent() uint

func (*OldBlock) GetOrder added in v1.0.18

func (b *OldBlock) GetOrder() uint

Acquire the order of block

func (*OldBlock) GetParents added in v1.0.18

func (b *OldBlock) GetParents() *IdSet

Get all parents set,the dag block has more than one parent

func (*OldBlock) GetState added in v1.0.21

func (b *OldBlock) GetState() model.BlockState

GetState

func (*OldBlock) GetStatus added in v1.0.18

func (b *OldBlock) GetStatus() model.BlockStatus

func (*OldBlock) GetWeight added in v1.0.18

func (b *OldBlock) GetWeight() uint64

Acquire the weight of blue blocks

func (*OldBlock) HasChildren added in v1.0.18

func (b *OldBlock) HasChildren() bool

Detecting the presence of child nodes

func (*OldBlock) HasParents added in v1.0.18

func (b *OldBlock) HasParents() bool

Testing whether it has parents

func (*OldBlock) Invalid added in v1.0.18

func (b *OldBlock) Invalid()

func (*OldBlock) IsLoaded added in v1.0.18

func (b *OldBlock) IsLoaded() bool

func (*OldBlock) IsOrdered added in v1.0.18

func (b *OldBlock) IsOrdered() bool

IsOrdered

func (*OldBlock) RemoveChild added in v1.0.18

func (b *OldBlock) RemoveChild(child uint)

func (*OldBlock) RemoveParent added in v1.0.21

func (b *OldBlock) RemoveParent(id uint)

func (*OldBlock) SetData added in v1.0.18

func (b *OldBlock) SetData(data IBlockData)

func (*OldBlock) SetHeight added in v1.0.18

func (b *OldBlock) SetHeight(h uint)

Setting the height of block in main chain

func (*OldBlock) SetID added in v1.0.18

func (b *OldBlock) SetID(id uint)

func (*OldBlock) SetLayer added in v1.0.18

func (b *OldBlock) SetLayer(layer uint)

Setting the layer of block

func (*OldBlock) SetOrder added in v1.0.18

func (b *OldBlock) SetOrder(o uint)

Setting the order of block

func (*OldBlock) SetStatus added in v1.0.18

func (b *OldBlock) SetStatus(status model.BlockStatus)

SetStatus

func (*OldBlock) SetStatusFlags added in v1.0.18

func (b *OldBlock) SetStatusFlags(flags model.BlockStatus)

func (*OldBlock) SetWeight added in v1.0.18

func (b *OldBlock) SetWeight(weight uint64)

Setting the weight of block

func (*OldBlock) UnsetStatusFlags added in v1.0.18

func (b *OldBlock) UnsetStatusFlags(flags model.BlockStatus)

func (*OldBlock) Valid added in v1.0.18

func (b *OldBlock) Valid()

type OldPhantomBlock added in v1.0.18

type OldPhantomBlock struct {
	*OldBlock
	// contains filtered or unexported fields
}

old block

func (*OldPhantomBlock) AddBlueDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) AddBlueDiffAnticone(id uint)

func (*OldPhantomBlock) AddPairBlueDiffAnticone added in v1.0.18

func (pb *OldPhantomBlock) AddPairBlueDiffAnticone(id uint, order uint)

func (*OldPhantomBlock) AddPairRedDiffAnticone added in v1.0.18

func (pb *OldPhantomBlock) AddPairRedDiffAnticone(id uint, order uint)

func (*OldPhantomBlock) AddRedDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) AddRedDiffAnticone(id uint)

func (*OldPhantomBlock) CleanDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) CleanDiffAnticone()

func (*OldPhantomBlock) Decode added in v1.0.18

func (pb *OldPhantomBlock) Decode(r io.Reader) error

decode

func (*OldPhantomBlock) Encode added in v1.0.18

func (pb *OldPhantomBlock) Encode(w io.Writer) error

encode

func (*OldPhantomBlock) GetBlueDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) GetBlueDiffAnticone() *IdSet

func (*OldPhantomBlock) GetBlueDiffAnticoneSize added in v1.0.18

func (pb *OldPhantomBlock) GetBlueDiffAnticoneSize() int

func (*OldPhantomBlock) GetBlueNum added in v1.0.21

func (pb *OldPhantomBlock) GetBlueNum() uint

GetBlueNum

func (*OldPhantomBlock) GetDiffAnticoneSize added in v1.0.21

func (pb *OldPhantomBlock) GetDiffAnticoneSize() int

func (*OldPhantomBlock) GetRedDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) GetRedDiffAnticone() *IdSet

func (*OldPhantomBlock) GetRedDiffAnticoneSize added in v1.0.21

func (pb *OldPhantomBlock) GetRedDiffAnticoneSize() int

func (*OldPhantomBlock) HasBlueDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) HasBlueDiffAnticone(id uint) bool

func (*OldPhantomBlock) HasRedDiffAnticone added in v1.0.21

func (pb *OldPhantomBlock) HasRedDiffAnticone(id uint) bool

func (*OldPhantomBlock) IsBluer added in v1.0.18

func (pb *OldPhantomBlock) IsBluer(other *OldPhantomBlock) bool

type Phantom

type Phantom struct {
	// contains filtered or unexported fields
}

func (*Phantom) AddBlock

func (ph *Phantom) AddBlock(ib IBlock) (*list.List, *list.List)

Add a block

func (*Phantom) CheckBlockOrderDB added in v1.0.18

func (ph *Phantom) CheckBlockOrderDB(maxDepth uint64) error

func (*Phantom) CheckMainChainDB

func (ph *Phantom) CheckMainChainDB(maxDepth uint64) error

func (*Phantom) CreateBlock

func (ph *Phantom) CreateBlock(b *Block) IBlock

Build self block

func (*Phantom) Decode

func (ph *Phantom) Decode(r io.Reader) error

decode

func (*Phantom) Encode

func (ph *Phantom) Encode(w io.Writer) error

encode

func (*Phantom) GetBlues

func (ph *Phantom) GetBlues(parents *IdSet) uint

func (*Phantom) GetDiffAnticone

func (ph *Phantom) GetDiffAnticone() *IdSet

func (*Phantom) GetDiffBlueSet

func (ph *Phantom) GetDiffBlueSet() *IdSet

func (*Phantom) GetMainChainTip

func (ph *Phantom) GetMainChainTip() IBlock

return the tip of main chain

func (*Phantom) GetMainChainTipId

func (ph *Phantom) GetMainChainTipId() uint

func (*Phantom) GetMainParent

func (ph *Phantom) GetMainParent(parents *IdSet) IBlock

return the main parent in the parents

func (*Phantom) GetMainParentConcurrency

func (ph *Phantom) GetMainParentConcurrency(b IBlock) int

The main parent concurrency of block

func (*Phantom) GetName

func (ph *Phantom) GetName() string

func (*Phantom) GetTipsList

func (ph *Phantom) GetTipsList() []IBlock

If the successor return nil, the underlying layer will use the default tips list.

func (*Phantom) Init

func (ph *Phantom) Init(bd *MeerDAG) bool

func (*Phantom) IsBlue

func (ph *Phantom) IsBlue(id uint) bool

func (*Phantom) IsDAG

func (ph *Phantom) IsDAG(parents []IBlock) bool

IsDAG

func (*Phantom) Load

func (ph *Phantom) Load() error

load

func (*Phantom) UpdateVirtualBlockOrder

func (ph *Phantom) UpdateVirtualBlockOrder() *PhantomBlock

func (*Phantom) UpdateWeight

func (ph *Phantom) UpdateWeight(ib IBlock)

type PhantomBlock

type PhantomBlock struct {
	*Block
	// contains filtered or unexported fields
}

func (*PhantomBlock) AddBlueDiffAnticone added in v1.0.18

func (pb *PhantomBlock) AddBlueDiffAnticone(id uint)

func (*PhantomBlock) AddPairBlueDiffAnticone added in v1.0.18

func (pb *PhantomBlock) AddPairBlueDiffAnticone(id uint, order uint)

func (*PhantomBlock) AddPairRedDiffAnticone added in v1.0.18

func (pb *PhantomBlock) AddPairRedDiffAnticone(id uint, order uint)

func (*PhantomBlock) AddRedDiffAnticone added in v1.0.18

func (pb *PhantomBlock) AddRedDiffAnticone(id uint)

func (*PhantomBlock) CleanDiffAnticone added in v1.0.18

func (pb *PhantomBlock) CleanDiffAnticone()

func (*PhantomBlock) Decode

func (pb *PhantomBlock) Decode(r io.Reader) error

decode

func (*PhantomBlock) Encode

func (pb *PhantomBlock) Encode(w io.Writer) error

encode

func (*PhantomBlock) GetBlueDiffAnticone

func (pb *PhantomBlock) GetBlueDiffAnticone() *IdSet

func (*PhantomBlock) GetBlueDiffAnticoneSize added in v1.0.18

func (pb *PhantomBlock) GetBlueDiffAnticoneSize() int

func (*PhantomBlock) GetBlueNum

func (pb *PhantomBlock) GetBlueNum() uint

GetBlueNum

func (*PhantomBlock) GetDiffAnticoneSize added in v1.0.18

func (pb *PhantomBlock) GetDiffAnticoneSize() int

func (*PhantomBlock) GetRedDiffAnticone

func (pb *PhantomBlock) GetRedDiffAnticone() *IdSet

func (*PhantomBlock) GetRedDiffAnticoneSize added in v1.0.18

func (pb *PhantomBlock) GetRedDiffAnticoneSize() int

func (*PhantomBlock) HasBlueDiffAnticone added in v1.0.18

func (pb *PhantomBlock) HasBlueDiffAnticone(id uint) bool

func (*PhantomBlock) HasRedDiffAnticone added in v1.0.18

func (pb *PhantomBlock) HasRedDiffAnticone(id uint) bool

func (*PhantomBlock) IsBluer

func (pb *PhantomBlock) IsBluer(other *PhantomBlock) bool

type Spectre

type Spectre struct {
	// contains filtered or unexported fields
}

func (*Spectre) AddBlock

func (sp *Spectre) AddBlock(b IBlock) (*list.List, *list.List)

func (*Spectre) CreateBlock

func (sp *Spectre) CreateBlock(b *Block) IBlock

Build self block

func (*Spectre) Decode

func (sp *Spectre) Decode(r io.Reader) error

decode

func (*Spectre) Encode

func (sp *Spectre) Encode(w io.Writer) error

encode

func (*Spectre) GetBlues

func (sp *Spectre) GetBlues(parents *IdSet) uint

GetBlues

func (*Spectre) GetMainChainTip

func (sp *Spectre) GetMainChainTip() IBlock

return the tip of main chain

func (*Spectre) GetMainChainTipId

func (sp *Spectre) GetMainChainTipId() uint

func (*Spectre) GetMainParent

func (sp *Spectre) GetMainParent(parents *IdSet) IBlock

return the main parent in the parents

func (*Spectre) GetMainParentConcurrency

func (sp *Spectre) GetMainParentConcurrency(b IBlock) int

The main parent concurrency of block

func (*Spectre) GetName

func (sp *Spectre) GetName() string

func (*Spectre) GetTipsList

func (sp *Spectre) GetTipsList() []IBlock

func (*Spectre) Init

func (sp *Spectre) Init(bd *MeerDAG) bool

func (*Spectre) InitVote

func (sp *Spectre) InitVote(b1 IBlock, b2 IBlock) (bool, error)

func (*Spectre) IsBlue

func (sp *Spectre) IsBlue(id uint) bool

IsBlue

func (*Spectre) IsDAG

func (sp *Spectre) IsDAG(parents []IBlock) bool

IsDAG

func (*Spectre) IsInPastOf

func (sp *Spectre) IsInPastOf(b1 IBlock, b2 IBlock) bool

TODO: test if there is ancestor-descendant relationship between b1 and b2

func (*Spectre) Load

func (sp *Spectre) Load() error

func (*Spectre) Vote

func (sp *Spectre) Vote(b1 IBlock, b2 IBlock) (bool, error)

func (*Spectre) VoteByBlock

func (sp *Spectre) VoteByBlock(virtualBlock IBlock) (bool, error)

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

func (*Spectre) Votes

func (sp *Spectre) Votes() map[hash.Hash]bool

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) GetMainParent added in v1.0.21

func (sd *SpectreBlockData) GetMainParent() *hash.Hash

func (*SpectreBlockData) GetParents

func (sd *SpectreBlockData) GetParents() []*hash.Hash

func (*SpectreBlockData) GetPriority

func (sd *SpectreBlockData) GetPriority() int

func (*SpectreBlockData) GetTimestamp

func (sd *SpectreBlockData) GetTimestamp() int64

func (*SpectreBlockData) GetWeight

func (sd *SpectreBlockData) GetWeight() uint64

Acquire the weight of block

type SyncMode

type SyncMode byte

Synchronization mode

const (
	DirectMode SyncMode = 0
	SubDAGMode SyncMode = 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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