og

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	NormalMode uint8 = iota
	FeedBackMode
)
View Source
const (
	OG01 = 01
	OG02 = 02
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
)
View Source
const (
	DuplicateMsgPeerNum = 5
)
View Source
const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message

Variables

ProtocolLengths are the number of implemented message corresponding to different protocol versions.

View Source
var ProtocolName = "og"

ProtocolName is the official short name of the protocol used during capability negotiation.

View Source
var ProtocolVersions = []uint{OG02, OG01}

ProtocolVersions are the supported versions of the og protocol (first is primary).

Functions

func CreateDB

func CreateDB() (ogdb.Database, error)

func GetOldDb

func GetOldDb() (ogdb.Database, error)

func InitLoggers

func InitLoggers(logger *logrus.Logger, logdir string)

func MsgCountInit

func MsgCountInit()

Types

type Account

type Account struct{}

type Announcer

type Announcer interface {
	BroadcastNewTx(txi types.Txi)
}

type BodiesRequestHandler

type BodiesRequestHandler interface {
	HandleBodiesRequest(msgReq *types.MessageBodiesRequest, peerID string)
}

type BodiesResponseHandler

type BodiesResponseHandler interface {
	HandleBodiesResponse(request *types.MessageBodiesResponse, peerId string)
}

type CampaignHandler

type CampaignHandler interface {
	HandleCampaign(request *types.MessageCampaign, peerId string)
}

type ConsensusDkgDealHandler

type ConsensusDkgDealHandler interface {
	HandleConsensusDkgDeal(request *types.MessageConsensusDkgDeal, peerId string)
}

type ConsensusDkgDealResponseHandler

type ConsensusDkgDealResponseHandler interface {
	HandleConsensusDkgDealResponse(request *types.MessageConsensusDkgDealResponse, peerId string)
}

type ConsensusDkgGenesisPublicKeyHandler

type ConsensusDkgGenesisPublicKeyHandler interface {
	HandleConsensusDkgGenesisPublicKey(request *types.MessageConsensusDkgGenesisPublicKey, peerId string)
}

type ConsensusDkgSigSetsHandler

type ConsensusDkgSigSetsHandler interface {
	HandleConsensusDkgSigSets(request *types.MessageConsensusDkgSigSets, peerId string)
}

type ConsensusPreCommitHandler

type ConsensusPreCommitHandler interface {
	HandleConsensusPreCommit(request *types.MessagePreCommit, peerId string)
}

type ConsensusPreVoteHandler

type ConsensusPreVoteHandler interface {
	HandleConsensusPreVote(request *types.MessagePreVote, peerId string)
}

type ConsensusProposalHandler

type ConsensusProposalHandler interface {
	HandleConsensusProposal(request *types.MessageProposal, peerId string)
}

type ConsensusVerifier

type ConsensusVerifier struct {
	VerifyCampaign   func(cp *types.Campaign) bool
	VerifyTermChange func(cp *types.TermChange) bool
	VerifySequencer  func(cp *types.Sequencer) bool
}

consensus related verification

func (*ConsensusVerifier) Name

func (c *ConsensusVerifier) Name() string

func (*ConsensusVerifier) Verify

func (c *ConsensusVerifier) Verify(t types.Txi) bool

type ControlMsgCache

type ControlMsgCache struct {
	ExpireTime time.Duration
	// contains filtered or unexported fields
}

msg request cache ,don't send duplicate message

func (*ControlMsgCache) Len

func (c *ControlMsgCache) Len() int

type ControlMsgHandler

type ControlMsgHandler interface {
	HandleControlMsg(msg *types.MessageControl, peerId string)
}

type DataLoader

type DataLoader struct {
	Dag    *core.Dag
	TxPool *core.TxPool
}

func (*DataLoader) GenerateGenesis

func (d *DataLoader) GenerateGenesis() *types.Sequencer

func (*DataLoader) GenerateGenesisBalance

func (loader *DataLoader) GenerateGenesisBalance() map[types.Address]*math.BigInt

func (*DataLoader) LoadLocalData

func (d *DataLoader) LoadLocalData()

LoadLocalData will load all necessary data (db, status, etc) from local database. If there is no data or data corrupted, rebuild.

func (*DataLoader) Name

func (d *DataLoader) Name() string

func (*DataLoader) Start

func (d *DataLoader) Start()

func (*DataLoader) Stop

func (d *DataLoader) Stop()

type DummyTxPoolMiniTx

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

func (*DummyTxPoolMiniTx) Add

func (p *DummyTxPoolMiniTx) Add(v types.Txi)

func (*DummyTxPoolMiniTx) GetRandomTips

func (p *DummyTxPoolMiniTx) GetRandomTips(n int) (v []types.Txi)

func (*DummyTxPoolMiniTx) Init

func (d *DummyTxPoolMiniTx) Init()

type EncryptionLayer

type EncryptionLayer interface {
	SetEncryptionKey(priv *crypto.PrivateKey)
}

type FIFOTipGenerator

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

func NewFIFOTIpGenerator

func NewFIFOTIpGenerator(upstream TipGenerator, maxCacheSize int) *FIFOTipGenerator

func (*FIFOTipGenerator) GetRandomTips

func (f *FIFOTipGenerator) GetRandomTips(n int) (v []types.Txi)

type FetchByHashHandlerRequest

type FetchByHashHandlerRequest interface {
	HandleFetchByHashRequest(req *types.MessageSyncRequest, sourceID string)
}

type FetchByHashResponseHandler

type FetchByHashResponseHandler interface {
	HandleFetchByHashResponse(resp *types.MessageSyncResponse, sourceID string)
}

type GetMsgHandler

type GetMsgHandler interface {
	HandleGetMsg(msg *types.MessageGetMsg, peerId string)
}

type GetNodeDataMsgHandler

type GetNodeDataMsgHandler interface {
	HandleGetNodeDataMsg(peerId string)
}

type GetReceiptsMsgHandler

type GetReceiptsMsgHandler interface {
	HandleGetReceiptsMsg(peerId string)
}

type GraphVerifier

type GraphVerifier struct {
	Dag    IDag
	TxPool ITxPool
}

GraphVerifier verifies if the tx meets the OG hash and graph standards.

func (*GraphVerifier) Name

func (v *GraphVerifier) Name() string

func (*GraphVerifier) Verify

func (v *GraphVerifier) Verify(txi types.Txi) (ok bool)

Verify do the graph validation according to the following rules that are marked as [My job]. Graph standards: A1: [My job] Randomly choose 2 tips. A2: [Not used] Node's parent cannot be its grandparents or ancestors. A3: [My job] Nodes produced by same source must be sequential (tx nonce ++). A4: [------] Double spending once A3 is not followed, whatever there is actual double spending. A5: [Pool's job] If A3 is followed but there is still double spending (tx nonce collision), keep the forked tx with smaller hash A6: [My job] Node cannot reference two un-ordered nodes as its parents B1: [My job] Nodes that are confirmed by at least N (=2) sequencers cannot be referenced. B2: [My job] Two layer hash validation Basically Verify checks whether txs are in their nonce order

type HeaderRequestHandler

type HeaderRequestHandler interface {
	HandleHeaderRequest(request *types.MessageHeaderRequest, peerID string)
}

type HeaderResponseHandler

type HeaderResponseHandler interface {
	HandleHeaderResponse(headerMsg *types.MessageHeaderResponse, peerID string)
}

type Hub

type Hub struct {
	CallbackRegistry     map[MessageType]func(*p2PMessage) // All callbacks
	CallbackRegistryOG02 map[MessageType]func(*p2PMessage) // All callbacks of OG02
	StatusDataProvider   NodeStatusDataProvider

	SubProtocols []p2p.Protocol

	// new peer event
	OnNewPeerConnected []chan string
	Downloader         *downloader.Downloader
	Fetcher            *fetcher.Fetcher

	NodeInfo       func() *p2p.NodeInfo
	IsReceivedHash func(hash types.Hash) bool
	// contains filtered or unexported fields
}

Hub is the middle layer between p2p and business layer When there is a general request coming from the upper layer, Hub will find the appropriate peer to handle. When there is a message coming from p2p, Hub will unmarshall this message and give it to message router. Hub will also prevent duplicate requests/responses. If there is any failure, Hub is NOT responsible for changing a peer and retry. (maybe enhanced in the future.) DO NOT INVOLVE ANY BUSINESS LOGICS HERE.

func NewHub

func NewHub(config *HubConfig) *Hub

func (*Hub) BestPeerId

func (h *Hub) BestPeerId() (peerId string, err error)

func (*Hub) BestPeerInfo

func (h *Hub) BestPeerInfo() (peerId string, hash types.Hash, seqId uint64, err error)

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(messageType MessageType, msg types.Message)

BroadcastMessage broadcast to whole network

func (*Hub) BroadcastMessageWithFilter

func (h *Hub) BroadcastMessageWithFilter(messageType MessageType, msg types.Message)

BroadcastMessage broadcast to whole network

func (h *Hub) BroadcastMessageWithLink(messageType MessageType, msg types.Message)

BroadcastMessage broadcast to whole network

func (*Hub) GetBenchmarks

func (h *Hub) GetBenchmarks() map[string]interface{}

func (*Hub) GetPeerHead

func (h *Hub) GetPeerHead(peerId string) (hash types.Hash, seqId uint64, err error)

func (*Hub) Init

func (h *Hub) Init(config *HubConfig)

func (*Hub) MulticastMessage

func (h *Hub) MulticastMessage(messageType MessageType, msg types.Message)

MulticastMessage multicast message to some peer

func (*Hub) MulticastToSource

func (h *Hub) MulticastToSource(messageType MessageType, msg types.Message, sourceMsgHash *types.Hash)

MulticastToSource multicast msg to source , for example , send tx request to the peer which hash the tx

func (*Hub) Name

func (h *Hub) Name() string

func (*Hub) NodeStatus

func (h *Hub) NodeStatus() *NodeStatus

NodeInfo retrieves some protocol metadata about the running host node.

func (*Hub) PeersInfo

func (h *Hub) PeersInfo() []*PeerInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*Hub) RelayMessage

func (h *Hub) RelayMessage(msgOut *p2PMessage)

func (*Hub) RemovePeer

func (h *Hub) RemovePeer(id string)

func (*Hub) RequestBodies

func (h *Hub) RequestBodies(peerId string, hashs types.Hashes) error

func (*Hub) RequestOneHeader

func (h *Hub) RequestOneHeader(peerId string, hash types.Hash) error

func (*Hub) SendBytesToPeer

func (h *Hub) SendBytesToPeer(peerId string, messageType MessageType, msg []byte) error

func (*Hub) SendGetMsg

func (h *Hub) SendGetMsg(peerId string, msg *types.MessageGetMsg) error

func (*Hub) SendToAnynomous

func (h *Hub) SendToAnynomous(messageType MessageType, msg types.Message, anyNomousPubKey *crypto.PublicKey)

SendToAnynomous send msg by Anynomous

func (*Hub) SendToPeer

func (h *Hub) SendToPeer(peerId string, messageType MessageType, msg types.Message) error

func (*Hub) SetEncryptionKey

func (h *Hub) SetEncryptionKey(priv *crypto.PrivateKey)

func (*Hub) SetPeerHead

func (h *Hub) SetPeerHead(peerId string, hash types.Hash, number uint64) error

SetPeerHead is just a hack to set the latest seq number known of the peer This value ought not to be stored in peer, but an outside map. This has nothing related to p2p.

func (*Hub) Start

func (h *Hub) Start()

func (*Hub) Stop

func (h *Hub) Stop()

type HubConfig

type HubConfig struct {
	OutgoingBufferSize            int
	IncomingBufferSize            int
	MessageCacheMaxSize           int
	MessageCacheExpirationSeconds int
	MaxPeers                      int
	BroadCastMode                 uint8
	DisableEncryptGossip          bool
}

func DefaultHubConfig

func DefaultHubConfig() HubConfig

type IDag

type IDag interface {
	GetTx(hash types.Hash) types.Txi
	GetTxByNonce(addr types.Address, nonce uint64) types.Txi
	GetSequencerByHeight(id uint64) *types.Sequencer
	GetTxisByNumber(id uint64) types.Txis
	LatestSequencer() *types.Sequencer
	GetSequencer(hash types.Hash, id uint64) *types.Sequencer
	Genesis() *types.Sequencer
	GetHeight() uint64
	GetSequencerByHash(hash types.Hash) *types.Sequencer
	GetBalance(addr types.Address) *math.BigInt
}

type ITxPool

type ITxPool interface {
	Get(hash types.Hash) types.Txi
	AddRemoteTx(tx types.Txi, noFeedBack bool) error
	RegisterOnNewTxReceived(c chan types.Txi, name string, allTx bool)
	GetLatestNonce(addr types.Address) (uint64, error)
	IsLocalHash(hash types.Hash) bool
	GetMaxWeight() uint64
}

type IncomingMessageHandler

type IncomingMessageHandler struct {
	Og  *Og
	Hub *Hub

	TxEnable func() bool
	// contains filtered or unexported fields
}

IncomingMessageHandler is the default handler of all incoming messages for OG

func NewIncomingMessageHandler

func NewIncomingMessageHandler(og *Og, hub *Hub, cacheSize int, expireTime time.Duration) *IncomingMessageHandler

NewIncomingMessageHandler

func (*IncomingMessageHandler) GetBenchmarks

func (m *IncomingMessageHandler) GetBenchmarks() map[string]interface{}

func (*IncomingMessageHandler) HandleBodiesRequest

func (h *IncomingMessageHandler) HandleBodiesRequest(msgReq *types.MessageBodiesRequest, peerId string)

func (*IncomingMessageHandler) HandleBodiesResponse

func (h *IncomingMessageHandler) HandleBodiesResponse(request *types.MessageBodiesResponse, peerId string)

func (*IncomingMessageHandler) HandleControlMsg

func (h *IncomingMessageHandler) HandleControlMsg(req *types.MessageControl, sourceId string)

func (*IncomingMessageHandler) HandleFetchByHashRequest

func (h *IncomingMessageHandler) HandleFetchByHashRequest(syncRequest *types.MessageSyncRequest, peerId string)

func (*IncomingMessageHandler) HandleGetMsg

func (h *IncomingMessageHandler) HandleGetMsg(msg *types.MessageGetMsg, sourcePeerId string)

func (*IncomingMessageHandler) HandleHeaderRequest

func (h *IncomingMessageHandler) HandleHeaderRequest(query *types.MessageHeaderRequest, peerId string)

func (*IncomingMessageHandler) HandleHeaderResponse

func (h *IncomingMessageHandler) HandleHeaderResponse(headerMsg *types.MessageHeaderResponse, peerId string)

func (*IncomingMessageHandler) HandlePing

func (h *IncomingMessageHandler) HandlePing(peerId string)

func (*IncomingMessageHandler) HandlePong

func (h *IncomingMessageHandler) HandlePong()

func (*IncomingMessageHandler) HandleSequencerHeader

func (h *IncomingMessageHandler) HandleSequencerHeader(msgHeader *types.MessageSequencerHeader, peerId string)

func (*IncomingMessageHandler) HandleTxsRequest

func (h *IncomingMessageHandler) HandleTxsRequest(msgReq *types.MessageTxsRequest, peerId string)

func (*IncomingMessageHandler) HandleTxsResponse

func (h *IncomingMessageHandler) HandleTxsResponse(request *types.MessageTxsResponse)

func (*IncomingMessageHandler) Name

func (m *IncomingMessageHandler) Name() string

func (*IncomingMessageHandler) RemoveControlMsgFromCache

func (h *IncomingMessageHandler) RemoveControlMsgFromCache(hash types.Hash)

func (*IncomingMessageHandler) Start

func (m *IncomingMessageHandler) Start()

func (*IncomingMessageHandler) Stop

func (m *IncomingMessageHandler) Stop()

type IncomingMessageHandlerOG02

type IncomingMessageHandlerOG02 struct {
	Og  *Og
	Hub *Hub
}

IncomingMessageHandler is the default handler of all incoming messages for OG

func (*IncomingMessageHandlerOG02) HandleGetNodeDataMsg

func (h *IncomingMessageHandlerOG02) HandleGetNodeDataMsg(peerId string)

func (*IncomingMessageHandlerOG02) HandleGetReceiptsMsg

func (h *IncomingMessageHandlerOG02) HandleGetReceiptsMsg(peerId string)

func (*IncomingMessageHandlerOG02) HandleNodeDataMsg

func (h *IncomingMessageHandlerOG02) HandleNodeDataMsg(peerId string)

type ManagerConfig

type ManagerConfig struct {
	AcquireTxQueueSize uint // length of the channel for tx acquiring
	BatchAcquireSize   uint // length of the buffer for batch tx acquire for a single node
}

type MessageCounter

type MessageCounter struct {
	// contains filtered or unexported fields
}
var MsgCounter *MessageCounter

global msg counter , generate global msg request id

func (*MessageCounter) DecodeMsg

func (z *MessageCounter) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (MessageCounter) EncodeMsg

func (z MessageCounter) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MessageCounter) Get

func (m *MessageCounter) Get() uint32

get current request id

func (MessageCounter) MarshalMsg

func (z MessageCounter) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (MessageCounter) Msgsize

func (z MessageCounter) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MessageCounter) UnmarshalMsg

func (z *MessageCounter) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type MessageRouter

type MessageRouter struct {
	Hub                                 *Hub
	PingHandler                         PingHandler
	PongHandler                         PongHandler
	FetchByHashRequestHandler           FetchByHashHandlerRequest
	FetchByHashResponseHandler          FetchByHashResponseHandler
	NewTxHandler                        NewTxHandler
	NewTxsHandler                       NewTxsHandler
	NewSequencerHandler                 NewSequencerHandler
	GetMsgHandler                       GetMsgHandler
	ControlMsgHandler                   ControlMsgHandler
	SequencerHeaderHandler              SequencerHeaderHandler
	BodiesRequestHandler                BodiesRequestHandler
	BodiesResponseHandler               BodiesResponseHandler
	TxsRequestHandler                   TxsRequestHandler
	TxsResponseHandler                  TxsResponseHandler
	HeaderRequestHandler                HeaderRequestHandler
	HeaderResponseHandler               HeaderResponseHandler
	CampaignHandler                     CampaignHandler
	TermChangeHandler                   TermChangeHandler
	ConsensusDkgDealHandler             ConsensusDkgDealHandler
	ConsensusDkgDealResponseHandler     ConsensusDkgDealResponseHandler
	ConsensusDkgSigSetsHandler          ConsensusDkgSigSetsHandler
	ConsensusDkgGenesisPublicKeyHandler ConsensusDkgGenesisPublicKeyHandler
	ConsensusProposalHandler            ConsensusProposalHandler
	ConsensusPreVoteHandler             ConsensusPreVoteHandler
	ConsensusPreCommitHandler           ConsensusPreCommitHandler
	TermChangeRequestHandler            TermChangeRequestHandler
	TermChangeResponseHandler           TermChangeResponseHandler
}

MessageRouter is a bridge between hub and components

func (*MessageRouter) BroadcastMessage

func (m *MessageRouter) BroadcastMessage(messageType MessageType, message types.Message)

BroadcastMessage send message to all peers

func (m *MessageRouter) BroadcastMessageWithLink(messageType MessageType, message types.Message)

func (*MessageRouter) MulticastMessage

func (m *MessageRouter) MulticastMessage(messageType MessageType, message types.Message)

MulticastMessage send message to a randomly chosen peer

func (*MessageRouter) MulticastToSource

func (m *MessageRouter) MulticastToSource(messageType MessageType, message types.Message, sourceMsgHash *types.Hash)

func (*MessageRouter) Name

func (m *MessageRouter) Name() string

func (*MessageRouter) RouteBodiesRequest

func (m *MessageRouter) RouteBodiesRequest(msg *p2PMessage)

func (*MessageRouter) RouteBodiesResponse

func (m *MessageRouter) RouteBodiesResponse(msg *p2PMessage)

func (*MessageRouter) RouteCampaign

func (m *MessageRouter) RouteCampaign(msg *p2PMessage)

func (*MessageRouter) RouteConsensusDkgDeal

func (m *MessageRouter) RouteConsensusDkgDeal(msg *p2PMessage)

func (*MessageRouter) RouteConsensusDkgDealResponse

func (m *MessageRouter) RouteConsensusDkgDealResponse(msg *p2PMessage)

func (*MessageRouter) RouteConsensusDkgGenesisPublicKey

func (m *MessageRouter) RouteConsensusDkgGenesisPublicKey(msg *p2PMessage)

func (*MessageRouter) RouteConsensusDkgSigSets

func (m *MessageRouter) RouteConsensusDkgSigSets(msg *p2PMessage)

func (*MessageRouter) RouteConsensusPreCommit

func (m *MessageRouter) RouteConsensusPreCommit(msg *p2PMessage)

func (*MessageRouter) RouteConsensusPreVote

func (m *MessageRouter) RouteConsensusPreVote(msg *p2PMessage)

func (*MessageRouter) RouteConsensusProposal

func (m *MessageRouter) RouteConsensusProposal(msg *p2PMessage)

func (*MessageRouter) RouteControlMsg

func (m *MessageRouter) RouteControlMsg(msg *p2PMessage)

func (*MessageRouter) RouteFetchByHashRequest

func (m *MessageRouter) RouteFetchByHashRequest(msg *p2PMessage)

func (*MessageRouter) RouteFetchByHashResponse

func (m *MessageRouter) RouteFetchByHashResponse(msg *p2PMessage)

func (*MessageRouter) RouteGetMsg

func (m *MessageRouter) RouteGetMsg(msg *p2PMessage)

func (*MessageRouter) RouteHeaderRequest

func (m *MessageRouter) RouteHeaderRequest(msg *p2PMessage)

func (*MessageRouter) RouteHeaderResponse

func (m *MessageRouter) RouteHeaderResponse(msg *p2PMessage)

func (*MessageRouter) RouteNewSequencer

func (m *MessageRouter) RouteNewSequencer(msg *p2PMessage)

func (*MessageRouter) RouteNewTx

func (m *MessageRouter) RouteNewTx(msg *p2PMessage)

func (*MessageRouter) RouteNewTxs

func (m *MessageRouter) RouteNewTxs(msg *p2PMessage)

func (*MessageRouter) RoutePing

func (m *MessageRouter) RoutePing(msg *p2PMessage)

func (*MessageRouter) RoutePong

func (m *MessageRouter) RoutePong(*p2PMessage)

func (*MessageRouter) RouteSequencerHeader

func (m *MessageRouter) RouteSequencerHeader(msg *p2PMessage)

func (*MessageRouter) RouteTermChange

func (m *MessageRouter) RouteTermChange(msg *p2PMessage)

func (*MessageRouter) RouteTermChangeRequest

func (m *MessageRouter) RouteTermChangeRequest(msg *p2PMessage)

func (*MessageRouter) RouteTermChangeResponse

func (m *MessageRouter) RouteTermChangeResponse(msg *p2PMessage)

func (*MessageRouter) RouteTxsRequest

func (m *MessageRouter) RouteTxsRequest(msg *p2PMessage)

func (*MessageRouter) RouteTxsResponse

func (m *MessageRouter) RouteTxsResponse(msg *p2PMessage)

func (*MessageRouter) Start

func (m *MessageRouter) Start()

func (*MessageRouter) Stop

func (m *MessageRouter) Stop()

type MessageRouterOG02

type MessageRouterOG02 struct {
	GetNodeDataMsgHandler GetNodeDataMsgHandler
	NodeDataMsgHandler    NodeDataMsgHandler
	GetReceiptsMsgHandler GetReceiptsMsgHandler
}

func (*MessageRouterOG02) Name

func (m *MessageRouterOG02) Name() string

func (*MessageRouterOG02) RouteGetNodeDataMsg

func (m *MessageRouterOG02) RouteGetNodeDataMsg(msg *p2PMessage)

func (*MessageRouterOG02) RouteGetReceiptsMsg

func (m *MessageRouterOG02) RouteGetReceiptsMsg(msg *p2PMessage)

func (*MessageRouterOG02) RouteNodeDataMsg

func (m *MessageRouterOG02) RouteNodeDataMsg(msg *p2PMessage)

func (*MessageRouterOG02) Start

func (m *MessageRouterOG02) Start()

func (*MessageRouterOG02) Stop

func (m *MessageRouterOG02) Stop()

type MessageType

type MessageType uint16
const (
	// Protocol messages belonging to OG/01
	StatusMsg MessageType = iota
	MessageTypePing
	MessageTypePong
	MessageTypeFetchByHashRequest
	MessageTypeFetchByHashResponse
	MessageTypeNewTx
	MessageTypeNewSequencer
	MessageTypeNewTxs
	MessageTypeSequencerHeader

	MessageTypeBodiesRequest
	MessageTypeBodiesResponse

	MessageTypeTxsRequest
	MessageTypeTxsResponse
	MessageTypeHeaderRequest
	MessageTypeHeaderResponse

	//for optimizing network
	MessageTypeGetMsg
	MessageTypeDuplicate
	MessageTypeControl

	//for consensus
	MessageTypeCampaign
	MessageTypeTermChange

	//for consensus dkg
	MessageTypeConsensusDkgDeal
	MessageTypeConsensusDkgDealResponse
	MessageTypeConsensusDkgSigSets

	MessageTypeConsensusDkgGenesisPublicKey

	MessageTypeTermChangeRequest
	MessageTypeTermChangeResponse

	MessageTypeSecret //encrypted message

	MessageTypeProposal
	MessageTypePreVote
	MessageTypePreCommit

	MessageTypeOg01Length //og01 length

	GetNodeDataMsg
	NodeDataMsg
	GetReceiptsMsg
	MessageTypeOg02Length
)

og protocol message codes

func (MessageType) Code

func (mt MessageType) Code() p2p.MsgCodeType

func (*MessageType) DecodeMsg

func (z *MessageType) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (MessageType) EncodeMsg

func (z MessageType) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (MessageType) MarshalMsg

func (z MessageType) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (MessageType) Msgsize

func (z MessageType) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (MessageType) String

func (mt MessageType) String() string

func (*MessageType) UnmarshalMsg

func (z *MessageType) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type NewSequencerHandler

type NewSequencerHandler interface {
	HandleNewSequencer(msg *types.MessageNewSequencer, peerId string)
}

type NewTxHandler

type NewTxHandler interface {
	HandleNewTx(msg *types.MessageNewTx, peerId string)
}

type NewTxsHandler

type NewTxsHandler interface {
	HandleNewTxs(newTxs *types.MessageNewTxs, peerId string)
}

type NodeDataMsgHandler

type NodeDataMsgHandler interface {
	HandleNodeDataMsg(peerId string)
}

type NodeStatus

type NodeStatus struct {
	Network    uint64     `json:"network"`    // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
	Difficulty *big.Int   `json:"difficulty"` // Total difficulty of the host's blockchain
	Genesis    types.Hash `json:"genesis"`    // SHA3 hash of the host's genesis block
	Head       types.Hash `json:"head"`       // SHA3 hash of the host's best owned block
}

NodeInfo represents a short summary of the Ethereum sub-protocol metadata known about the host peer.

type NodeStatusDataProvider

type NodeStatusDataProvider interface {
	GetCurrentNodeStatus() StatusData
	GetHeight() uint64
}

type OGConfig

type OGConfig struct {
	NetworkId   uint64
	CryptoType  crypto.CryptoType
	GenesisPath string
}

func DefaultOGConfig

func DefaultOGConfig() OGConfig

type Og

type Og struct {
	Dag      *core.Dag
	TxPool   *core.TxPool
	Manager  *MessageRouter
	TxBuffer *TxBuffer

	NewLatestSequencerCh chan bool //for broadcasting new latest sequencer to record height

	NetworkId  uint64
	CryptoType crypto.CryptoType
	// contains filtered or unexported fields
}

func NewOg

func NewOg(config OGConfig) (*Og, error)

func (*Og) BroadcastLatestSequencer

func (og *Og) BroadcastLatestSequencer()

BroadcastLatestSequencer broadcast the newest sequencer header , seuqencer header is a network state , representing peer's height other peers will know our height and know whether thy were updated and sync with the best height

func (*Og) GetCurrentNodeStatus

func (og *Og) GetCurrentNodeStatus() StatusData

func (*Og) GetHeight

func (og *Og) GetHeight() uint64

func (*Og) GetSequencerByHash

func (og *Og) GetSequencerByHash(hash types.Hash) *types.Sequencer

func (*Og) Name

func (og *Og) Name() string

func (*Og) Start

func (og *Og) Start()

func (*Og) Stop

func (og *Og) Stop()

type PeerInfo

type PeerInfo struct {
	Version     int    `json:"version"`      // Ethereum protocol version negotiated
	SequencerId uint64 `json:"sequencer_id"` // Total difficulty of the peer's blockchain
	Head        string `json:"head"`         // SHA3 hash of the peer's best owned block
	ShortId     string `json:"short_id"`
	Link        bool   `json:"link"`
	Addrs       string `json:"addrs"`
	InBound     bool   `json:"in_bound"`
}

type PeerProvider

type PeerProvider interface {
	BestPeerInfo() (peerId string, hash types.Hash, seqId uint64, err error)
	GetPeerHead(peerId string) (hash types.Hash, seqId uint64, err error)
}

type PingHandler

type PingHandler interface {
	HandlePing(peerId string)
}

type PongHandler

type PongHandler interface {
	HandlePong()
}

type RequestCache

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

type SendingType

type SendingType uint8

func (*SendingType) DecodeMsg

func (z *SendingType) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (SendingType) EncodeMsg

func (z SendingType) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (SendingType) MarshalMsg

func (z SendingType) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (SendingType) Msgsize

func (z SendingType) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*SendingType) UnmarshalMsg

func (z *SendingType) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type SequencerHeaderHandler

type SequencerHeaderHandler interface {
	HandleSequencerHeader(msgHeader *types.MessageSequencerHeader, peerId string)
}

type StatusData

type StatusData struct {
	ProtocolVersion uint32
	NetworkId       uint64
	CurrentBlock    types.Hash
	GenesisBlock    types.Hash
	CurrentId       uint64
}

statusData is the network packet for the status message.

func (*StatusData) DecodeMsg

func (z *StatusData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*StatusData) EncodeMsg

func (z *StatusData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*StatusData) MarshalMsg

func (z *StatusData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*StatusData) Msgsize

func (z *StatusData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*StatusData) String

func (s *StatusData) String() string

func (*StatusData) UnmarshalMsg

func (z *StatusData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Syncer

type Syncer interface {
	Enqueue(hash *types.Hash, childHash types.Hash, sendBloomFilter bool)
	ClearQueue()
	IsCachedHash(hash types.Hash) bool
}

type TermChangeHandler

type TermChangeHandler interface {
	HandleTermChange(request *types.MessageTermChange, peerId string)
}

type TermChangeRequestHandler

type TermChangeRequestHandler interface {
	HandleTermChangeRequest(request *types.MessageTermChangeRequest, peerId string)
}

type TermChangeResponseHandler

type TermChangeResponseHandler interface {
	HandleTermChangeResponse(request *types.MessageTermChangeResponse, peerId string)
}

type TipGenerator

type TipGenerator interface {
	GetRandomTips(n int) (v []types.Txi)
}

type TxBuffer

type TxBuffer struct {
	Syncer    Syncer
	Announcer Announcer

	SelfGeneratedNewTxChan chan types.Txi
	ReceivedNewTxChan      chan types.Txi
	ReceivedNewTxsChan     chan []types.Txi

	OnProposalSeqCh chan types.Hash
	// contains filtered or unexported fields
}

TxBuffer rebuild graph by buffering newly incoming txs and find their parents. Tx will be buffered here until parents are got. Once the parents are got, Tx will be send to TxPool for further processing.

func NewTxBuffer

func NewTxBuffer(config TxBufferConfig) *TxBuffer

func (*TxBuffer) GetBenchmarks

func (b *TxBuffer) GetBenchmarks() map[string]interface{}

func (*TxBuffer) GetFromAllKnownSource

func (b *TxBuffer) GetFromAllKnownSource(hash types.Hash) types.Txi

func (*TxBuffer) GetFromBuffer

func (b *TxBuffer) GetFromBuffer(hash types.Hash) types.Txi

func (*TxBuffer) GetFromProviders

func (b *TxBuffer) GetFromProviders(hash types.Hash) types.Txi

func (*TxBuffer) IsCachedHash

func (b *TxBuffer) IsCachedHash(hash types.Hash) bool

func (*TxBuffer) IsKnownHash

func (b *TxBuffer) IsKnownHash(hash types.Hash) bool

isKnownHash tests if the tx is ever heard of, either in local or in buffer. if tx is known, do not broadcast anymore

func (*TxBuffer) IsReceivedHash

func (b *TxBuffer) IsReceivedHash(hash types.Hash) bool

func (*TxBuffer) Name

func (b *TxBuffer) Name() string

func (*TxBuffer) Start

func (b *TxBuffer) Start()

func (*TxBuffer) Stop

func (b *TxBuffer) Stop()

type TxBufferConfig

type TxBufferConfig struct {
	Dag                              IDag
	Verifiers                        []Verifier
	Syncer                           Syncer
	TxAnnouncer                      Announcer
	TxPool                           ITxPool
	DependencyCacheMaxSize           int
	DependencyCacheExpirationSeconds int
	NewTxQueueSize                   int
	KnownCacheMaxSize                int
	KnownCacheExpirationSeconds      int
	AddedToPoolQueueSize             int
}

type TxCreator

type TxCreator struct {
	Signer             crypto.Signer
	Miner              miner.Miner
	TipGenerator       TipGenerator // usually tx_pool
	MaxTxHash          types.Hash   // The difficultiy of TxHash
	MaxMinedHash       types.Hash   // The difficultiy of MinedHash
	MaxConnectingTries int          // Max number of times to find a pair of parents. If exceeded, try another nonce.
	DebugNodeId        int          // Only for debug. This value indicates tx sender and is temporarily saved to tx.height
	GraphVerifier      Verifier     // To verify the graph structure
	// contains filtered or unexported fields
}

TxCreator creates tx and do the signing and mining

func (*TxCreator) GenerateSequencer

func (m *TxCreator) GenerateSequencer(issuer types.Address, Height uint64, accountNonce uint64, privateKey *crypto.PrivateKey, blsPubKey []byte) (seq *types.Sequencer)

func (*TxCreator) NewSignedSequencer

func (m *TxCreator) NewSignedSequencer(issuer types.Address, height uint64, accountNonce uint64, privateKey crypto.PrivateKey) types.Txi

func (*TxCreator) NewSignedTx

func (m *TxCreator) NewSignedTx(from types.Address, to types.Address, value *math.BigInt, accountNonce uint64,
	privateKey crypto.PrivateKey) types.Txi

func (*TxCreator) NewTxWithSeal

func (m *TxCreator) NewTxWithSeal(from types.Address, to types.Address, value *math.BigInt, data []byte,
	nonce uint64, pubkey crypto.PublicKey, sig crypto.Signature) (tx types.Txi, err error)

func (*TxCreator) NewUnsignedSequencer

func (m *TxCreator) NewUnsignedSequencer(issuer types.Address, Height uint64, accountNonce uint64) *types.Sequencer

func (*TxCreator) NewUnsignedTx

func (m *TxCreator) NewUnsignedTx(from types.Address, to types.Address, value *math.BigInt, accountNonce uint64) types.Txi

func (*TxCreator) SealTx

func (m *TxCreator) SealTx(tx types.Txi, priveKey *crypto.PrivateKey) (ok bool)

SealTx do mining first, then pick up parents from tx pool which could leads to a proper hash. If there is no proper parents, Mine again.

func (*TxCreator) Stop

func (t *TxCreator) Stop()

type TxFormatVerifier

type TxFormatVerifier struct {
	Signer       crypto.Signer
	CryptoType   crypto.CryptoType
	MaxTxHash    types.Hash // The difficulty of TxHash
	MaxMinedHash types.Hash // The difficulty of MinedHash
}

func (*TxFormatVerifier) Name

func (v *TxFormatVerifier) Name() string

func (*TxFormatVerifier) Verify

func (v *TxFormatVerifier) Verify(t types.Txi) bool

func (*TxFormatVerifier) VerifyHash

func (v *TxFormatVerifier) VerifyHash(t types.Txi) bool

func (*TxFormatVerifier) VerifySignature

func (v *TxFormatVerifier) VerifySignature(t types.Txi) bool

func (*TxFormatVerifier) VerifySourceAddress

func (v *TxFormatVerifier) VerifySourceAddress(t types.Txi) bool

type TxsRequestHandler

type TxsRequestHandler interface {
	HandleTxsRequest(msgReq *types.MessageTxsRequest, peerID string)
}

type TxsResponseHandler

type TxsResponseHandler interface {
	HandleTxsResponse(request *types.MessageTxsResponse)
}

type Verifier

type Verifier interface {
	Verify(t types.Txi) bool
	Name() string
}

GraphVerifier verifies if the tx meets the standards

Directories

Path Synopsis
Package fetcher contains the sequencer announcement based synchronisation.
Package fetcher contains the sequencer announcement based synchronisation.

Jump to

Keyboard shortcuts

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