chain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0, BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestProcessingStatusUnknown = RequestProcessingStatus(iota)
	RequestProcessingStatusBacklog
	RequestProcessingStatusCompleted
)
View Source
const (
	// confirmation time assumption. Average time from posting a transaction to finality
	ConfirmationTime = 10 * time.Second

	// additional period after committee quorum of connections is reached
	AdditionalConnectPeriod = 3 * time.Second

	// time tick for consensus and state manager objects
	TimerTickPeriod = 100 * time.Millisecond

	// retry delay for congested input channel for the consensus and state manager objects.channel.
	ReceiveMsgChannelRetryDelay = 500 * time.Millisecond

	RequestBalancesPeriod = 10 * time.Second

	// if node is behind the current state (not synced) it send GetBatch messages to pseudo-randomly
	// selected peer to get the batch it needs. Node expects answer, if not the message is repeated to another
	// peer after some time
	PeriodBetweenSyncMessages = 1 * time.Second

	// if pongs do not make a quorum, pings are repeated to all peer nodes
	RepeatPingAfter = 5 * time.Second

	// State Manager is requesting transaction to confirm a pending batch from the goshimmer node.
	// Request is repeated if necessary.
	StateTransactionRequestTimeout = 10 * time.Second

	// maximum time difference allowed between leader and local clocks for consensus
	MaxClockDifferenceAllowed = 3 * time.Second

	// check arg solidification period
	CheckArgSolidificationEvery = 1 * time.Second
)
View Source
const (
	MsgStateIndexPingPong      = 0 + peering.FirstUserMsgCode
	MsgNotifyRequests          = 1 + peering.FirstUserMsgCode
	MsgNotifyFinalResultPosted = 2 + peering.FirstUserMsgCode
	MsgStartProcessingRequest  = 3 + peering.FirstUserMsgCode
	MsgSignedHash              = 4 + peering.FirstUserMsgCode
	MsgGetBatch                = 5 + peering.FirstUserMsgCode
	MsgStateUpdate             = 6 + peering.FirstUserMsgCode
	MsgBatchHeader             = 7 + peering.FirstUserMsgCode
	MsgTestTrace               = 8 + peering.FirstUserMsgCode
)

Message types for the committee communications.

Variables

This section is empty.

Functions

func RegisterChainConstructor

func RegisterChainConstructor(constr chainConstructor)

Types

type BalancesMsg

type BalancesMsg struct {
	Balances map[valuetransaction.ID][]*balance.Balance
}

type BlockHeaderMsg

type BlockHeaderMsg struct {
	PeerMsgHeader
	Size                uint16
	AnchorTransactionID valuetransaction.ID
}

the header of the block message sent by peers in the process of syncing it is sent as a first message while syncing a batch

func (*BlockHeaderMsg) Read

func (msg *BlockHeaderMsg) Read(r io.Reader) error

func (*BlockHeaderMsg) Write

func (msg *BlockHeaderMsg) Write(w io.Writer) error

type Chain

type Chain interface {
	ID() *coretypes.ChainID
	Color() *balance.Color
	Address() address.Address
	Size() uint16
	Quorum() uint16
	OwnPeerIndex() uint16
	NumPeers() uint16
	SendMsg(targetPeerIndex uint16, msgType byte, msgData []byte) error
	SendMsgToCommitteePeers(msgType byte, msgData []byte, ts int64) uint16
	IsAlivePeer(peerIndex uint16) bool
	ReceiveMessage(msg interface{})
	InitTestRound()
	HasQuorum() bool
	PeerStatus() []*PeerStatus
	BlobCache() coretypes.BlobCache
	//
	SetReadyStateManager()
	SetReadyConsensus()
	Dismiss()
	IsDismissed() bool
	// requests
	GetRequestProcessingStatus(*coretypes.RequestID) RequestProcessingStatus
	EventRequestProcessed() *events.Event
	// chain processors
	Processors() *processors.ProcessorCache
}

func New

func New(
	chr *registry.ChainRecord,
	log *logger.Logger,
	netProvider peering.NetworkProvider,
	dksProvider tcrypto.RegistryProvider,
	blobProvider coretypes.BlobCache,
	onActivation func(),
) Chain

type GetBlockMsg

type GetBlockMsg struct {
	PeerMsgHeader
}

request block of updates from peer. Used in syn process

func (*GetBlockMsg) Read

func (msg *GetBlockMsg) Read(r io.Reader) error

func (*GetBlockMsg) Write

func (msg *GetBlockMsg) Write(w io.Writer) error

type NotifyFinalResultPostedMsg

type NotifyFinalResultPostedMsg struct {
	PeerMsgHeader
	TxId valuetransaction.ID
}

message is sent by the leader to all peers immediately after the final transaction is posted to the tangle. Main purpose of the message is to prevent unnecessary leader rotation in long confirmation times Final signature is sent to prevent possibility for a leader node to lie (is it necessary)

func (*NotifyFinalResultPostedMsg) Read

func (*NotifyFinalResultPostedMsg) Write

func (msg *NotifyFinalResultPostedMsg) Write(w io.Writer) error

type NotifyReqMsg

type NotifyReqMsg struct {
	PeerMsgHeader
	// list of request ids ordered by the time of arrival
	RequestIDs []coretypes.RequestID
}

message is sent to the leader of the state processing it is sent upon state change or upon arrival of the new request the receiving operator will ignore repeating messages

func (*NotifyReqMsg) Read

func (msg *NotifyReqMsg) Read(r io.Reader) error

func (*NotifyReqMsg) Write

func (msg *NotifyReqMsg) Write(w io.Writer) error

type Operator

type Operator interface {
	EventStateTransitionMsg(*StateTransitionMsg)
	EventBalancesMsg(BalancesMsg)
	EventRequestMsg(*RequestMsg)
	EventNotifyReqMsg(*NotifyReqMsg)
	EventStartProcessingBatchMsg(*StartProcessingBatchMsg)
	EventResultCalculated(msg *VMResultMsg)
	EventSignedHashMsg(*SignedHashMsg)
	EventNotifyFinalResultPostedMsg(*NotifyFinalResultPostedMsg)
	EventTransactionInclusionLevelMsg(msg *TransactionInclusionLevelMsg)
	EventTimerMsg(TimerTick)
	Close()
	//
	IsRequestInBacklog(*coretypes.RequestID) bool
}

type PeerMsgHeader

type PeerMsgHeader struct {
	// is set upon receive the message
	SenderIndex uint16
	// state index in the context of which the message is sent
	BlockIndex uint32
}

all peer messages have this

type PeerStatus

type PeerStatus struct {
	Index     int
	PeeringID string
	IsSelf    bool
	Connected bool
}

func (*PeerStatus) String

func (p *PeerStatus) String() string

type PendingBlockMsg

type PendingBlockMsg struct {
	Block state.Block
}

message of complete batch. Is sent by consensus operator to the state manager as a VM result - state manager to itself when batch is completed after syncing

type RequestMsg

type RequestMsg struct {
	*sctransaction.Transaction
	Index      uint16
	FreeTokens coretypes.ColoredBalances
}

func (*RequestMsg) RequestBlock

func (reqMsg *RequestMsg) RequestBlock() *sctransaction.RequestSection

func (*RequestMsg) RequestId

func (reqMsg *RequestMsg) RequestId() *coretypes.RequestID

func (*RequestMsg) Timelock

func (reqMsg *RequestMsg) Timelock() uint32

type RequestProcessingStatus

type RequestProcessingStatus int

type SignedHashMsg

type SignedHashMsg struct {
	PeerMsgHeader
	// timestamp of this message. Field is set upon receive the message to sender's timestamp
	Timestamp int64
	// returns hash of all req ids
	BatchHash hashing.HashValue
	// original timestamp, the parameter for calculations, which is signed as part of the essence
	OrigTimestamp int64
	// hash of the signed data (essence)
	EssenceHash hashing.HashValue
	// signature
	SigShare tbdn.SigShare
}

after calculations the result peer responds to the start processing msg with SignedHashMsg, which contains result hash and signatures

func (*SignedHashMsg) Read

func (msg *SignedHashMsg) Read(r io.Reader) error

func (*SignedHashMsg) Write

func (msg *SignedHashMsg) Write(w io.Writer) error

type StartProcessingBatchMsg

type StartProcessingBatchMsg struct {
	PeerMsgHeader
	// timestamp of the message. Field is set upon receive the message to sender's timestamp
	Timestamp int64
	// batch of request ids
	RequestIds []coretypes.RequestID
	// reward address
	FeeDestination coretypes.AgentID
	// balances/outputs
	Balances map[valuetransaction.ID][]*balance.Balance
}

message is sent by the leader to other peers to initiate request processing other peers are expected to check is timestamp is acceptable then process request batch and sign the result hash with the timestamp proposed by the leader

func (*StartProcessingBatchMsg) Read

func (msg *StartProcessingBatchMsg) Read(r io.Reader) error

func (*StartProcessingBatchMsg) Write

func (msg *StartProcessingBatchMsg) Write(w io.Writer) error

type StateIndexPingPongMsg

type StateIndexPingPongMsg struct {
	PeerMsgHeader
	RSVP bool
}

Ping is sent to receive Pong

func (*StateIndexPingPongMsg) Read

func (msg *StateIndexPingPongMsg) Read(r io.Reader) error

func (*StateIndexPingPongMsg) Write

func (msg *StateIndexPingPongMsg) Write(w io.Writer) error

type StateManager

type StateManager interface {
	EvidenceStateIndex(idx uint32)
	EventStateIndexPingPongMsg(msg *StateIndexPingPongMsg)
	EventGetBlockMsg(msg *GetBlockMsg)
	EventBlockHeaderMsg(msg *BlockHeaderMsg)
	EventStateUpdateMsg(msg *StateUpdateMsg)
	EventStateTransactionMsg(msg *StateTransactionMsg)
	EventPendingBlockMsg(msg PendingBlockMsg)
	EventTimerMsg(msg TimerTick)
	Close()
}

type StateTransactionEvidenced

type StateTransactionEvidenced struct {
	TxId      valuetransaction.ID
	StateHash hashing.HashValue
}

message is sent to the consensus manager after it receives state transaction which is valid but not confirmed yet.

type StateTransactionMsg

type StateTransactionMsg struct {
	*sctransaction.Transaction
}

type StateTransitionMsg

type StateTransitionMsg struct {
	// new variable state
	VariableState state.VirtualState
	// corresponding state transaction
	AnchorTransaction *sctransaction.Transaction
	// processed requests
	RequestIDs []*coretypes.RequestID
	// is the state index last seen
	Synchronized bool
}

state manager notifies consensus operator about changed state only sent internally within committee state transition is always from state N to state N+1

type StateUpdateMsg

type StateUpdateMsg struct {
	PeerMsgHeader
	// state update
	StateUpdate state.StateUpdate
	// position in a batch
	IndexInTheBlock uint16
}

state update sent to peer. Used in sync process, as part of batch

func (*StateUpdateMsg) Read

func (msg *StateUpdateMsg) Read(r io.Reader) error

func (*StateUpdateMsg) Write

func (msg *StateUpdateMsg) Write(w io.Writer) error

type TestTraceMsg

type TestTraceMsg struct {
	PeerMsgHeader
	InitTime      int64
	InitPeerIndex uint16
	Sequence      []uint16
	NumHops       uint16
}

used for testing of the communications

func (*TestTraceMsg) Read

func (msg *TestTraceMsg) Read(r io.Reader) error

func (*TestTraceMsg) Write

func (msg *TestTraceMsg) Write(w io.Writer) error

type TimerTick

type TimerTick int

type TransactionInclusionLevelMsg

type TransactionInclusionLevelMsg struct {
	TxId  *valuetransaction.ID
	Level byte
}

type VMResultMsg

type VMResultMsg struct {
	Task   *vm.VMTask
	Leader uint16
}

VMResultMsg is the message sent by the async VM task to the chan object upon success full finish

Directories

Path Synopsis
the file contains functions responsible for the request batch selection logic
the file contains functions responsible for the request batch selection logic
statemgr package implements object which is responsible for the smart contract ledger state to be synchronized and validated
statemgr package implements object which is responsible for the smart contract ledger state to be synchronized and validated

Jump to

Keyboard shortcuts

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