Skip to content

Commit

Permalink
Include the round number in block BLS signatures (ethereum#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asa Oines authored Nov 16, 2019
1 parent fdc970d commit 1601c0b
Show file tree
Hide file tree
Showing 20 changed files with 394 additions and 308 deletions.
6 changes: 5 additions & 1 deletion consensus/istanbul/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p/enode"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ type Backend interface {

// Commit delivers an approved proposal to backend.
// The delivered proposal will be put into blockchain.
Commit(proposal Proposal, bitmap *big.Int, seals []byte) error
Commit(proposal Proposal, aggregatedSeal types.IstanbulAggregatedSeal) error

// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
// the time difference of the proposal and current time is also returned.
Expand All @@ -73,6 +74,9 @@ type Backend interface {
// LastProposal retrieves latest committed proposal and the address of proposer
LastProposal() (Proposal, common.Address)

// LastSubject retrieves latest committed subject (view and digest)
LastSubject() (Subject, error)

// HasProposal checks if the combination of the given hash and height matches any existing blocks
HasProposal(hash common.Hash, number *big.Int) bool

Expand Down
18 changes: 14 additions & 4 deletions consensus/istanbul/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (sb *Backend) GetDataDir() string {
}

// Commit implements istanbul.Backend.Commit
func (sb *Backend) Commit(proposal istanbul.Proposal, bitmap *big.Int, seals []byte) error {
func (sb *Backend) Commit(proposal istanbul.Proposal, aggregatedSeal types.IstanbulAggregatedSeal) error {
// Check if the proposal is a valid block
block := &types.Block{}
block, ok := proposal.(*types.Block)
Expand All @@ -278,14 +278,14 @@ func (sb *Backend) Commit(proposal istanbul.Proposal, bitmap *big.Int, seals []b

h := block.Header()
// Append seals into extra-data
err := writeCommittedSeals(h, bitmap, seals, false)
err := writeAggregatedSeal(h, aggregatedSeal, false)
if err != nil {
return err
}
// update block's header
block = block.WithSeal(h)

sb.logger.Info("Committed", "address", sb.Address(), "hash", proposal.Hash(), "number", proposal.Number().Uint64())
sb.logger.Info("Committed", "address", sb.Address(), "round", aggregatedSeal.Round.Uint64(), "hash", proposal.Hash(), "number", proposal.Number().Uint64())
// - if the proposed and committed blocks are the same, send the proposed hash
// to commit channel, which is being watched inside the engine.Seal() function.
// - otherwise, we try to insert the block.
Expand Down Expand Up @@ -347,7 +347,7 @@ func (sb *Backend) Verify(proposal istanbul.Proposal) (time.Duration, error) {
err = sb.VerifyHeader(sb.chain, block.Header(), false)

// ignore errEmptyCommittedSeals error because we don't have the committed seals yet
if err != nil && err != errEmptyCommittedSeals {
if err != nil && err != errEmptyAggregatedSeal {
if err == consensus.ErrFutureBlock {
return time.Unix(block.Header().Time.Int64(), 0).Sub(now()), consensus.ErrFutureBlock
} else {
Expand Down Expand Up @@ -559,6 +559,16 @@ func (sb *Backend) LastProposal() (istanbul.Proposal, common.Address) {
return block, proposer
}

func (sb *Backend) LastSubject() (istanbul.Subject, error) {
lastProposal, _ := sb.LastProposal()
istExtra, err := types.ExtractIstanbulExtra(lastProposal.Header())
if err != nil {
return istanbul.Subject{}, err
}
lastView := &istanbul.View{Sequence: lastProposal.Number(), Round: istExtra.AggregatedSeal.Round}
return istanbul.Subject{View: lastView, Digest: lastProposal.Hash()}, nil
}

func (sb *Backend) HasBadProposal(hash common.Hash) bool {
if sb.hasBadBlock == nil {
return false
Expand Down
6 changes: 3 additions & 3 deletions consensus/istanbul/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestCommit(t *testing.T) {
{
// normal case
nil,
make([]byte, types.IstanbulExtraCommittedSeal),
make([]byte, types.IstanbulExtraBlsSignature),
func() *types.Block {
chain, engine := newBlockChain(1, true)
block := makeBlockWithoutSeal(chain, engine, chain.Genesis())
Expand All @@ -138,7 +138,7 @@ func TestCommit(t *testing.T) {
},
{
// invalid signature
errInvalidCommittedSeals,
errInvalidAggregatedSeal,
nil,
func() *types.Block {
chain, engine := newBlockChain(1, true)
Expand All @@ -157,7 +157,7 @@ func TestCommit(t *testing.T) {
}()

backend.proposedBlockHash = expBlock.Hash()
if err := backend.Commit(expBlock, big.NewInt(0), test.expectedSignature); err != nil {
if err := backend.Commit(expBlock, types.IstanbulAggregatedSeal{Round: big.NewInt(0), Bitmap: big.NewInt(0), Signature: test.expectedSignature}); err != nil {
if err != test.expectedErr {
t.Errorf("error mismatch: have %v, want %v", err, test.expectedErr)
}
Expand Down
Loading

0 comments on commit 1601c0b

Please sign in to comment.