Skip to content

Commit

Permalink
dbft: simplify OnTransaction logic with slices package
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Aug 9, 2024
1 parent 429f283 commit 82a8d2f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions dbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,17 @@ func (d *DBFT[H]) OnTransaction(tx Transaction[H]) {
return
}

for i := range d.MissingTransactions {
if tx.Hash() == d.MissingTransactions[i] {
d.addTransaction(tx)
// `addTransaction` checks for responses and commits. If this was the last transaction
// Context could be initialized on a new height, clearing this field.
if len(d.MissingTransactions) == 0 {
return
}
d.MissingTransactions = slices.Delete(d.MissingTransactions, i, i)
return
}
i := slices.Index(d.MissingTransactions, tx.Hash())
if i < 0 {
return
}
d.addTransaction(tx)
// `addTransaction` checks for responses and commits. If this was the last transaction
// Context could be initialized on a new height, clearing this field.
if len(d.MissingTransactions) == 0 {
return

Check warning on line 181 in dbft.go

View check run for this annotation

Codecov / codecov/patch

dbft.go#L181

Added line #L181 was not covered by tests
}
d.MissingTransactions = slices.Delete(d.MissingTransactions, i, i)
}

// OnTimeout advances state machine as if timeout was fired.
Expand Down

0 comments on commit 82a8d2f

Please sign in to comment.