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

*: extend PreBlock processing callback #129

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 27 additions & 15 deletions dbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (d *DBFT[H]) addTransaction(tx Transaction[H]) {
return
}

d.verifyPreCommitPayloadsAgainstPreBlock()
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved

d.extendTimer(2)
d.sendPrepareResponse()
d.checkPrepare()
Expand Down Expand Up @@ -391,24 +393,34 @@ func (d *DBFT[H]) updateExistingPayloads(msg ConsensusPayload[H]) {
}

if d.isAntiMEVExtensionEnabled() {
for i, m := range d.PreCommitPayloads {
if m != nil && m.ViewNumber() == d.ViewNumber {
if preHeader := d.MakePreHeader(); preHeader != nil {
pub := d.Validators[m.ValidatorIndex()]
if err := preHeader.Verify(pub, m.GetPreCommit().Data()); err != nil {
d.PreCommitPayloads[i] = nil
d.Logger.Warn("can't validate preCommit data",
zap.Error(err))
}
}
}
}
d.verifyPreCommitPayloadsAgainstPreBlock()
// Commits can't be verified, we have no idea what's the header.
} else {
d.verifyCommitPayloadsAgainstHeader()
}
}

// verifyPreCommitPayloadsAgainstPreBlock performs verification of PreCommit payloads
// against generated PreBlock.
func (d *DBFT[H]) verifyPreCommitPayloadsAgainstPreBlock() {
if !d.hasAllTransactions() {
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
return
}
for i, m := range d.PreCommitPayloads {
if m != nil && m.ViewNumber() == d.ViewNumber {
if preBlock := d.CreatePreBlock(); preBlock != nil {
pub := d.Validators[m.ValidatorIndex()]
if err := preBlock.Verify(pub, m.GetPreCommit().Data()); err != nil {
d.PreCommitPayloads[i] = nil
d.Logger.Warn("PreCommit verification failed",
zap.Uint16("from", m.ValidatorIndex()),
zap.Error(err))
}
}
}
}
}

// verifyCommitPayloadsAgainstHeader performs verification of commit payloads
// against generated header.
func (d *DBFT[H]) verifyCommitPayloadsAgainstHeader() {
Expand Down Expand Up @@ -532,10 +544,10 @@ func (d *DBFT[H]) onPreCommit(msg ConsensusPayload[H]) {
d.Logger.Info("received PreCommit", zap.Uint("validator", uint(msg.ValidatorIndex())))
d.extendTimer(4)

preHeader := d.MakePreHeader()
if preHeader != nil {
preBlock := d.CreatePreBlock()
if preBlock != nil {
pub := d.Validators[msg.ValidatorIndex()]
if err := preHeader.Verify(pub, msg.GetPreCommit().Data()); err == nil {
if err := preBlock.Verify(pub, msg.GetPreCommit().Data()); err == nil {
d.checkPreCommit()
} else {
d.PreCommitPayloads[msg.ValidatorIndex()] = nil
Expand Down
3 changes: 2 additions & 1 deletion pre_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type PreBlock[H Hash] interface {
SetData(key PrivateKey) error
// Verify checks if data related to PreCommit phase is correct. This method is
// refined on PreBlock rather than on PreCommit message since PreBlock itself is
// required for PreCommit's data verification.
// required for PreCommit's data verification. It's guaranteed that all
// proposed transactions are collected by the moment of call to Verify.
Verify(key PublicKey, data []byte) error

// Transactions returns PreBlock's transaction list. This list may be different
Expand Down