Documentation ¶
Index ¶
- Constants
- Variables
- func GetCandidates(store store.StoreInterface, topN int) []types.Producer
- type BftConfig
- type BftConsensus
- func (bftConsensus *BftConsensus) ChangeTime(interval time.Duration)
- func (bftConsensus *BftConsensus) Close()
- func (bftConsensus *BftConsensus) GetProducers(height uint64, topN int) ([]types.Producer, error)
- func (bftConsensus *BftConsensus) ReceiveMsg(peer *consensusTypes.PeerInfo, t uint64, buf []byte)
- func (bftConsensus *BftConsensus) Run(privKey *secp256k1.PrivateKey) (*types.Block, error)
- type BftConsensusService
- func (bftConsensusService *BftConsensusService) Api() []app.API
- func (bftConsensusService *BftConsensusService) CommandFlags() ([]cli.Command, []cli.Flag)
- func (bftConsensusService *BftConsensusService) DefaultConfig(netType params.NetType) *BftConfig
- func (bftConsensusService *BftConsensusService) GetProducers(height uint64, topN int) ([]chainTypes.Producer, error)
- func (bftConsensusService *BftConsensusService) Init(executeContext *app.ExecuteContext) error
- func (bftConsensusService *BftConsensusService) Name() string
- func (bftConsensusService *BftConsensusService) Start(executeContext *app.ExecuteContext) error
- func (bftConsensusService *BftConsensusService) Stop(executeContext *app.ExecuteContext) error
- type BlockMultiSigValidator
- func (blockMultiSigValidator *BlockMultiSigValidator) ExecuteBlock(context *block.BlockExecuteContext) error
- func (blockMultiSigValidator *BlockMultiSigValidator) VerifyBody(block *types.Block) error
- func (blockMultiSigValidator *BlockMultiSigValidator) VerifyHeader(header, parent *types.BlockHeader) error
- type Challenge
- type Commitment
- type CompletedBlockMessage
- type ConsensusApi
- type ConsensusOp
- type Fail
- type GetBlock
- type GetProducers
- type IConsenMsg
- type IRewardCalculator
- type Leader
- func (leader *Leader) Close()
- func (leader *Leader) OnCommit(peer consensusTypes.IPeerInfo, commit *Commitment)
- func (leader *Leader) OnResponse(peer consensusTypes.IPeerInfo, response *Response)
- func (leader *Leader) ProcessConsensus(msg IConsenMsg, round int, chBestHeight <-chan uint64) (error, *secp256k1.Signature, []byte)
- func (leader *Leader) Reset()
- func (leader *Leader) Validate(msg IConsenMsg, r *big.Int, s *big.Int) bool
- type Member
- func (member *Member) OnChallenge(peer consensusTypes.IPeerInfo, challengeMsg *Challenge)
- func (member *Member) OnFail(peer consensusTypes.IPeerInfo, failMsg *Fail)
- func (member *Member) OnSetUp(peer consensusTypes.IPeerInfo, setUp *Setup)
- func (member *Member) ProcessConsensus(round int, chNewBlock <-chan uint64) (IConsenMsg, error)
- func (member *Member) Reset()
- func (member *Member) WaitChallenge()
- func (member *Member) WaitSetUp(round int, chNewBlock <-chan uint64)
- type MemberInfo
- type MinerGenesisProcessor
- type MsgWrap
- type MultiSignature
- type RegisterAsProducerTransactionExecutor
- type RegisterAsProducerTransactionSelector
- type Response
- type RewardCalculator
- type Sender
- type Setup
Constants ¶
View Source
const ( INIT = iota WAIT_SETUP WAIT_SETUP_TIMEOUT WAIT_COMMIT WAIT_COMMIT_COMPELED WAIT_COMMIT_IMEOUT WAIT_CHALLENGE WAIT_CHALLENGE_TIMEOUT WAIT_RESPONSE WAIT_RESPONSE_COMPELED WAIT_RESPONSE_TIMEOUT COMPLETED ERROR )
View Source
const ( MsgTypeSetUp = 0 MsgTypeCommitment = 1 MsgTypeResponse = 2 MsgTypeChallenge = 3 SetupMagic = 0xfefefbfe CommitMagic = 0xfefefbfd ChallegeMagic = 0xfefefbfc //FailMagic = 0xfefefbfb ResponseMagic = 0xfefefbfa )
The messages of this module can only be used in functions that call this module (consensus and its corresponding submodules) For example, the MsgTypeCommitment message, defined in consensus, must be sent and received using a function in consensus
View Source
const MAX_PRODUCER = 21
View Source
const (
MODULENAME = "bft"
)
Variables ¶
View Source
var ( ErrSignBlock = errors.New("sign block error") ErrWalletNotOpen = errors.New("wallet is close") ErrBpConfig = errors.New("the pubkey config not in bp nodes") ErrBFTNotReady = errors.New("BFT node not ready") ErrBpNotInList = errors.New("bp node not in local list") ErrMultiSig = errors.New("ErrMultiSig") ErrWaitCommit = errors.New("waitForCommit fail") ErrWaitResponse = errors.New("waitForResponse fail") ErrChallenge = errors.New("challenge error") ErrSignatureNotValid = errors.New("signature not valid") ErrTimeout = errors.New("time out") ErrLowHeight = errors.New("leader's height lower") ErrHighHeight = errors.New("leader's height higher") ErrStatus = errors.New("error status") ErrLeaderMistake = errors.New("setUp: mistake leader") ErrValidateMsg = errors.New("validate message error") ErrGenerateNouncePriv = errors.New("generate nounce fail") ErrMsgSize = errors.New("err msg size") ErrGasUsed = errors.New("gasUsed not match gasUsed in blockheader") ErrNotMyTurn = errors.New("not my turn") )
View Source
var ( MinerFlag = cli.BoolFlag{ Name: "miner", Usage: "is miner", } DefaultConfigMainnet = BftConfig{ MyPk: nil, StartMiner: true, ProducerNum: params.GenesisProducerNumMainnet, BlockInterval: params.BlockInterval, ChangeInterval: params.ChangeInterval, } DefaultConfigTestnet = BftConfig{ MyPk: nil, StartMiner: true, ProducerNum: params.GenesisProducerNumTestnet, BlockInterval: params.BlockInterval, ChangeInterval: params.ChangeInterval, } )
View Source
var (
MinerPrefix = []byte("miner")
)
View Source
var NumberOfMsg = 7
Functions ¶
func GetCandidates ¶
func GetCandidates(store store.StoreInterface, topN int) []types.Producer
Types ¶
type BftConsensus ¶
type BftConsensus struct { CoinBase crypto.CommonAddress PrivKey *secp256k1.PrivateKey BlockGenerator blockmgr.IBlockBlockGenerator ChainService chain.ChainServiceInterface DbService *database.DatabaseService WaitTime time.Duration // contains filtered or unexported fields }
func NewBftConsensus ¶
func NewBftConsensus( chainService chain.ChainServiceInterface, blockGenerator blockmgr.IBlockBlockGenerator, dbService *database.DatabaseService, sener Sender, config *BftConfig, addPeer, removePeer *event.Feed) *BftConsensus
func (*BftConsensus) ChangeTime ¶
func (bftConsensus *BftConsensus) ChangeTime(interval time.Duration)
func (*BftConsensus) Close ¶
func (bftConsensus *BftConsensus) Close()
func (*BftConsensus) GetProducers ¶
func (*BftConsensus) ReceiveMsg ¶
func (bftConsensus *BftConsensus) ReceiveMsg(peer *consensusTypes.PeerInfo, t uint64, buf []byte)
func (*BftConsensus) Run ¶
func (bftConsensus *BftConsensus) Run(privKey *secp256k1.PrivateKey) (*types.Block, error)
type BftConsensusService ¶
type BftConsensusService struct { P2pServer p2pService.P2P `service:"p2p"` ChainService chainService.ChainServiceInterface `service:"chain"` BroadCastor blockMgrService.ISendMessage `service:"blockmgr"` BlockMgrNotifier blockMgrService.IBlockNotify `service:"blockmgr"` BlockGenerator blockMgrService.IBlockBlockGenerator `service:"blockmgr"` DatabaseService *database.DatabaseService `service:"database"` WalletService *accountService.AccountService `service:"accounts"` BftConsensus *BftConsensus NetType params.NetType Config *BftConfig ConsensusEngine consensusTypes.IConsensusEngine Miner *secp256k1.PrivateKey // contains filtered or unexported fields }
func (*BftConsensusService) Api ¶
func (bftConsensusService *BftConsensusService) Api() []app.API
func (*BftConsensusService) CommandFlags ¶
func (bftConsensusService *BftConsensusService) CommandFlags() ([]cli.Command, []cli.Flag)
func (*BftConsensusService) DefaultConfig ¶
func (bftConsensusService *BftConsensusService) DefaultConfig(netType params.NetType) *BftConfig
func (*BftConsensusService) GetProducers ¶
func (bftConsensusService *BftConsensusService) GetProducers(height uint64, topN int) ([]chainTypes.Producer, error)
func (*BftConsensusService) Init ¶
func (bftConsensusService *BftConsensusService) Init(executeContext *app.ExecuteContext) error
func (*BftConsensusService) Name ¶
func (bftConsensusService *BftConsensusService) Name() string
func (*BftConsensusService) Start ¶
func (bftConsensusService *BftConsensusService) Start(executeContext *app.ExecuteContext) error
func (*BftConsensusService) Stop ¶
func (bftConsensusService *BftConsensusService) Stop(executeContext *app.ExecuteContext) error
type BlockMultiSigValidator ¶
type BlockMultiSigValidator struct {
// contains filtered or unexported fields
}
func (*BlockMultiSigValidator) ExecuteBlock ¶
func (blockMultiSigValidator *BlockMultiSigValidator) ExecuteBlock(context *block.BlockExecuteContext) error
func (*BlockMultiSigValidator) VerifyBody ¶
func (blockMultiSigValidator *BlockMultiSigValidator) VerifyBody(block *types.Block) error
func (*BlockMultiSigValidator) VerifyHeader ¶
func (blockMultiSigValidator *BlockMultiSigValidator) VerifyHeader(header, parent *types.BlockHeader) error
type Challenge ¶
type Commitment ¶
type Commitment struct { Height uint64 Magic uint32 Round int BpKey *secp256k1.PublicKey Q *secp256k1.PublicKey }
func (*Commitment) String ¶
func (commitment *Commitment) String() string
type CompletedBlockMessage ¶
type CompletedBlockMessage struct { MultiSignature StateRoot []byte //sencond round leader should send stateroot, then member verify }
func CompletedBlockFromMessage ¶
func CompletedBlockFromMessage(bytes []byte) (*CompletedBlockMessage, error)
func (*CompletedBlockMessage) AsMessage ¶
func (completedBlockMessage *CompletedBlockMessage) AsMessage() []byte
func (*CompletedBlockMessage) AsSignMessage ¶
func (completedBlockMessage *CompletedBlockMessage) AsSignMessage() []byte
type ConsensusApi ¶
type ConsensusApi struct {
// contains filtered or unexported fields
}
name: consensus api usage: Query the consensus node function prefix:consensus
func (*ConsensusApi) ChangeWaitTime ¶
func (consensusApi *ConsensusApi) ChangeWaitTime(waitTime int)
name: changeWaitTime usage: Modify the waiting time of the leader (ms) params: 1.wait time (ms) return: example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"consensus_changeWaitTime","params":[100000], "id": 3}' -H "Content-Type:application/json"
response:
{"jsonrpc":"2.0","id":3,"result":null}
func (*ConsensusApi) GetMiners ¶
func (consensusApi *ConsensusApi) GetMiners() []*secp256k1.PublicKey
name: getMiners() usage: Gets the current mining node params: return: mining nodes's pub key example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"consensus_getMiners","params":[""], "id": 3}' -H "Content-Type:application/json"
response:
{"jsonrpc":"2.0","id":3,"result":['0x02c682c9f503465a27d1941d1a25547b5ea879a7145056283599a33869982513df', '0x036a09f9012cb3f73c11ceb2aae4242265c2aa35ebec20dbc28a78712802f457db'] }
type ConsensusOp ¶
type ConsensusOp struct {
store.StoreInterface
}
func (*ConsensusOp) GetProducer ¶
func (consensusOp *ConsensusOp) GetProducer() ([]*types.Producer, error)
func (*ConsensusOp) SaveProducer ¶
func (consensusOp *ConsensusOp) SaveProducer(p []*types.Producer) error
type IConsenMsg ¶
type IRewardCalculator ¶
type IRewardCalculator interface {
AccumulateRewards(sig *MultiSignature, Producers types.ProducerSet, totalGasBalance *big.Int, height uint64)
}
type Leader ¶
type Leader struct {
// contains filtered or unexported fields
}
func NewLeader ¶
func NewLeader(privkey *secp256k1.PrivateKey, p2pServer Sender, waitTime time.Duration, producers []*MemberInfo, minMember int, curHeight uint64, msgPool chan *MsgWrap) *Leader
func (*Leader) OnCommit ¶
func (leader *Leader) OnCommit(peer consensusTypes.IPeerInfo, commit *Commitment)
func (*Leader) OnResponse ¶
func (leader *Leader) OnResponse(peer consensusTypes.IPeerInfo, response *Response)
func (*Leader) ProcessConsensus ¶
func (leader *Leader) ProcessConsensus(msg IConsenMsg, round int, chBestHeight <-chan uint64) (error, *secp256k1.Signature, []byte)
leader member setup ----->
<----- commit
challenge ----->
<----- response
type Member ¶
type Member struct {
// contains filtered or unexported fields
}
func NewMember ¶
func NewMember(prvKey *secp256k1.PrivateKey, p2pServer Sender, waitTime time.Duration, producers []*MemberInfo, minMember int, curHeight uint64, msgPool chan *MsgWrap) *Member
func (*Member) OnChallenge ¶
func (member *Member) OnChallenge(peer consensusTypes.IPeerInfo, challengeMsg *Challenge)
func (*Member) ProcessConsensus ¶
func (member *Member) ProcessConsensus(round int, chNewBlock <-chan uint64) (IConsenMsg, error)
func (*Member) WaitChallenge ¶
func (member *Member) WaitChallenge()
type MemberInfo ¶
type MinerGenesisProcessor ¶
type MinerGenesisProcessor struct { }
func NewMinerGenesisProcessor ¶
func NewMinerGenesisProcessor() *MinerGenesisProcessor
func (*MinerGenesisProcessor) Genesis ¶
func (minerGenesisProcessor *MinerGenesisProcessor) Genesis(context *chain.GenesisContext) error
type MultiSignature ¶
func (*MultiSignature) AsMessage ¶
func (multiSignature *MultiSignature) AsMessage() []byte
func (*MultiSignature) AsSignMessage ¶
func (multiSignature *MultiSignature) AsSignMessage() []byte
func (*MultiSignature) Num ¶
func (multiSignature *MultiSignature) Num() int
type RegisterAsProducerTransactionExecutor ¶
type RegisterAsProducerTransactionExecutor struct { }
func (*RegisterAsProducerTransactionExecutor) ExecuteTransaction ¶
func (registerAsProducerTransactionExecutor *RegisterAsProducerTransactionExecutor) ExecuteTransaction(context *transactions.ExecuteTransactionContext) *types.ExecuteTransactionResult
type RegisterAsProducerTransactionSelector ¶
type RegisterAsProducerTransactionSelector struct{}
***********DEPLOY**************//
func (*RegisterAsProducerTransactionSelector) Select ¶
func (registerAsProducerTransactionSelector *RegisterAsProducerTransactionSelector) Select(tx *types.Transaction) bool
type RewardCalculator ¶
type RewardCalculator struct {
// contains filtered or unexported fields
}
func NewRewardCalculator ¶
func NewRewardCalculator(trieStore store.StoreInterface, sig *MultiSignature, producers types.ProducerSet, totalGasBalance *big.Int, height uint64) *RewardCalculator
func (*RewardCalculator) AccumulateRewards ¶
func (calculator *RewardCalculator) AccumulateRewards(height uint64) error
AccumulateRewards credits,The leader gets half of the reward and other ,Other participants get the average of the other half
Click to show internal directories.
Click to hide internal directories.