ising

package
v0.0.0-...-2cf7c70 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProbeFactor        = 1
	ResultFactor       = 3
	ProbeDuration      = config.ConsensusTime / ProbeFactor
	WaitForProbeResult = config.ConsensusTime / ResultFactor
	MsgChanCap         = 1

	// probe service will detect BlockNumDetected blocks of neighbor per time
	BlockNumDetected = 5

	// block detecting starts from height (current height - BlockDepthDetected)
	BlockDepthDetected = 10
)
View Source
const (
	TxnAmountToBePackaged      = 1024
	WaitingForFloodingFinished = time.Second * 1
	WaitingForVotingFinished   = time.Second * 5
	TimeoutTolerance           = time.Second * 2
)
View Source
const (
	InitialBlockHeight = 5
)

Variables

This section is empty.

Functions

func BuildIsingPayload

func BuildIsingPayload(msg IsingMessage, sender *crypto.PubKey) (*message.IsingPayload, error)

func HeightHashToString

func HeightHashToString(height uint32, blockHash Uint256) string

HeightHashToString uses block height and block hash to generate a uniq string

func StartIsingConsensus

func StartIsingConsensus(account *vault.Account, node protocol.Noder)

func StringToHeightHash

func StringToHeightHash(str string) (uint32, Uint256)

StringToHeightHash recovers block height and block hash from string which generated by HeightHashToString

Types

type BlockFlooding

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

func NewBlockFlooding

func NewBlockFlooding(block *ledger.Block) *BlockFlooding

func (*BlockFlooding) Deserialize

func (bf *BlockFlooding) Deserialize(r io.Reader) error

func (*BlockFlooding) Serialize

func (bf *BlockFlooding) Serialize(w io.Writer) error

type BlockHistoryPayload

type BlockHistoryPayload struct {
	StartHeight uint32
	BlockNum    uint32
}

Contains block history [StartHeight, StartHeight + BlockNum) to be detected

type BlockInfo

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

type BlockWithVotes

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

BlockWithVotes describes cached block with votes got from neighbors.

type BuiltinMining

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

func NewBuiltinMining

func NewBuiltinMining(account *vault.Account, txnCollector *transaction.TxnCollector) *BuiltinMining

func (*BuiltinMining) BuildBlock

func (bm *BuiltinMining) BuildBlock(height uint32, winningHash Uint256,
	winningHashType ledger.WinningHashType) (*ledger.Block, error)

func (*BuiltinMining) CreateCoinbaseTransaction

func (bm *BuiltinMining) CreateCoinbaseTransaction() *transaction.Transaction

type ConsensusService

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

func NewConsensusService

func NewConsensusService(account *vault.Account, node protocol.Noder) *ConsensusService

func (*ConsensusService) Start

func (cs *ConsensusService) Start()

type IsingMessage

type IsingMessage interface {
	serialization.SerializableData
}

func RecoverFromIsingPayload

func RecoverFromIsingPayload(payload *message.IsingPayload) (IsingMessage, error)

type IsingMessageType

type IsingMessageType byte
const (
	BlockFloodingMsg IsingMessageType = 0x00
	BlockRequestMsg  IsingMessageType = 0x01
	BlockResponseMsg IsingMessageType = 0x02
	BlockProposalMsg IsingMessageType = 0x03
	MindChangingMsg  IsingMessageType = 0x04
	StateProbeMsg    IsingMessageType = 0x05
	StateResponseMsg IsingMessageType = 0x06
)

type MindChanging

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

func NewMindChanging

func NewMindChanging(hash *Uint256, height uint32, ctype voting.VotingContentType) *MindChanging

func (*MindChanging) Deserialize

func (mc *MindChanging) Deserialize(r io.Reader) error

func (*MindChanging) Serialize

func (mc *MindChanging) Serialize(w io.Writer) error

type Mining

type Mining interface {
	BuildBlock(height uint32, winningHash Uint256, winningHashType ledger.WinningHashType) (*ledger.Block, error)
}

type Notice

type Notice struct {
	BlockHistory map[string]uint64
}

chan messaage sent from probe to proposer

type ProbeService

type ProbeService struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProbeService

func NewProbeService(account *vault.Account, node protocol.Noder) *ProbeService

func (*ProbeService) BuildNotice

func (ps *ProbeService) BuildNotice() *Notice

func (*ProbeService) HandleStateResponseMsg

func (ps *ProbeService) HandleStateResponseMsg(msg *StateResponse, sender *crypto.PubKey)

func (*ProbeService) ReceiveConsensusMsg

func (ps *ProbeService) ReceiveConsensusMsg(v interface{})

func (*ProbeService) Reset

func (ps *ProbeService) Reset()

func (*ProbeService) SendConsensusMsg

func (ps *ProbeService) SendConsensusMsg(msg IsingMessage) error

func (*ProbeService) Start

func (ps *ProbeService) Start() error

type ProbeType

type ProbeType byte
const (
	// detected block history of neighbors
	BlockHistory ProbeType = iota
)

type Proposal

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

func NewProposal

func NewProposal(hash *Uint256, height uint32, ctype voting.VotingContentType) *Proposal

func (*Proposal) Deserialize

func (p *Proposal) Deserialize(r io.Reader) error

func (*Proposal) Serialize

func (p *Proposal) Serialize(w io.Writer) error

type ProposerCache

type ProposerCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProposerCache

func NewProposerCache() *ProposerCache

func (*ProposerCache) Add

func (pc *ProposerCache) Add(height uint32, votingContent voting.VotingContent)

func (*ProposerCache) Get

func (pc *ProposerCache) Get(height uint32) (*ProposerInfo, error)

type ProposerInfo

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

type ProposerService

type ProposerService struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProposerService

func NewProposerService(account *vault.Account, node protocol.Noder) *ProposerService

func (*ProposerService) BlockPersistCompleted

func (ps *ProposerService) BlockPersistCompleted(v interface{})

func (*ProposerService) BlockSyncingFinished

func (ps *ProposerService) BlockSyncingFinished(v interface{})

func (*ProposerService) ChangeProposer

func (ps *ProposerService) ChangeProposer()

func (*ProposerService) ConsensusRoutine

func (ps *ProposerService) ConsensusRoutine(vType voting.VotingContentType)

func (*ProposerService) CurrentVoting

func (ps *ProposerService) CurrentVoting(vType voting.VotingContentType) voting.Voting

func (*ProposerService) GetReceiverNode

func (ps *ProposerService) GetReceiverNode(nids []uint64) []protocol.Noder

GetReceiverNode returns neighbors nodes according to neighbor node ID passed in. If 'nids' passed in is nil then returns all neighbor nodes.

func (*ProposerService) HandleBlockFloodingMsg

func (ps *ProposerService) HandleBlockFloodingMsg(bfMsg *BlockFlooding, sender *crypto.PubKey)

func (*ProposerService) HandleMindChangingMsg

func (ps *ProposerService) HandleMindChangingMsg(mindChanging *MindChanging, sender *crypto.PubKey)

func (*ProposerService) HandleProposalMsg

func (ps *ProposerService) HandleProposalMsg(proposal *Proposal, sender *crypto.PubKey)

func (*ProposerService) HandleRequestMsg

func (ps *ProposerService) HandleRequestMsg(req *Request, sender *crypto.PubKey)

func (*ProposerService) HandleResponseMsg

func (ps *ProposerService) HandleResponseMsg(resp *Response, sender *crypto.PubKey)

func (*ProposerService) HandleStateProbeMsg

func (ps *ProposerService) HandleStateProbeMsg(msg *StateProbe, sender *crypto.PubKey)

func (*ProposerService) Initialize

func (ps *ProposerService) Initialize(vType voting.VotingContentType)

func (*ProposerService) IsBlockProposer

func (ps *ProposerService) IsBlockProposer() bool

func (*ProposerService) ProbeRoutine

func (ps *ProposerService) ProbeRoutine()

func (*ProposerService) ProduceNewBlock

func (ps *ProposerService) ProduceNewBlock()

func (*ProposerService) ProposerRoutine

func (ps *ProposerService) ProposerRoutine()

func (*ProposerService) ReceiveConsensusMsg

func (ps *ProposerService) ReceiveConsensusMsg(v interface{})

func (*ProposerService) SendConsensusMsg

func (ps *ProposerService) SendConsensusMsg(msg IsingMessage, to []protocol.Noder) error

func (*ProposerService) SendNewProposal

func (ps *ProposerService) SendNewProposal(votingHeight uint32, vType voting.VotingContentType) error

func (*ProposerService) SetOrChangeMind

func (ps *ProposerService) SetOrChangeMind(votingType voting.VotingContentType,
	votingHeight uint32, maybeFinalHash *Uint256)

func (*ProposerService) Start

func (ps *ProposerService) Start() error

func (*ProposerService) StartConsensus

func (ps *ProposerService) StartConsensus(isProposer bool)

func (*ProposerService) SyncBlock

func (ps *ProposerService) SyncBlock(isProposer bool)

func (*ProposerService) TimeoutRoutine

func (ps *ProposerService) TimeoutRoutine()

type Request

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

func NewRequest

func NewRequest(hash *Uint256, height uint32, ctype voting.VotingContentType) *Request

func (*Request) Deserialize

func (req *Request) Deserialize(r io.Reader) error

func (*Request) Serialize

func (req *Request) Serialize(w io.Writer) error

type Response

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

func NewResponse

func NewResponse(hash *Uint256, height uint32, ctype voting.VotingContentType, content voting.VotingContent) *Response

func (*Response) Deserialize

func (resp *Response) Deserialize(r io.Reader) error

func (*Response) Serialize

func (resp *Response) Serialize(w io.Writer) error

type StateProbe

type StateProbe struct {
	ProbeType    ProbeType
	ProbePayload interface{}
}

func (*StateProbe) Deserialize

func (sp *StateProbe) Deserialize(r io.Reader) error

func (*StateProbe) Serialize

func (sp *StateProbe) Serialize(w io.Writer) error

type StateResponse

type StateResponse struct {
	PersistedBlocks map[uint32]Uint256
}

func (*StateResponse) Deserialize

func (sr *StateResponse) Deserialize(r io.Reader) error

func (*StateResponse) Serialize

func (sr *StateResponse) Serialize(w io.Writer) error

type SyncCache

type SyncCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SyncCache cached blocks sent by block proposer when wait for block syncing finished.

func NewSyncBlockCache

func NewSyncBlockCache() *SyncCache

func (*SyncCache) AddBlockToSyncCache

func (sc *SyncCache) AddBlockToSyncCache(block *ledger.Block) error

AddBlockToSyncCache caches received block and the voter count when receive block. Returns nil if block already existed.

func (*SyncCache) AddVoteForBlock

func (sc *SyncCache) AddVoteForBlock(hash Uint256, height uint32, voter uint64) error

AddVoteForBlock adds vote for block when receive valid proposal.

func (*SyncCache) BlockInSyncCache

func (sc *SyncCache) BlockInSyncCache(hash Uint256, height uint32) (*BlockInfo, bool)

BlockInSyncCache returns block info and true is the block exists in cache.

func (*SyncCache) CachedBlockHeight

func (sc *SyncCache) CachedBlockHeight() int

CachedBlockHeight returns cached block height.

func (*SyncCache) ChangeVoteForBlock

func (sc *SyncCache) ChangeVoteForBlock(hash Uint256, height uint32, voter uint64) error

ChangeVoteForBlock change vote for block when receive valid mind changing.

func (*SyncCache) GetBlockFromSyncCache

func (sc *SyncCache) GetBlockFromSyncCache(height uint32) (*ledger.VBlock, error)

GetBlockFromSyncCache returns cached block by height.

func (*SyncCache) RemoveBlockFromCache

func (sc *SyncCache) RemoveBlockFromCache(height uint32) error

RemoveBlockFromCache removes cached block which height is minimum.

func (*SyncCache) SetConsensusHeight

func (sc *SyncCache) SetConsensusHeight(height uint32)

type TimeLock

type TimeLock struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTimeLock

func NewTimeLock() *TimeLock

func (*TimeLock) LockForHeight

func (tl *TimeLock) LockForHeight(height uint32, timer *time.Timer)

func (*TimeLock) RemoveForHeight

func (tl *TimeLock) RemoveForHeight(height uint32)

func (*TimeLock) WaitForTimeout

func (tl *TimeLock) WaitForTimeout(height uint32) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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