Skip to content

Commit

Permalink
send: report error on PreCommit/Commit construction
Browse files Browse the repository at this point in the history
No functional changes, but at least it will be easier to track malformed
empty commits.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Jan 22, 2025
1 parent 026852c commit ed1456d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,43 @@ func (d *DBFT[H]) sendPrepareResponse() {
d.broadcast(msg)
}

func (c *Context[H]) makePreCommit() ConsensusPayload[H] {
if msg := c.PreCommitPayloads[c.MyIndex]; msg != nil {
func (d *DBFT[H]) makePreCommit() ConsensusPayload[H] {
if msg := d.PreCommitPayloads[d.MyIndex]; msg != nil {
return msg
}

if preB := c.CreatePreBlock(); preB != nil {
if preB := d.CreatePreBlock(); preB != nil {
var preData []byte
if err := preB.SetData(c.Priv); err == nil {
if err := preB.SetData(d.Priv); err == nil {
preData = preB.Data()
} else {
d.Logger.Error("PreCommit data construction failed", zap.Error(err))
}

preCommit := c.Config.NewPreCommit(preData)
preCommit := d.Config.NewPreCommit(preData)

return c.Config.NewConsensusPayload(c, PreCommitType, preCommit)
return d.Config.NewConsensusPayload(&d.Context, PreCommitType, preCommit)
}

return nil
}

func (c *Context[H]) makeCommit() ConsensusPayload[H] {
if msg := c.CommitPayloads[c.MyIndex]; msg != nil {
func (d *DBFT[H]) makeCommit() ConsensusPayload[H] {
if msg := d.CommitPayloads[d.MyIndex]; msg != nil {
return msg
}

if b := c.MakeHeader(); b != nil {
if b := d.MakeHeader(); b != nil {
var sign []byte
if err := b.Sign(c.Priv); err == nil {
if err := b.Sign(d.Priv); err == nil {
sign = b.Signature()
} else {
d.Logger.Error("block signing failed", zap.Error(err))
}

commit := c.Config.NewCommit(sign)
commit := d.Config.NewCommit(sign)

return c.Config.NewConsensusPayload(c, CommitType, commit)
return d.Config.NewConsensusPayload(&d.Context, CommitType, commit)
}

return nil
Expand Down

0 comments on commit ed1456d

Please sign in to comment.