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 all commits
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
18 changes: 14 additions & 4 deletions consensus/ibft/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"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 @@ -117,17 +118,26 @@ 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))
signer, err := ecrecoverImpl(committedSeal.Signature, wrapCommitHash(proposalHash))
if err != nil {
i.logger.Error("unable to recover seal", "err", err)

return false
}

if !i.activeValidatorSet.Includes(validator) {
i.logger.Error("seal generated by validator not in the active set", "validator", validator.String())
if signer != types.BytesToAddress(committedSeal.Signer) {
i.logger.Error("mismatch between signer and message sender", "err", err)

return false
}

if !i.activeValidatorSet.Includes(signer) {
i.logger.Error("seal generated by validator not in the active set", "validator", signer.String())

return false
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
lukechampine.com/blake3 v1.1.7 // indirect
)

require github.com/0xPolygon/go-ibft v0.0.0-20220729102524-0f95a9c3a08c
require github.com/0xPolygon/go-ibft v0.0.0-20220810095021-e43142f8d267

require (
cloud.google.com/go v0.102.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/0xPolygon/go-ibft v0.0.0-20220729102524-0f95a9c3a08c h1:y9Fw+byHhcrV8378z20d2WlyIoHOZiZbPIVAQ9VDuyw=
github.com/0xPolygon/go-ibft v0.0.0-20220729102524-0f95a9c3a08c/go.mod h1:pXhBaK+CcHr3eUAWynKyHGTxgDwpJ3O1tvbGthN+pN4=
github.com/0xPolygon/go-ibft v0.0.0-20220810095021-e43142f8d267 h1:+mFLx9IKW16fOcTKjZjkom3TGnihOuPwYAz2c6+UUWQ=
github.com/0xPolygon/go-ibft v0.0.0-20220810095021-e43142f8d267/go.mod h1:QPrugDXgsCFy2FeCJ0YokPrnyi1GoLhDj/PLO1dSoNY=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
Expand Down
5 changes: 3 additions & 2 deletions vendor/github.com/0xPolygon/go-ibft/core/backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vendor/github.com/0xPolygon/go-ibft/core/ibft.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions vendor/github.com/0xPolygon/go-ibft/core/state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions vendor/github.com/0xPolygon/go-ibft/messages/helpers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cloud.google.com/go/iam
## explicit; go 1.16
cloud.google.com/go/secretmanager/apiv1
cloud.google.com/go/secretmanager/internal
# github.com/0xPolygon/go-ibft v0.0.0-20220729102524-0f95a9c3a08c
# github.com/0xPolygon/go-ibft v0.0.0-20220810095021-e43142f8d267
## explicit; go 1.17
github.com/0xPolygon/go-ibft/core
github.com/0xPolygon/go-ibft/messages
Expand Down