|
|
@ -535,47 +535,48 @@ func (consensus *Consensus) preCommitAndPropose(blk *types.Block) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct committed message
|
|
|
|
// Construct committed message
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
|
|
|
network, err := consensus.construct(msg_pb.MessageType_COMMITTED, nil, []*bls.PrivateKeyWrapper{leaderPriKey}) |
|
|
|
network, err := consensus.construct(msg_pb.MessageType_COMMITTED, nil, []*bls.PrivateKeyWrapper{leaderPriKey}) |
|
|
|
consensus.mutex.Unlock() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
consensus.getLogger().Warn().Err(err). |
|
|
|
consensus.getLogger().Warn().Err(err). |
|
|
|
Msg("[preCommitAndPropose] Unable to construct Committed message") |
|
|
|
Msg("[preCommitAndPropose] Unable to construct Committed message") |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
msgToSend, FBFTMsg := |
|
|
|
|
|
|
|
network.Bytes, |
|
|
|
|
|
|
|
network.FBFTMsg |
|
|
|
|
|
|
|
bareMinimumCommit := FBFTMsg.Payload |
|
|
|
|
|
|
|
consensus.FBFTLog.AddMessage(FBFTMsg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blk.SetCurrentCommitSig(bareMinimumCommit) |
|
|
|
go func() { |
|
|
|
|
|
|
|
msgToSend, FBFTMsg := |
|
|
|
|
|
|
|
network.Bytes, |
|
|
|
|
|
|
|
network.FBFTMsg |
|
|
|
|
|
|
|
bareMinimumCommit := FBFTMsg.Payload |
|
|
|
|
|
|
|
consensus.FBFTLog.AddMessage(FBFTMsg) |
|
|
|
|
|
|
|
|
|
|
|
if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, true); err != nil { |
|
|
|
blk.SetCurrentCommitSig(bareMinimumCommit) |
|
|
|
consensus.getLogger().Error().Err(err).Msg("[preCommitAndPropose] Failed to add block to chain") |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if leader successfully finalizes the block, send committed message to validators
|
|
|
|
if _, err := consensus.Blockchain.InsertChain([]*types.Block{blk}, true); err != nil { |
|
|
|
if err := consensus.msgSender.SendWithRetry( |
|
|
|
consensus.getLogger().Error().Err(err).Msg("[preCommitAndPropose] Failed to add block to chain") |
|
|
|
blk.NumberU64(), |
|
|
|
} |
|
|
|
msg_pb.MessageType_COMMITTED, []nodeconfig.GroupID{ |
|
|
|
|
|
|
|
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)), |
|
|
|
// if leader successfully finalizes the block, send committed message to validators
|
|
|
|
}, |
|
|
|
if err := consensus.msgSender.SendWithRetry( |
|
|
|
p2p.ConstructMessage(msgToSend)); err != nil { |
|
|
|
blk.NumberU64(), |
|
|
|
consensus.getLogger().Warn().Err(err).Msg("[preCommitAndPropose] Cannot send committed message") |
|
|
|
msg_pb.MessageType_COMMITTED, []nodeconfig.GroupID{ |
|
|
|
} else { |
|
|
|
nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID)), |
|
|
|
consensus.getLogger().Info(). |
|
|
|
}, |
|
|
|
Str("blockHash", blk.Hash().Hex()). |
|
|
|
p2p.ConstructMessage(msgToSend)); err != nil { |
|
|
|
Uint64("blockNum", consensus.blockNum). |
|
|
|
consensus.getLogger().Warn().Err(err).Msg("[preCommitAndPropose] Cannot send committed message") |
|
|
|
Msg("[preCommitAndPropose] Sent Committed Message") |
|
|
|
} else { |
|
|
|
} |
|
|
|
consensus.getLogger().Info(). |
|
|
|
consensus.consensusTimeout[timeoutConsensus].Start() |
|
|
|
Str("blockHash", blk.Hash().Hex()). |
|
|
|
|
|
|
|
Uint64("blockNum", consensus.blockNum). |
|
|
|
|
|
|
|
Msg("[preCommitAndPropose] Sent Committed Message") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
consensus.consensusTimeout[timeoutConsensus].Start() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send signal to Node to propose the new block for consensus
|
|
|
|
|
|
|
|
consensus.getLogger().Info().Msg("[preCommitAndPropose] sending block proposal signal") |
|
|
|
|
|
|
|
|
|
|
|
// Send signal to Node to propose the new block for consensus
|
|
|
|
consensus.ReadySignal <- AsyncProposal |
|
|
|
consensus.getLogger().Info().Msg("[preCommitAndPropose] sending block proposal signal") |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
consensus.ReadySignal <- AsyncProposal |
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|