Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(vs ReaderWriter, vsOther Iterable) error

    Adds vsOther to vs

    func AddPower

    func AddPower(vs ReaderWriter, id crypto.PublicKey, power *big.Int) error

    func Subtract

    func Subtract(vs ReaderWriter, vsOther Iterable) error

      Subtracts vsOther from vs

      func SubtractPower

      func SubtractPower(vs ReaderWriter, id crypto.PublicKey, power *big.Int) error

      func Write

      func Write(vs Writer, vsOther Iterable) error

      Types

      type Bucket

      type Bucket struct {
      	// Delta tracks the changes to validator power made since the previous rotation
      	Delta *Set
      	// Previous the value for all validator powers at the point of the last rotation
      	// (the sum of all the deltas over all rotations) - these are the history of the complete validator sets at each rotation
      	Previous *Set
      	// Tracks the current working version of the next set; Previous + Delta
      	Next *Set
      	// Flow tracks the absolute value of all flows (difference between previous cum bucket and current delta) towards and away from each validator (tracking each validator separately to avoid double counting flows made against the same validator
      	Flow *Set
      }

      func NewBucket

      func NewBucket(initialSets ...Iterable) *Bucket

      func (*Bucket) CurrentSet

      func (vc *Bucket) CurrentSet() *Set

      func (*Bucket) Equal

      func (vc *Bucket) Equal(vwOther *Bucket) error

      func (*Bucket) Power

      func (vc *Bucket) Power(id crypto.Address) (*big.Int, error)

        Implement Reader

        func (*Bucket) SetPower

        func (vc *Bucket) SetPower(id crypto.PublicKey, power *big.Int) (*big.Int, error)

          SetPower ensures that validator power would not change too quickly in a single block

          func (*Bucket) String

          func (vc *Bucket) String() string

          type Cache

          type Cache struct {
          	*Bucket
          }

            Cache is just a Ring with no memory

            func NewCache

            func NewCache(backend Iterable) *Cache

            func (*Cache) Reset

            func (vc *Cache) Reset(backend Iterable)

            func (*Cache) Sync

            func (vc *Cache) Sync(output Writer) error

            type History

            type History interface {
            	ValidatorChanges(blocksAgo int) IterableReader
            	Validators(blocksAgo int) IterableReader
            }

            type Iterable

            type Iterable interface {
            	IterateValidators(func(id crypto.Addressable, power *big.Int) error) error
            }

            type IterableReader

            type IterableReader interface {
            	Reader
            	Iterable
            }

            type IterableReaderWriter

            type IterableReaderWriter interface {
            	ReaderWriter
            	Iterable
            }

            type Reader

            type Reader interface {
            	Power(id crypto.Address) (*big.Int, error)
            }

            type ReaderWriter

            type ReaderWriter interface {
            	Reader
            	Writer
            }

            type Ring

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

              Ring stores the validator power history in buckets as a riNng buffer. The primary storage is a the difference between each rotation (commit - i.e. block) in 'delta' and the cumulative result of each delta in cum, where the result of the delta at i is stored in the cum at i+1. For example suppose we have 4 buckets then graphically:

              delta [d1| d2 | d3 | d4 ] cum [v0|v0+d1|v0+d1+d2 |v0+d1+d2+d3 ]

              After the fourth rotation we loop back to the 0th bucket (with [pwer

              delta [d5 | d6| d7 | d8 ] cum [v0+d1+d2+d3+d4|...| | ]

              func NewRing

              func NewRing(initialSet Iterable, windowSize int) *Ring

                NewRing provides a sliding window over the last size buckets of validator power changes

                func (*Ring) CumulativePower

                func (vc *Ring) CumulativePower() *Set

                  CumulativePower gets the sum of all powers added in any bucket

                  func (*Ring) CurrentSet

                  func (vc *Ring) CurrentSet() *Set

                  func (*Ring) Equal

                  func (vc *Ring) Equal(vcOther *Ring) error

                  func (*Ring) GetPower

                  func (vc *Ring) GetPower(id crypto.Address) *big.Int

                  func (*Ring) Head

                  func (vc *Ring) Head() *Bucket

                    Get the current accumulator bucket

                    func (*Ring) Next

                    func (vc *Ring) Next() *Bucket

                    func (*Ring) OrderedBuckets

                    func (vc *Ring) OrderedBuckets() []*Bucket

                      Returns buckets in order head, previous, ...

                      func (*Ring) Power

                      func (vc *Ring) Power(id crypto.Address) (*big.Int, error)

                        Power gets the balance at index from the delta bucket then falling through to the cumulative

                        func (*Ring) PreviousDelta

                        func (vc *Ring) PreviousDelta(delay int) *Set

                        func (*Ring) PreviousSet

                        func (vc *Ring) PreviousSet(delay int) *Set

                        func (*Ring) ReIndex

                        func (vc *Ring) ReIndex(newHead int)

                        func (*Ring) Rotate

                        func (vc *Ring) Rotate() (totalPowerChange *big.Int, totalFlow *big.Int, err error)

                          Rotate the current head bucket to the next bucket and returns the change in total power between the previous bucket and the current head, and the total flow which is the sum of absolute values of all changes each validator's power after rotation the next head is a copy of the current head

                          func (*Ring) SetPower

                          func (vc *Ring) SetPower(id crypto.PublicKey, power *big.Int) (*big.Int, error)

                          func (*Ring) Size

                          func (vc *Ring) Size() int

                            Get the number of buckets in the ring (use Current().Count() to get the current number of validators)

                            func (*Ring) String

                            func (vc *Ring) String() string

                            func (*Ring) ValidatorChanges

                            func (vc *Ring) ValidatorChanges(blocksAgo int) IterableReader

                            func (*Ring) Validators

                            func (vc *Ring) Validators(blocksAgo int) IterableReader

                            type Set

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

                              A Validator multiset - can be used to capture the global state of validators or as an accumulator each block

                              func Copy

                              func Copy(vss ...Iterable) *Set

                                Copy each of iterable in vss into a new Set - note any iterations errors thrown by the iterable itself will be swallowed Use Write instead if source iterables may error

                                func CopyTrim

                                func CopyTrim(vss ...Iterable) *Set

                                func Diff

                                func Diff(before, after IterableReader) (*Set, error)

                                  Returns the asymmetric difference, diff, between two Sets such that applying diff to before results in after

                                  func NewSet

                                  func NewSet() *Set

                                    Create a new Validators which can act as an accumulator for validator power changes

                                    func NewTrimSet

                                    func NewTrimSet() *Set

                                      Like Set but removes entries when power is set to 0 this make Count() == CountNonZero() and prevents a set from leaking but does mean that a zero will not be iterated over when performing an update which is necessary in Ring

                                      func UnpersistSet

                                      func UnpersistSet(pvs []*Validator) *Set

                                      func (*Set) ChangePower

                                      func (vs *Set) ChangePower(id crypto.PublicKey, power *big.Int) *big.Int

                                        Add the power of a validator and returns the flow into that validator

                                        func (*Set) CountNonZero

                                        func (vs *Set) CountNonZero() int

                                        func (*Set) Equal

                                        func (vs *Set) Equal(vsOther *Set) error

                                          Returns an error if the Sets are not equal describing which part of their structures differ

                                          func (*Set) Flow

                                          func (vs *Set) Flow(id crypto.PublicKey, power *big.Int) *big.Int

                                            Returns the flow that would be induced by a validator power change

                                            func (*Set) Flush

                                            func (vs *Set) Flush(output Writer, backend Reader) error

                                            func (*Set) GetPower

                                            func (vs *Set) GetPower(id crypto.Address) *big.Int

                                              Error free version of Power

                                              func (*Set) IterateValidators

                                              func (vs *Set) IterateValidators(iter func(id crypto.Addressable, power *big.Int) error) error

                                                Iterates over validators sorted by address

                                                func (*Set) MaxFlow

                                                func (vs *Set) MaxFlow() *big.Int

                                                  Returns the maximum allowable flow whilst ensuring the majority of validators are non-byzantine after the transition So need at most ceiling((Total Power)/3) - 1, in integer division we have ceiling(X*p/q) = (p(X+1)-1)/q For p = 1 just X/q so we want (Total Power)/3 - 1

                                                  func (*Set) MaybePower

                                                  func (vs *Set) MaybePower(id crypto.Address) *big.Int

                                                    Returns the power of id but only if it is set

                                                    func (*Set) Power

                                                    func (vs *Set) Power(id crypto.Address) (*big.Int, error)

                                                      Version of Power to match interface

                                                      func (*Set) SetPower

                                                      func (vs *Set) SetPower(id crypto.PublicKey, power *big.Int) (*big.Int, error)

                                                        Implements Writer, but will never error

                                                        func (*Set) Size

                                                        func (vs *Set) Size() int

                                                        func (*Set) String

                                                        func (vs *Set) String() string

                                                        func (*Set) Strings

                                                        func (vs *Set) Strings() string

                                                        func (*Set) TotalPower

                                                        func (vs *Set) TotalPower() *big.Int

                                                        func (*Set) Validators

                                                        func (vs *Set) Validators() []*Validator

                                                        type Validator

                                                        type Validator struct {
                                                        	Address              *github_com_hyperledger_burrow_crypto.Address `protobuf:"bytes,1,opt,name=Address,proto3,customtype=github.com/hyperledger/burrow/crypto.Address" json:"Address,omitempty"`
                                                        	PublicKey            crypto.PublicKey                              `protobuf:"bytes,2,opt,name=PublicKey,proto3" json:"PublicKey"`
                                                        	Power                uint64                                        `protobuf:"varint,3,opt,name=Power,proto3" json:"Power,omitempty"`
                                                        	XXX_NoUnkeyedLiteral struct{}                                      `json:"-"`
                                                        	XXX_unrecognized     []byte                                        `json:"-"`
                                                        	XXX_sizecache        int32                                         `json:"-"`
                                                        }

                                                        func FromAccount

                                                        func FromAccount(acc *acm.Account, power uint64) *Validator

                                                        func New

                                                        func New(publicKey crypto.PublicKey, power *big.Int) *Validator

                                                        func (*Validator) BigPower

                                                        func (v *Validator) BigPower() *big.Int

                                                        func (*Validator) Descriptor

                                                        func (*Validator) Descriptor() ([]byte, []int)

                                                        func (*Validator) FillAddress

                                                        func (v *Validator) FillAddress()

                                                        func (*Validator) GetAddress

                                                        func (v *Validator) GetAddress() crypto.Address

                                                        func (*Validator) GetPower

                                                        func (m *Validator) GetPower() uint64

                                                        func (*Validator) GetPublicKey

                                                        func (m *Validator) GetPublicKey() crypto.PublicKey

                                                        func (*Validator) ProtoMessage

                                                        func (*Validator) ProtoMessage()

                                                        func (*Validator) Reset

                                                        func (m *Validator) Reset()

                                                        func (*Validator) Size

                                                        func (m *Validator) Size() (n int)

                                                        func (*Validator) String

                                                        func (v *Validator) String() string

                                                        func (*Validator) XXX_DiscardUnknown

                                                        func (m *Validator) XXX_DiscardUnknown()

                                                        func (*Validator) XXX_Marshal

                                                        func (m *Validator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

                                                        func (*Validator) XXX_Merge

                                                        func (m *Validator) XXX_Merge(src proto.Message)

                                                        func (*Validator) XXX_MessageName

                                                        func (*Validator) XXX_MessageName() string

                                                        func (*Validator) XXX_Size

                                                        func (m *Validator) XXX_Size() int

                                                        func (*Validator) XXX_Unmarshal

                                                        func (m *Validator) XXX_Unmarshal(b []byte) error

                                                        type Writer

                                                        type Writer interface {
                                                        	SetPower(id crypto.PublicKey, power *big.Int) (flow *big.Int, err error)
                                                        }