phases

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const BFTPercent = 2.0 / 3.0
View Source
const MajorityPercent = 0.5

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalRequest added in v0.8.0

type AdditionalRequest struct {
	RequestIndex int
	Candidates   []core.RecordRef
}

type Communicator added in v0.6.3

type Communicator interface {
	// ExchangePhase1 used in first consensus step to exchange data between participants
	ExchangePhase1(
		ctx context.Context,
		originClaim *packets.NodeAnnounceClaim,
		participants []core.Node,
		packet *packets.Phase1Packet,
	) (map[core.RecordRef]*packets.Phase1Packet, error)
	// ExchangePhase2 used in second consensus step to exchange data between participants
	ExchangePhase2(ctx context.Context, list network.UnsyncList, participants []core.Node, packet *packets.Phase2Packet) (map[core.RecordRef]*packets.Phase2Packet, error)
	// ExchangePhase21 is used between phases 2 and 3 of consensus to send additional MissingNode requests
	ExchangePhase21(ctx context.Context, list network.UnsyncList, packet *packets.Phase2Packet, additionalRequests []*AdditionalRequest) ([]packets.ReferendumVote, error)
	// ExchangePhase3 used in third consensus step to exchange data between participants
	ExchangePhase3(ctx context.Context, participants []core.Node, packet *packets.Phase3Packet) (map[core.RecordRef]*packets.Phase3Packet, error)

	component.Initer
}

Communicator interface provides methods to exchange data between nodes

type CommunicatorMock added in v0.6.3

type CommunicatorMock struct {
	ExchangePhase1Func       func(p context.Context, p1 *packets.NodeAnnounceClaim, p2 []core.Node, p3 *packets.Phase1Packet) (r map[core.RecordRef]*packets.Phase1Packet, r1 error)
	ExchangePhase1Counter    uint64
	ExchangePhase1PreCounter uint64
	ExchangePhase1Mock       mCommunicatorMockExchangePhase1

	ExchangePhase2Func       func(p context.Context, p1 network.UnsyncList, p2 []core.Node, p3 *packets.Phase2Packet) (r map[core.RecordRef]*packets.Phase2Packet, r1 error)
	ExchangePhase2Counter    uint64
	ExchangePhase2PreCounter uint64
	ExchangePhase2Mock       mCommunicatorMockExchangePhase2

	ExchangePhase21Func       func(p context.Context, p1 network.UnsyncList, p2 *packets.Phase2Packet, p3 []*AdditionalRequest) (r []packets.ReferendumVote, r1 error)
	ExchangePhase21Counter    uint64
	ExchangePhase21PreCounter uint64
	ExchangePhase21Mock       mCommunicatorMockExchangePhase21

	ExchangePhase3Func       func(p context.Context, p1 []core.Node, p2 *packets.Phase3Packet) (r map[core.RecordRef]*packets.Phase3Packet, r1 error)
	ExchangePhase3Counter    uint64
	ExchangePhase3PreCounter uint64
	ExchangePhase3Mock       mCommunicatorMockExchangePhase3

	InitFunc       func(p context.Context) (r error)
	InitCounter    uint64
	InitPreCounter uint64
	InitMock       mCommunicatorMockInit
	// contains filtered or unexported fields
}

CommunicatorMock implements github.com/insolar/insolar/consensus/phases.Communicator

func NewCommunicatorMock added in v0.6.3

func NewCommunicatorMock(t minimock.Tester) *CommunicatorMock

NewCommunicatorMock returns a mock for github.com/insolar/insolar/consensus/phases.Communicator

func (*CommunicatorMock) AllMocksCalled added in v0.6.3

func (m *CommunicatorMock) AllMocksCalled() bool

AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled, it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled())

func (*CommunicatorMock) CheckMocksCalled added in v0.6.3

func (m *CommunicatorMock) CheckMocksCalled()

CheckMocksCalled checks that all mocked methods of the interface have been called at least once Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller

func (*CommunicatorMock) ExchangePhase1 added in v0.6.3

ExchangePhase1 implements github.com/insolar/insolar/consensus/phases.Communicator interface

func (*CommunicatorMock) ExchangePhase1Finished added in v0.7.5

func (m *CommunicatorMock) ExchangePhase1Finished() bool

ExchangePhase1Finished returns true if mock invocations count is ok

func (*CommunicatorMock) ExchangePhase1MinimockCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase1MinimockCounter() uint64

ExchangePhase1MinimockCounter returns a count of CommunicatorMock.ExchangePhase1Func invocations

func (*CommunicatorMock) ExchangePhase1MinimockPreCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase1MinimockPreCounter() uint64

ExchangePhase1MinimockPreCounter returns the value of CommunicatorMock.ExchangePhase1 invocations

func (*CommunicatorMock) ExchangePhase2 added in v0.6.3

ExchangePhase2 implements github.com/insolar/insolar/consensus/phases.Communicator interface

func (*CommunicatorMock) ExchangePhase21 added in v0.8.0

ExchangePhase21 implements github.com/insolar/insolar/consensus/phases.Communicator interface

func (*CommunicatorMock) ExchangePhase21Finished added in v0.8.0

func (m *CommunicatorMock) ExchangePhase21Finished() bool

ExchangePhase21Finished returns true if mock invocations count is ok

func (*CommunicatorMock) ExchangePhase21MinimockCounter added in v0.8.0

func (m *CommunicatorMock) ExchangePhase21MinimockCounter() uint64

ExchangePhase21MinimockCounter returns a count of CommunicatorMock.ExchangePhase21Func invocations

func (*CommunicatorMock) ExchangePhase21MinimockPreCounter added in v0.8.0

func (m *CommunicatorMock) ExchangePhase21MinimockPreCounter() uint64

ExchangePhase21MinimockPreCounter returns the value of CommunicatorMock.ExchangePhase21 invocations

func (*CommunicatorMock) ExchangePhase2Finished added in v0.7.5

func (m *CommunicatorMock) ExchangePhase2Finished() bool

ExchangePhase2Finished returns true if mock invocations count is ok

func (*CommunicatorMock) ExchangePhase2MinimockCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase2MinimockCounter() uint64

ExchangePhase2MinimockCounter returns a count of CommunicatorMock.ExchangePhase2Func invocations

func (*CommunicatorMock) ExchangePhase2MinimockPreCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase2MinimockPreCounter() uint64

ExchangePhase2MinimockPreCounter returns the value of CommunicatorMock.ExchangePhase2 invocations

func (*CommunicatorMock) ExchangePhase3 added in v0.6.3

func (m *CommunicatorMock) ExchangePhase3(p context.Context, p1 []core.Node, p2 *packets.Phase3Packet) (r map[core.RecordRef]*packets.Phase3Packet, r1 error)

ExchangePhase3 implements github.com/insolar/insolar/consensus/phases.Communicator interface

func (*CommunicatorMock) ExchangePhase3Finished added in v0.7.5

func (m *CommunicatorMock) ExchangePhase3Finished() bool

ExchangePhase3Finished returns true if mock invocations count is ok

func (*CommunicatorMock) ExchangePhase3MinimockCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase3MinimockCounter() uint64

ExchangePhase3MinimockCounter returns a count of CommunicatorMock.ExchangePhase3Func invocations

func (*CommunicatorMock) ExchangePhase3MinimockPreCounter added in v0.6.3

func (m *CommunicatorMock) ExchangePhase3MinimockPreCounter() uint64

ExchangePhase3MinimockPreCounter returns the value of CommunicatorMock.ExchangePhase3 invocations

func (*CommunicatorMock) Finish added in v0.6.3

func (m *CommunicatorMock) Finish()

Finish checks that all mocked methods of the interface have been called at least once Deprecated: please use MinimockFinish or use Finish method of minimock.Controller

func (*CommunicatorMock) Init added in v0.8.0

func (m *CommunicatorMock) Init(p context.Context) (r error)

Init implements github.com/insolar/insolar/consensus/phases.Communicator interface

func (*CommunicatorMock) InitFinished added in v0.8.0

func (m *CommunicatorMock) InitFinished() bool

InitFinished returns true if mock invocations count is ok

func (*CommunicatorMock) InitMinimockCounter added in v0.8.0

func (m *CommunicatorMock) InitMinimockCounter() uint64

InitMinimockCounter returns a count of CommunicatorMock.InitFunc invocations

func (*CommunicatorMock) InitMinimockPreCounter added in v0.8.0

func (m *CommunicatorMock) InitMinimockPreCounter() uint64

InitMinimockPreCounter returns the value of CommunicatorMock.Init invocations

func (*CommunicatorMock) MinimockFinish added in v0.6.3

func (m *CommunicatorMock) MinimockFinish()

MinimockFinish checks that all mocked methods of the interface have been called at least once

func (*CommunicatorMock) MinimockWait added in v0.6.3

func (m *CommunicatorMock) MinimockWait(timeout time.Duration)

MinimockWait waits for all mocked methods to be called at least once this method is called by minimock.Controller

func (*CommunicatorMock) ValidateCallCounters added in v0.6.3

func (m *CommunicatorMock) ValidateCallCounters()

ValidateCallCounters checks that all mocked methods of the interface have been called at least once Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller

func (*CommunicatorMock) Wait added in v0.6.3

func (m *CommunicatorMock) Wait(timeout time.Duration)

Wait waits for all mocked methods to be called at least once Deprecated: please use MinimockWait or use Wait method of minimock.Controller

type CommunicatorMockExchangePhase1Expectation added in v0.7.5

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

func (*CommunicatorMockExchangePhase1Expectation) Return added in v0.7.5

type CommunicatorMockExchangePhase1Input added in v0.7.5

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

type CommunicatorMockExchangePhase1Result added in v0.7.5

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

type CommunicatorMockExchangePhase21Expectation added in v0.8.0

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

func (*CommunicatorMockExchangePhase21Expectation) Return added in v0.8.0

type CommunicatorMockExchangePhase21Input added in v0.8.0

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

type CommunicatorMockExchangePhase21Result added in v0.8.0

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

type CommunicatorMockExchangePhase2Expectation added in v0.7.5

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

func (*CommunicatorMockExchangePhase2Expectation) Return added in v0.7.5

type CommunicatorMockExchangePhase2Input added in v0.7.5

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

type CommunicatorMockExchangePhase2Result added in v0.7.5

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

type CommunicatorMockExchangePhase3Expectation added in v0.7.5

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

func (*CommunicatorMockExchangePhase3Expectation) Return added in v0.7.5

type CommunicatorMockExchangePhase3Input added in v0.7.5

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

type CommunicatorMockExchangePhase3Result added in v0.7.5

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

type CommunicatorMockInitExpectation added in v0.8.0

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

func (*CommunicatorMockInitExpectation) Return added in v0.8.0

type CommunicatorMockInitInput added in v0.8.0

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

type CommunicatorMockInitResult added in v0.8.0

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

type ConsensusCommunicator added in v0.8.0

type ConsensusCommunicator struct {
	ConsensusNetwork network.ConsensusNetwork `inject:""`
	PulseHandler     network.PulseHandler     `inject:""`
	Cryptography     core.CryptographyService `inject:""`
	NodeKeeper       network.NodeKeeper       `inject:""`
	// contains filtered or unexported fields
}

ConsensusCommunicator is simple Communicator implementation which communicates with each participants

func NewCommunicator added in v0.8.0

func NewCommunicator() *ConsensusCommunicator

NewCommunicator constructor creates new ConsensusCommunicator

func (*ConsensusCommunicator) ExchangePhase1 added in v0.8.0

func (nc *ConsensusCommunicator) ExchangePhase1(
	ctx context.Context,
	originClaim *packets.NodeAnnounceClaim,
	participants []core.Node,
	packet *packets.Phase1Packet,
) (map[core.RecordRef]*packets.Phase1Packet, error)

ExchangePhase1 used in first consensus phase to exchange data between participants

func (*ConsensusCommunicator) ExchangePhase2 added in v0.8.0

func (nc *ConsensusCommunicator) ExchangePhase2(ctx context.Context, list network.UnsyncList,
	participants []core.Node, packet *packets.Phase2Packet) (map[core.RecordRef]*packets.Phase2Packet, error)

ExchangePhase2 used in second consensus phase to exchange data between participants

func (*ConsensusCommunicator) ExchangePhase21 added in v0.8.0

func (nc *ConsensusCommunicator) ExchangePhase21(ctx context.Context, list network.UnsyncList, packet *packets.Phase2Packet,
	additionalRequests []*AdditionalRequest) ([]packets.ReferendumVote, error)

ExchangePhase21 used in second consensus phase to exchange data between participants

func (*ConsensusCommunicator) ExchangePhase3 added in v0.8.0

func (nc *ConsensusCommunicator) ExchangePhase3(ctx context.Context, participants []core.Node, packet *packets.Phase3Packet) (map[core.RecordRef]*packets.Phase3Packet, error)

ExchangePhase3 used in third consensus step to exchange data between participants

func (*ConsensusCommunicator) Init added in v0.8.0

Start method implements Starter interface

type FirstPhase

type FirstPhase interface {
	Execute(ctx context.Context, pulse *core.Pulse) (*FirstPhaseState, error)
}

func NewFirstPhase added in v0.7.5

func NewFirstPhase() FirstPhase

type FirstPhaseImpl added in v0.8.0

type FirstPhaseImpl struct {
	Calculator   merkle.Calculator        `inject:""`
	Communicator Communicator             `inject:""`
	Cryptography core.CryptographyService `inject:""`
	NodeKeeper   network.NodeKeeper       `inject:""`
}

func (*FirstPhaseImpl) Execute added in v0.8.0

func (fp *FirstPhaseImpl) Execute(ctx context.Context, pulse *core.Pulse) (*FirstPhaseState, error)

Execute do first phase

type FirstPhaseState added in v0.6.3

type FirstPhaseState struct {
	PulseEntry *merkle.PulseEntry

	PulseHash  merkle.OriginHash
	PulseProof *merkle.PulseProof

	ValidProofs map[core.Node]*merkle.PulseProof
	FaultProofs map[core.RecordRef]*merkle.PulseProof

	UnsyncList network.UnsyncList
}

type Phase2MatrixState added in v0.8.0

type Phase2MatrixState struct {
	// wether any nodes in current consensus need to advance to phase 2.1
	NeedPhase21 bool

	Active                   []core.RecordRef
	TimedOut                 []core.RecordRef
	AdditionalRequestsPhase2 []*AdditionalRequest
}

type PhaseManager

type PhaseManager interface {
	OnPulse(ctx context.Context, pulse *core.Pulse, pulseStartTime time.Time) error
}

func NewPhaseManager

func NewPhaseManager() PhaseManager

NewPhaseManager creates and returns a new phase manager.

type Phases added in v0.6.3

type Phases struct {
	FirstPhase  FirstPhase  `inject:""`
	SecondPhase SecondPhase `inject:""`
	ThirdPhase  ThirdPhase  `inject:""`

	PulseManager core.PulseManager  `inject:""`
	NodeKeeper   network.NodeKeeper `inject:""`
	Calculator   merkle.Calculator  `inject:""`
	// contains filtered or unexported fields
}

func (*Phases) OnPulse added in v0.6.3

func (pm *Phases) OnPulse(ctx context.Context, pulse *core.Pulse, pulseStartTime time.Time) error

OnPulse starts calculate args on phases.

type SecondPhase

type SecondPhase interface {
	Execute(ctx context.Context, pulse *core.Pulse, state *FirstPhaseState) (*SecondPhaseState, error)
	Execute21(ctx context.Context, pulse *core.Pulse, state *SecondPhaseState) (*SecondPhaseState, error)
}

func NewSecondPhase added in v0.7.5

func NewSecondPhase() SecondPhase

type SecondPhaseImpl added in v0.8.0

type SecondPhaseImpl struct {
	NodeKeeper   network.NodeKeeper       `inject:""`
	Calculator   merkle.Calculator        `inject:""`
	Communicator Communicator             `inject:""`
	Cryptography core.CryptographyService `inject:""`
}

func (*SecondPhaseImpl) Execute added in v0.8.0

func (sp *SecondPhaseImpl) Execute(ctx context.Context, pulse *core.Pulse, state *FirstPhaseState) (*SecondPhaseState, error)

func (*SecondPhaseImpl) Execute21 added in v0.8.0

func (sp *SecondPhaseImpl) Execute21(ctx context.Context, pulse *core.Pulse, state *SecondPhaseState) (*SecondPhaseState, error)

type SecondPhaseState added in v0.6.3

type SecondPhaseState struct {
	*FirstPhaseState

	GlobuleHash  merkle.OriginHash
	GlobuleProof *merkle.GlobuleProof

	MatrixState *Phase2MatrixState
	Matrix      *StateMatrix

	BitSet packets.BitSet
}

type StateMatrix added in v0.8.0

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

func NewStateMatrix added in v0.8.0

func NewStateMatrix(mapper packets.BitSetMapper) *StateMatrix

func (*StateMatrix) ApplyBitSet added in v0.8.0

func (sm *StateMatrix) ApplyBitSet(sender core.RecordRef, set packets.BitSet) error

func (*StateMatrix) CalculatePhase2 added in v0.8.0

func (sm *StateMatrix) CalculatePhase2(origin core.RecordRef) (*Phase2MatrixState, error)

func (*StateMatrix) ReceivedProofFromNode added in v0.8.0

func (sm *StateMatrix) ReceivedProofFromNode(origin, nodeID core.RecordRef) error

type ThirdPhase added in v0.6.3

type ThirdPhase interface {
	Execute(ctx context.Context, pulse *core.Pulse, state *SecondPhaseState) (*ThirdPhaseState, error)
}

func NewThirdPhase added in v0.7.5

func NewThirdPhase() ThirdPhase

type ThirdPhaseImpl added in v0.8.0

type ThirdPhaseImpl struct {
	Cryptography core.CryptographyService `inject:""`
	Communicator Communicator             `inject:""`
	NodeKeeper   network.NodeKeeper       `inject:""`
	Calculator   merkle.Calculator        `inject:""`
}

func (*ThirdPhaseImpl) Execute added in v0.8.0

func (tp *ThirdPhaseImpl) Execute(ctx context.Context, pulse *core.Pulse, state *SecondPhaseState) (*ThirdPhaseState, error)

type ThirdPhaseState added in v0.8.0

type ThirdPhaseState struct {
	ActiveNodes  []core.RecordRef
	UnsyncList   network.UnsyncList
	GlobuleProof *merkle.GlobuleProof
}

Jump to

Keyboard shortcuts

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