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

feat(consensus/grandpa): Add warp sync proof verification #4240

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions dot/network/mock_warp_sync_provider_test.go

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

15 changes: 15 additions & 0 deletions dot/network/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@ import (
"fmt"

"github.com/ChainSafe/gossamer/dot/network/messages"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa"
primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa"
"github.com/ChainSafe/gossamer/lib/common"
libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
)

const MaxAllowedSameRequestPerPeer = 5

type WarpSyncVerificationResult struct {
dimartiro marked this conversation as resolved.
Show resolved Hide resolved
SetId grandpa.SetID
AuthorityList primitives.AuthorityList
Header types.Header
Completed bool
}

// WarpSyncProvider is an interface for generating warp sync proofs
type WarpSyncProvider interface {
// Generate proof starting at given block hash. The proof is accumulated until maximum proof
// size is reached.
Generate(start common.Hash) (encodedProof []byte, err error)
Verify(
encodedProof []byte,
setId grandpa.SetID,
authorities primitives.AuthorityList,
) (*WarpSyncVerificationResult, error)
}

func (s *Service) handleWarpSyncRequest(req messages.WarpProofRequest) ([]byte, error) {
Expand Down
3 changes: 1 addition & 2 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ChainSafe/gossamer/dot/sync"
"github.com/ChainSafe/gossamer/dot/system"
"github.com/ChainSafe/gossamer/dot/types"
consensus_grandpa "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa"
"github.com/ChainSafe/gossamer/internal/database"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/internal/metrics"
Expand Down Expand Up @@ -350,7 +349,7 @@ func (nodeBuilder) createNetworkService(config *cfg.Config, stateSrvc *state.Ser
return nil, fmt.Errorf("failed to parse network log level: %w", err)
}

warpSyncProvider := consensus_grandpa.NewWarpSyncProofProvider(
warpSyncProvider := grandpa.NewWarpSyncProofProvider(
stateSrvc.Block, stateSrvc.Grandpa,
)

Expand Down
2 changes: 2 additions & 0 deletions dot/types/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,5 @@ func AuthoritiesRawToAuthorityAsAddress(authsRaw []AuthorityRaw, kt crypto.KeyTy
}
return auths, nil
}

type AuthorityList []Authority
4 changes: 2 additions & 2 deletions internal/client/consensus/grandpa/justification.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type decodeGrandpaJustification[
Hasher runtime.Hasher[Hash],
] GrandpaJustification[Hash, N]

func decodeJustification[
func DecodeJustification[
Hash runtime.Hash,
N runtime.Number,
Hasher runtime.Hasher[Hash],
Expand Down Expand Up @@ -100,7 +100,7 @@ func DecodeGrandpaJustificationVerifyFinalizes[
setID uint64,
voters grandpa.VoterSet[string],
) (GrandpaJustification[Hash, N], error) {
justification, err := decodeJustification[Hash, N, Hasher](encoded)
justification, err := DecodeJustification[Hash, N, Hasher](encoded)
if err != nil {
return GrandpaJustification[Hash, N]{}, fmt.Errorf("error decoding justification for header: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/consensus/grandpa/justification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestJustificationEncoding(t *testing.T) {
encodedJustification, err := scale.Marshal(expected)
require.NoError(t, err)

justification, err := decodeJustification[hash.H256, uint64, runtime.BlakeTwo256](encodedJustification)
justification, err := DecodeJustification[hash.H256, uint64, runtime.BlakeTwo256](encodedJustification)
require.NoError(t, err)
require.Equal(t, expected, justification.Justification)
}
Expand Down
180 changes: 0 additions & 180 deletions internal/client/consensus/grandpa/warp_sync.go

This file was deleted.

Loading
Loading