Documentation ¶
Index ¶
- Constants
- type CommitteeMember
- type ConsensusCommon
- func (cc *ConsensusCommon) AggregateSign(sigs []bls.Signature) bls.Signature
- func (cc *ConsensusCommon) AggregateSign2(sigs []bls.Signature) []byte
- func (cc *ConsensusCommon) AggregateVerify(sig bls.Signature, hashes [][32]byte, pubKeys []bls.PublicKey) (bool, error)
- func (cc *ConsensusCommon) Destroy() bool
- func (cc *ConsensusCommon) GetPairing() *bls.Pairing
- func (cc *ConsensusCommon) GetParams() *bls.Params
- func (cc *ConsensusCommon) GetPublicKey() *bls.PublicKey
- func (cc *ConsensusCommon) GetSystem() *bls.System
- func (cc *ConsensusCommon) Hash256Msg(msg []byte) [32]byte
- func (cc *ConsensusCommon) SignMessage(msg []byte) (bls.Signature, [32]byte)
- func (cc *ConsensusCommon) SignMessage2(msg []byte) ([]byte, [32]byte)
- func (cc *ConsensusCommon) VerifySignature(signature, msgHash, blsPK []byte) bool
- type Delegate
- type DelegateIntern
- type DelegateSet
- func (valSet *DelegateSet) Add(val *Delegate) (added bool)
- func (valSet *DelegateSet) Copy() *DelegateSet
- func (valSet *DelegateSet) GetByAddress(address []byte) (index int, val *Delegate)
- func (valSet *DelegateSet) GetByIndex(index int) (address []byte, val *Delegate)
- func (valSet *DelegateSet) HasAddress(address []byte) bool
- func (valSet *DelegateSet) Iterate(fn func(index int, val *Delegate) bool)
- func (valSet *DelegateSet) Remove(address []byte) (removedVal *Delegate, removed bool)
- func (valSet *DelegateSet) Size() int
- func (valSet *DelegateSet) String() string
- func (valSet *DelegateSet) StringIndented(indent string) string
- func (valSet *DelegateSet) TotalVotingPower() int64
- func (valSet *DelegateSet) Update(val *Delegate) (updated bool)
- type Distributor
- type NetAddress
- func (na *NetAddress) Dial() (net.Conn, error)
- func (na *NetAddress) DialString() string
- func (na *NetAddress) DialTimeout(timeout time.Duration) (net.Conn, error)
- func (na *NetAddress) Equals(other interface{}) bool
- func (na *NetAddress) Local() bool
- func (na *NetAddress) RFC1918() bool
- func (na *NetAddress) RFC3849() bool
- func (na *NetAddress) RFC3927() bool
- func (na *NetAddress) RFC3964() bool
- func (na *NetAddress) RFC4193() bool
- func (na *NetAddress) RFC4380() bool
- func (na *NetAddress) RFC4843() bool
- func (na *NetAddress) RFC4862() bool
- func (na *NetAddress) RFC6052() bool
- func (na *NetAddress) RFC6145() bool
- func (na *NetAddress) ReachabilityTo(o *NetAddress) int
- func (na *NetAddress) Routable() bool
- func (na *NetAddress) Same(other interface{}) bool
- func (na *NetAddress) String() string
- func (na *NetAddress) Valid() bool
- type Validator
- type ValidatorSet
- func (vals *ValidatorSet) Add(val *Validator) (added bool)
- func (vals *ValidatorSet) Copy() *ValidatorSet
- func (vals *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)
- func (vals *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)
- func (vals *ValidatorSet) HasAddress(address []byte) bool
- func (vals *ValidatorSet) IsNilOrEmpty() bool
- func (vals *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)
- func (vals *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)
- func (vals *ValidatorSet) Size() int
- func (v *ValidatorSet) String() string
- func (vals *ValidatorSet) TotalVotingPower() int64
- func (vals *ValidatorSet) Update(val *Validator) (updated bool)
- type ValidatorsByAddress
Constants ¶
const ( COMMISSION_RATE_MAX = uint64(100 * 1e07) // 100% COMMISSION_RATE_MIN = uint64(1 * 1e07) // 1% COMMISSION_RATE_DEFAULT = uint64(10 * 1e07) // 10% )
================================= commission rate 1% presents 1e07, unit is shannon (1e09)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommitteeMember ¶ added in v1.2.0
type CommitteeMember struct { Name string PubKey ecdsa.PublicKey NetAddr NetAddress CSPubKey bls.PublicKey CSIndex int }
CommitteeMember is validator structure + consensus fields
func NewCommitteeMember ¶ added in v1.2.0
func NewCommitteeMember() *CommitteeMember
create new committee member
func (*CommitteeMember) String ¶ added in v1.2.0
func (cm *CommitteeMember) String() string
func (*CommitteeMember) ToString ¶ added in v1.2.0
func (cm *CommitteeMember) ToString() string
type ConsensusCommon ¶ added in v1.2.0
type ConsensusCommon struct { PrivKey bls.PrivateKey //my private key PubKey bls.PublicKey //my public key //global params of BLS System bls.System Params bls.Params Pairing bls.Pairing Initialized bool }
func (*ConsensusCommon) AggregateSign ¶ added in v1.2.0
func (cc *ConsensusCommon) AggregateSign(sigs []bls.Signature) bls.Signature
func (*ConsensusCommon) AggregateSign2 ¶ added in v1.2.0
func (cc *ConsensusCommon) AggregateSign2(sigs []bls.Signature) []byte
func (*ConsensusCommon) AggregateVerify ¶ added in v1.2.0
func (cc *ConsensusCommon) AggregateVerify(sig bls.Signature, hashes [][32]byte, pubKeys []bls.PublicKey) (bool, error)
all voter sign the same msg.
func (*ConsensusCommon) Destroy ¶ added in v1.2.0
func (cc *ConsensusCommon) Destroy() bool
BLS is implemented by C, memeory need to be freed. Signatures also need to be freed but Not here!!!
func (*ConsensusCommon) GetPairing ¶ added in v1.2.0
func (cc *ConsensusCommon) GetPairing() *bls.Pairing
func (*ConsensusCommon) GetParams ¶ added in v1.2.0
func (cc *ConsensusCommon) GetParams() *bls.Params
func (*ConsensusCommon) GetPublicKey ¶ added in v1.2.0
func (cc *ConsensusCommon) GetPublicKey() *bls.PublicKey
func (*ConsensusCommon) GetSystem ¶ added in v1.2.0
func (cc *ConsensusCommon) GetSystem() *bls.System
func (*ConsensusCommon) Hash256Msg ¶ added in v1.2.0
func (cc *ConsensusCommon) Hash256Msg(msg []byte) [32]byte
sign the part of msg
func (*ConsensusCommon) SignMessage ¶ added in v1.2.0
func (cc *ConsensusCommon) SignMessage(msg []byte) (bls.Signature, [32]byte)
sign the part of msg
func (*ConsensusCommon) SignMessage2 ¶ added in v1.2.0
func (cc *ConsensusCommon) SignMessage2(msg []byte) ([]byte, [32]byte)
the return with slice byte
func (*ConsensusCommon) VerifySignature ¶ added in v1.2.0
func (cc *ConsensusCommon) VerifySignature(signature, msgHash, blsPK []byte) bool
type Delegate ¶
type Delegate struct { Name []byte `json:"name"` Address meter.Address `json:"address"` PubKey ecdsa.PublicKey `json:"pub_key"` BlsPubKey bls.PublicKey `json:"bsl_pubkey"` VotingPower int64 `json:"voting_power"` NetAddr NetAddress `json:"network_addr"` Commission uint64 `json:"commission"` DistList []*Distributor `json:"distibutor_list"` // contains filtered or unexported fields }
make sure to update that method if changes are made here
func NewDelegate ¶
func (*Delegate) Copy ¶
Creates a new copy of the Delegate so we can mutate accum. Panics if the Delegate is nil.
func (*Delegate) GetInternCombinePubKey ¶
func (*Delegate) SetInternCombinePublicKey ¶
type DelegateIntern ¶
type DelegateIntern struct { Name []byte Address meter.Address PubKey []byte //actually the comb of ecdsa & bls publickeys VotingPower int64 NetAddr NetAddress Commission uint64 DistList []*Distributor }
make sure to update that method if changes are made here
type DelegateSet ¶
type DelegateSet struct { // NOTE: persisted via reflect, must be exported. Delegates []*Delegate `json:"Delegates"` // contains filtered or unexported fields }
DelegateSet represent a set of *Delegate at a given height. The Delegates can be fetched by address or index. The index is in order of .Address, so the indices are fixed for all rounds of a given blockchain height. On the other hand, the .AccumPower of each Delegate and the designated .GetProposer() of a set changes every round, upon calling .IncrementAccum(). NOTE: Not goroutine-safe. NOTE: All get/set to Delegates should copy the value for safety.
func NewDelegateSet ¶
func NewDelegateSet(vals []*Delegate) *DelegateSet
func (*DelegateSet) Add ¶
func (valSet *DelegateSet) Add(val *Delegate) (added bool)
Add adds val to the Delegate set and returns true. It returns false if val is already in the set.
func (*DelegateSet) Copy ¶
func (valSet *DelegateSet) Copy() *DelegateSet
Copy each Delegate into a new DelegateSet
func (*DelegateSet) GetByAddress ¶
func (valSet *DelegateSet) GetByAddress(address []byte) (index int, val *Delegate)
GetByAddress returns an index of the Delegate with address and Delegate itself if found. Otherwise, -1 and nil are returned.
func (*DelegateSet) GetByIndex ¶
func (valSet *DelegateSet) GetByIndex(index int) (address []byte, val *Delegate)
GetByIndex returns the Delegate's address and Delegate itself by index. It returns nil values if index is less than 0 or greater or equal to len(DelegateSet.Delegates).
func (*DelegateSet) HasAddress ¶
func (valSet *DelegateSet) HasAddress(address []byte) bool
HasAddress returns true if address given is in the Delegate set, false - otherwise. DelegateSet is not sorted
func (*DelegateSet) Iterate ¶
func (valSet *DelegateSet) Iterate(fn func(index int, val *Delegate) bool)
Iterate will run the given function over the set.
func (*DelegateSet) Remove ¶
func (valSet *DelegateSet) Remove(address []byte) (removedVal *Delegate, removed bool)
Remove deletes the Delegate with address. It returns the Delegate removed and true. If returns nil and false if Delegate is not present in the set.
func (*DelegateSet) Size ¶
func (valSet *DelegateSet) Size() int
Size returns the length of the Delegate set.
func (*DelegateSet) String ¶
func (valSet *DelegateSet) String() string
func (*DelegateSet) StringIndented ¶
func (valSet *DelegateSet) StringIndented(indent string) string
String
func (*DelegateSet) TotalVotingPower ¶
func (valSet *DelegateSet) TotalVotingPower() int64
TotalVotingPower returns the sum of the voting powers of all Delegates.
func (*DelegateSet) Update ¶
func (valSet *DelegateSet) Update(val *Delegate) (updated bool)
Update updates val and returns true. It returns false if val is not present in the set.
type Distributor ¶
type NetAddress ¶
type NetAddress struct { IP net.IP `json:"ip"` Port uint16 `json:"port"` // contains filtered or unexported fields }
NetAddress defines information about a peer on the network including its ID, IP address, and port.
func NewNetAddress ¶
func NewNetAddress(addr net.Addr) *NetAddress
NewNetAddress returns a new NetAddress using the provided TCP address. When testing, other net.Addr (except TCP) will result in using 0.0.0.0:0. When normal run, other net.Addr (except TCP) will panic. TODO: socks proxies?
func NewNetAddressIPPort ¶
func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress
NewNetAddressIPPort returns a new NetAddress using the provided IP and port number.
func (*NetAddress) Dial ¶
func (na *NetAddress) Dial() (net.Conn, error)
Dial calls net.Dial on the address.
func (*NetAddress) DialString ¶
func (na *NetAddress) DialString() string
func (*NetAddress) DialTimeout ¶
DialTimeout calls net.DialTimeout on the address.
func (*NetAddress) Equals ¶
func (na *NetAddress) Equals(other interface{}) bool
Equals reports whether na and other are the same addresses, including their ID, IP, and Port.
func (*NetAddress) Local ¶
func (na *NetAddress) Local() bool
Local returns true if it is a local address.
func (*NetAddress) RFC1918 ¶
func (na *NetAddress) RFC1918() bool
func (*NetAddress) RFC3849 ¶
func (na *NetAddress) RFC3849() bool
func (*NetAddress) RFC3927 ¶
func (na *NetAddress) RFC3927() bool
func (*NetAddress) RFC3964 ¶
func (na *NetAddress) RFC3964() bool
func (*NetAddress) RFC4193 ¶
func (na *NetAddress) RFC4193() bool
func (*NetAddress) RFC4380 ¶
func (na *NetAddress) RFC4380() bool
func (*NetAddress) RFC4843 ¶
func (na *NetAddress) RFC4843() bool
func (*NetAddress) RFC4862 ¶
func (na *NetAddress) RFC4862() bool
func (*NetAddress) RFC6052 ¶
func (na *NetAddress) RFC6052() bool
func (*NetAddress) RFC6145 ¶
func (na *NetAddress) RFC6145() bool
func (*NetAddress) ReachabilityTo ¶
func (na *NetAddress) ReachabilityTo(o *NetAddress) int
ReachabilityTo checks whenever o can be reached from na.
func (*NetAddress) Routable ¶
func (na *NetAddress) Routable() bool
Routable returns true if the address is routable.
func (*NetAddress) Same ¶
func (na *NetAddress) Same(other interface{}) bool
Same returns true is na has the same non-empty ID or DialString as other.
func (*NetAddress) String ¶
func (na *NetAddress) String() string
String representation: <IP>:<PORT>
func (*NetAddress) Valid ¶
func (na *NetAddress) Valid() bool
For IPv4 these are either a 0 or all bits set address. For IPv6 a zero address or one that matches the RFC3849 documentation address format.
type Validator ¶
type Validator struct { Name string Address meter.Address PubKey ecdsa.PublicKey BlsPubKey bls.PublicKey VotingPower int64 NetAddr NetAddress CommitKey []byte }
Volatile state for each Validator NOTE: The Accum is not included in Validator.Hash(); make sure to update that method if changes are made here
func NewValidator ¶
type ValidatorSet ¶
type ValidatorSet struct { // NOTE: persisted via reflect, must be exported. Validators []*Validator `json:"validators"` Proposer *Validator `json:"proposer"` // contains filtered or unexported fields }
ValidatorSet represent a set of *Validator at a given height. The validators can be fetched by address or index. The index is in order of .Address, so the indices are fixed for all rounds of a given blockchain height. On the other hand, the .AccumPower of each validator and the designated .GetProposer() of a set changes every round, upon calling .IncrementAccum(). NOTE: Not goroutine-safe. NOTE: All get/set to validators should copy the value for safety.
func NewValidatorSet ¶
func NewValidatorSet(valz []*Validator) *ValidatorSet
func NewValidatorSet2 ¶
func NewValidatorSet2(vals []*Validator) *ValidatorSet
validator slice itself is sorted.
func (*ValidatorSet) Add ¶
func (vals *ValidatorSet) Add(val *Validator) (added bool)
Add adds val to the validator set and returns true. It returns false if val is already in the set.
func (*ValidatorSet) Copy ¶
func (vals *ValidatorSet) Copy() *ValidatorSet
Copy each validator into a new ValidatorSet
func (*ValidatorSet) GetByAddress ¶
func (vals *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)
GetByAddress returns an index of the validator with address and validator itself if found. Otherwise, -1 and nil are returned.
func (*ValidatorSet) GetByIndex ¶
func (vals *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)
GetByIndex returns the validator's address and validator itself by index. It returns nil values if index is less than 0 or greater or equal to len(ValidatorSet.Validators).
func (*ValidatorSet) HasAddress ¶
func (vals *ValidatorSet) HasAddress(address []byte) bool
HasAddress returns true if address given is in the validator set, false - otherwise.
func (*ValidatorSet) IsNilOrEmpty ¶
func (vals *ValidatorSet) IsNilOrEmpty() bool
Nil or empty validator sets are invalid.
func (*ValidatorSet) Iterate ¶
func (vals *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)
Iterate will run the given function over the set.
func (*ValidatorSet) Remove ¶
func (vals *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)
Remove deletes the validator with address. It returns the validator removed and true. If returns nil and false if validator is not present in the set.
func (*ValidatorSet) Size ¶
func (vals *ValidatorSet) Size() int
Size returns the length of the validator set.
func (*ValidatorSet) String ¶
func (v *ValidatorSet) String() string
func (*ValidatorSet) TotalVotingPower ¶
func (vals *ValidatorSet) TotalVotingPower() int64
TotalVotingPower returns the sum of the voting powers of all validators.
func (*ValidatorSet) Update ¶
func (vals *ValidatorSet) Update(val *Validator) (updated bool)
Update updates val and returns true. It returns false if val is not present in the set.
type ValidatorsByAddress ¶
type ValidatorsByAddress []*Validator
Sort validators by address
func (ValidatorsByAddress) Len ¶
func (valz ValidatorsByAddress) Len() int
func (ValidatorsByAddress) Less ¶
func (valz ValidatorsByAddress) Less(i, j int) bool
func (ValidatorsByAddress) Swap ¶
func (valz ValidatorsByAddress) Swap(i, j int)