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

[Consensus] Refactor for guarantee signer indices (4/4) #2204

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
948503e
wip
Mar 17, 2022
5c776a5
wip
Mar 17, 2022
3dfa541
starting to fix tests
Mar 17, 2022
965801a
adding tests
Mar 18, 2022
7e2c445
happy path test
Mar 18, 2022
e7a12cb
Added toDo for fixing tests for unhappy paths
Mar 19, 2022
b269309
• fixed packer tests
Mar 19, 2022
dbdde62
re-gen mocks
Mar 19, 2022
35317c4
fix validPadding
zhangchiqing Mar 22, 2022
c55905e
fix findguarantors
zhangchiqing Mar 22, 2022
776021d
refactor ingestion/core.go
zhangchiqing Mar 24, 2022
7f350f1
move FindGuarantors to protocol
zhangchiqing Mar 25, 2022
6743ea6
remove commented code
zhangchiqing Mar 28, 2022
02f4ef2
fix name
zhangchiqing Mar 28, 2022
98f1136
fix tests
zhangchiqing Mar 28, 2022
fc51370
small refactor
zhangchiqing Mar 28, 2022
df0f155
fix import
zhangchiqing Mar 28, 2022
e899471
Apply suggestions from code review
zhangchiqing Mar 28, 2022
d6a8ae8
fix error type
zhangchiqing Mar 28, 2022
a4361de
fix type
zhangchiqing Mar 28, 2022
4d03608
fix error message
zhangchiqing Mar 28, 2022
f18e6e2
update comments
zhangchiqing Mar 29, 2022
c4e6fad
update comment
zhangchiqing Mar 29, 2022
8d5e452
update tests
zhangchiqing Mar 29, 2022
747df3d
fix identity_test
zhangchiqing Mar 29, 2022
c4fb10a
fix tests
zhangchiqing Mar 29, 2022
3cb260e
fix unittest
zhangchiqing Mar 29, 2022
d5bc29f
fix cluster tests
zhangchiqing Mar 29, 2022
7a0bdef
fix tests
zhangchiqing Mar 29, 2022
b955303
fixtures ingestion engine tests
zhangchiqing Mar 30, 2022
066abdc
fix execution_test
zhangchiqing Mar 30, 2022
4cf71a4
fix consensus inclusion tests
zhangchiqing Mar 30, 2022
09edfff
fix bootstrap constraint check
zhangchiqing Mar 30, 2022
a852093
fix cycle dep from NewClusterList (#2225)
zhangchiqing Mar 30, 2022
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
4 changes: 2 additions & 2 deletions cmd/bootstrap/cmd/seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/packer"
"github.com/onflow/flow-go/module/signature"
)

func constructRootResultAndSeal(
Expand Down Expand Up @@ -47,7 +47,7 @@ func constructRootResultAndSeal(
qcsWithSignerIDs := make([]*flow.QuorumCertificateWithSignerIDs, 0, len(clusterQCs))
for i, clusterQC := range clusterQCs {
members := assignments[i]
signerIDs, err := packer.DecodeSignerIdentifiersFromIndices(members, clusterQC.SignerIndices)
signerIDs, err := signature.DecodeSignerIndicesToIdentifiers(members, clusterQC.SignerIndices)
if err != nil {
log.Fatal().Err(err).Msgf("could not decode signer IDs from clusterQC at index %v", i)
}
Expand Down
7 changes: 4 additions & 3 deletions consensus/follower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/onflow/flow-go/module/signature"

"github.com/rs/zerolog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -16,7 +18,6 @@ import (
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
mockmodule "github.com/onflow/flow-go/module/mock"
"github.com/onflow/flow-go/module/packer"
mockstorage "github.com/onflow/flow-go/storage/mock"
"github.com/onflow/flow-go/utils/unittest"
)
Expand Down Expand Up @@ -107,7 +108,7 @@ func (s *HotStuffFollowerSuite) SetupTest() {
View: 52078,
}

signerIndices, err := packer.EncodeSignerIdentifiersToIndices(identities.NodeIDs(), identities.NodeIDs()[:3])
signerIndices, err := signature.EncodeSignersToIndices(identities.NodeIDs(), identities.NodeIDs()[:3])
require.NoError(s.T(), err)
s.rootQC = &flow.QuorumCertificate{
View: s.rootHeader.View,
Expand Down Expand Up @@ -339,7 +340,7 @@ func (mc *MockConsensus) extendBlock(blockView uint64, parent *flow.Header) *flo
nextBlock := unittest.BlockHeaderWithParentFixture(parent)
nextBlock.View = blockView
nextBlock.ProposerID = mc.identities[int(blockView)%len(mc.identities)].NodeID
signerIndices, _ := packer.EncodeSignerIdentifiersToIndices(mc.identities.NodeIDs(), mc.identities.NodeIDs())
signerIndices, _ := signature.EncodeSignersToIndices(mc.identities.NodeIDs(), mc.identities.NodeIDs())
nextBlock.ParentVoterIndices = signerIndices
return &nextBlock
}
8 changes: 3 additions & 5 deletions consensus/hotstuff/integration/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ import (
"github.com/onflow/flow-go/consensus/hotstuff/notifications"
"github.com/onflow/flow-go/consensus/hotstuff/pacemaker"
"github.com/onflow/flow-go/consensus/hotstuff/pacemaker/timeout"
hsig "github.com/onflow/flow-go/consensus/hotstuff/signature"
"github.com/onflow/flow-go/consensus/hotstuff/validator"
"github.com/onflow/flow-go/consensus/hotstuff/voteaggregator"
"github.com/onflow/flow-go/consensus/hotstuff/votecollector"
"github.com/onflow/flow-go/consensus/hotstuff/voter"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/irrecoverable"
module "github.com/onflow/flow-go/module/mock"
"github.com/onflow/flow-go/module/packer"
msig "github.com/onflow/flow-go/module/signature"
"github.com/onflow/flow-go/utils/unittest"
)
Expand Down Expand Up @@ -209,7 +207,7 @@ func NewInstance(t require.TestingT, options ...Option) *Instance {
View: block.View,
BlockID: block.BlockID,
SignerID: in.localID,
SigData: unittest.RandomBytes(hsig.SigLen * 2), // double sig, one staking, one beacon
SigData: unittest.RandomBytes(msig.SigLen * 2), // double sig, one staking, one beacon
}
return vote
},
Expand All @@ -222,7 +220,7 @@ func NewInstance(t require.TestingT, options ...Option) *Instance {
voterIDs = append(voterIDs, vote.SignerID)
}

signerIndices, err := packer.EncodeSignerIdentifiersToIndices(in.participants.NodeIDs(), voterIDs)
signerIndices, err := msig.EncodeSignersToIndices(in.participants.NodeIDs(), voterIDs)
require.NoError(t, err, "could not encode signer indices")

qc := &flow.QuorumCertificate{
Expand Down Expand Up @@ -349,7 +347,7 @@ func NewInstance(t require.TestingT, options ...Option) *Instance {
rbRector := helper.MakeRandomBeaconReconstructor(msig.RandomBeaconThreshold(int(in.participants.Count())))
rbRector.On("Verify", mock.Anything, mock.Anything).Return(nil).Maybe()

indices, err := packer.EncodeSignerIdentifiersToIndices(in.participants.NodeIDs(), []flow.Identifier(in.participants.NodeIDs()))
indices, err := msig.EncodeSignersToIndices(in.participants.NodeIDs(), []flow.Identifier(in.participants.NodeIDs()))
require.NoError(t, err)

packer := &mocks.Packer{}
Expand Down
6 changes: 3 additions & 3 deletions consensus/hotstuff/mocks/packer.go

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

8 changes: 4 additions & 4 deletions consensus/hotstuff/mocks/verifier.go

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

23 changes: 22 additions & 1 deletion consensus/hotstuff/model/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

var (
ErrUnverifiableBlock = errors.New("block proposal can't be verified, because its view is above the finalized view, but its QC is below the finalized view")
ErrInvalidFormat = errors.New("invalid signature format")
ErrInvalidSignature = errors.New("invalid signature")
)

Expand All @@ -26,6 +25,28 @@ func IsNoVoteError(err error) bool {
return errors.As(err, &e)
}

// InvalidFormatError indicates that some data has an incompatible format.
type InvalidFormatError struct {
err error
}

func NewInvalidFormatError(err error) error {
return InvalidFormatError{err}
}

func NewInvalidFormatErrorf(msg string, args ...interface{}) error {
return InvalidFormatError{fmt.Errorf(msg, args...)}
}

func (e InvalidFormatError) Error() string { return e.err.Error() }
func (e InvalidFormatError) Unwrap() error { return e.err }

// IsInvalidFormatError returns whether err is a InvalidFormatError
func IsInvalidFormatError(err error) bool {
var e InvalidFormatError
return errors.As(err, &e)
}

// ConfigurationError indicates that a constructor or component was initialized with
// invalid or inconsistent parameters.
type ConfigurationError struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package packer
package model

import (
"bytes"
"fmt"

"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/model/encoding/rlp"
)
Expand Down Expand Up @@ -49,7 +47,7 @@ func UnpackRandomBeaconSig(sigData []byte) (crypto.Signature, error) {
packer := SigDataPacker{}
sig, err := packer.Decode(sigData)
if err != nil {
return nil, fmt.Errorf("could not decode sig data %s: %w", err, model.ErrInvalidFormat)
return nil, NewInvalidFormatErrorf("could not decode sig data: %w", err)
}
return sig.ReconstructedRandomBeaconSig, nil
}
20 changes: 1 addition & 19 deletions consensus/hotstuff/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ type RandomBeaconReconstructor interface {
Reconstruct() (crypto.Signature, error)
}

// SigType is the aggregable signature type.
type SigType uint8

// SigType specifies the role of the signature in the protocol.
// Both types are aggregatable cryptographic signatures.
// * SigTypeRandomBeacon type is for random beacon signatures.
// * SigTypeStaking is for Hotstuff signatures.
const (
SigTypeStaking SigType = iota
SigTypeRandomBeacon
)

// Valid returns true if the signature is either SigTypeStaking or SigTypeRandomBeacon
// else return false
func (t SigType) Valid() bool {
return t == SigTypeStaking || t == SigTypeRandomBeacon
}

// WeightedSignatureAggregator aggregates signatures of the same signature scheme and the
// same message from different signers. The public keys and message are agreed upon upfront.
// It is also recommended to only aggregate signatures generated with keys representing
Expand Down Expand Up @@ -131,5 +113,5 @@ type Packer interface {
// It returns:
// - (sigData, nil) if successfully unpacked the signature data
// - (nil, model.ErrInvalidFormat) if failed to unpack the signature data
Unpack(signerIDs []flow.Identifier, sigData []byte) (*BlockSignatureData, error)
Unpack(signerIdentities flow.IdentityList, sigData []byte) (*BlockSignatureData, error)
}
Loading