Documentation ¶
Index ¶
- Constants
- Variables
- func Bytes2Hex(d []byte) string
- func BytesIntersection(a, b [][]byte) [][]byte
- func BytesIntersectionMap(a map[string]struct{}, b [][]byte) [][]byte
- func BytesToUint32(b []byte) uint32
- func CipherHash256(cipher cipher.Cipher, in ...[]byte) []byte
- func CloneByteSlice(bytes []byte) []byte
- func ConcatenateBytes(bss [][]byte) []byte
- func CopyBytes(b []byte) (copiedBytes []byte)
- func CopyBytesSlice(in [][]byte) [][]byte
- func DatabasePath(basePath string, id ChainID) string
- func EncodeAndHash(o interface{}) ([]byte, error)
- func ForPrint(v interface{}, poss ...int) []byte
- func ForPrintSlice(s []byte, startPos int, endPos int) []byte
- func ForPrintSliceString(v interface{}, maxSize ...int) string
- func ForPrintValue(val reflect.Value, startPos, endPos int) []byte
- func FormalizeBasePath(path string) string
- func FromHex(s string) []byte
- func HasHexPrefix(str string) bool
- func Hash256NoError(in ...[]byte) []byte
- func Hash256s(in ...[]byte) ([]byte, error)
- func HashEquals(h1, h2 *Hash) bool
- func HashLess(a, b Hash) bool
- func HashObject(o interface{}) ([]byte, error)
- func HashPair(a []byte, b []byte) []byte
- func HashRipemd160(data []byte) []byte
- func HashSliceEquals(h1, h2 []byte) bool
- func HashsEquals(hs1, hs2 []Hash) bool
- func HeaderIndexHash(posBuffer [13]byte, index byte) []byte
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func HexToPrivKey(h string) (cipher.ECCPrivateKey, error)
- func HomeDir() string
- func InitNodeIDMap(nodeids []NodeID)
- func InitShareObject(sopath string) *plugin.Plugin
- func IntToBytes(n int) []byte
- func IsHex(str string) bool
- func IsHexAddress(s string) bool
- func IsHexCharacter(c byte) bool
- func IsNilHash(bs []byte) bool
- func IsNodeIDIn(nidhs []Hash, nid NodeID) bool
- func KeyCount() map[string]int
- func LeftPadBytes(slice []byte, l int) []byte
- func MerkleHash(hashList [][]byte, toBeProof int, proofs *MerkleProofs) (root []byte, err error)
- func MerkleHashComplete(hashList [][]byte, toBeProof int, proofs *MerkleProofs) ([]byte, error)
- func PackNodeIdsToBytes(nodeIds []NodeID) []byte
- func ParseBytesToNodeIdBytes(s []byte) ([][]byte, error)
- func PointerSliceLess(slice interface{}, i, j int) (less bool, needCompare bool)
- func PrintBytesSlice(bss [][]byte, length int) string
- func PrivateToPublicSlice(priv []byte) ([]byte, error)
- func RandomBytes(length int) []byte
- func RegisterNoCheckAddress(addrs ...Address)
- func RegisterReservedAddress(addrs ...Address)
- func RegisterSystemContract(noGas bool, addrs ...Address)
- func ReverseBytes(bs []byte) []byte
- func RightPadBytes(slice []byte, l int) []byte
- func SignHash(hash []byte) (pub, sig []byte, err error)
- func SignMsg(msg interface{}) (pub, sig []byte, err error)
- func SplitBytes(bs []byte, size int) ([][]byte, error)
- func SystemHash256(in ...[]byte) []byte
- func ToHeaderPosHashBuffer(id ChainID, height Height) [13]byte
- func ValuesMerkleTreeHash(values interface{}, toBeProof int, proofs *MerkleProofs) (rootHash []byte, err error)
- func VerifyHash(hash, pub, sig []byte) bool
- func VerifyMsg(v interface{}, pub, sig []byte) bool
- func Watch(tp int)
- func WatchDelta(ovfl bool)
- func WatchHeight(id ChainID, height Height)
- type AbstractService
- type AccountSharding
- func (as AccountSharding) AllIDs() []ChainID
- func (as AccountSharding) GetMaskBits() uint
- func (as AccountSharding) LocalID() ChainID
- func (as AccountSharding) Number() int
- func (as AccountSharding) ParentID() ChainID
- func (as AccountSharding) Pos(id ChainID) int
- func (as AccountSharding) ShardTo(v interface{}) ChainID
- func (as *AccountSharding) String() string
- type AccountShards
- type Address
- func AddressFromPubSlice(pub []byte) (Address, error)
- func BigToAddress(b *big.Int) Address
- func BytesToAddress(b []byte) Address
- func BytesToAddressP(b []byte) *Address
- func CreateAddress(b Address, nonce uint64) Address
- func HexToAddress(s string) Address
- func StringsToAddresses(strings []string) []Address
- func (a Address) Big() *big.Int
- func (a Address) Bytes() []byte
- func (a Address) Clone() Address
- func (a *Address) Generate() error
- func (a Address) Hash() Hash
- func (a Address) Hex() string
- func (a Address) IsNoGas() bool
- func (a Address) IsReserved() bool
- func (a Address) IsSystemContract() bool
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) NoCheck() bool
- func (a *Address) SetBytes(b []byte)
- func (a Address) String() string
- func (a *Address) UnmarshalText(input []byte) error
- type AddressShard
- type Addresser
- type BitIndex
- type Bits
- type BlockNum
- type BootNode
- type ChainAttr
- type ChainAttrs
- func (a *ChainAttrs) Add(attrs ...ChainAttr) error
- func (a *ChainAttrs) AddByName(names ...string) error
- func (a ChainAttrs) Clone() ChainAttrs
- func (a ChainAttrs) Contains(attr ChainAttr) bool
- func (a ChainAttrs) FromMap(m map[ChainAttr]struct{}) ChainAttrs
- func (a ChainAttrs) Len() int
- func (a ChainAttrs) Less(i, j int) bool
- func (a ChainAttrs) Swap(i, j int)
- func (a ChainAttrs) ToMap() map[ChainAttr]struct{}
- func (a ChainAttrs) ToStringSlice() []string
- type ChainID
- func (id ChainID) Bytes() []byte
- func (id ChainID) Formalize() []byte
- func (id ChainID) HashValue() ([]byte, error)
- func (id ChainID) IsMain() bool
- func (id ChainID) IsNil() bool
- func (id ChainID) IsReserved() bool
- func (id ChainID) IsSub() bool
- func (id ChainID) IsUserDefined() bool
- func (id ChainID) String() string
- type ChainIDs
- type ChainInfos
- func (c *ChainInfos) AddBootNode(bootNode Dataserver) bool
- func (c *ChainInfos) AddDataNode(node NodeID) bool
- func (c *ChainInfos) AddrIsAdmin(addr Address) bool
- func (c *ChainInfos) Clone() *ChainInfos
- func (c *ChainInfos) GetDataNodes() []NodeID
- func (c *ChainInfos) HasAttribute(attr ChainAttr) bool
- func (c *ChainInfos) HasDataNode(nid NodeID) bool
- func (c *ChainInfos) Index(nid NodeID) int
- func (c *ChainInfos) IsGenesisDataNode(nid NodeID) bool
- func (c *ChainInfos) IsMainChain() bool
- func (c *ChainInfos) IsPocChain() bool
- func (c *ChainInfos) IsRewardChain() bool
- func (c *ChainInfos) Key() []byte
- func (c *ChainInfos) PubIsAdmin(pub []byte) bool
- func (c *ChainInfos) RemoveBootNode(node NodeID) bool
- func (c *ChainInfos) RemoveDataNode(node NodeID) bool
- func (c *ChainInfos) ReportTo() ChainID
- func (c *ChainInfos) Sort()
- func (c *ChainInfos) String() string
- type ChainInfosShouldBe
- type ChainMode
- type ChainStruct
- type Cipherer
- type CoinID
- type CommID
- type DataNode
- type DataNodes
- type Dataserver
- func (d *Dataserver) Clone() *Dataserver
- func (d Dataserver) Compare(o Dataserver) int
- func (d Dataserver) GetNodeID() (*NodeID, error)
- func (d *Dataserver) GetRpcAddr() string
- func (d *Dataserver) HashValue() ([]byte, error)
- func (d Dataserver) String() string
- func (d Dataserver) Validation() error
- type DvppError
- type DvppFormatError
- type ElectionType
- type Endpoint
- type EpochNum
- type EraNum
- type GasPool
- type Hash
- func BigToHash(b *big.Int) Hash
- func BytesToHash(b []byte) Hash
- func BytesToHashP(b []byte) *Hash
- func CopyHashs(hs []Hash) []Hash
- func EncodeHash(v interface{}) Hash
- func Hash256(v ...[]byte) Hash
- func Hash256WithError(v ...[]byte) (Hash, error)
- func Hash256p(v ...[]byte) *Hash
- func HexToHash(s string) Hash
- func NewHash(b []byte) *Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h *Hash) Clone() *Hash
- func (h *Hash) Equals(v *Hash) bool
- func (h Hash) Generate(rand *mrand.Rand, size int) reflect.Value
- func (h Hash) HashValue() ([]byte, error)
- func (h Hash) Hex() string
- func (h Hash) IsEmpty() bool
- func (h Hash) IsNil() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) PrintString() string
- func (h *Hash) SetBytes(b []byte)
- func (h *Hash) Slice() []byte
- func (h *Hash) SliceEqual(val []byte) bool
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h *Hash) UnmarshalText(input []byte) error
- type Hasher
- type Height
- func (h Height) BlockNum() BlockNum
- func (h Height) Bytes() []byte
- func (h Height) Compare(o Height) int
- func (h Height) EpochNum() EpochNum
- func (h Height) EraNum() EraNum
- func (h Height) HashValue() ([]byte, error)
- func (h Height) IsLastOfEpoch() bool
- func (h Height) IsNil() bool
- func (h Height) Split() (epochNum EpochNum, blockNum BlockNum)
- func (h Height) String() string
- type Identifier
- type LastBlockMap
- type LruMap
- type MerkleProofs
- func (p *MerkleProofs) Append(h Hash, order bool)
- func (p *MerkleProofs) Clone() *MerkleProofs
- func (p *MerkleProofs) Deserialization(r io.Reader) (shouldBeNil bool, err error)
- func (p *MerkleProofs) Get(index int) (h Hash, order bool, err error)
- func (p *MerkleProofs) Key() (key uint64, ok bool)
- func (p *MerkleProofs) Len() int
- func (p *MerkleProofs) Order(i int) bool
- func (p *MerkleProofs) Proof(toBeProof Hash) ([]byte, error)
- func (p *MerkleProofs) Serialization(w io.Writer) error
- func (p MerkleProofs) String() string
- type NetInfo
- type NetType
- type NodeID
- func BytesToNodeID(b []byte) NodeID
- func GenerateNodeID() *NodeID
- func ParseBytesToNodeIds(s []byte) ([]NodeID, error)
- func ParseNodeID(nodeString string) (*NodeID, error)
- func ParseNodeIDBytes(nodeBytes []byte) (*NodeID, error)
- func PubToNodeID(pub []byte) (NodeID, error)
- func StringsToNodeIDs(strings []string) ([]NodeID, error)
- func (nid *NodeID) Bytes() []byte
- func (nid *NodeID) Clone() *NodeID
- func (nid *NodeID) Compare(to *NodeID) int
- func (nid *NodeID) Generate() error
- func (nid NodeID) Hash() Hash
- func (nid *NodeID) HashValue() ([]byte, error)
- func (nid NodeID) MarshalText() ([]byte, error)
- func (nid NodeID) New() *NodeID
- func (nid *NodeID) SetBytes(b []byte)
- func (nid NodeID) String() string
- func (nid *NodeID) UnmarshalText(input []byte) error
- type NodeIDSet
- func (ns *NodeIDSet) Delete(id *NodeID)
- func (ns *NodeIDSet) Get(i int) (*NodeID, bool)
- func (ns *NodeIDSet) GetIndex(id *NodeID) (int, bool)
- func (ns *NodeIDSet) GetNodeIDs(chainid ChainID) NodeIDs
- func (ns *NodeIDSet) Len() int
- func (ns *NodeIDSet) Less(i, j int) bool
- func (ns *NodeIDSet) Put(id *NodeID) bool
- func (ns *NodeIDSet) Swap(i, j int)
- type NodeIDs
- func (ns *NodeIDs) AppendByHex(nidHex string) error
- func (ns NodeIDs) Clone() NodeIDs
- func (ns NodeIDs) Contains(nid NodeID) bool
- func (ns NodeIDs) Equals(os NodeIDs) bool
- func (ns NodeIDs) IsIn(nid NodeID) bool
- func (ns NodeIDs) Len() int
- func (ns NodeIDs) Less(i, j int) bool
- func (ns NodeIDs) Remove(os NodeIDs) NodeIDs
- func (ns NodeIDs) Swap(i, j int)
- func (ns NodeIDs) ToBytesSlice() [][]byte
- func (ns NodeIDs) ToMap() map[NodeID]struct{}
- func (ns NodeIDs) Union(os NodeIDs) NodeIDs
- type NodeIdentifier
- type NodeType
- type RoutinePool
- type Seed
- type Service
- type ServiceStateChanger
- type ServiceStatus
- type ShardInfo
- type WorkerFunc
Constants ¶
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不同,流程完全一致
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 )
const ( // 监测事件类型 P2P = iota Event Block )
Variables ¶
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 // 是否以单链方式启动 )
var ( MainChainStruct = ChainStruct{ ID: MainChainID, ParentID: NilChainID, Mode: Root, } // TypeOfChainStructPtr = reflect.TypeOf((*ChainStruct)(nil)) TypeOfChainInfosPtr = reflect.TypeOf((*ChainInfos)(nil)) )
var ( RealCipher cipher.Cipher = cipher.NewCipher(cipher.SECP256K1SHA3) SystemPrivKey cipher.ECCPrivateKey // 节点私钥 ErrSignatureVerifyFailed = errors.New("signature verify failed") )
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) )
var (
DefaultRpcEndpoint = Endpoint{NetType: "tcp", Address: DefaultRpcAddress}
)
var ErrGasLimitReached = errors.New("gas limit reached")
Functions ¶
func BytesIntersection ¶
func BytesIntersectionMap ¶
func BytesToUint32 ¶
func CipherHash256 ¶
func CloneByteSlice ¶
func ConcatenateBytes ¶
将参数的 slice数组 首尾相接返回一个slice,允许nil和空,返回的slice不为nil
func CopyBytesSlice ¶
func DatabasePath ¶
func ForPrintSliceString ¶
func FormalizeBasePath ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func HasHexPrefix ¶
hasHexPrefix validates str begins with '0x' or '0X'.
func Hash256NoError ¶
func HashEquals ¶
func HashObject ¶
如果对象实现了common.Hasher接口,则直接使用HashValue()方法生成Hash值, 否则将对象序列化后进行Hash
func HashRipemd160 ¶
func HashSliceEquals ¶
func HashsEquals ¶
func HeaderIndexHash ¶
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func HexToPrivKey ¶
func InitNodeIDMap ¶
func InitNodeIDMap(nodeids []NodeID)
func InitShareObject ¶
func IntToBytes ¶
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
func IsHexCharacter ¶
isHexCharacter returns bool of c being a valid hexadecimal.
func IsNodeIDIn ¶
func LeftPadBytes ¶
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 ParseBytesToNodeIdBytes ¶
func PointerSliceLess ¶
当为一个指针类型对象slice进行排序时,需要编写的Less方法,其中前半部分是要判断i/j下标所指对 象是否为nil,nil会被认为最小,如果两个都为nil则认为相等。只有当两个均不为nil时才需要后续的 比较,此时不用再判断nil。 当needCompare返回false时,Less方法可以直接返回less值;否则,需要继续下标所指对象内容的比较
func PrintBytesSlice ¶
func PrivateToPublicSlice ¶
func RandomBytes ¶
func RegisterNoCheckAddress ¶
func RegisterNoCheckAddress(addrs ...Address)
func RegisterReservedAddress ¶
func RegisterReservedAddress(addrs ...Address)
func RegisterSystemContract ¶
func ReverseBytes ¶
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func SplitBytes ¶
按 size 长度分割 bs 为slice数组,每个slice长度都为size
func SystemHash256 ¶
func ToHeaderPosHashBuffer ¶
func ValuesMerkleTreeHash ¶
func ValuesMerkleTreeHash(values interface{}, toBeProof int, proofs *MerkleProofs) (rootHash []byte, err error)
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 (s AbstractService) Copy() AbstractService
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) 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 BigToAddress ¶
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddressP ¶
func CreateAddress ¶
CreateAddress creates an ethereum address given the bytes and the nonce
func HexToAddress ¶
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 (Address) IsReserved ¶
func (Address) IsSystemContract ¶
func (Address) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Address) SetBytes ¶
SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.
func (*Address) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type AddressShard ¶
func (*AddressShard) IsIn ¶
func (s *AddressShard) IsIn(addr Address) bool
func (*AddressShard) IsValid ¶
func (s *AddressShard) IsValid() bool
type Bits ¶
type Bits []byte
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 ChainAttrs ¶
type ChainAttrs []ChainAttr // 链可能具有的多种Attribute
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 (ChainID) IsReserved ¶
func (ChainID) IsUserDefined ¶
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) 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 ChainStruct ¶
type ChainStruct struct { ID ChainID `json:"id"` ParentID ChainID `json:"parentid"` Mode ChainMode `json:"mode"` }
TODO v1.5.0 链ID及父链ID组成了一颗以0链为根的逻辑链ID树。
根为0号主链,负责维护链结构及全局Seed;
主链的分片:可能存在的第二层,当子链达到一定数量时主链也可以分片,每个主链分片的ParentID都是0号主链, 这些主链分片主要负责接收、验证及打包各子链(包括子链的分片)上报的块头。
子链:所有业务的链,ParentID为0号主链。如果子链没有分片,则此链为实体链,需要定期向上级(主链无分片 时:向0号主链,主链有分片时:根据主链分片的属性设定计算得到的主链分片)上报块头。因为是实体链,链上完成 相应交易。
子链的分片:当子链账户过多或交易过大时,子链可以分裂为2个分片(每个分片还可以继续分裂,分片分裂仅代表 其用户段被分割到新的分片中,所有分片的ParentID都是相同的:子链ID)。当一个子链有了分片,该子链就成为虚拟 链,该虚拟链无需共识,所有分片仅需要该子链BootNode中的DataPort来组建数据网络。所有交易都发生在对应的分 片上。分片链的ParentID为子链ID,定期向上级(主链)汇报块头信息(同子链)。
分片的生成(初步想法):已存在的链A
新建2条链A1,A2,一个分片账户前缀Bit:0,一个账户前缀Bit:1
停A链,锁定数据
将链A数据复制给A1, A2(更简单一些,将链A的数据节点分一半给A1,另一半给A2,但是如何保证链A运行不受影响?)
选举A1,A2两条链的委员会
两条链选举全部成功后,启动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 DataNode ¶
type DataNode struct { NodeID NodeID // 节点ID IsGenesis bool // 是否为创世数据节点,仅为一个标示 RpcAddress string // 数据节点的RPC地址及端口(为了抗攻击,可以使用集群应用的地址代理一群全节点) }
链数据节点:
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 ¶
func NewDvppError ¶
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) RewardNeeded ¶
func (t ElectionType) RewardNeeded() bool
func (ElectionType) String ¶
func (t ElectionType) String() string
type Endpoint ¶
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.
type Hash ¶
type Hash [HashLength]byte
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHashP ¶
func Hash256WithError ¶
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash) PrintString ¶
func (*Hash) SetBytes ¶
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) SliceEqual ¶
func (Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type LastBlockMap ¶
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) Set ¶
func (m *LastBlockMap) Set(key ChainID, value Height)
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) 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 ¶
type NodeID ¶
type NodeID [NodeIDBytes]byte
func BytesToNodeID ¶
func GenerateNodeID ¶
func GenerateNodeID() *NodeID
func ParseBytesToNodeIds ¶
func ParseNodeID ¶
func ParseNodeIDBytes ¶
func PubToNodeID ¶
func StringsToNodeIDs ¶
func (NodeID) MarshalText ¶
func (*NodeID) UnmarshalText ¶
type NodeIDSet ¶
type NodeIDSet struct {
// contains filtered or unexported fields
}
func NewNodeIDSet ¶
func (*NodeIDSet) GetNodeIDs ¶
type NodeIDs ¶
type NodeIDs []NodeID
func ByteSlicesToNodeIDs ¶
func IdentifiersToNodeIDs ¶
func IdentifiersToNodeIDs(nis []NodeIdentifier) NodeIDs
func (*NodeIDs) AppendByHex ¶
func (NodeIDs) ToBytesSlice ¶
type NodeIdentifier ¶
节点
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 ServiceStateChanger ¶
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{})