voting

package
v0.3.1-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCachedBlockHeight = 5
)
View Source
const (
	MinVoterNum = 3
)
View Source
const (
	// When current block height is n, the block for height n+VotedBlockHeightIncrement is being voted.
	VotedBlockHeightIncrement = 1
)
View Source
const (
	// When current block height is n, the signature chain for height n+VotedSigChainHeightIncrement is being voted.
	VotedSigChainHeightIncrement = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockCache

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

func NewBlockCache

func NewBlockCache() *BlockCache

When receive new block message from consensus layer, cache it.

func (*BlockCache) AddBlockToCache

func (bc *BlockCache) AddBlockToCache(block *ledger.Block) error

AddBlockToCache returns nil if block already existed in cache

func (*BlockCache) BlockInCache

func (bc *BlockCache) BlockInCache(hash Uint256, height uint32) bool

BlockInCache returns whether the block has been cached.

func (*BlockCache) CachedBlockHeight

func (bc *BlockCache) CachedBlockHeight() int

CachedBlockHeight return cached block height

func (*BlockCache) CachedBlockNum

func (bc *BlockCache) CachedBlockNum() int

CachedBlockNum return the block number in cache

func (*BlockCache) Dump

func (bc *BlockCache) Dump(height uint32)

func (*BlockCache) GetBestBlockFromCache

func (bc *BlockCache) GetBestBlockFromCache(height uint32) *ledger.Block

GetBestBlockFromCache returns latest block in cache

func (*BlockCache) GetBlockFromCache

func (bc *BlockCache) GetBlockFromCache(hash Uint256, height uint32) *ledger.Block

GetBlockFromCache returns block according to block hash passed in.

func (*BlockCache) GetMinCachedHeight

func (bc *BlockCache) GetMinCachedHeight() uint32

GetMinCachedHeight returns min block height cached

func (*BlockCache) GetWorseBlockFromCache

func (bc *BlockCache) GetWorseBlockFromCache(height uint32) *ledger.Block

GetBestBlockFromCache returns latest block in cache

func (*BlockCache) RemoveBlockFromCache

func (bc *BlockCache) RemoveBlockFromCache(hash Uint256, height uint32) error

RemoveBlockFromCache return true if the block doesn't exist in cache.

func (*BlockCache) RemoveBlocksByHeight

func (bc *BlockCache) RemoveBlocksByHeight(height uint32) error

RemoveBlocksByHeight removes cached blocks according to the height.

type BlockVoting

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

func NewBlockVoting

func NewBlockVoting() *BlockVoting

func (*BlockVoting) AddToCache

func (bv *BlockVoting) AddToCache(content VotingContent) error

func (*BlockVoting) CacheProposal

func (bv *BlockVoting) CacheProposal(height uint32) (uint32, int)

func (*BlockVoting) DumpState

func (bv *BlockVoting) DumpState(hash Uint256, desc string, verbose bool)

func (*BlockVoting) Exist

func (bv *BlockVoting) Exist(hash Uint256, height uint32) bool

func (*BlockVoting) GetBestVotingContent

func (bv *BlockVoting) GetBestVotingContent(height uint32) (VotingContent, error)

func (*BlockVoting) GetConfirmingHash

func (bv *BlockVoting) GetConfirmingHash() Uint256

func (*BlockVoting) GetVotingContent

func (bv *BlockVoting) GetVotingContent(hash Uint256, height uint32) (VotingContent, error)

func (*BlockVoting) GetVotingContentFromPool

func (bv *BlockVoting) GetVotingContentFromPool(hash Uint256, height uint32) (VotingContent, error)

func (*BlockVoting) GetVotingHeight

func (bv *BlockVoting) GetVotingHeight() uint32

func (*BlockVoting) GetVotingPool

func (bv *BlockVoting) GetVotingPool() VotingPool

func (*BlockVoting) GetWorseVotingContent

func (bv *BlockVoting) GetWorseVotingContent(height uint32) (VotingContent, error)

func (*BlockVoting) HasNeighborState

func (bv *BlockVoting) HasNeighborState(id uint64, blockhash Uint256, state State) bool

func (*BlockVoting) HasSelfState

func (bv *BlockVoting) HasSelfState(blockhash Uint256, state State) bool

func (*BlockVoting) Reset

func (bv *BlockVoting) Reset()

func (*BlockVoting) SetConfirmingHash

func (bv *BlockVoting) SetConfirmingHash(hash Uint256)

func (*BlockVoting) SetNeighborState

func (bv *BlockVoting) SetNeighborState(id uint64, blockhash Uint256, s State)

func (*BlockVoting) SetSelfState

func (bv *BlockVoting) SetSelfState(blockhash Uint256, s State)

func (*BlockVoting) SetVotingHeight

func (bv *BlockVoting) SetVotingHeight(height uint32)

func (*BlockVoting) VerifyVotingContent

func (bv *BlockVoting) VerifyVotingContent(content VotingContent) bool

func (*BlockVoting) VotingType

func (bv *BlockVoting) VotingType() VotingContentType

type BlockVotingPool

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

func NewBlockVotingPool

func NewBlockVotingPool() *BlockVotingPool

func (*BlockVotingPool) AddToReceivePool

func (bvp *BlockVotingPool) AddToReceivePool(height uint32, nodeID uint64, weight int, hash Uint256)

func (*BlockVotingPool) AddToSendPool

func (bvp *BlockVotingPool) AddToSendPool(height uint32, nid uint64, hash Uint256)

func (*BlockVotingPool) AddVoteThenCounting

func (bvp *BlockVotingPool) AddVoteThenCounting(height uint32, nodeID uint64, weight int, hash Uint256) (*Uint256, error)

func (*BlockVotingPool) GetMind

func (bvp *BlockVotingPool) GetMind(height uint32) (Uint256, bool)

func (*BlockVotingPool) HasReceivedVoteFrom

func (bvp *BlockVotingPool) HasReceivedVoteFrom(height uint32, nodeID uint64) bool

func (*BlockVotingPool) Reset

func (bvp *BlockVotingPool) Reset()

func (*BlockVotingPool) SetMind

func (bvp *BlockVotingPool) SetMind(height uint32, mind Uint256) map[uint64]Uint256

type SigChainVoting

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

func NewSigChainVoting

func NewSigChainVoting(txnCollector *transaction.TxnCollector) *SigChainVoting

func (*SigChainVoting) AddToCache

func (scv *SigChainVoting) AddToCache(content VotingContent) error

func (*SigChainVoting) CacheProposal

func (scv *SigChainVoting) CacheProposal(height uint32) (uint32, int)

func (*SigChainVoting) DumpState

func (scv *SigChainVoting) DumpState(hash Uint256, desc string, verbose bool)

func (*SigChainVoting) Exist

func (scv *SigChainVoting) Exist(hash Uint256, height uint32) bool

func (*SigChainVoting) GetBestVotingContent

func (scv *SigChainVoting) GetBestVotingContent(height uint32) (VotingContent, error)

func (*SigChainVoting) GetConfirmingHash

func (scv *SigChainVoting) GetConfirmingHash() Uint256

func (*SigChainVoting) GetVotingContent

func (scv *SigChainVoting) GetVotingContent(hash Uint256, height uint32) (VotingContent, error)

func (*SigChainVoting) GetVotingContentFromPool

func (scv *SigChainVoting) GetVotingContentFromPool(hash Uint256, height uint32) (VotingContent, error)

func (*SigChainVoting) GetVotingHeight

func (scv *SigChainVoting) GetVotingHeight() uint32

func (*SigChainVoting) GetVotingPool

func (scv *SigChainVoting) GetVotingPool() VotingPool

func (*SigChainVoting) GetWorseVotingContent

func (scv *SigChainVoting) GetWorseVotingContent(height uint32) (VotingContent, error)

func (*SigChainVoting) HasNeighborState

func (scv *SigChainVoting) HasNeighborState(id uint64, hash Uint256, state State) bool

func (*SigChainVoting) HasSelfState

func (scv *SigChainVoting) HasSelfState(hash Uint256, state State) bool

func (*SigChainVoting) Reset

func (scv *SigChainVoting) Reset()

func (*SigChainVoting) SetConfirmingHash

func (scv *SigChainVoting) SetConfirmingHash(hash Uint256)

func (*SigChainVoting) SetNeighborState

func (scv *SigChainVoting) SetNeighborState(id uint64, hash Uint256, s State)

func (*SigChainVoting) SetSelfState

func (scv *SigChainVoting) SetSelfState(hash Uint256, s State)

func (*SigChainVoting) SetVotingHeight

func (scv *SigChainVoting) SetVotingHeight(height uint32)

func (*SigChainVoting) VerifyVotingContent

func (scv *SigChainVoting) VerifyVotingContent(content VotingContent) bool

func (*SigChainVoting) VotingType

func (scv *SigChainVoting) VotingType() VotingContentType

type SigChainVotingPool

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

func NewSigChainVotingPool

func NewSigChainVotingPool() *SigChainVotingPool

func (*SigChainVotingPool) AddToReceivePool

func (scvp *SigChainVotingPool) AddToReceivePool(height uint32, nodeID uint64, weight int, hash Uint256)

func (*SigChainVotingPool) AddToSendPool

func (scvp *SigChainVotingPool) AddToSendPool(height uint32, nid uint64, hash Uint256)

func (*SigChainVotingPool) AddVoteThenCounting

func (scvp *SigChainVotingPool) AddVoteThenCounting(height uint32, nodeID uint64, weight int, hash Uint256) (*Uint256, error)

func (*SigChainVotingPool) GetMind

func (scvp *SigChainVotingPool) GetMind(height uint32) (Uint256, bool)

func (*SigChainVotingPool) HasReceivedVoteFrom

func (scvp *SigChainVotingPool) HasReceivedVoteFrom(height uint32, nodeID uint64) bool

func (*SigChainVotingPool) Reset

func (scvp *SigChainVotingPool) Reset()

func (*SigChainVotingPool) SetMind

func (scvp *SigChainVotingPool) SetMind(height uint32, mind Uint256) map[uint64]Uint256

type State

type State uint32
const (
	InitialState State = 1 << iota

	// set self state after receive block
	FloodingFinished

	// set neighbor state after sending request
	RequestSent

	// set neighbor state after receive request
	RequestReceived

	// set self state after sending proposal
	ProposalSent

	// set neighbor state after receive proposal
	ProposalReceived
)

func (*State) ClearAll

func (p *State) ClearAll()

func (*State) ClearBit

func (p *State) ClearBit(bit State)

func (State) HasBit

func (p State) HasBit(bit State) bool

func (*State) SetBit

func (p *State) SetBit(bit State)

type VoteInfo

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

type Voting

type Voting interface {
	// add voting entity to cache
	AddToCache(content VotingContent) error
	// get voting content type
	VotingType() VotingContentType
	// set hash in process
	SetConfirmingHash(hash Uint256)
	// get hash in process
	GetConfirmingHash() Uint256
	// set self state
	SetSelfState(hash Uint256, s State)
	// check proposer state
	HasSelfState(hash Uint256, s State) bool
	// set voter state
	SetNeighborState(nid uint64, hash Uint256, s State)
	// check voter state
	HasNeighborState(nid uint64, hash Uint256, s State) bool
	// get current voting height
	GetVotingHeight() uint32
	// get best voting content
	GetBestVotingContent(height uint32) (VotingContent, error)
	// get worse voting content for testing mind changing
	GetWorseVotingContent(height uint32) (VotingContent, error)
	// get voting content from memory pool
	GetVotingContentFromPool(hash Uint256, height uint32) (VotingContent, error)
	// get voting content from memory pool and ledger
	GetVotingContent(hash Uint256, height uint32) (VotingContent, error)
	// verify voting content
	VerifyVotingContent(content VotingContent) bool
	// get voting pool
	GetVotingPool() VotingPool
	// consensus state detection through proposal received from neighbors
	CacheProposal(height uint32) (uint32, int)
	// check if exist in local memory
	Exist(hash Uint256, height uint32) bool
	// voting pool cleanup
	Reset()
	// dump consensus state for testing
	DumpState(hash Uint256, desc string, verbose bool)
}

type VotingContent

type VotingContent interface {
	Hash() Uint256
}

type VotingContentType

type VotingContentType byte
const (
	SigChainTxnVote VotingContentType = 0
	BlockVote       VotingContentType = 1
)

type VotingPool

type VotingPool interface {
	// get mind of local node
	GetMind(height uint32) (Uint256, bool)
	// change mind for local node
	SetMind(height uint32, hash Uint256) map[uint64]Uint256
	// add a sent vote to send pool
	AddToSendPool(height uint32, nid uint64, hash Uint256)
	// add a received vote to receive pool
	AddToReceivePool(height uint32, nid uint64, weight int, hash Uint256)
	// check if has received vote from a specified neighbor
	HasReceivedVoteFrom(height uint32, nodeID uint64) bool
	// add vote to receive pool then count votes
	AddVoteThenCounting(height uint32, nodeID uint64, weight int, hash Uint256) (*Uint256, error)
	// voting pool reset
	Reset()
}

Jump to

Keyboard shortcuts

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