og

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 34 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.

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 = []uint32{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 Sha256 added in v0.0.2

func Sha256(bytes []byte) []byte

Types

type ActionTxHandler added in v0.0.2

type ActionTxHandler interface {
	HandleActionTx(request *p2p_message.MessageNewActionTx, perid string)
}

type Announcer

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

type ArchiveHandler added in v0.0.2

type ArchiveHandler interface {
	HandleArchive(request *p2p_message.MessageNewArchive, peerId string)
}

type BodiesRequestHandler

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

type BodiesResponseHandler

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

type CampaignHandler

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

type ConsensusDkgDealHandler

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

type ConsensusDkgDealResponseHandler

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

type ConsensusDkgGenesisPublicKeyHandler

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

type ConsensusDkgSigSetsHandler

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

type ConsensusPreCommitHandler

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

type ConsensusPreVoteHandler

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

type ConsensusProposalHandler

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

type ConsensusVerifier

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

consensus related verification

func (*ConsensusVerifier) Independent added in v0.0.2

func (v *ConsensusVerifier) Independent() bool

func (*ConsensusVerifier) Name

func (c *ConsensusVerifier) Name() string

func (*ConsensusVerifier) String added in v0.0.2

func (c *ConsensusVerifier) String() 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 *p2p_message.MessageControl, peerId string)
}

type DataLoader

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

func (*DataLoader) GenerateGenesis

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

func (*DataLoader) GenerateGenesisBalance

func (loader *DataLoader) GenerateGenesisBalance() map[common.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) GetByNonce added in v0.0.3

func (P *DummyTxPoolMiniTx) GetByNonce(addr common.Address, nonce uint64) 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) GetByNonce added in v0.0.3

func (f *FIFOTipGenerator) GetByNonce(addr common.Address, nonce uint64) types.Txi

func (*FIFOTipGenerator) GetRandomTips

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

func (*FIFOTipGenerator) IsBadSeq added in v0.0.3

func (f *FIFOTipGenerator) IsBadSeq(seq *tx_types.Sequencer) error

type FetchByHashHandlerRequest

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

type FetchByHashResponseHandler

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

type GetMsgHandler

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

type GetNodeDataMsgHandler

type GetNodeDataMsgHandler interface {
	HandleGetNodeDataMsg(peerId string)
}

type GetReceiptsMsgHandler

type GetReceiptsMsgHandler interface {
	HandleGetReceiptsMsg(peerId string)
}

type GetStateRoot added in v0.0.2

type GetStateRoot interface {
	PreConfirm(seq *tx_types.Sequencer) (hash common.Hash, err error)
}

type GraphVerifier

type GraphVerifier struct {
	Dag    IDag
	TxPool ITxPool
}

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

func (*GraphVerifier) Independent added in v0.0.2

func (v *GraphVerifier) Independent() bool

func (*GraphVerifier) Name

func (v *GraphVerifier) Name() string

func (*GraphVerifier) String added in v0.0.2

func (c *GraphVerifier) String() 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 *p2p_message.MessageHeaderRequest, peerID string)
}

type HeaderResponseHandler

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

type Hub

type Hub struct {
	CallbackRegistry     map[p2p_message.MessageType]func(*p2PMessage) // All callbacks
	CallbackRegistryOG02 map[p2p_message.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 common.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 common.Hash, seqId uint64, err error)

func (*Hub) BroadcastMessage

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

BroadcastMessage broadcast to whole network

func (*Hub) BroadcastMessageWithFilter

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

BroadcastMessage broadcast to whole network

func (h *Hub) BroadcastMessageWithLink(messageType p2p_message.MessageType, msg p2p_message.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 common.Hash, seqId uint64, err error)

func (*Hub) Init

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

func (*Hub) MulticastMessage

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

MulticastMessage multicast message to some peer

func (*Hub) MulticastToSource

func (h *Hub) MulticastToSource(messageType p2p_message.MessageType, msg p2p_message.Message, sourceMsgHash *common.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 common.Hashes) error

func (*Hub) RequestOneHeader

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

func (*Hub) SendBytesToPeer

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

func (*Hub) SendGetMsg

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

func (*Hub) SendToAnynomous

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

SendToAnynomous send msg by Anynomous

func (*Hub) SendToPeer

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

func (*Hub) SetEncryptionKey

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

func (*Hub) SetPeerHead

func (h *Hub) SetPeerHead(peerId string, hash common.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 common.Hash) types.Txi
	GetTxByNonce(addr common.Address, nonce uint64) types.Txi
	GetSequencerByHeight(id uint64) *tx_types.Sequencer
	GetTxisByNumber(id uint64) types.Txis
	LatestSequencer() *tx_types.Sequencer
	GetSequencer(hash common.Hash, id uint64) *tx_types.Sequencer
	Genesis() *tx_types.Sequencer
	GetHeight() uint64
	GetSequencerByHash(hash common.Hash) *tx_types.Sequencer
	GetBalance(addr common.Address, tokenID int32) *math.BigInt
	GetLatestNonce(addr common.Address) (uint64, error)
}

type ITxPool

type ITxPool interface {
	Get(hash common.Hash) types.Txi
	AddRemoteTx(tx types.Txi, noFeedBack bool) error
	RegisterOnNewTxReceived(c chan types.Txi, name string, allTx bool)
	GetLatestNonce(addr common.Address) (uint64, error)
	IsLocalHash(hash common.Hash) bool
	GetMaxWeight() uint64
	GetByNonce(addr common.Address, nonce uint64) types.Txi
	IsBadSeq(seq *tx_types.Sequencer) error
}

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 *p2p_message.MessageBodiesRequest, peerId string)

func (*IncomingMessageHandler) HandleBodiesResponse

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

func (*IncomingMessageHandler) HandleControlMsg

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

func (*IncomingMessageHandler) HandleFetchByHashRequest

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

func (*IncomingMessageHandler) HandleGetMsg

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

func (*IncomingMessageHandler) HandleHeaderRequest

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

func (*IncomingMessageHandler) HandleHeaderResponse

func (h *IncomingMessageHandler) HandleHeaderResponse(headerMsg *p2p_message.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 *p2p_message.MessageSequencerHeader, peerId string)

func (*IncomingMessageHandler) HandleTxsRequest

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

func (*IncomingMessageHandler) HandleTxsResponse

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

func (*IncomingMessageHandler) Name

func (m *IncomingMessageHandler) Name() string

func (*IncomingMessageHandler) RemoveControlMsgFromCache

func (h *IncomingMessageHandler) RemoveControlMsgFromCache(hash common.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
}

func (*MessageCounter) Get

func (m *MessageCounter) Get() uint32

get current request id

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
	ArchiveHandler                      ArchiveHandler
	ActionTxHandler                     ActionTxHandler
	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 p2p_message.MessageType, message p2p_message.Message)

BroadcastMessage send message to all peers

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

func (*MessageRouter) MulticastMessage

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

MulticastMessage send message to a randomly chosen peer

func (*MessageRouter) MulticastToSource

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

func (*MessageRouter) Name

func (m *MessageRouter) Name() string

func (*MessageRouter) RouteActionTx added in v0.0.2

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

func (*MessageRouter) RouteArchive added in v0.0.2

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

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) SendToPeer added in v0.0.3

func (m *MessageRouter) SendToPeer(peerId string, messageType p2p_message.MessageType, msg p2p_message.Message)

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 NewSequencerHandler

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

type NewTxHandler

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

type NewTxsHandler

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

type NodeDataMsgHandler

type NodeDataMsgHandler interface {
	HandleNodeDataMsg(peerId string)
}

type NodeStatus

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

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

type NodeStatusDataProvider

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

type OGConfig

type OGConfig struct {
	NetworkId   uint64
	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
	// 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() p2p_message.StatusData

func (*Og) GetHeight

func (og *Og) GetHeight() uint64

func (*Og) GetSequencerByHash

func (og *Og) GetSequencerByHash(hash common.Hash) *tx_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 common.Hash, seqId uint64, err error)
	GetPeerHead(peerId string) (hash common.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

type SequencerHeaderHandler

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

type Syncer

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

type TermChangeHandler

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

type TermChangeRequestHandler

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

type TermChangeResponseHandler

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

type TipGenerator

type TipGenerator interface {
	GetRandomTips(n int) (v []types.Txi)
	GetByNonce(addr common.Address, nonce uint64) types.Txi
	IsBadSeq(seq *tx_types.Sequencer) error
}

type TxBuffer

type TxBuffer struct {
	Verifiers []Verifier
	Syncer    Syncer
	Announcer Announcer

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

	OnProposalSeqCh chan common.Hash
	//children               *childrenCache //key : phash ,value :
	//HandlingQueue           txQueue
	TestNoVerify bool
	// 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) Dump added in v0.0.3

func (d *TxBuffer) Dump() string

func (*TxBuffer) DumpKnownCache added in v0.0.3

func (d *TxBuffer) DumpKnownCache() string

func (*TxBuffer) GetBenchmarks

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

func (*TxBuffer) GetFromAllKnownSource

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

func (*TxBuffer) GetFromBuffer

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

func (*TxBuffer) GetFromProviders

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

func (*TxBuffer) IsCachedHash

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

func (*TxBuffer) IsKnownHash

func (b *TxBuffer) IsKnownHash(hash common.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 common.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
	TestNoVerify                     bool
}

type TxCreator

type TxCreator struct {
	Miner              miner.Miner
	TipGenerator       TipGenerator // usually tx_pool
	MaxTxHash          common.Hash  // The difficultiy of TxHash
	MaxMinedHash       common.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

	NoVerifyMindHash  bool
	NoVerifyMaxTxHash bool
	GetStateRoot      GetStateRoot
	TxFormatVerifier  TxFormatVerifier
	// contains filtered or unexported fields
}

TxCreator creates tx and do the signing and mining

func (*TxCreator) GenerateSequencer

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

func (*TxCreator) GetArchiveNonce added in v0.0.2

func (t *TxCreator) GetArchiveNonce() uint64

func (*TxCreator) NewActionTxWithSeal added in v0.0.2

func (m *TxCreator) NewActionTxWithSeal(from common.Address, to common.Address, value *math.BigInt, action byte,
	nonce uint64, enableSpo bool, TokenId int32, tokenName string, pubkey crypto.PublicKey, sig crypto.Signature) (tx types.Txi, err error)

func (*TxCreator) NewArchiveWithSeal added in v0.0.2

func (m *TxCreator) NewArchiveWithSeal(data []byte) (tx types.Txi, err error)

func (*TxCreator) NewSignedSequencer

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

NewSignedSequencer this function is for test

func (*TxCreator) NewSignedTx

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

func (*TxCreator) NewTxWithSeal

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

func (*TxCreator) NewUnsignedSequencer

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

func (*TxCreator) NewUnsignedTx

func (m *TxCreator) NewUnsignedTx(from common.Address, to common.Address, value *math.BigInt, accountNonce uint64, tokenId int32) 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 {
	MaxTxHash         common.Hash // The difficulty of TxHash
	MaxMinedHash      common.Hash // The difficulty of MinedHash
	NoVerifyMindHash  bool
	NoVerifyMaxTxHash bool
	NoVerifySignatrue bool
}

func (*TxFormatVerifier) Independent added in v0.0.2

func (v *TxFormatVerifier) Independent() bool

func (*TxFormatVerifier) Name

func (v *TxFormatVerifier) Name() string

func (*TxFormatVerifier) SignatureValues added in v0.0.2

func (t *TxFormatVerifier) SignatureValues(sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

func (*TxFormatVerifier) String added in v0.0.2

func (c *TxFormatVerifier) String() 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 *p2p_message.MessageTxsRequest, peerID string)
}

type TxsResponseHandler

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

type Verifier

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

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