Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endorsement-proposal verify step #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions consensus/vbft/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,11 @@ func (self *Server) processMsgEvent() error {
self.fetchProposal(msgBlkNum, pMsg.EndorsedProposer)
}

if err := self.verifyProposalEndorsementMessage(msgBlkNum, pMsg.EndorsedProposer, pMsg.EndorsedBlockHash, pMsg.EndorseForEmpty); err != nil {
log.Errorf("failed to verify endorsement msg (%d): %s", msgBlkNum, err)
return nil
}

// add endorse to block-pool
if err := self.blockPool.newBlockEndorsement(pMsg); err != nil {
log.Errorf("failed to add endorsement (%d): %s", msgBlkNum, err)
Expand Down Expand Up @@ -1379,6 +1384,12 @@ func (self *Server) processMsgEvent() error {
// sealProposal(msg.BlockHash)
// else if WaitCommitsTimer has not started:
// start WaitCommitsTimer

if err := self.verifyProposalEndorsementMessage(msgBlkNum, pMsg.BlockProposer, pMsg.CommitBlockHash, pMsg.CommitForEmpty); err != nil {
log.Errorf("failed to verify commit msg (%d): %s", msgBlkNum, err)
return nil
}

if err := self.blockPool.newBlockCommitment(pMsg); err != nil {
log.Errorf("failed to add commit msg (%d): %s", msgBlkNum, err)
return nil
Expand Down Expand Up @@ -1430,6 +1441,19 @@ func (self *Server) processMsgEvent() error {
return nil
}

func (self *Server) verifyProposalEndorsementMessage(blockNum uint32, proposer uint32, blockHash common.Uint256, forEmpty bool) (err error) {
proposal := self.findBlockProposal(blockNum, proposer, forEmpty)
if proposal == nil {
return fmt.Errorf("missing relevant proposal, block height %v, hash %s, proposer %v", blockNum, blockHash.ToHexString(), proposal)
}
proposedBlockHash := proposal.Block.Block.Hash()
if !bytes.Equal(proposedBlockHash[:], blockHash[:]) {
return fmt.Errorf("unmatched proposal from same proposer, block height %v, hash %s, existing hash %s proposer %v", blockNum,
blockHash.ToHexString(), proposedBlockHash, proposal)
}
return
}

func (self *Server) actionLoop() {
self.quitWg.Add(1)
defer self.quitWg.Done()
Expand Down