polygon

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: LGPL-3.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	MaxTotalVotingPower      = int64(math.MaxInt64) / 8
	PriorityWindowSizeFactor = 2
)

Variables

This section is empty.

Functions

func CalcProducerDelay

func CalcProducerDelay(number uint64, succession int, ctx *Context) uint64

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 IsErrTooMuchChange(err error) bool

func PutEpochSwitchInfo

func PutEpochSwitchInfo(service *native.NativeService, chainId uint64, info *CosmosEpochSwitchInfo)

func SealHash

func SealHash(header *types.Header) (hash ecommon.Hash)

SealHash returns the hash of a block prior to it being sealed.

func ValidatorListString

func ValidatorListString(vals []*Validator) string

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 NewBorHandler

func NewBorHandler() *BorHandler

NewHandler ...

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 Context

type Context struct {
	ExtraInfo ExtraInfo
	ChainID   uint64
	Cdc       *codec.Codec
}

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 CosmosProofValue struct {
	Kp    string
	Value []byte
}

type ExtraInfo

type ExtraInfo struct {
	Sprint              uint64
	Period              uint64
	ProducerDelay       uint64
	BackupMultiplier    uint64
	HeimdallPolyChainID uint64
}

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 HeaderWithOptionalProof struct {
	Header types.Header
	Proof  []byte
}

type HeaderWithOptionalSnap

type HeaderWithOptionalSnap struct {
	Header   types.Header
	Snapshot *Snapshot
}

HeaderWithOptionalSnap ...

type HeimdallHandler

type HeimdallHandler struct {
}

func NewHeimdallHandler

func NewHeimdallHandler() *HeimdallHandler

NewHeimdallHandler ...

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.

func (*Snapshot) Difficulty

func (s *Snapshot) Difficulty(signer common.Address) uint64

func (*Snapshot) GetSignerSuccessionNumber

func (s *Snapshot) GetSignerSuccessionNumber(signer common.Address) (int, error)

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

type TotalVotingPowerExceededError struct {
	Sum        int64
	Validators []*Validator
}

TotalVotingPowerExceededError is returned when the maximum allowed total voting power is exceeded

func (*TotalVotingPowerExceededError) Error

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

func NewValidator(address common.Address, votingPower int64) *Validator

NewValidator creates new validator

func ParseValidators

func ParseValidators(validatorsBytes []byte) ([]*Validator, error)

ParseValidators returns validator set bytes

func ValidatorFromHeimdall

func ValidatorFromHeimdall(val *polygonTypes.HeimdallValidator) (v Validator, err error)

func (*Validator) Cmp

func (v *Validator) Cmp(other *Validator) *Validator

Cmp returns the one validator with a higher ProposerPriority. If ProposerPriority is same, it returns the validator with lexicographically smaller address

func (*Validator) Copy

func (v *Validator) Copy() *Validator

Copy creates a new copy of the validator so we can mutate ProposerPriority. Panics if the validator is nil.

func (*Validator) HeaderBytes

func (v *Validator) HeaderBytes() []byte

HeaderBytes return header bytes

func (*Validator) MinimalVal

func (v *Validator) MinimalVal() MinimalVal

MinimalVal returns block number of last validator update

func (*Validator) PowerBytes

func (v *Validator) PowerBytes() []byte

PowerBytes return power bytes

func (*Validator) String

func (v *Validator) String() string

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)

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.

Jump to

Keyboard shortcuts

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