Documentation
¶
Overview ¶
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. * * The poly network is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The poly network is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with The poly network . If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- func CalcProducerDelay(number uint64, succession int, ctx *Context) uint64
- func GetCanonicalHeight(native *native.NativeService, chainID uint64) (height uint64, err error)
- func IsErrTooMuchChange(err error) bool
- func PutEpochSwitchInfo(service *native.NativeService, chainId uint64, info *CosmosEpochSwitchInfo)
- func SealHash(native *native.NativeService, header *eth.Header) (hash ecommon.Hash)
- func ValidatorListString(vals []*Validator) string
- func VerifyCosmosHeader(myHeader *CosmosHeader, info *CosmosEpochSwitchInfo) error
- type BorHandler
- type Context
- type CosmosEpochSwitchInfo
- type CosmosHeader
- type CosmosProof
- type CosmosProofValue
- type ExtraInfo
- type HeaderWithDifficultySum
- type HeaderWithOptionalProof
- type HeaderWithOptionalSnap
- type HeimdallHandler
- type MinimalVal
- type Snapshot
- type Span
- type TotalVotingPowerExceededError
- type Validator
- type ValidatorSet
- func (vals *ValidatorSet) Copy() *ValidatorSet
- func (vals *ValidatorSet) CopyIncrementProposerPriority(times int) *ValidatorSet
- func (vals *ValidatorSet) GetByAddress(address common.Address) (index int, val *Validator)
- func (vals *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)
- func (vals *ValidatorSet) GetProposer() (proposer *Validator)
- func (vals *ValidatorSet) HasAddress(address []byte) bool
- func (vals *ValidatorSet) IncrementProposerPriority(times int)
- func (vals *ValidatorSet) IsNilOrEmpty() bool
- func (vals *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)
- func (vals *ValidatorSet) RescalePriorities(diffMax int64)
- func (vals *ValidatorSet) Size() int
- func (vals *ValidatorSet) String() string
- func (vals *ValidatorSet) StringIndented(indent string) string
- func (vals *ValidatorSet) TotalVotingPower() int64
- func (vals *ValidatorSet) UpdateWithChangeSet(changes []*Validator) error
- type ValidatorsByAddress
Constants ¶
const ( MaxTotalVotingPower = int64(math.MaxInt64) / 8 PriorityWindowSizeFactor = 2 )
Variables ¶
This section is empty.
Functions ¶
func CalcProducerDelay ¶
CalcProducerDelay is the block delay algorithm based on block time, period, producerDelay and turn-ness of a signer
func GetCanonicalHeight ¶
func GetCanonicalHeight(native *native.NativeService, chainID uint64) (height uint64, err error)
GetCanonicalHeight ...
func IsErrTooMuchChange ¶
func PutEpochSwitchInfo ¶
func PutEpochSwitchInfo(service *native.NativeService, chainId uint64, info *CosmosEpochSwitchInfo)
func ValidatorListString ¶
ValidatorListString returns a prettified validator list for logging purposes.
func VerifyCosmosHeader ¶
func VerifyCosmosHeader(myHeader *CosmosHeader, info *CosmosEpochSwitchInfo) error
Types ¶
type BorHandler ¶
type BorHandler struct { }
BorHandler ...
func (*BorHandler) SyncBlockHeader ¶
func (h *BorHandler) SyncBlockHeader(native *native.NativeService) error
SyncBlockHeader ...
func (*BorHandler) SyncCrossChainMsg ¶
func (h *BorHandler) SyncCrossChainMsg(native *native.NativeService) error
SyncCrossChainMsg ...
func (*BorHandler) SyncGenesisHeader ¶
func (h *BorHandler) SyncGenesisHeader(native *native.NativeService) (err error)
SyncGenesisHeader ...
type CosmosEpochSwitchInfo ¶
type CosmosEpochSwitchInfo struct { // The height where validators set changed last time. Poly only accept // header and proof signed by new validators. That means the header // can not be lower than this height. Height int64 // Hash of the block at `Height`. Poly don't save the whole header. // So we can identify the content of this block by `BlockHash`. BlockHash polygonCmn.HexBytes // The hash of new validators set which used to verify validators set // committed with proof. NextValidatorsHash polygonCmn.HexBytes // The cosmos chain-id of this chain basing Cosmos-sdk. ChainID string }
func GetEpochSwitchInfo ¶
func GetEpochSwitchInfo(service *native.NativeService, chainId uint64) (*CosmosEpochSwitchInfo, error)
func (*CosmosEpochSwitchInfo) Deserialization ¶
func (info *CosmosEpochSwitchInfo) Deserialization(source *common.ZeroCopySource) error
func (*CosmosEpochSwitchInfo) Serialization ¶
func (info *CosmosEpochSwitchInfo) Serialization(sink *common.ZeroCopySink)
type CosmosHeader ¶
type CosmosHeader struct { Header polygonTypes.Header Commit *polygonTypes.Commit Valsets []*polygonTypes.Validator }
type CosmosProof ¶
type CosmosProof struct { Value CosmosProofValue Proof merkle.Proof Header CosmosHeader }
type CosmosProofValue ¶
type HeaderWithDifficultySum ¶
type HeaderWithDifficultySum struct { HeaderWithOptionalSnap *HeaderWithOptionalSnap `json:"headerWithOptionalSnap"` DifficultySum *big.Int `json:"difficultySum"` SnapParentHash *ecommon.Hash `json:"snapParentHash"` }
func GetCanonicalHeader ¶
func GetCanonicalHeader(native *native.NativeService, chainID uint64, height uint64) (headerWithSum *HeaderWithDifficultySum, err error)
GetCanonicalHeader ...
type HeaderWithOptionalProof ¶
type HeaderWithOptionalSnap ¶
HeaderWithOptionalSnap ...
type HeimdallHandler ¶
type HeimdallHandler struct { }
func (*HeimdallHandler) SyncBlockHeader ¶
func (h *HeimdallHandler) SyncBlockHeader(native *native.NativeService) error
func (*HeimdallHandler) SyncCrossChainMsg ¶
func (h *HeimdallHandler) SyncCrossChainMsg(native *native.NativeService) error
SyncCrossChainMsg ...
func (*HeimdallHandler) SyncGenesisHeader ¶
func (h *HeimdallHandler) SyncGenesisHeader(native *native.NativeService) (err error)
SyncGenesisHeader ...
type MinimalVal ¶
type MinimalVal struct { ID uint64 `json:"ID"` VotingPower uint64 `json:"power"` // TODO add 10^-18 here so that we dont overflow easily Signer common.Address `json:"signer"` }
MinimalVal is the minimal validator representation Used to send validator information to bor validator contract
func SortMinimalValByAddress ¶
func SortMinimalValByAddress(a []MinimalVal) []MinimalVal
SortMinimalValByAddress sorts validators
func ValidatorsToMinimalValidators ¶
func ValidatorsToMinimalValidators(vals []Validator) (minVals []MinimalVal)
ValidatorsToMinimalValidators converts array of validators to minimal validators
type Snapshot ¶
type Snapshot struct { Hash common.Hash `json:"hash"` // Block hash where the snapshot was created ValidatorSet *ValidatorSet `json:"validatorSet"` // Validator set at this moment }
Snapshot is the state of the authorization voting at a given point in time.
type Span ¶
type Span struct { ID uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id" yaml:"id"` StartBlock uint64 `protobuf:"varint,2,opt,name=start_block,json=startBlock,proto3" json:"start_block" yaml:"start_block"` EndBlock uint64 `protobuf:"varint,3,opt,name=end_block,json=endBlock,proto3" json:"end_block" yaml:"end_block"` ValidatorSet ValidatorSet `protobuf:"bytes,4,opt,name=validator_set,json=validatorSet,proto3" json:"validator_set" yaml:"validator_set"` SelectedProducers []Validator `` /* 128-byte string literal not displayed */ BorChainId string `protobuf:"bytes,6,opt,name=bor_chain_id,json=borChainId,proto3" json:"bor_chain_id" yaml:"bor_chain_id"` }
func SpanFromHeimdall ¶
func SpanFromHeimdall(hs *polygonTypes.HeimdallSpan) (span *Span, err error)
func VerifySpan ¶
func VerifySpan(native *native.NativeService, heimdallPolyChainID uint64, proof *CosmosProof) (span *Span, err error)
type TotalVotingPowerExceededError ¶
TotalVotingPowerExceededError is returned when the maximum allowed total voting power is exceeded
func (*TotalVotingPowerExceededError) Error ¶
func (e *TotalVotingPowerExceededError) Error() string
type Validator ¶
type Validator struct { ID uint64 `json:"ID"` Address common.Address `json:"signer"` VotingPower int64 `json:"power"` ProposerPriority int64 `json:"accum"` }
Validator represets Volatile state for each Validator
func NewValidator ¶
NewValidator creates new validator
func ParseValidators ¶
ParseValidators returns validator set bytes
func ValidatorFromHeimdall ¶
func ValidatorFromHeimdall(val *polygonTypes.HeimdallValidator) (v Validator, err error)
func (*Validator) Cmp ¶
Cmp returns the one validator with a higher ProposerPriority. If ProposerPriority is same, it returns the validator with lexicographically smaller address
func (*Validator) Copy ¶
Copy creates a new copy of the validator so we can mutate ProposerPriority. Panics if the validator is nil.
func (*Validator) HeaderBytes ¶
HeaderBytes return header bytes
func (*Validator) MinimalVal ¶
func (v *Validator) MinimalVal() MinimalVal
MinimalVal returns block number of last validator update
func (*Validator) PowerBytes ¶
PowerBytes return power bytes
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 - ie. the validators are sorted by their address. On the other hand, the .ProposerPriority of each validator and the designated .GetProposer() of a set changes every round, upon calling .IncrementProposerPriority(). NOTE: Not goroutine-safe. NOTE: All get/set to validators should copy the value for safety.
func NewValidatorSet ¶
func NewValidatorSet(valz []*Validator) *ValidatorSet
NewValidatorSet initializes a ValidatorSet by copying over the values from `valz`, a list of Validators. If valz is nil or empty, the new ValidatorSet will have an empty list of Validators. The addresses of validators in `valz` must be unique otherwise the function panics.
func ValidatorSetFromHeimdall ¶
func ValidatorSetFromHeimdall(hvs *polygonTypes.HeimdallValidatorSet) (bvs ValidatorSet, err error)
func (*ValidatorSet) Copy ¶
func (vals *ValidatorSet) Copy() *ValidatorSet
Copy each validator into a new ValidatorSet.
func (*ValidatorSet) CopyIncrementProposerPriority ¶
func (vals *ValidatorSet) CopyIncrementProposerPriority(times int) *ValidatorSet
Increment ProposerPriority and update the proposer on a copy, and return it.
func (*ValidatorSet) GetByAddress ¶
func (vals *ValidatorSet) GetByAddress(address common.Address) (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) GetProposer ¶
func (vals *ValidatorSet) GetProposer() (proposer *Validator)
GetProposer returns the current proposer. If the validator set is empty, nil is returned.
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) IncrementProposerPriority ¶
func (vals *ValidatorSet) IncrementProposerPriority(times int)
IncrementProposerPriority increments ProposerPriority of each validator and updates the proposer. Panics if validator set is empty. `times` must be positive.
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) RescalePriorities ¶
func (vals *ValidatorSet) RescalePriorities(diffMax int64)
func (*ValidatorSet) Size ¶
func (vals *ValidatorSet) Size() int
Size returns the length of the validator set.
func (*ValidatorSet) String ¶
func (vals *ValidatorSet) String() string
func (*ValidatorSet) StringIndented ¶
func (vals *ValidatorSet) StringIndented(indent string) string
func (*ValidatorSet) TotalVotingPower ¶
func (vals *ValidatorSet) TotalVotingPower() int64
TotalVotingPower returns the sum of the voting powers of all validators. It recomputes the total voting power if required.
func (*ValidatorSet) UpdateWithChangeSet ¶
func (vals *ValidatorSet) UpdateWithChangeSet(changes []*Validator) error
UpdateWithChangeSet attempts to update the validator set with 'changes'. It performs the following steps:
- validates the changes making sure there are no duplicates and splits them in updates and deletes
- verifies that applying the changes will not result in errors
- computes the total voting power BEFORE removals to ensure that in the next steps the priorities across old and newly added validators are fair
- computes the priorities of new validators against the final set
- applies the updates against the validator set
- applies the removals against the validator set
- performs scaling and centering of priority values
If an error is detected during verification steps, it is returned and the validator set is not changed.
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)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library.
|
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. |
common
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library.
|
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. |
secp256k1
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library.
|
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library. |