common

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: Apache-2.0 Imports: 24 Imported by: 15

README

go-common

Documentation

Index

Constants

View Source
const (
	ETNone             ElectionType = 0
	ETVrf              ElectionType = 1
	ETManagedCommittee ElectionType = 4
	// Deprecated
	ETFixedCommittee ElectionType = 2
	// Deprecated
	ETFixedSpectator ElectionType = 3

	NilEpoch  = EpochNum(math.MaxUint64)
	NilEra    = EraNum(math.MaxUint64)
	NilHeight = Height(math.MaxUint64)
	NilBlock  = BlockNum(math.MaxUint32)
)

ETManagedCommittee: 现在加了一个新的选举类型:ManagedCommittee == 4,配置成这种类型的链,有以下特点: 1. 在此链中共识的节点不再参与其他链的选举,直到节点退出此链的共识 2. 此类型链不再上报奖励请求,即无奖励 3. 此链的选举开始时间与VRF一致,但选举请求不经过打包直接在0链基础网络上广播 4. 可以参与选举的节点,会以NodeID列表的方式存储在本链models.AddressOfChainSettings的 models.ManagedCommNodeIdsName为名的键值中,多个值首尾相接形成的byte slice值。通过修改这 个值,来控制下次可以参选的候选人名单。 5. 所有节点收到选举请求时,会判断自身NodeID是否在候选人名单中,如果在,就可以加入该链基础网络和下 届共识网络等待同步信息后再发送选举结果(报名),此处流程与VRF选举一致,不过报名消息类型不同 6. 选举不再控制committee.size的下限,上限与VRF选举一致,Committee由报名的且合法的候选人,按 NodeID由小到大排序组成,并打包广播到本链网络中,除选举算法与VRF不同,流程完全一致

View Source
const (
	// 配置缺省值
	DefaultP2PPort1   = 31000
	DefaultP2pPort2   = 31050
	DefaultRpcAddress = "127.0.0.1:23017"
	DefaultCompatible = true

	BlocksInEpoch = 1000 // Epoch块数量
	EpochsInEra   = 36
	BlocksInEra   = EpochsInEra * BlocksInEpoch

	// 链id相关常量
	ReservedMaxChainID uint32 = 1 << 20
	MainChainID               = ChainID(0)
	NilChainID                = ChainID(ReservedMaxChainID)

	// 类型长度
	NodeIDBits        = 512
	NodeIDBytes       = NodeIDBits / 8
	HashLength        = 32
	AddressLength     = 20
	SeedLength        = 20
	ChainBytesLength  = 4 // 链id所占byte数
	HeightBytesLength = 8 // 块高所占byte数

	// 分片个数上限:<= 2^MaxExponentOfShards
	MaxExponentOfShards = 8

	// 常用常量
	INTMAX int = int(^uint(0) >> 1)
	INTMIN int = ^INTMAX
)
View Source
const (
	// 监测事件类型
	P2P = iota
	Event
	Block
)

Variables

View Source
var (
	TypeOfAddress = reflect.TypeOf((*Address)(nil)).Elem()
	TypeOfHash    = reflect.TypeOf((*Hash)(nil)).Elem()
	EmptyNodeID   = NodeID{}

	SystemNodeID NodeID // 节点NodeID,系统启动时从配置文件初始化

	NodeIDMap     = make(map[NodeID]int)
	TxCount       uint64                                      // 系统模拟交易数
	NetDelay      []int                                       // 系统网络延时区间[NetDelay[0]-NetDelay[1]]
	WaitingTime   time.Duration                               // 系统共识状态切换等待时间,等待其它节点
	LastMsgTime   int64                                       // 系统最后一条p2p消息时间
	LastEventTime int64                                       // 系统最后一个共识事件处理时间
	LastBlockTime int64                                       // 系统最后出块时间
	LastBlocks    = LastBlockMap{M: make(map[ChainID]Height)} // 记录各条链处理的最后一个块
	PkgedBlocks   = LastBlockMap{M: make(map[ChainID]Height)} // 记录各条链已被父链打包的最后一个块
	Overflow      bool                                        // delta pool 是否溢出
	NdType        *NodeType
	ForChain      *ChainID
	FullData      bool
	StandAlone    bool // 是否以单链方式启动
)
View Source
var (
	MainChainStruct = ChainStruct{
		ID:       MainChainID,
		ParentID: NilChainID,
		Mode:     Root,
	}

	// TypeOfChainStructPtr   = reflect.TypeOf((*ChainStruct)(nil))
	TypeOfChainInfosPtr = reflect.TypeOf((*ChainInfos)(nil))
)
View Source
var (
	RealCipher    cipher.Cipher        = cipher.NewCipher(cipher.SECP256K1SHA3)
	SystemPrivKey cipher.ECCPrivateKey // 节点私钥

	ErrSignatureVerifyFailed = errors.New("signature verify failed")
)
View Source
var (
	EmptyPlaceHolder     struct{} = struct{}{}
	EmptyByteSliceHolder []byte   = make([]byte, 0)

	BytesBufferPool = sync.Pool{
		New: func() interface{} {
			return new(bytes.Buffer)
		},
	}

	BigIntPool = sync.Pool{
		New: func() interface{} {
			return new(big.Int)
		},
	}

	ErrAlreadyInitialized  = errors.New("already initialized")
	ErrAlreadyStarted      = errors.New("already started")
	ErrAlreadyStopped      = errors.New("already stopped")
	ErrNeedInitialization  = errors.New("need initialization")
	ErrNotStarted          = errors.New("not started yet")
	ErrIllegalStatus       = errors.New("illegal status")
	ErrInsufficientLength  = errors.New("insufficient length")
	ErrLength              = errors.New("length error")
	ErrNil                 = errors.New("nil value")
	ErrNotFound            = errors.New("not found")
	ErrDuplicated          = errors.New("duplicated")
	ErrIllegalParams       = errors.New("illegal parameters")
	ErrUnsupported         = errors.New("unsupported")
	ErrUnknown             = errors.New("unknown error")
	ErrAlreadyDone         = errors.New("already done, operation ignored")
	ErrReservedAddress     = errors.New("reserved address")
	ErrMissMatch           = errors.New("miss match")
	ErrInsufficientBalance = errors.New("insufficient balance for transfer")

	EmptyHash    = Hash{}
	NilHashSlice = []byte(nil)
	NilHash      = BytesToHash(NilHashSlice)
)
View Source
var (
	DefaultRpcEndpoint = Endpoint{NetType: "tcp", Address: DefaultRpcAddress}
)
View Source
var ErrGasLimitReached = errors.New("gas limit reached")

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func BytesIntersection

func BytesIntersection(a, b [][]byte) [][]byte

func BytesIntersectionMap

func BytesIntersectionMap(a map[string]struct{}, b [][]byte) [][]byte

func BytesToUint32

func BytesToUint32(b []byte) uint32

func CipherHash256

func CipherHash256(cipher cipher.Cipher, in ...[]byte) []byte

func CloneByteSlice

func CloneByteSlice(bytes []byte) []byte

func ConcatenateBytes

func ConcatenateBytes(bss [][]byte) []byte

将参数的 slice数组 首尾相接返回一个slice,允许nil和空,返回的slice不为nil

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func CopyBytesSlice

func CopyBytesSlice(in [][]byte) [][]byte

func DatabasePath

func DatabasePath(basePath string, id ChainID) string

func EncodeAndHash

func EncodeAndHash(o interface{}) ([]byte, error)

序列化对象后进行hash计算

func ForPrint

func ForPrint(v interface{}, poss ...int) []byte

func ForPrintSlice

func ForPrintSlice(s []byte, startPos int, endPos int) []byte

func ForPrintSliceString

func ForPrintSliceString(v interface{}, maxSize ...int) string

func ForPrintValue

func ForPrintValue(val reflect.Value, startPos, endPos int) []byte

func FormalizeBasePath

func FormalizeBasePath(path string) string

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func HasHexPrefix

func HasHexPrefix(str string) bool

hasHexPrefix validates str begins with '0x' or '0X'.

func Hash256NoError

func Hash256NoError(in ...[]byte) []byte

func Hash256s

func Hash256s(in ...[]byte) ([]byte, error)

func HashEquals

func HashEquals(h1, h2 *Hash) bool

func HashLess

func HashLess(a, b Hash) bool

func HashObject

func HashObject(o interface{}) ([]byte, error)

如果对象实现了common.Hasher接口,则直接使用HashValue()方法生成Hash值, 否则将对象序列化后进行Hash

func HashPair

func HashPair(a []byte, b []byte) []byte

func HashRipemd160

func HashRipemd160(data []byte) []byte

func HashSliceEquals

func HashSliceEquals(h1, h2 []byte) bool

func HashsEquals

func HashsEquals(hs1, hs2 []Hash) bool

func HeaderIndexHash

func HeaderIndexHash(posBuffer [13]byte, index byte) []byte

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func HexToPrivKey

func HexToPrivKey(h string) (cipher.ECCPrivateKey, error)

func HomeDir

func HomeDir() string

func InitNodeIDMap

func InitNodeIDMap(nodeids []NodeID)

func InitShareObject

func InitShareObject(sopath string) *plugin.Plugin

func IntToBytes

func IntToBytes(n int) []byte

func IsHex

func IsHex(str string) bool

IsHex validates whether each byte is valid hexadecimal string.

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func IsHexCharacter

func IsHexCharacter(c byte) bool

isHexCharacter returns bool of c being a valid hexadecimal.

func IsNilHash

func IsNilHash(bs []byte) bool

func IsNodeIDIn

func IsNodeIDIn(nidhs []Hash, nid NodeID) bool

func KeyCount

func KeyCount() map[string]int

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func MerkleHash

func MerkleHash(hashList [][]byte, toBeProof int, proofs *MerkleProofs) (root []byte, err error)

depth: 如果为正数,则为指定merkle tree的深度,此时如果深度指定的完全二叉树叶子 大于len(hashList),则每一层至多补一个NilHashSlice

func MerkleHashComplete

func MerkleHashComplete(hashList [][]byte, toBeProof int, proofs *MerkleProofs) ([]byte, error)

MerkleHash 将hashList参数按照固定算法计算merkle tree root hash并返回。 如果proof不为空,则将hashList[toBeProof]的值的merkle tree证明按顺序放入proof中 出现错误时,返回error不为空,[]byte无意义,注意!!!此时proof不保证无变动 toBeProof为要证明的对象在hashList数组中的下标

func PackNodeIdsToBytes

func PackNodeIdsToBytes(nodeIds []NodeID) []byte

func ParseBytesToNodeIdBytes

func ParseBytesToNodeIdBytes(s []byte) ([][]byte, error)

func PointerSliceLess

func PointerSliceLess(slice interface{}, i, j int) (less bool, needCompare bool)

当为一个指针类型对象slice进行排序时,需要编写的Less方法,其中前半部分是要判断i/j下标所指对 象是否为nil,nil会被认为最小,如果两个都为nil则认为相等。只有当两个均不为nil时才需要后续的 比较,此时不用再判断nil。 当needCompare返回false时,Less方法可以直接返回less值;否则,需要继续下标所指对象内容的比较

func PrintBytesSlice

func PrintBytesSlice(bss [][]byte, length int) string

func PrivateToPublicSlice

func PrivateToPublicSlice(priv []byte) ([]byte, error)

func RandomBytes

func RandomBytes(length int) []byte

func RegisterNoCheckAddress

func RegisterNoCheckAddress(addrs ...Address)

func RegisterReservedAddress

func RegisterReservedAddress(addrs ...Address)

func RegisterSystemContract

func RegisterSystemContract(noGas bool, addrs ...Address)

func ReverseBytes

func ReverseBytes(bs []byte) []byte

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func SignHash

func SignHash(hash []byte) (pub, sig []byte, err error)

sign msg

func SignMsg

func SignMsg(msg interface{}) (pub, sig []byte, err error)

sign msg

func SplitBytes

func SplitBytes(bs []byte, size int) ([][]byte, error)

按 size 长度分割 bs 为slice数组,每个slice长度都为size

func SystemHash256

func SystemHash256(in ...[]byte) []byte

func ToHeaderPosHashBuffer

func ToHeaderPosHashBuffer(id ChainID, height Height) [13]byte

func ValuesMerkleTreeHash

func ValuesMerkleTreeHash(values interface{}, toBeProof int, proofs *MerkleProofs) (rootHash []byte, err error)

func VerifyHash

func VerifyHash(hash, pub, sig []byte) bool

verify msg hash signature

func VerifyMsg

func VerifyMsg(v interface{}, pub, sig []byte) bool

verify msg signature

func Watch

func Watch(tp int)

监控事件发生时间

func WatchDelta

func WatchDelta(ovfl bool)

监控delta水位线

func WatchHeight

func WatchHeight(id ChainID, height Height)

监控链数据块高度

Types

type AbstractService

type AbstractService struct {
	InitFunc  func() error
	StartFunc func() error
	CloseFunc func() error
	// contains filtered or unexported fields
}

func (*AbstractService) Close

func (s *AbstractService) Close() error

func (AbstractService) Copy

func (*AbstractService) Init

func (s *AbstractService) Init() error

func (*AbstractService) SetChanger

func (s *AbstractService) SetChanger(changer ServiceStateChanger)

func (*AbstractService) Start

func (s *AbstractService) Start() error

type AccountSharding

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

func (AccountSharding) AllIDs

func (as AccountSharding) AllIDs() []ChainID

func (AccountSharding) GetMaskBits

func (as AccountSharding) GetMaskBits() uint

func (AccountSharding) LocalID

func (as AccountSharding) LocalID() ChainID

func (AccountSharding) Number

func (as AccountSharding) Number() int

func (AccountSharding) ParentID

func (as AccountSharding) ParentID() ChainID

func (AccountSharding) Pos

func (as AccountSharding) Pos(id ChainID) int

返回id在shard中的所在位置

func (AccountSharding) ShardTo

func (as AccountSharding) ShardTo(v interface{}) ChainID

func (*AccountSharding) String

func (as *AccountSharding) String() string

type AccountShards

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

func NewAccountShards

func NewAccountShards(parent ChainStruct, chains []ChainID) AccountShards

func (AccountShards) GetMaskBits

func (s AccountShards) GetMaskBits() uint

type Address

type Address [AddressLength]byte

func AddressFromPubSlice

func AddressFromPubSlice(pub []byte) (Address, error)

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddressP

func BytesToAddressP(b []byte) *Address

func CreateAddress

func CreateAddress(b Address, nonce uint64) Address

CreateAddress creates an ethereum address given the bytes and the nonce

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func StringsToAddresses

func StringsToAddresses(strings []string) []Address

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Clone

func (a Address) Clone() Address

func (*Address) Generate

func (a *Address) Generate() error

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) IsNoGas

func (a Address) IsNoGas() bool

func (Address) IsReserved

func (a Address) IsReserved() bool

func (Address) IsSystemContract

func (a Address) IsSystemContract() bool

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (Address) NoCheck

func (a Address) NoCheck() bool

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type AddressShard

type AddressShard struct {
	Index BitIndex // 最后一位所在下标(从0开始),注意不是位长度(从1开始)
	Value Bits
}

func (*AddressShard) IsIn

func (s *AddressShard) IsIn(addr Address) bool

func (*AddressShard) IsValid

func (s *AddressShard) IsValid() bool

type Addresser

type Addresser interface {
	Address() Address
}

type BitIndex

type BitIndex int

func (BitIndex) BitPos

func (p BitIndex) BitPos() uint

指定位所在字节的位下标(高位开始从0到7)

func (BitIndex) BytePos

func (p BitIndex) BytePos() int

指定位所在字节下标

func (BitIndex) Mask

func (p BitIndex) Mask(b byte) byte

将b的高位按index保留最后一字节所需位数

type Bits

type Bits []byte

func (Bits) Bit

func (bs Bits) Bit(index BitIndex) bool

返回第index位是否为1(不存在时返回false)

func (Bits) Bits

func (bs Bits) Bits(length int) []bool

返回最高(也就是最前)连续的length个bit位的值,对应位1时返回true,否则false 如果bs位数不足,返回的数组实际长度有可能小于length

func (Bits) Byte

func (bs Bits) Byte(index int) (v byte, exist bool)

type BlockNum

type BlockNum uint32 // 在一个共识周期中的块高

func (BlockNum) Bytes

func (bn BlockNum) Bytes() []byte

func (BlockNum) IsLastOfEpoch

func (bn BlockNum) IsLastOfEpoch() bool

是否为一个Epoch里的最后一个块

func (BlockNum) IsNil

func (bn BlockNum) IsNil() bool

func (BlockNum) String

func (bn BlockNum) String() string

type BootNode

type BootNode struct {
	NodeID         NodeID `yaml:"nodeID" json:"nodeID"`       // 节点ID
	IP             string `yaml:"ip" json:"ip"`               // 入口IP
	BasicPort      uint16 `yaml:"bNetPort" json:"bNetPort"`   // 基础网络
	ConsensusPort0 uint16 `yaml:"cNetPort0" json:"cNetPort0"` // 共识网络
	ConsensusPort1 uint16 `yaml:"cNetPort1" json:"cNetPort1"` // 共识网络
	DataPort       uint16 `yaml:"dNetPort" json:"dNetPort"`   // 数据网络只有在分片链间传递数据时才会使用,而且使用的是父链的DataPort
}

网络入口:仅支持网络的发现,单独的BootNode不建立TCP链接(否则需要数据转发,在结构化网络中更是会导致算法失败) BootNode必须是数据节点,数据节点可以不是BootNode,否则无法评判及惩罚

type ChainAttr

type ChainAttr string // 标示链的类型、能力、特性等
const (
	AttrPoC    ChainAttr = "POC"    // PoC算法支持
	AttrReward ChainAttr = "REWARD" // 奖励链,只能有一条
	AttrNoGas  ChainAttr = "NOGAS"  // 本链及子孙链不收Gas费,可以被子孙链属性覆盖
)

func (ChainAttr) IsValid

func (a ChainAttr) IsValid() bool

type ChainAttrs

type ChainAttrs []ChainAttr // 链可能具有的多种Attribute

func (*ChainAttrs) Add

func (a *ChainAttrs) Add(attrs ...ChainAttr) error

因为长度不大,直接轮训判重

func (*ChainAttrs) AddByName

func (a *ChainAttrs) AddByName(names ...string) error

func (ChainAttrs) Clone

func (a ChainAttrs) Clone() ChainAttrs

func (ChainAttrs) Contains

func (a ChainAttrs) Contains(attr ChainAttr) bool

func (ChainAttrs) FromMap

func (a ChainAttrs) FromMap(m map[ChainAttr]struct{}) ChainAttrs

func (ChainAttrs) Len

func (a ChainAttrs) Len() int

func (ChainAttrs) Less

func (a ChainAttrs) Less(i, j int) bool

func (ChainAttrs) Swap

func (a ChainAttrs) Swap(i, j int)

func (ChainAttrs) ToMap

func (a ChainAttrs) ToMap() map[ChainAttr]struct{}

func (ChainAttrs) ToStringSlice

func (a ChainAttrs) ToStringSlice() []string

type ChainID

type ChainID uint32 // 链ID

func BytesToChainID

func BytesToChainID(bs []byte) ChainID

func (ChainID) Bytes

func (id ChainID) Bytes() []byte

func (ChainID) Formalize

func (id ChainID) Formalize() []byte

func (ChainID) HashValue

func (id ChainID) HashValue() ([]byte, error)

func (ChainID) IsMain

func (id ChainID) IsMain() bool

func (ChainID) IsNil

func (id ChainID) IsNil() bool

func (ChainID) IsReserved

func (id ChainID) IsReserved() bool

func (ChainID) IsSub

func (id ChainID) IsSub() bool

func (ChainID) IsUserDefined

func (id ChainID) IsUserDefined() bool

func (ChainID) String

func (id ChainID) String() string

type ChainIDs

type ChainIDs []ChainID

func (ChainIDs) Clone

func (ids ChainIDs) Clone() ChainIDs

func (ChainIDs) Len

func (ids ChainIDs) Len() int

func (ChainIDs) Less

func (ids ChainIDs) Less(i, j int) bool

func (ChainIDs) Swap

func (ids ChainIDs) Swap(i, j int)

type ChainInfos

type ChainInfos struct {
	ChainStruct    `json:"chain"`
	SecondCoinId   CoinID       // 本链第二货币ID,0为主货币,表示本链没有第二货币
	SecondCoinName string       // 如果存在第二货币,则为货币的显示名,否则为""
	HaveSecondCoin bool         // not in use, but should be !SecondCoinId.IsSovereign()
	AdminPubs      [][]byte     // 管理员公钥列表
	GenesisCommIds NodeIDs      // 创世committee成员
	BootNodes      []Dataserver // 创世bootnode节点信息
	Election       ElectionType //
	ChainVersion   string       // not in use
	Syncblock      bool         // not in use
	GenesisDatas   NodeIDs      // 创世数据节点列表
	Datas          NodeIDs      `json:"datanodes"` // 数据节点nodeid列表
	Attributes     ChainAttrs   // 链属性
}

TODO: v1.3.6,目前BootNode和DataNode可以分开设置,但DataRpcPort应该在DataNode中,而不是BootNode。

可以新增两个属性:GenesisDataInfos和DataInfos,用来保存数据节点的ID/IP以及RPC端口号,为了兼容旧版本,
当新增字段为空时不计算Hash,并只有在通过系统合约修改链结构时才会将所有GenesisDatas/Datas的值补上RPC信
息放到GenesisDataInfos/DataInfos中。

TODO: v1.5.0,DataPort也应该在DataNode的设置中;同时需要增加分片信息,因为目前的分片前缀是根据在同一

父链下分片的个数确定的,但我们的链只能做一分二的动作,也就是说同一父链下的分片前缀很有可能长度不一致,如1链
下有5个分片他们的前缀分别为:00,01,100,101,11,其中100和101是由10分裂而来的,这个信息只能记录在链结
构中,在生成ShardInfo时产生效果。

func (*ChainInfos) AddBootNode

func (c *ChainInfos) AddBootNode(bootNode Dataserver) bool

func (*ChainInfos) AddDataNode

func (c *ChainInfos) AddDataNode(node NodeID) bool

func (*ChainInfos) AddrIsAdmin

func (c *ChainInfos) AddrIsAdmin(addr Address) bool

func (*ChainInfos) Clone

func (c *ChainInfos) Clone() *ChainInfos

func (*ChainInfos) GetDataNodes

func (c *ChainInfos) GetDataNodes() []NodeID

func (*ChainInfos) HasAttribute

func (c *ChainInfos) HasAttribute(attr ChainAttr) bool

func (*ChainInfos) HasDataNode

func (c *ChainInfos) HasDataNode(nid NodeID) bool

func (*ChainInfos) Index

func (c *ChainInfos) Index(nid NodeID) int

func (*ChainInfos) IsGenesisDataNode

func (c *ChainInfos) IsGenesisDataNode(nid NodeID) bool

func (*ChainInfos) IsMainChain

func (c *ChainInfos) IsMainChain() bool

func (*ChainInfos) IsPocChain

func (c *ChainInfos) IsPocChain() bool

func (*ChainInfos) IsRewardChain

func (c *ChainInfos) IsRewardChain() bool

func (*ChainInfos) Key

func (c *ChainInfos) Key() []byte

func (*ChainInfos) PubIsAdmin

func (c *ChainInfos) PubIsAdmin(pub []byte) bool

func (*ChainInfos) RemoveBootNode

func (c *ChainInfos) RemoveBootNode(node NodeID) bool

func (*ChainInfos) RemoveDataNode

func (c *ChainInfos) RemoveDataNode(node NodeID) bool

func (*ChainInfos) ReportTo

func (c *ChainInfos) ReportTo() ChainID

当前链上报的目标链,与parentId不一定一致

func (*ChainInfos) Sort

func (c *ChainInfos) Sort()

func (*ChainInfos) String

func (c *ChainInfos) String() string

type ChainInfosShouldBe

type ChainInfosShouldBe struct {
	ChainStruct
	ReportTo          ChainID      // 记录本链上报Header时的目的链(与父链不一定一样,如:子链分片上报给主链分片或0号主链)
	Attributes        ChainAttrs   // 链属性(PoC/Reward等)
	LocalCurrencyID   CoinID       // 本链第二货币ID,0为主货币,表示本链没有第二货币
	LocalCurrencyName string       // 如果存在第二货币,则为货币的显示名,否则为""
	AdminPubs         [][]byte     // 管理员公钥列表
	GenesisCommIds    NodeIDs      // 创世committee成员(有序,只有创世链才有创世委员会,其他链的首届委员会都是经过创建流程选举产生)
	BootNodes         []BootNode   // 链的入口,不得少于N个(N=1)
	Election          ElectionType // 链共识委员会的选举类型
	DataNodes         DataNodes    // 链数据节点。不再有创世非创世之分,但数据节点不得少于M个(M=3),如果没有数据节点,可以认为是虚拟链
	Extra             string       // 附加信息
}

TODO: 有关链结构的数据应该的样子:

虚拟链:只有BootNode.DataPort,而没有数据节点的链,他们是由子链分裂分片后产生的

type ChainMode

type ChainMode byte
const (
	// 链模式
	Root ChainMode = 0x10 + iota
	Branch
	Shard
	UnknownMode
)

func (ChainMode) String

func (m ChainMode) String() string

type ChainStruct

type ChainStruct struct {
	ID       ChainID   `json:"id"`
	ParentID ChainID   `json:"parentid"`
	Mode     ChainMode `json:"mode"`
}

TODO v1.5.0 链ID及父链ID组成了一颗以0链为根的逻辑链ID树。

  1. 根为0号主链,负责维护链结构及全局Seed;

  2. 主链的分片:可能存在的第二层,当子链达到一定数量时主链也可以分片,每个主链分片的ParentID都是0号主链, 这些主链分片主要负责接收、验证及打包各子链(包括子链的分片)上报的块头。

  3. 子链:所有业务的链,ParentID为0号主链。如果子链没有分片,则此链为实体链,需要定期向上级(主链无分片 时:向0号主链,主链有分片时:根据主链分片的属性设定计算得到的主链分片)上报块头。因为是实体链,链上完成 相应交易。

  4. 子链的分片:当子链账户过多或交易过大时,子链可以分裂为2个分片(每个分片还可以继续分裂,分片分裂仅代表 其用户段被分割到新的分片中,所有分片的ParentID都是相同的:子链ID)。当一个子链有了分片,该子链就成为虚拟 链,该虚拟链无需共识,所有分片仅需要该子链BootNode中的DataPort来组建数据网络。所有交易都发生在对应的分 片上。分片链的ParentID为子链ID,定期向上级(主链)汇报块头信息(同子链)。

    分片的生成(初步想法):已存在的链A

  5. 新建2条链A1,A2,一个分片账户前缀Bit:0,一个账户前缀Bit:1

  6. 停A链,锁定数据

  7. 将链A数据复制给A1, A2(更简单一些,将链A的数据节点分一半给A1,另一半给A2,但是如何保证链A运行不受影响?)

  8. 选举A1,A2两条链的委员会

  9. 两条链选举全部成功后,启动A1/A2

func NewChainStruct

func NewChainStruct(id, parentId ChainID) (cs *ChainStruct, err error)

func (ChainStruct) String

func (s ChainStruct) String() string

func (ChainStruct) Validate

func (s ChainStruct) Validate() error

type Cipherer

type Cipherer interface {
	Priv() []byte
	Pub() []byte
}

密钥对

type CoinID

type CoinID uint16 // 货币ID,TKM=0

func (CoinID) IsSovereign

func (c CoinID) IsSovereign() bool

true为主货币,false为其他币种(各链的第二货币)

type CommID

type CommID int

func (CommID) String

func (i CommID) String() string

type DataNode

type DataNode struct {
	NodeID     NodeID // 节点ID
	IsGenesis  bool   // 是否为创世数据节点,仅为一个标示
	RpcAddress string // 数据节点的RPC地址及端口(为了抗攻击,可以使用集群应用的地址代理一群全节点)
}

链数据节点:

type DataNodes

type DataNodes []DataNode

按(IsGenesis, NodeID) 排序

func (DataNodes) Len

func (ds DataNodes) Len() int

func (DataNodes) Less

func (ds DataNodes) Less(i, j int) bool

func (DataNodes) Swap

func (ds DataNodes) Swap(i, j int)

type Dataserver

type Dataserver struct {
	ChainID        uint32 `yaml:"chainID" 		json:"chainID"`
	NodeIDString   string `yaml:"nodeID" 		json:"nodeID"`
	IP             string `yaml:"ip" 			json:"ip"`
	BasicPort      uint16 `yaml:"bNetPort" 		json:"bNetPort"`
	ConsensusPort0 uint16 `yaml:"cNetPort0" 	json:"cNetPort0"`
	ConsensusPort1 uint16 `yaml:"cNetPort1" 	json:"cNetPort1"`
	DataPort0      uint16 `yaml:"dNetPort0" 	json:"dNetPort0"`
	DataPort1      uint16 `yaml:"dNetPort1" 	json:"dNetPort1"`
	DataRpcPort    uint16 `yaml:"dataRpcPort" 	json:"dataRpcPort"`
}

func (*Dataserver) Clone

func (d *Dataserver) Clone() *Dataserver

func (Dataserver) Compare

func (d Dataserver) Compare(o Dataserver) int

func (Dataserver) GetNodeID

func (d Dataserver) GetNodeID() (*NodeID, error)

func (*Dataserver) GetRpcAddr

func (d *Dataserver) GetRpcAddr() string

func (*Dataserver) HashValue

func (d *Dataserver) HashValue() ([]byte, error)

func (Dataserver) String

func (d Dataserver) String() string

func (Dataserver) Validation

func (d Dataserver) Validation() error

type DvppError

type DvppError struct {
	Message  string
	Embedded error
}

func NewDvppError

func NewDvppError(msg string, embeded error) DvppError

func (DvppError) Error

func (e DvppError) Error() string

type DvppFormatError

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

func NewFormatError

func NewFormatError(format string, values ...interface{}) DvppFormatError

func (DvppFormatError) Error

func (e DvppFormatError) Error() string

type ElectionType

type ElectionType byte

func StringToElectionType

func StringToElectionType(name string) (ElectionType, bool)

字符串转ElectionType,无效字符串bool返回false

func (ElectionType) Exclusiveness

func (t ElectionType) Exclusiveness() bool

func (ElectionType) IsManaged

func (t ElectionType) IsManaged() bool

func (ElectionType) IsValid

func (t ElectionType) IsValid() bool

func (ElectionType) IsVrf

func (t ElectionType) IsVrf() bool

func (ElectionType) Name

func (t ElectionType) Name() string

返回在链结构配置中有效的ElectionType的名称

func (ElectionType) RewardNeeded

func (t ElectionType) RewardNeeded() bool

func (ElectionType) String

func (t ElectionType) String() string

type Endpoint

type Endpoint struct {
	NetType string `yaml:"net" json:"net"`
	Address string `yaml:"addr" json:"addr"`
}

func (Endpoint) IsNil

func (ep Endpoint) IsNil() bool

func (Endpoint) Network

func (ep Endpoint) Network() string

func (Endpoint) String

func (ep Endpoint) String() string

type EpochNum

type EpochNum uint64 // 共识周期

func (EpochNum) Bytes

func (en EpochNum) Bytes() []byte

func (EpochNum) IsNil

func (en EpochNum) IsNil() bool

func (EpochNum) String

func (en EpochNum) String() string

type EraNum

type EraNum uint64 // 计费周期

func (EraNum) Bytes

func (e EraNum) Bytes() []byte

func (EraNum) Equals

func (e EraNum) Equals(era *EraNum) bool

func (EraNum) IsNil

func (e EraNum) IsNil() bool

func (*EraNum) String

func (e *EraNum) String() string

func (*EraNum) Value

func (e *EraNum) Value() EraNum

type GasPool

type GasPool uint64

GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

AddGas makes gas available for execution.

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

Gas returns the amount of gas remaining in the pool.

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error

SubGas deducts the given amount from the pool if enough gas is available and returns an error otherwise.

type Hash

type Hash [HashLength]byte

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHashP

func BytesToHashP(b []byte) *Hash

func CopyHashs

func CopyHashs(hs []Hash) []Hash

func EncodeHash

func EncodeHash(v interface{}) Hash

调用HashObject方法,并将结果转为Hash对象,如果有错误,则返回全0Hash值

func Hash256

func Hash256(v ...[]byte) Hash

func Hash256WithError

func Hash256WithError(v ...[]byte) (Hash, error)

func Hash256p

func Hash256p(v ...[]byte) *Hash

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func NewHash

func NewHash(b []byte) *Hash

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*Hash) Clone

func (h *Hash) Clone() *Hash

func (*Hash) Equals

func (h *Hash) Equals(v *Hash) bool

func (Hash) Generate

func (h Hash) Generate(rand *mrand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) HashValue

func (h Hash) HashValue() ([]byte, error)

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) IsEmpty

func (h Hash) IsEmpty() bool

func (Hash) IsNil

func (h Hash) IsNil() bool

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) PrintString

func (h *Hash) PrintString() string

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (*Hash) Slice

func (h *Hash) Slice() []byte

func (*Hash) SliceEqual

func (h *Hash) SliceEqual(val []byte) bool

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type Hasher

type Hasher interface {
	HashValue() ([]byte, error)
}

可以计算Hash值的接口类型

type Height

type Height uint64 // 总块高

func BytesToHeight

func BytesToHeight(bs []byte) Height

func ToHeight

func ToHeight(epoch EpochNum, bn BlockNum) Height

func (Height) BlockNum

func (h Height) BlockNum() BlockNum

func (Height) Bytes

func (h Height) Bytes() []byte

func (Height) Compare

func (h Height) Compare(o Height) int

func (Height) EpochNum

func (h Height) EpochNum() EpochNum

func (Height) EraNum

func (h Height) EraNum() EraNum

func (Height) HashValue

func (h Height) HashValue() ([]byte, error)

func (Height) IsLastOfEpoch

func (h Height) IsLastOfEpoch() bool

是否为当前Epoch的最后一个块

func (Height) IsNil

func (h Height) IsNil() bool

func (Height) Split

func (h Height) Split() (epochNum EpochNum, blockNum BlockNum)

func (Height) String

func (h Height) String() string

type Identifier

type Identifier interface {
	Cipherer
	Address() Address
	AddressP() *Address
}

账户

type LastBlockMap

type LastBlockMap struct {
	M map[ChainID]Height
	// contains filtered or unexported fields
}

func (*LastBlockMap) CAS

func (m *LastBlockMap) CAS(key ChainID, value Height) bool

当value大于当前保存的值时,进行替换,并返回true。否则返回false

func (*LastBlockMap) CopyMap

func (m *LastBlockMap) CopyMap() map[ChainID]Height

func (*LastBlockMap) Get

func (m *LastBlockMap) Get(key ChainID) (Height, bool)

func (*LastBlockMap) Set

func (m *LastBlockMap) Set(key ChainID, value Height)

type LruMap

type LruMap struct {
	Map *lru.Cache
}

func NewLruMap

func NewLruMap(size int) *LruMap

func (*LruMap) Add

func (m *LruMap) Add(key interface{}, value interface{}) bool

func (*LruMap) Clear

func (m *LruMap) Clear()

func (*LruMap) Contains

func (m *LruMap) Contains(key interface{}) bool

func (*LruMap) Get

func (m *LruMap) Get(key interface{}) interface{}

func (*LruMap) Remove

func (m *LruMap) Remove(key interface{})

type MerkleProofs

type MerkleProofs struct {
	Hashs []Hash   `json:"hashs"` // 下标从0开始的 按顺序与ToBeProof迭代计算Hash的Hash列表
	Paths *big.Int `json:"paths"` // 位操作数,Hashs的下标对应的Bit位表示对应Hash值在进行Hash运算时放在前面(1)还是后面(0),顺序正好是被证明对象二进制值
}

由于序列化时采用了16位计数,所以最大支持的证明高度不能超过65535

func NewMerkleProofs

func NewMerkleProofs() *MerkleProofs

func (*MerkleProofs) Append

func (p *MerkleProofs) Append(h Hash, order bool)

h: 证明路经上的一个点 order: 这个点在证明路经的左侧(true)还是右侧(false)

func (*MerkleProofs) Clone

func (p *MerkleProofs) Clone() *MerkleProofs

func (*MerkleProofs) Deserialization

func (p *MerkleProofs) Deserialization(r io.Reader) (shouldBeNil bool, err error)

func (*MerkleProofs) Get

func (p *MerkleProofs) Get(index int) (h Hash, order bool, err error)

获取证明路径上的第index(从0开始)个Hash值及其顺序,如果order为true,则返回的Hash值在前,否则在后

func (*MerkleProofs) Key

func (p *MerkleProofs) Key() (key uint64, ok bool)

当前证明值的key,溢出时ok为false

func (*MerkleProofs) Len

func (p *MerkleProofs) Len() int

func (*MerkleProofs) Order

func (p *MerkleProofs) Order(i int) bool

对应Hash值在计算上一级hash时,放在前面(true)还是后面(false)

func (*MerkleProofs) Proof

func (p *MerkleProofs) Proof(toBeProof Hash) ([]byte, error)

根据输入,按证明计算,返回结果。如果证明为空,则输入被返回

func (*MerkleProofs) Serialization

func (p *MerkleProofs) Serialization(w io.Writer) error

1字节是否为nil的标志(common.NilOrFalse/common.NotNilOrTrue) + binary.BigEndian.PutUint16(len(Hashs)) + binary.BigEndian.PutUint16(len(Hashs[0])) + Hashs[0] + ... + binary.BigEndian.PutUint16(len(Hashs[len(Hashs)-1])) + Hashs[len(Hashs)-1] + binary.BigEndian.PutUint16(len(Paths.Bytes())) + Paths.Bytes()

func (MerkleProofs) String

func (p MerkleProofs) String() string

type NetInfo

type NetInfo struct {
	NodeID *NodeID // 节点ID
	// contains filtered or unexported fields
}

func NewNetInfo

func NewNetInfo(id *NodeID, basicAddr, consensusAddr1 string, consensusAddr2 string, dataPort1, dataPort2 string) NetInfo

func (NetInfo) AddAddr

func (n NetInfo) AddAddr(ntype NetType, addr *Endpoint)

func (NetInfo) GetAddr

func (n NetInfo) GetAddr(ntype NetType) *Endpoint

type NetType

type NetType byte
const (
	// 网络类型
	BasicNet NetType = iota
	ConsensusNet1
	ConsensusNet2
	RootDataNet   // 只在主链层,包含主链及其下级分链所有数据节点
	BranchDataNet // 只在分链层,包含分链及其下级分片链所有数据节点

)

func ChooseConNetByEpoch

func ChooseConNetByEpoch(num EpochNum) NetType

func (NetType) String

func (n NetType) String() string

type NodeID

type NodeID [NodeIDBytes]byte

func BytesToNodeID

func BytesToNodeID(b []byte) NodeID

func GenerateNodeID

func GenerateNodeID() *NodeID

func ParseBytesToNodeIds

func ParseBytesToNodeIds(s []byte) ([]NodeID, error)

func ParseNodeID

func ParseNodeID(nodeString string) (*NodeID, error)

func ParseNodeIDBytes

func ParseNodeIDBytes(nodeBytes []byte) (*NodeID, error)

func PubToNodeID

func PubToNodeID(pub []byte) (NodeID, error)

func StringsToNodeIDs

func StringsToNodeIDs(strings []string) ([]NodeID, error)

func (*NodeID) Bytes

func (nid *NodeID) Bytes() []byte

func (*NodeID) Clone

func (nid *NodeID) Clone() *NodeID

func (*NodeID) Compare

func (nid *NodeID) Compare(to *NodeID) int

func (*NodeID) Generate

func (nid *NodeID) Generate() error

func (NodeID) Hash

func (nid NodeID) Hash() Hash

func (*NodeID) HashValue

func (nid *NodeID) HashValue() ([]byte, error)

与Hash()方法兼容

func (NodeID) MarshalText

func (nid NodeID) MarshalText() ([]byte, error)

func (NodeID) New

func (nid NodeID) New() *NodeID

func (*NodeID) SetBytes

func (nid *NodeID) SetBytes(b []byte)

func (NodeID) String

func (nid NodeID) String() string

func (*NodeID) UnmarshalText

func (nid *NodeID) UnmarshalText(input []byte) error

type NodeIDSet

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

func NewNodeIDSet

func NewNodeIDSet(ids ...*NodeID) *NodeIDSet

func (*NodeIDSet) Delete

func (ns *NodeIDSet) Delete(id *NodeID)

func (*NodeIDSet) Get

func (ns *NodeIDSet) Get(i int) (*NodeID, bool)

func (*NodeIDSet) GetIndex

func (ns *NodeIDSet) GetIndex(id *NodeID) (int, bool)

func (*NodeIDSet) GetNodeIDs

func (ns *NodeIDSet) GetNodeIDs(chainid ChainID) NodeIDs

func (*NodeIDSet) Len

func (ns *NodeIDSet) Len() int

func (*NodeIDSet) Less

func (ns *NodeIDSet) Less(i, j int) bool

func (*NodeIDSet) Put

func (ns *NodeIDSet) Put(id *NodeID) bool

func (*NodeIDSet) Swap

func (ns *NodeIDSet) Swap(i, j int)

type NodeIDs

type NodeIDs []NodeID

func ByteSlicesToNodeIDs

func ByteSlicesToNodeIDs(bss [][]byte) (NodeIDs, error)

func IdentifiersToNodeIDs

func IdentifiersToNodeIDs(nis []NodeIdentifier) NodeIDs

func (*NodeIDs) AppendByHex

func (ns *NodeIDs) AppendByHex(nidHex string) error

func (NodeIDs) Clone

func (ns NodeIDs) Clone() NodeIDs

func (NodeIDs) Contains

func (ns NodeIDs) Contains(nid NodeID) bool

func (NodeIDs) Equals

func (ns NodeIDs) Equals(os NodeIDs) bool

func (NodeIDs) IsIn

func (ns NodeIDs) IsIn(nid NodeID) bool

func (NodeIDs) Len

func (ns NodeIDs) Len() int

func (NodeIDs) Less

func (ns NodeIDs) Less(i, j int) bool

func (NodeIDs) Remove

func (ns NodeIDs) Remove(os NodeIDs) NodeIDs

func (NodeIDs) Swap

func (ns NodeIDs) Swap(i, j int)

func (NodeIDs) ToBytesSlice

func (ns NodeIDs) ToBytesSlice() [][]byte

func (NodeIDs) ToMap

func (ns NodeIDs) ToMap() map[NodeID]struct{}

func (NodeIDs) Union

func (ns NodeIDs) Union(os NodeIDs) NodeIDs

type NodeIdentifier

type NodeIdentifier interface {
	Cipherer
	NodeID() NodeID
	NodeIDP() *NodeID
}

节点

type NodeType

type NodeType byte
const (
	Consensus    NodeType = 0
	Data         NodeType = 1
	Memo         NodeType = 2
	NoneNodeType NodeType = 0xFF
)

func (NodeType) String

func (n NodeType) String() string

type RoutinePool

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

func NewRoutinePool

func NewRoutinePool(name string, routineSize int, queueSize int, workFunc WorkerFunc, keyGetter func(interface{}) string) *RoutinePool

func (*RoutinePool) PostHigher

func (p *RoutinePool) PostHigher(v interface{})

func (*RoutinePool) PostLower

func (p *RoutinePool) PostLower(v interface{})

func (*RoutinePool) Start

func (p *RoutinePool) Start()

func (*RoutinePool) Stop

func (p *RoutinePool) Stop()

type Seed

type Seed [SeedLength]byte

func BytesToSeed

func BytesToSeed(b []byte) Seed

func (*Seed) Byte

func (s *Seed) Byte() []byte

func (*Seed) Clone

func (s *Seed) Clone() *Seed

func (*Seed) Equals

func (s *Seed) Equals(v interface{}) bool

func (*Seed) Generate

func (s *Seed) Generate() error

func (*Seed) IsZero

func (s *Seed) IsZero() bool

func (*Seed) SetBytes

func (s *Seed) SetBytes(b []byte) *Seed

func (*Seed) String

func (s *Seed) String() string

type Service

type Service interface {
	String() string
	Init() error
	Start() error
	Close() error
}

type ServiceStateChanger

type ServiceStateChanger interface {
	Initializer() error
	Starter() error
	Closer() error
}

type ServiceStatus

type ServiceStatus byte
const (
	// 系统service状态
	SSCreated ServiceStatus = iota
	SSInitialized
	SSStarted
	SSStopped
)

func (*ServiceStatus) CheckInit

func (ss *ServiceStatus) CheckInit() error

func (*ServiceStatus) CheckStart

func (ss *ServiceStatus) CheckStart() error

func (*ServiceStatus) CheckStop

func (ss *ServiceStatus) CheckStop() error

type ShardInfo

type ShardInfo interface {
	GetMaskBits() uint           // 返回计算分片用到前面几位?
	LocalID() ChainID            // LocalID returns current chain/shard chainID
	AllIDs() []ChainID           // AllOthers returns all chainID besides local chainID
	ShardTo(interface{}) ChainID // ShardTo returns a shard chainID according to the parameter.
	Pos(id ChainID) int          // 传入的ChainID在Shard Group中的位置下标
}

func NewShardInfo

func NewShardInfo(parent ChainStruct, currentChain ChainID, shards []ChainID) ShardInfo

type WorkerFunc

type WorkerFunc func(workerName string, event interface{})

Directories

Path Synopsis
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
Package math provides integer math utilities.
Package math provides integer math utilities.

Jump to

Keyboard shortcuts

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