Documentation ¶
Index ¶
- Constants
- Variables
- type BftConfig
- type BftConsensus
- func (bftConsensus *BftConsensus) ChangeTime(interval time.Duration)
- func (bftConsensus *BftConsensus) Close()
- func (bftConsensus *BftConsensus) GetProducers(height uint64, topN int) ([]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() *BftConfig
- func (bftConsensusService *BftConsensusService) GetProducers(height uint64, topN int) ([]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 *chain.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) (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) (IConsenMsg, error)
- func (member *Member) Reset()
- func (member *Member) WaitChallenge()
- func (member *Member) WaitSetUp()
- type MemberInfo
- type MinerGenesisProcessor
- type MsgWrap
- type MultiSignature
- type Producer
- type ProducerSet
- 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 MsgTypeFail = 4 MsgTypeValidateReq = 5 MsgTypeValidateRes = 6 MaxMsgSize = 20 << 20 SetupMagic = 0xfefefbfe CommitMagic = 0xfefefbfd ChallegeMagic = 0xfefefbfc FailMagic = 0xfefefbfb ResponseMagic = 0xfefefbfa )
本模块的消息只能在调用本模块(consensus及对应的子模块)的函数中使用,否则会出错 例如MsgTypeCommitment消息,在consensus中定义的,发送和接收此消息必须使用consensus中的函数
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",
}
)
View Source
var (
MinerPrefix = []byte("miner")
)
View Source
var NumberOfMsg = 7
Functions ¶
This section is empty.
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 *BftConsensus) GetProducers(height uint64, topN int) ([]Producer, error)
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 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() *BftConfig
func (*BftConsensusService) GetProducers ¶
func (bftConsensusService *BftConsensusService) GetProducers(height uint64, topN int) ([]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 NewBlockMultiSigValidator ¶
func NewBlockMultiSigValidator(getProducers GetProducers, getBlock GetBlock, producerNum int) *BlockMultiSigValidator
func (*BlockMultiSigValidator) ExecuteBlock ¶
func (blockMultiSigValidator *BlockMultiSigValidator) ExecuteBlock(context *chain.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: 共识rpc接口 usage: 查询共识节点功能 prefix:consensus
func (*ConsensusApi) ChangeWaitTime ¶
func (consensusApi *ConsensusApi) ChangeWaitTime(waitTime int)
name: changeWaitTime usage: 修改leader等待时间 (ms) params: 1.等待时间(ms) return: 私钥 example: curl http://localhost:15645 -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: 获取当前出块节点 params: 无 return: 出块节点信息 example: curl http://localhost:15645 -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() ([]*Producer, error)
func (*ConsensusOp) SaveProducer ¶
func (consensusOp *ConsensusOp) SaveProducer(p []*Producer) error
type IConsenMsg ¶
type IRewardCalculator ¶
type IRewardCalculator interface {
AccumulateRewards(sig *MultiSignature, Producers 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) (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) (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 Producer ¶
func GetCandidates ¶
func GetCandidates(store store.StoreInterface, topN int) []Producer
func (*Producer) Address ¶
func (producer *Producer) Address() crypto.CommonAddress
type ProducerSet ¶
type ProducerSet []Producer
func (*ProducerSet) IsLocalAddress ¶
func (produceSet *ProducerSet) IsLocalAddress(addr crypto.CommonAddress) bool
func (*ProducerSet) IsLocalIP ¶
func (produceSet *ProducerSet) IsLocalIP(ip string) bool
type RegisterAsProducerTransactionExecutor ¶
type RegisterAsProducerTransactionExecutor struct { }
func (*RegisterAsProducerTransactionExecutor) ExecuteTransaction ¶
func (registerAsProducerTransactionExecutor *RegisterAsProducerTransactionExecutor) ExecuteTransaction(context *chain.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 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.