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

Update interface of IsValidCommittedSeal and InsertBlock by go-ibft's update #677

Merged
merged 4 commits into from
Aug 11, 2022
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
13 changes: 11 additions & 2 deletions consensus/ibft/consensus_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"github.com/0xPolygon/go-ibft/messages"
"github.com/0xPolygon/polygon-edge/consensus"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -42,16 +43,24 @@ func (i *backendIBFT) BuildProposal(blockNumber uint64) []byte {
return block.MarshalRLP()
}

func (i *backendIBFT) InsertBlock(proposal []byte, committedSeals [][]byte) {
func (i *backendIBFT) InsertBlock(
proposal []byte,
committedSeals []*messages.CommittedSeal,
) {
newBlock := &types.Block{}
if err := newBlock.UnmarshalRLP(proposal); err != nil {
i.logger.Error("cannot unmarshal proposal", "err", err)

return
}

seals := make([][]byte, len(committedSeals))
for idx := range committedSeals {
seals[idx] = committedSeals[idx].Signature
}

// Push the committed seals to the header
header, err := writeCommittedSeals(newBlock.Header, committedSeals)
header, err := writeCommittedSeals(newBlock.Header, seals)
if err != nil {
i.logger.Error("cannot write committed seals", "err", err)

Expand Down
9 changes: 7 additions & 2 deletions consensus/ibft/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"errors"
"fmt"

"github.com/0xPolygon/go-ibft/messages"
protoIBFT "github.com/0xPolygon/go-ibft/messages/proto"
"github.com/0xPolygon/polygon-edge/types"
)
Expand Down Expand Up @@ -116,9 +118,12 @@ func (i *backendIBFT) IsValidProposalHash(proposal, hash []byte) bool {
return bytes.Equal(blockHash, hash)
}

func (i *backendIBFT) IsValidCommittedSeal(proposalHash, seal []byte) bool {
func (i *backendIBFT) IsValidCommittedSeal(
proposalHash []byte,
committedSeal *messages.CommittedSeal,
) bool {
// seal was generated based on the proposal hash
validator, err := ecrecoverImpl(seal, wrapCommitHash(proposalHash))
validator, err := ecrecoverImpl(committedSeal.Signature, wrapCommitHash(proposalHash))
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
i.logger.Error("unable to recover seal", "err", err)

Expand Down