inter

package
v0.0.0-...-59e56fa Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonCanonicalEncoding = errors.New("Non canonical encoded event")
	ErrInvalidEncoding      = errors.New("Invalid encoded event")
)
View Source
var (
	// EmptyTxHash is hash of empty transactions list. Used to check that event doesn't have transactions not having full event.
	EmptyTxHash = types.DeriveSha(types.Transactions{})
)

Functions

func ASCIIschemeForEach

func ASCIIschemeForEach(
	scheme string,
	callback ForEachEvent,
) (
	nodes []idx.StakerID,
	events map[idx.StakerID][]*Event,
	names map[string]*Event,
)

ASCIIschemeToDAG parses events from ASCII-scheme for test purpose. Use joiners ║ ╬ ╠ ╣ ╫ ╚ ╝ ╩ and optional fillers ─ ═ to draw ASCII-scheme. Result:

  • nodes is an array of node addresses;
  • events maps node address to array of its events;
  • names maps human readable name to the event;

func ASCIIschemeToDAG

func ASCIIschemeToDAG(
	scheme string,
) (
	nodes []idx.StakerID,
	events map[idx.StakerID][]*Event,
	names map[string]*Event,
)

func DAGtoASCIIscheme

func DAGtoASCIIscheme(events Events) (string, error)

DAGtoASCIIscheme builds ASCII-scheme of events for debug purpose.

func FmtFrame

func FmtFrame(frame idx.Frame, isRoot bool) string

FmtFrame returns string representation.

func ForEachRandEvent

func ForEachRandEvent(
	nodes []idx.StakerID,
	eventCount int,
	parentCount int,
	r *rand.Rand,
	callback ForEachEvent,
) (
	events map[idx.StakerID][]*Event,
)

ForEachRandEvent generates random events for test purpose. Result:

  • callbacks are called for each new event;
  • events maps node address to array of its events;

func ForEachRandFork

func ForEachRandFork(
	nodes []idx.StakerID,
	cheatersArr []idx.StakerID,
	eventCount int,
	parentCount int,
	forksCount int,
	r *rand.Rand,
	callback ForEachEvent,
) (
	events map[idx.StakerID][]*Event,
)

ForEachRandFork generates random events with forks for test purpose. Result:

  • callbacks are called for each new event;
  • events maps node address to array of its events;

func GenNodes

func GenNodes(
	nodeCount int,
) (
	nodes []idx.StakerID,
)

GenNodes generates nodes. Result:

  • nodes is an array of node addresses;

func GenRandEvents

func GenRandEvents(
	nodes []idx.StakerID,
	eventCount int,
	parentCount int,
	r *rand.Rand,
) (
	events map[idx.StakerID][]*Event,
)

GenRandEvents generates random events for test purpose. Result:

  • events maps node address to array of its events;

Types

type Block

type Block struct {
	Index      idx.Block
	Time       Timestamp
	TxHash     common.Hash
	Events     hash.Events
	SkippedTxs []uint // indexes of skipped txs, starting from first tx of first event, ending with last tx of last event
	GasUsed    uint64

	PrevHash hash.Event

	Root    common.Hash
	Atropos hash.Event
}

Block is a "chain" block.

func NewBlock

func NewBlock(index idx.Block, time Timestamp, atropos hash.Event, prevHash hash.Event, events hash.Events) *Block

NewBlock makes block from topological ordered events.

type Cheaters

type Cheaters []idx.StakerID

Cheaters is a slice type for storing cheaters list.

func (Cheaters) GetRlp

func (s Cheaters) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (Cheaters) Len

func (s Cheaters) Len() int

Len returns the length of s.

func (Cheaters) Set

func (s Cheaters) Set() map[idx.StakerID]struct{}

Set returns map of cheaters

func (Cheaters) Swap

func (s Cheaters) Swap(i, j int)

Swap swaps the i'th and the j'th element in s.

type ConsensusCallbacks

type ConsensusCallbacks struct {
	// ApplyBlock is callback type to apply the new block to the state
	ApplyBlock func(block *Block, decidedFrame idx.Frame, cheaters Cheaters) (newAppHash common.Hash, sealEpoch bool)
	// SelectValidatorsGroup is a callback type to select new validators group.
	SelectValidatorsGroup func(oldEpoch, newEpoch idx.Epoch) (newValidators *pos.Validators)
	// OnEventConfirmed is callback type to notify about event confirmation.
	OnEventConfirmed func(event *EventHeaderData, seqDepth idx.Event)
	// IsEventAllowedIntoBlock is callback type to check is event may be within block or not
	IsEventAllowedIntoBlock func(event *EventHeaderData, seqDepth idx.Event) bool
}

ConsensusCallbacks contains callbacks called during block processing by consensus engine

type Event

type Event struct {
	EventHeader
	Transactions types.Transactions
	// contains filtered or unexported fields
}

Event is the graph vertex in the Lachesis consensus algorithm

func FakeFuzzingEvents

func FakeFuzzingEvents() (res []*Event)

FakeFuzzingEvents generates random independent events with the same epoch for testing purpose.

func NewEvent

func NewEvent() *Event

NewEvent constructs empty event

func (*Event) CalcSize

func (e *Event) CalcSize() int

CalcSize re-calculates event's size

func (*Event) DecodeRLP

func (e *Event) DecodeRLP(src *rlp.Stream) error

DecodeRLP implements rlp.Decoder interface. Its goal to override custom decoder of promoted field EventHeaderData.

func (*Event) EncodeRLP

func (e *Event) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder interface. Its goal to override custom encoder of promoted field EventHeaderData.

func (*Event) RecacheSize

func (e *Event) RecacheSize() int

RecacheSize re-calculates event's size and caches it

func (*Event) Sign

func (e *Event) Sign(signer func([]byte) ([]byte, error)) error

Sign event by signer.

func (*Event) SignBy

func (e *Event) SignBy(priv *ecdsa.PrivateKey) error

SignBy signs event by private key.

func (*Event) Size

func (e *Event) Size() int

Size returns cached event size

func (*Event) VerifySignature

func (e *Event) VerifySignature(address common.Address) bool

VerifySignature checks the signature against e.Creator.

type EventHeader

type EventHeader struct {
	EventHeaderData

	Sig []byte
}

EventHeader is the graph vertex in the Lachesis consensus algorithm Doesn't contain transactions, only their hash

func (*EventHeader) DecodeRLP

func (e *EventHeader) DecodeRLP(src *rlp.Stream) error

DecodeRLP implements rlp.Decoder interface. Its goal to override custom decoder of promoted field EventHeaderData.

func (*EventHeader) EncodeRLP

func (e *EventHeader) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder interface. Its goal to override custom encoder of promoted field EventHeaderData.

type EventHeaderData

type EventHeaderData struct {
	Version uint32 // serialization version

	Epoch idx.Epoch
	Seq   idx.Event

	Frame  idx.Frame
	IsRoot bool

	Creator idx.StakerID

	PrevEpochHash common.Hash
	Parents       hash.Events

	GasPowerLeft GasPowerLeft
	GasPowerUsed uint64

	Lamport     idx.Lamport
	ClaimedTime Timestamp
	MedianTime  Timestamp

	TxHash common.Hash

	Extra []byte
	// contains filtered or unexported fields
}

EventHeaderData is the graph vertex in the Lachesis consensus algorithm Doesn't contain transactions, only their hash Doesn't contain event signature

func (*EventHeaderData) CalcHash

func (e *EventHeaderData) CalcHash() hash.Event

CalcHash re-calculates event's ID

func (*EventHeaderData) DataToSign

func (e *EventHeaderData) DataToSign() []byte

DataToSign returns data which must be signed to sign the event

func (*EventHeaderData) DecodeRLP

func (e *EventHeaderData) DecodeRLP(src *rlp.Stream) error

DecodeRLP implements rlp.Decoder interface.

func (*EventHeaderData) EncodeRLP

func (e *EventHeaderData) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder interface.

func (*EventHeaderData) Hash

func (e *EventHeaderData) Hash() hash.Event

Hash returns cached event ID

func (*EventHeaderData) IsSelfParent

func (e *EventHeaderData) IsSelfParent(hash hash.Event) bool

IsSelfParent is true if specified ID is event's self-parent

func (*EventHeaderData) MarshalBinary

func (e *EventHeaderData) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*EventHeaderData) NoTransactions

func (e *EventHeaderData) NoTransactions() bool

NoTransactions is used to check that event doesn't have transactions not having full event.

func (*EventHeaderData) RecacheHash

func (e *EventHeaderData) RecacheHash() hash.Event

RecacheHash re-calculates event's ID and caches it

func (*EventHeaderData) SelfParent

func (e *EventHeaderData) SelfParent() *hash.Event

SelfParent returns event's self-parent, if any

func (*EventHeaderData) String

func (e *EventHeaderData) String() string

String returns string representation.

func (*EventHeaderData) UnmarshalBinary

func (e *EventHeaderData) UnmarshalBinary(raw []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler interface.

type Events

type Events []*Event

Events is a ordered slice of events.

func (Events) ByParents

func (ee Events) ByParents() (res Events)

ByParents returns events topologically ordered by parent dependency. Used only for tests.

func (Events) String

func (ee Events) String() string

String returns human readable representation.

type ForEachEvent

type ForEachEvent struct {
	Process func(e *Event, name string)
	Build   func(e *Event, name string) *Event
}

type GasPowerLeft

type GasPowerLeft struct {
	Gas [2]uint64
}

GasPowerLeft is long-term gas power left and short-term gas power left

func (*GasPowerLeft) Add

func (g *GasPowerLeft) Add(diff uint64)

Add add to all gas power lefts

func (*GasPowerLeft) Max

func (g *GasPowerLeft) Max() uint64

Max returns maximum within long-term gas power left and short-term gas power left

func (*GasPowerLeft) Min

func (g *GasPowerLeft) Min() uint64

Min returns minimum within long-term gas power left and short-term gas power left

func (*GasPowerLeft) String

func (g *GasPowerLeft) String() string

String returns string representation.

func (*GasPowerLeft) Sub

func (g *GasPowerLeft) Sub(diff uint64) *GasPowerLeft

Sub subtracts from all gas power lefts

type HeadersByCreator

type HeadersByCreator map[idx.StakerID]*EventHeaderData

HeadersByCreator is a event headers grouped by creator. ( creator --> event header )

func (HeadersByCreator) Bytes

func (hh HeadersByCreator) Bytes() []byte

Bytes gets the byte representation of the headers map.

func (*HeadersByCreator) DecodeRLP

func (hh *HeadersByCreator) DecodeRLP(s *rlp.Stream) error

DecodeRLP is for RLP deserialization.

func (HeadersByCreator) EncodeRLP

func (hh HeadersByCreator) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder interface.

type Timestamp

type Timestamp uint64

Timestamp is a logical time.

func BytesToTimestamp

func BytesToTimestamp(b []byte) Timestamp

BytesToTimestamp converts bytes to timestamp.

func FromUnix

func FromUnix(t int64) Timestamp

func MaxTimestamp

func MaxTimestamp(x, y Timestamp) Timestamp

MaxTimestamp return max value.

func (Timestamp) Bytes

func (t Timestamp) Bytes() []byte

Bytes gets the byte representation of the index.

func (Timestamp) Time

func (t Timestamp) Time() time.Time

func (Timestamp) Unix

func (t Timestamp) Unix() int64

Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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