Skip to content

Commit

Permalink
Update interface of IsValidCommittedSeal and InsertBlock by go-ibft's…
Browse files Browse the repository at this point in the history
… update (#677)

* Update interface of IsValidCommittedSeal and InsertBlock based on go-ibft's update

* Update go-ibft

* Additional check of signer in IsValidCommittedSeal
  • Loading branch information
Kourin1996 committed Aug 11, 2022
1 parent e977be7 commit fb219ba
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 21 deletions.
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

0 comments on commit fb219ba

Please sign in to comment.