psec

package
v0.0.0-...-03c5838 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright (C) 2018 go-cloudcard authors

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	STANDBYNUM = 5

	NoBlockArrive = iota
	NotEnoughWitness
	RecvConsensusBlock
)
View Source
const (
	MsgPreprepare = iota + 100
	MsgPrepare
	MsgCommit
)
View Source
const (
	StagePreprepared = iota + 200
	StagePrepared
	StageCommitted
)
View Source
const (
	MaxMiningDuration = int64(10 * 365 * 24 * 60 * 60)
)

Variables

View Source
var (
	StandbyNodesMapIsEmptyError = errors.New("standby nodes map is empty")
	StandbyNodeNotFoundError    = errors.New("the standby node not found")
	StandbyNodeSignError        = errors.New("the standby node sign failed")

	PBFTSignMessageError = errors.New("PBFT sign msg error")
)
View Source
var (
	ErrInvalidBlockWitness        = errors.New("invalid block witness")
	ErrAppendNewBlockFailed       = errors.New("failed to append new block to real chain")
	ErrCannotMintWhenDisable      = errors.New("cannot mint block now, waiting for enable it again")
	ErrCannotMintWhenPending      = errors.New("cannot mint block now, waiting for cancel suspended again")
	ErrWaitingBlockInLastSlot     = errors.New("cannot mint block now, waiting for last block")
	ErrGenerateNextConsensusState = errors.New("failed to generate next consensus state")
	ErrInvalidBlockProposer       = errors.New("invalid block proposer")
	ErrCloneWitnessTrie           = errors.New("failed to clone witness trie")
	ErrNotBlockMintTime           = errors.New("now is not time to mint block")
	ErrFoundNilProposer           = errors.New("found a nil proposer")
	ErrInvalidWitnesses           = errors.New("the size of initial witness in genesis block is invalid, should be equal ")
	ErrBlockMintedInNextSlot      = errors.New("cannot mint block now, there is a block minted in current slot")
	ErrGetTerm                    = errors.New("failed to get term with current genesis and term")
	ErrInvalidProtoToTerm         = errors.New("protobuf message cannot be converted into Term")

	ErrVerifyPreprepareMsgError = errors.New("verify preprepare msg sign error")
	ErrSeqIdIsTooLow            = errors.New("msg seq id is too low")
	ErrWrongMiner               = errors.New("wrong miner")
)

Functions

func FindProposer

func FindProposer(now int64, miners []byteutils.Hash) (proposer byteutils.Hash, err error)

func TraverseTerm

func TraverseTerm(trie *trie.Trie) ([]byteutils.Hash, error)

Types

type Group

type Group struct {
	Master  string
	Members [3]string
}

func NewGroup

func NewGroup() *Group

func (*Group) GetMaster

func (gp *Group) GetMaster() string

func (*Group) GetMembers

func (gp *Group) GetMembers() []string

func (*Group) SetMaster

func (gp *Group) SetMaster(master string)

func (*Group) SetMembers

func (gp *Group) SetMembers(members []string)

type InternalMessage

type InternalMessage struct {
	MsgType MessageType
	ViewId  int64
	SeqId   int64
	Digest  string
	NodeId  string
}

InternalMessage

type MessageLogs

type MessageLogs struct {
	ReqMsg      *RequestMessage
	PrepareMsgs map[string]*InternalMessage
	CommitMsgs  map[string]*InternalMessage
}

MessageLogs

type MessageType

type MessageType int
const (
	MsgTypePrepare MessageType = 2000 + iota
	MsgTypeCommit
)

type PBFT

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

Pbft

func NewPbft

func NewPbft(consensus core.Consensus, ns network.Service, chain *core.BlockChain) *PBFT

NewPbft

func (*PBFT) Preprepare

func (pbft *PBFT) Preprepare(block *core.Block) error

func (*PBFT) SignPreprepareMsg

func (pbft *PBFT) SignPreprepareMsg(msg *corepb.PreprepareMsg) error

func (*PBFT) SignVoteMsg

func (pbft *PBFT) SignVoteMsg(msg *corepb.VoteMsg) error

type Paxos

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

func NewPaxos

func NewPaxos(consensus core.Consensus, ns network.Service, chain *core.BlockChain) *Paxos

func (*Paxos) Clear

func (paxos *Paxos) Clear()

func (*Paxos) HandleMessage

func (paxos *Paxos) HandleMessage()

func (*Paxos) NotifyNoBlockArrive

func (paxos *Paxos) NotifyNoBlockArrive()

func (*Paxos) NotifyNotEnoughWitness

func (paxos *Paxos) NotifyNotEnoughWitness()

func (*Paxos) NotifyRecvConsensusBlock

func (paxos *Paxos) NotifyRecvConsensusBlock()

func (*Paxos) Propose

func (paxos *Paxos) Propose(proposalId uint64) (*corepb.Propose, error)

func (*Paxos) ProposeID

func (paxos *Paxos) ProposeID(proposer string)

func (*Paxos) Run

func (paxos *Paxos) Run()

func (*Paxos) SendMessage

func (paxos *Paxos) SendMessage()

func (*Paxos) SignPropose

func (paxos *Paxos) SignPropose(pbPropose *corepb.Propose) error

func (*Paxos) Stop

func (paxos *Paxos) Stop()

type PbftState

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

type PrePrepareMessage

type PrePrepareMessage struct {
	ViewId int64
	SeqId  int64
	Digest string
	ReqMsg *RequestMessage
}

PrePrepareMessage

type Psec

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

Psec

func NewPsec

func NewPsec(db cdb.Storage) *Psec

func (*Psec) AutoVote

func (psec *Psec) AutoVote(addr *core.Address, amount *big.Int)

AutoVote

func (*Psec) CancelVote

func (psec *Psec) CancelVote(addr *core.Address, amount *big.Int) error

CancelVote

func (*Psec) Coinbase

func (psec *Psec) Coinbase() *core.Address

func (*Psec) DisableMining

func (psec *Psec) DisableMining()

func (*Psec) EnableMining

func (psec *Psec) EnableMining()

func (*Psec) HandleFork

func (psec *Psec) HandleFork() error

func (*Psec) IsEnable

func (psec *Psec) IsEnable() bool

func (*Psec) IsStandby

func (psec *Psec) IsStandby() bool

func (*Psec) IsSuspend

func (psec *Psec) IsSuspend() bool

func (*Psec) IsValidStandbyNode

func (psec *Psec) IsValidStandbyNode(addr string) bool

func (*Psec) NewState

func (psec *Psec) NewState(root *corepb.ConsensusRoot, db cdb.Storage, needChangeLog bool) (state.ConsensusState, error)

NewState creates a new psec state.

func (*Psec) Paxos

func (psec *Psec) Paxos() core.Paxos

func (*Psec) ResumeMining

func (psec *Psec) ResumeMining()

func (*Psec) SetCoinbase

func (psec *Psec) SetCoinbase(addr *core.Address)

func (*Psec) SetTermId

func (psec *Psec) SetTermId(id uint64)

func (*Psec) Setup

func (psec *Psec) Setup(cloudcard core.cloudcard) error

func (*Psec) StandbyCount

func (psec *Psec) StandbyCount() int

func (*Psec) StandbyPeers

func (psec *Psec) StandbyPeers() map[string]string

func (*Psec) Start

func (psec *Psec) Start()

start psec service

func (*Psec) StartMining

func (psec *Psec) StartMining()

func (*Psec) StartStandBy

func (psec *Psec) StartStandBy()

func (*Psec) Stop

func (psec *Psec) Stop()

disable mining and exit consensus

func (*Psec) SuspendMining

func (psec *Psec) SuspendMining()

func (*Psec) TermId

func (psec *Psec) TermId() uint64

func (*Psec) UpdateFixedBlock

func (psec *Psec) UpdateFixedBlock()

func (*Psec) VerifyBlock

func (psec *Psec) VerifyBlock(*core.Block) error

func (*Psec) Vote

func (psec *Psec) Vote(addr *core.Address, amount *big.Int) error

Vote

type PsecState

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

TermState

func (*PsecState) Copy

func (ps *PsecState) Copy() (state.ConsensusState, error)

func (*PsecState) GenesisConsensusState

func (ps *PsecState) GenesisConsensusState(chain *core.BlockChain) (state.ConsensusState, error)

func (*PsecState) NextConsensusState

func (ps *PsecState) NextConsensusState(elapsedSecond int64, worldState state.WorldState) (state.ConsensusState, error)

func (*PsecState) Proposer

func (ps *PsecState) Proposer() byteutils.Hash

func (*PsecState) Replay

func (ps *PsecState) Replay(done state.ConsensusState) error

func (*PsecState) RootHash

func (ps *PsecState) RootHash() *corepb.ConsensusRoot

func (*PsecState) String

func (ps *PsecState) String() string

func (*PsecState) Term

func (ps *PsecState) Term() ([]byteutils.Hash, error)

func (*PsecState) TermRoot

func (ps *PsecState) TermRoot() byteutils.Hash

func (*PsecState) Timestamp

func (ps *PsecState) Timestamp() int64

type RequestMessage

type RequestMessage struct {
	SeqId     int64
	Timestamp int64
	Proposer  string
	Content   interface{}
}

RequestMessage

type ResponseMessage

type ResponseMessage struct {
	ViewId    int64
	Timestamp int64
	NodeId    string
	Result    string
}

ResponseMessage

type SortableVoters

type SortableVoters []*core.Voter

func (SortableVoters) Data

func (sv SortableVoters) Data() []*core.Voter

func (SortableVoters) Len

func (sv SortableVoters) Len() int

func (SortableVoters) Less

func (sv SortableVoters) Less(i, j int) bool

func (SortableVoters) Swap

func (sv SortableVoters) Swap(i, j int)

type Stage

type Stage int
const (
	StageIdle Stage = 1000 + iota
	StagePrePrepared
	StagePrepared
	StageCommitted
)

func (*Stage) Response

func (state *Stage) Response(msg *ResponseMessage) error

Response

type State

type State struct {
	ViewId       int64
	MsgLogs      *MessageLogs
	LastSeqId    int64
	CurrentStage Stage
}

PbftState

func NewState

func NewState(viewId int64, lastSeq int64) *State

NewState

func (*State) Commit

func (state *State) Commit(commitMsg *InternalMessage) (*ResponseMessage, *RequestMessage, error)

Commit

func (*State) PrePrepare

func (state *State) PrePrepare(prePrepareMsg *PrePrepareMessage) (*InternalMessage, error)

PrePrepare

func (*State) Prepare

func (state *State) Prepare(prepareMsg *InternalMessage) (*InternalMessage, error)

Prepare

func (*State) Start

func (state *State) Start(reqMsg *RequestMessage) (*PrePrepareMessage, error)

Start

type Term

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

func (*Term) SetTimestamp

func (term *Term) SetTimestamp(time int64)

func (*Term) SetWitnesses

func (term *Term) SetWitnesses(witnesses []*core.Witness)

func (*Term) Witnesses

func (term *Term) Witnesses() []*core.Witness

Jump to

Keyboard shortcuts

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