From 3973e400eb032059777d7fa6c5c4ab31f5894c7c Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 22 Oct 2024 14:32:04 -0300 Subject: [PATCH 01/44] feat(dot/sync): Implement warp sync strategy --- dot/network/messages/warp_sync.go | 42 ++++++ dot/peerset/constants.go | 10 ++ dot/sync/fullsync.go | 2 +- dot/sync/service.go | 1 + dot/sync/warp_sync.go | 235 ++++++++++++++++++++++++++++++ 5 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 dot/sync/warp_sync.go diff --git a/dot/network/messages/warp_sync.go b/dot/network/messages/warp_sync.go index 2e2897b6a1..d73588eb23 100644 --- a/dot/network/messages/warp_sync.go +++ b/dot/network/messages/warp_sync.go @@ -6,6 +6,9 @@ package messages import ( "fmt" + "github.com/ChainSafe/gossamer/dot/types" + "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa" + "github.com/ChainSafe/gossamer/internal/primitives/core/hash" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/pkg/scale" ) @@ -15,6 +18,12 @@ type WarpProofRequest struct { Begin common.Hash } +func NewWarpProofRequest(from common.Hash) *WarpProofRequest { + return &WarpProofRequest{ + Begin: from, + } +} + // Decode decodes the message into a WarpProofRequest func (wpr *WarpProofRequest) Decode(in []byte) error { return scale.Unmarshal(in, wpr) @@ -37,4 +46,37 @@ func (wpr *WarpProofRequest) String() string { return fmt.Sprintf("WarpProofRequest begin=%v", wpr.Begin) } +type WarpSyncFragment struct { + Header types.Header + Justification grandpa.GrandpaJustification[hash.H256, uint64] +} + +type WarpSyncProof struct { + Proofs []WarpSyncFragment + // indicates whether the warp sync has been completed + IsFinished bool + proofsLength int +} + +func (wsp *WarpSyncProof) Decode(in []byte) error { + return scale.Unmarshal(in, wsp) +} + +func (wsp *WarpSyncProof) Encode() ([]byte, error) { + if wsp == nil { + return nil, fmt.Errorf("cannot encode nil WarpSyncProof") + } + return scale.Marshal(*wsp) +} + +func (wsp *WarpSyncProof) String() string { + if wsp == nil { + return "WarpSyncProof=nil" + } + + return fmt.Sprintf("WarpSyncProof proofs=%v isFinished=%v proofsLength=%v", + wsp.Proofs, wsp.IsFinished, wsp.proofsLength) +} + +var _ P2PMessage = (*WarpSyncProof)(nil) var _ P2PMessage = (*WarpProofRequest)(nil) diff --git a/dot/peerset/constants.go b/dot/peerset/constants.go index d195b1e0db..095d334ec4 100644 --- a/dot/peerset/constants.go +++ b/dot/peerset/constants.go @@ -76,4 +76,14 @@ const ( // SameBlockSyncRequest used when a peer send us more than the max number of the same request. SameBlockSyncRequest Reputation = math.MinInt32 SameBlockSyncRequestReason = "same block sync request" + + // UnexpectedResponseValue is used when peer send an unexpected response. + UnexpectedResponseValue Reputation = -(1 << 29) + // UnexpectedResponseReason is used when peer send an unexpected response. + UnexpectedResponseReason = "Unexpected response" + + // BadWarpProofValue is used when peer send invalid warp sync proof. + BadWarpProofValue Reputation = -(1 << 29) + // BadWarpProofReason is used when peer send invalid warp sync proof. + BadWarpProofReason = "Bad warp proof" ) diff --git a/dot/sync/fullsync.go b/dot/sync/fullsync.go index 5ae57ea2c8..b8985fb107 100644 --- a/dot/sync/fullsync.go +++ b/dot/sync/fullsync.go @@ -109,7 +109,7 @@ func (f *FullSyncStrategy) NextActions() ([]*SyncTask, error) { } // our best block is equal or ahead of current target. - // in the node's pov we are not legging behind so there's nothing to do + // in the node's pov we are not lagging behind so there's nothing to do // or we didn't receive block announces, so lets ask for more blocks if uint32(bestBlockHeader.Number) >= currentTarget { return f.createTasks(reqsFromQueue), nil diff --git a/dot/sync/service.go b/dot/sync/service.go index a290e1f322..a4ed54c083 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -299,6 +299,7 @@ func (s *SyncService) runStrategy() { s.currentStrategy.ShowMetrics() logger.Trace("finish process to acquire more blocks") + // TODO: why not use s.currentStrategy.IsSynced()? if done { s.currentStrategy = s.defaultStrategy } diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go new file mode 100644 index 0000000000..61f73861df --- /dev/null +++ b/dot/sync/warp_sync.go @@ -0,0 +1,235 @@ +package sync + +import ( + "slices" + "time" + + "github.com/ChainSafe/gossamer/dot/network" + "github.com/ChainSafe/gossamer/dot/network/messages" + "github.com/ChainSafe/gossamer/dot/peerset" + "github.com/ChainSafe/gossamer/dot/types" + consensus_grandpa "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" + primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" + "github.com/ChainSafe/gossamer/lib/grandpa" + "github.com/libp2p/go-libp2p/core/peer" +) + +type WarpSyncPhase uint + +const ( + WarpProof = iota + TargetBlock + Completed +) + +type WarpSyncStrategy struct { + // Strategy dependencies and config + peers *peerViewSet + badBlocks []string + reqMaker network.RequestMaker + warpSyncProvider grandpa.WarpSyncProofProvider + + // Warp sync state + startedAt time.Time + phase WarpSyncPhase + syncedFragments int + setId consensus_grandpa.SetID + authorities primitives.AuthorityList + lastBlock types.Header + result types.BlockData +} + +type WarpSyncConfig struct { + Telemetry Telemetry + BadBlocks []string + RequestMaker network.RequestMaker +} + +// NewWarpSyncStrategy returns a new warp sync strategy +func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { + return &WarpSyncStrategy{ + badBlocks: cfg.BadBlocks, + reqMaker: cfg.RequestMaker, + peers: &peerViewSet{ + view: make(map[peer.ID]peerView), + target: 0, + }, + startedAt: time.Now(), + } +} + +// OnBlockAnnounce on every new block announce received +// Synce it is a warp sync strategy, we are going to only update the peerset reputation +// And peers target block +func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnounceMessage) ( + repChange *Change, err error) { + blockAnnounceHeader := types.NewHeader(msg.ParentHash, msg.StateRoot, msg.ExtrinsicsRoot, msg.Number, msg.Digest) + blockAnnounceHeaderHash := blockAnnounceHeader.Hash() + + logger.Infof("received block announce from %s: #%d (%s) best block: %v", + from, + blockAnnounceHeader.Number, + blockAnnounceHeaderHash, + msg.BestBlock, + ) + + if slices.Contains(w.badBlocks, blockAnnounceHeaderHash.String()) { + logger.Infof("bad block received from %s: #%d (%s) is a bad block", + from, blockAnnounceHeader.Number, blockAnnounceHeaderHash) + + return &Change{ + who: from, + rep: peerset.ReputationChange{ + Value: peerset.BadBlockAnnouncementValue, + Reason: peerset.BadBlockAnnouncementReason, + }, + }, errBadBlockReceived + } + + if msg.BestBlock { + w.peers.update(from, blockAnnounceHeaderHash, uint32(blockAnnounceHeader.Number)) //nolint:gosec + } + + return &Change{ + who: from, + rep: peerset.ReputationChange{ + Value: peerset.GossipSuccessValue, + Reason: peerset.GossipSuccessReason, + }, + }, nil +} + +func (w *WarpSyncStrategy) OnBlockAnnounceHandshake(from peer.ID, msg *network.BlockAnnounceHandshake) error { + w.peers.update(from, msg.BestBlockHash, msg.BestBlockNumber) + return nil +} + +// NextActions returns the next actions to be taken by the sync service +func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { + w.startedAt = time.Now() + + var task SyncTask + switch w.phase { + case WarpProof: + task = SyncTask{ + request: messages.NewWarpProofRequest(w.lastBlock.Hash()), + response: &messages.WarpSyncProof{}, + requestMaker: w.reqMaker, + } + case TargetBlock: + req := messages.NewBlockRequest( + *messages.NewFromBlock(w.lastBlock.Hash()), + 1, + messages.RequestedDataHeader+ + messages.RequestedDataBody+ + messages.RequestedDataJustification, + messages.Ascending, + ) + task = SyncTask{ + request: req, + response: &messages.BlockResponseMessage{}, + requestMaker: w.reqMaker, + } + } + + return []*SyncTask{&task}, nil +} + +// Process processes the results of the sync tasks, getting the best warp sync response and +// Updating our block state +func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( + done bool, repChanges []Change, bans []peer.ID, err error) { + switch w.phase { + case WarpProof: + var warpProofResult *network.WarpSyncVerificationResult + + repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) + if !warpProofResult.Completed { + // Partial warp proof + w.setId = warpProofResult.SetId + w.authorities = warpProofResult.AuthorityList + w.lastBlock = warpProofResult.Header + } else { + w.phase = TargetBlock + w.lastBlock = warpProofResult.Header + } + case TargetBlock: + var validRes []RequestResponseData + + repChanges, bans, validRes = validateResults(results, w.badBlocks) + + // TODO: check if this can cause an issue + w.result = *validRes[0].responseData[0] + w.phase = Completed + } + + return w.IsSynced(), repChanges, bans, nil +} + +func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( + repChanges []Change, peersToBlock []peer.ID, result *network.WarpSyncVerificationResult) { + repChanges = make([]Change, 0) + peersToBlock = make([]peer.ID, 0) + bestProof := &messages.WarpSyncProof{} + bestResult := &network.WarpSyncVerificationResult{} + + for _, result := range results { + switch response := result.response.(type) { + case *messages.WarpSyncProof: + if !result.completed { + continue + } + + // If invalid warp sync proof, then we should block the peer and update its reputation + encodedProof, err := response.Encode() + if err != nil { + // This should never happen since the proof is already decoded without issues + panic("fail to encode warp proof") + } + + // Best proof will be the finished proof or the proof with more fragments + res, err := w.warpSyncProvider.Verify(encodedProof, w.setId, w.authorities) + + if err != nil { + repChanges = append(repChanges, Change{ + who: result.who, + rep: peerset.ReputationChange{ + Value: peerset.BadWarpProofValue, + Reason: peerset.BadWarpProofReason, + }}) + peersToBlock = append(peersToBlock, result.who) + } + + if response.IsFinished || len(response.Proofs) > len(bestProof.Proofs) { + bestProof = response + bestResult = res + } + default: + repChanges = append(repChanges, Change{ + who: result.who, + rep: peerset.ReputationChange{ + Value: peerset.UnexpectedResponseValue, + Reason: peerset.UnexpectedResponseReason, + }}) + peersToBlock = append(peersToBlock, result.who) + continue + } + } + + return repChanges, peersToBlock, bestResult +} + +func (w *WarpSyncStrategy) ShowMetrics() { + totalSyncSeconds := time.Since(w.startedAt).Seconds() + + fps := float64(w.syncedFragments) / totalSyncSeconds + logger.Infof("⛓️ synced %d warp sync fragments "+ + "took: %.2f seconds, fps: %.2f fragments/second, target best block number #%d", + w.syncedFragments, totalSyncSeconds, fps, w.lastBlock.Number) +} + +func (w *WarpSyncStrategy) IsSynced() bool { + return w.phase == Completed +} + +var _ Strategy = (*WarpSyncStrategy)(nil) From 14e80be40007cd4a4a7bdf2dd0d88819b72e0fe1 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 22 Oct 2024 14:55:20 -0300 Subject: [PATCH 02/44] Add missing license --- dot/sync/warp_sync.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 61f73861df..3f7e0a47ea 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -1,3 +1,6 @@ +// Copyright 2024 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + package sync import ( From cfa416b2be8a05a9ebd9e05c304d654b6b62cd11 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 24 Oct 2024 10:48:31 -0300 Subject: [PATCH 03/44] Add result method in strategies and switch logic --- dot/sync/fullsync.go | 5 +++++ dot/sync/service.go | 11 ++++++++--- dot/sync/warp_sync.go | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dot/sync/fullsync.go b/dot/sync/fullsync.go index b8985fb107..9175d24baa 100644 --- a/dot/sync/fullsync.go +++ b/dot/sync/fullsync.go @@ -405,6 +405,11 @@ func (f *FullSyncStrategy) IsSynced() bool { return uint32(highestBlock)+messages.MaxBlocksInResponse >= f.peers.getTarget() } +func (f *FullSyncStrategy) Result() any { + logger.Debug("trying to get a result from full sync strategy which is supposed to run forever") + return nil +} + type RequestResponseData struct { req *messages.BlockRequestMessage responseData []*types.BlockData diff --git a/dot/sync/service.go b/dot/sync/service.go index a4ed54c083..dc930459e3 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -92,6 +92,7 @@ type Strategy interface { Process(results []*SyncTaskResult) (done bool, repChanges []Change, blocks []peer.ID, err error) ShowMetrics() IsSynced() bool + Result() any } type SyncService struct { @@ -100,8 +101,9 @@ type SyncService struct { network Network blockState BlockState - currentStrategy Strategy - defaultStrategy Strategy + currentStrategy Strategy + fullSyncStrategy Strategy + warpStrategy Strategy workerPool *syncWorkerPool waitPeersDuration time.Duration @@ -301,6 +303,9 @@ func (s *SyncService) runStrategy() { // TODO: why not use s.currentStrategy.IsSynced()? if done { - s.currentStrategy = s.defaultStrategy + // Switch to full sync when warp sync finishes + if s.warpStrategy != nil { + s.currentStrategy = s.fullSyncStrategy + } } } diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 3f7e0a47ea..ce2ff46e09 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -235,4 +235,8 @@ func (w *WarpSyncStrategy) IsSynced() bool { return w.phase == Completed } +func (w *WarpSyncStrategy) Result() any { + return w.result +} + var _ Strategy = (*WarpSyncStrategy)(nil) From 48bddbc0084754bb9ad838ccd557643e316f97bb Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 24 Oct 2024 10:53:36 -0300 Subject: [PATCH 04/44] Fix tests --- dot/services.go | 2 +- dot/sync/configuration.go | 3 +-- dot/sync/message_integration_test.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dot/services.go b/dot/services.go index 653b400c22..a6e80fe6c6 100644 --- a/dot/services.go +++ b/dot/services.go @@ -544,7 +544,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync sync.WithNetwork(net), sync.WithBlockState(st.Block), sync.WithSlotDuration(slotDuration), - sync.WithStrategies(fullSync, nil), + sync.WithStrategy(fullSync), sync.WithMinPeers(config.Network.MinPeers), ), nil } diff --git a/dot/sync/configuration.go b/dot/sync/configuration.go index e144a87cbc..15b22b07b1 100644 --- a/dot/sync/configuration.go +++ b/dot/sync/configuration.go @@ -7,10 +7,9 @@ import "time" type ServiceConfig func(svc *SyncService) -func WithStrategies(currentStrategy, defaultStrategy Strategy) ServiceConfig { +func WithStrategy(currentStrategy Strategy) ServiceConfig { return func(svc *SyncService) { svc.currentStrategy = currentStrategy - svc.defaultStrategy = defaultStrategy } } diff --git a/dot/sync/message_integration_test.go b/dot/sync/message_integration_test.go index 55e560a3be..b69e9d7dfd 100644 --- a/dot/sync/message_integration_test.go +++ b/dot/sync/message_integration_test.go @@ -153,7 +153,7 @@ func newFullSyncService(t *testing.T) *SyncService { WithBlockState(stateSrvc.Block), WithNetwork(mockNetwork), WithSlotDuration(6 * time.Second), - WithStrategies(fullSync, nil), + WithStrategy(fullSync), } syncLogLvl := log.Info From 8e2d855b431fc718ddf7fc2254eb543cc917c5b0 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 12:06:19 -0300 Subject: [PATCH 05/44] Small fixes and first tests --- dot/sync/warp_sync.go | 43 +++++++++++++++++++-------- dot/sync/warp_sync_test.go | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 dot/sync/warp_sync_test.go diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index ce2ff46e09..42080915a2 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -11,7 +11,6 @@ import ( "github.com/ChainSafe/gossamer/dot/network/messages" "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" - consensus_grandpa "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" "github.com/ChainSafe/gossamer/lib/grandpa" "github.com/libp2p/go-libp2p/core/peer" @@ -31,28 +30,33 @@ type WarpSyncStrategy struct { badBlocks []string reqMaker network.RequestMaker warpSyncProvider grandpa.WarpSyncProofProvider + blockState BlockState // Warp sync state startedAt time.Time phase WarpSyncPhase syncedFragments int - setId consensus_grandpa.SetID + setId primitives.SetID authorities primitives.AuthorityList - lastBlock types.Header + lastBlock *types.Header result types.BlockData } type WarpSyncConfig struct { - Telemetry Telemetry - BadBlocks []string - RequestMaker network.RequestMaker + Telemetry Telemetry + BadBlocks []string + RequestMaker network.RequestMaker + warpSyncProvider grandpa.WarpSyncProofProvider + BlockState BlockState } // NewWarpSyncStrategy returns a new warp sync strategy func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { return &WarpSyncStrategy{ - badBlocks: cfg.BadBlocks, - reqMaker: cfg.RequestMaker, + warpSyncProvider: cfg.warpSyncProvider, + blockState: cfg.BlockState, + badBlocks: cfg.BadBlocks, + reqMaker: cfg.RequestMaker, peers: &peerViewSet{ view: make(map[peer.ID]peerView), target: 0, @@ -111,17 +115,22 @@ func (w *WarpSyncStrategy) OnBlockAnnounceHandshake(from peer.ID, msg *network.B func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { w.startedAt = time.Now() + lastBlock, err := w.lastBlockHeader() + if err != nil { + return nil, err + } + var task SyncTask switch w.phase { case WarpProof: task = SyncTask{ - request: messages.NewWarpProofRequest(w.lastBlock.Hash()), + request: messages.NewWarpProofRequest(lastBlock.Hash()), response: &messages.WarpSyncProof{}, requestMaker: w.reqMaker, } case TargetBlock: req := messages.NewBlockRequest( - *messages.NewFromBlock(w.lastBlock.Hash()), + *messages.NewFromBlock(lastBlock.Hash()), 1, messages.RequestedDataHeader+ messages.RequestedDataBody+ @@ -151,10 +160,10 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( // Partial warp proof w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList - w.lastBlock = warpProofResult.Header + w.lastBlock = &warpProofResult.Header } else { w.phase = TargetBlock - w.lastBlock = warpProofResult.Header + w.lastBlock = &warpProofResult.Header } case TargetBlock: var validRes []RequestResponseData @@ -239,4 +248,14 @@ func (w *WarpSyncStrategy) Result() any { return w.result } +func (w *WarpSyncStrategy) lastBlockHeader() (header *types.Header, err error) { + if w.lastBlock == nil { + w.lastBlock, err = w.blockState.GetHighestFinalisedHeader() + if err != nil { + return nil, err + } + } + return w.lastBlock, nil +} + var _ Strategy = (*WarpSyncStrategy)(nil) diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go new file mode 100644 index 0000000000..b18ac1cacf --- /dev/null +++ b/dot/sync/warp_sync_test.go @@ -0,0 +1,59 @@ +// Copyright 2024 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package sync + +import ( + "testing" + + "github.com/ChainSafe/gossamer/dot/network/messages" + "github.com/ChainSafe/gossamer/dot/types" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" +) + +func TestNextActions(t *testing.T) { + ctrl := gomock.NewController(t) + mockBlockState := NewMockBlockState(ctrl) + + genesisHeader := &types.Header{ + Number: 1, + } + mockBlockState.EXPECT().GetHighestFinalisedHeader().Return(genesisHeader, nil).AnyTimes() + + tc := map[string]struct { + phase WarpSyncPhase + lastBlock *types.Header + expectedRequestType interface{} + expectedResponseType interface{} + }{ + "warp_sync_phase": { + phase: WarpProof, + expectedRequestType: &messages.WarpProofRequest{}, + expectedResponseType: &messages.WarpSyncProof{}, + }, + "target_block_phase": { + phase: TargetBlock, + expectedRequestType: &messages.BlockRequestMessage{}, + expectedResponseType: &messages.BlockResponseMessage{}, + }, + } + + for name, c := range tc { + t.Run(name, func(t *testing.T) { + strategy := NewWarpSyncStrategy(&WarpSyncConfig{ + BlockState: mockBlockState, + }) + + strategy.phase = c.phase + + tasks, err := strategy.NextActions() + require.NoError(t, err) + require.Equal(t, 1, len(tasks), "expected 1 task") + + task := tasks[0] + require.IsType(t, c.expectedRequestType, task.request) + require.IsType(t, c.expectedResponseType, task.response) + }) + } +} From f4d620b042fbfadf4f5d1a35496536e1e09d5a68 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 13:20:53 -0300 Subject: [PATCH 06/44] Modify current strategy selection --- dot/services.go | 2 +- dot/sync/configuration.go | 10 ++++++++-- dot/sync/service.go | 11 +++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dot/services.go b/dot/services.go index a6e80fe6c6..3a04665938 100644 --- a/dot/services.go +++ b/dot/services.go @@ -544,7 +544,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync sync.WithNetwork(net), sync.WithBlockState(st.Block), sync.WithSlotDuration(slotDuration), - sync.WithStrategy(fullSync), + sync.WithFullSyncStrategy(fullSync), sync.WithMinPeers(config.Network.MinPeers), ), nil } diff --git a/dot/sync/configuration.go b/dot/sync/configuration.go index 15b22b07b1..9e01c3996d 100644 --- a/dot/sync/configuration.go +++ b/dot/sync/configuration.go @@ -7,9 +7,15 @@ import "time" type ServiceConfig func(svc *SyncService) -func WithStrategy(currentStrategy Strategy) ServiceConfig { +func WithWarpSyncStrategy(warpSyncStrategy Strategy) ServiceConfig { return func(svc *SyncService) { - svc.currentStrategy = currentStrategy + svc.warpSyncStrategy = warpSyncStrategy + } +} + +func WithFullSyncStrategy(fullSyncStrategy Strategy) ServiceConfig { + return func(svc *SyncService) { + svc.fullSyncStrategy = fullSyncStrategy } } diff --git a/dot/sync/service.go b/dot/sync/service.go index dc930459e3..a415e37146 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -103,7 +103,7 @@ type SyncService struct { currentStrategy Strategy fullSyncStrategy Strategy - warpStrategy Strategy + warpSyncStrategy Strategy workerPool *syncWorkerPool waitPeersDuration time.Duration @@ -129,6 +129,13 @@ func NewSyncService(logLvl log.Level, cfgs ...ServiceConfig) *SyncService { cfg(svc) } + // Set initial strategy + if svc.warpSyncStrategy != nil { + svc.currentStrategy = svc.warpSyncStrategy + } else { + svc.currentStrategy = svc.fullSyncStrategy + } + return svc } @@ -304,7 +311,7 @@ func (s *SyncService) runStrategy() { // TODO: why not use s.currentStrategy.IsSynced()? if done { // Switch to full sync when warp sync finishes - if s.warpStrategy != nil { + if s.warpSyncStrategy != nil { s.currentStrategy = s.fullSyncStrategy } } From 36bb2178a7ccd8601aefcb397d41b0db999d7db4 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 13:35:22 -0300 Subject: [PATCH 07/44] Share peer view set between strategies --- dot/services.go | 4 ++++ dot/sync/fullsync.go | 6 ++---- dot/sync/fullsync_test.go | 23 ++++++++++++++++++++++- dot/sync/peer_view.go | 6 ++++++ dot/sync/warp_sync.go | 8 +++----- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/dot/services.go b/dot/services.go index 3a04665938..c7612151a9 100644 --- a/dot/services.go +++ b/dot/services.go @@ -526,6 +526,9 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync requestMaker := net.GetRequestResponseProtocol(network.SyncID, blockRequestTimeout, network.MaxBlockResponseSize) + // Should be shared between all sync strategies + peersView := sync.NewPeerViewSet() + syncCfg := &sync.FullSyncConfig{ BlockState: st.Block, StorageState: st.Storage, @@ -536,6 +539,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync Telemetry: telemetryMailer, BadBlocks: genesisData.BadBlocks, RequestMaker: requestMaker, + Peers: peersView, } fullSync := sync.NewFullSyncStrategy(syncCfg) diff --git a/dot/sync/fullsync.go b/dot/sync/fullsync.go index 9175d24baa..248f3bd67a 100644 --- a/dot/sync/fullsync.go +++ b/dot/sync/fullsync.go @@ -43,6 +43,7 @@ type FullSyncConfig struct { BadBlocks []string NumOfTasks int RequestMaker network.RequestMaker + Peers *peerViewSet } type importer interface { @@ -75,15 +76,12 @@ func NewFullSyncStrategy(cfg *FullSyncConfig) *FullSyncStrategy { reqMaker: cfg.RequestMaker, blockState: cfg.BlockState, numOfTasks: cfg.NumOfTasks, + peers: cfg.Peers, blockImporter: newBlockImporter(cfg), unreadyBlocks: newUnreadyBlocks(), requestQueue: &requestsQueue[*messages.BlockRequestMessage]{ queue: list.New(), }, - peers: &peerViewSet{ - view: make(map[peer.ID]peerView), - target: 0, - }, } } diff --git a/dot/sync/fullsync_test.go b/dot/sync/fullsync_test.go index 04536f5125..7d571ffc1b 100644 --- a/dot/sync/fullsync_test.go +++ b/dot/sync/fullsync_test.go @@ -30,7 +30,10 @@ type WestendBlocks struct { } func TestFullSyncNextActions(t *testing.T) { + t.Parallel() + t.Run("best_block_greater_or_equal_current_target", func(t *testing.T) { + t.Parallel() // current target is 0 and best block is 0, then we should // get an empty set of tasks @@ -40,6 +43,7 @@ func TestFullSyncNextActions(t *testing.T) { cfg := &FullSyncConfig{ BlockState: mockBlockState, + Peers: NewPeerViewSet(), } fs := NewFullSyncStrategy(cfg) @@ -49,12 +53,15 @@ func TestFullSyncNextActions(t *testing.T) { }) t.Run("target_block_greater_than_best_block", func(t *testing.T) { + t.Parallel() + mockBlockState := NewMockBlockState(gomock.NewController(t)) mockBlockState.EXPECT().BestBlockHeader().Return( types.NewEmptyHeader(), nil) cfg := &FullSyncConfig{ BlockState: mockBlockState, + Peers: NewPeerViewSet(), } fs := NewFullSyncStrategy(cfg) @@ -76,6 +83,8 @@ func TestFullSyncNextActions(t *testing.T) { }) t.Run("having_requests_in_the_queue", func(t *testing.T) { + t.Parallel() + refTo := func(v uint32) *uint32 { return &v } @@ -148,7 +157,11 @@ func TestFullSyncNextActions(t *testing.T) { for tname, tt := range cases { tt := tt t.Run(tname, func(t *testing.T) { - fs := NewFullSyncStrategy(&FullSyncConfig{}) + t.Parallel() + + fs := NewFullSyncStrategy(&FullSyncConfig{ + Peers: NewPeerViewSet(), + }) fs.requestQueue = tt.setupRequestQueue(t) fs.numOfTasks = 1 @@ -179,6 +192,8 @@ func TestFullSyncNextActions(t *testing.T) { } func TestFullSyncProcess(t *testing.T) { + t.Parallel() + westendBlocks := &WestendBlocks{} err := yaml.Unmarshal(rawWestendBlocks, westendBlocks) require.NoError(t, err) @@ -192,6 +207,8 @@ func TestFullSyncProcess(t *testing.T) { require.NoError(t, err) t.Run("requested_max_but_received_less_blocks", func(t *testing.T) { + t.Parallel() + syncTaskResults := []*SyncTaskResult{ // first task // 1 -> 10 @@ -294,6 +311,8 @@ func TestFullSyncProcess(t *testing.T) { func TestFullSyncBlockAnnounce(t *testing.T) { t.Run("announce_a_far_block_without_any_commom_ancestor", func(t *testing.T) { + t.Parallel() + highestFinalizedHeader := &types.Header{ ParentHash: common.BytesToHash([]byte{0}), StateRoot: common.BytesToHash([]byte{3, 3, 3, 3}), @@ -315,6 +334,7 @@ func TestFullSyncBlockAnnounce(t *testing.T) { fsCfg := &FullSyncConfig{ BlockState: mockBlockState, + Peers: NewPeerViewSet(), } fs := NewFullSyncStrategy(fsCfg) @@ -372,6 +392,7 @@ func TestFullSyncBlockAnnounce(t *testing.T) { Return(false, nil) fsCfg := &FullSyncConfig{ BlockState: mockBlockState, + Peers: NewPeerViewSet(), } fs := NewFullSyncStrategy(fsCfg) diff --git a/dot/sync/peer_view.go b/dot/sync/peer_view.go index 241a078b25..be7dd8b94b 100644 --- a/dot/sync/peer_view.go +++ b/dot/sync/peer_view.go @@ -22,6 +22,12 @@ type peerViewSet struct { target uint32 } +func NewPeerViewSet() *peerViewSet { + return &peerViewSet{ + view: make(map[peer.ID]peerView), + } +} + func (p *peerViewSet) update(peerID peer.ID, bestHash common.Hash, bestNumber uint32) { p.mtx.Lock() defer p.mtx.Unlock() diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 42080915a2..57c45c1063 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -48,6 +48,7 @@ type WarpSyncConfig struct { RequestMaker network.RequestMaker warpSyncProvider grandpa.WarpSyncProofProvider BlockState BlockState + Peers *peerViewSet } // NewWarpSyncStrategy returns a new warp sync strategy @@ -57,11 +58,8 @@ func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { blockState: cfg.BlockState, badBlocks: cfg.BadBlocks, reqMaker: cfg.RequestMaker, - peers: &peerViewSet{ - view: make(map[peer.ID]peerView), - target: 0, - }, - startedAt: time.Now(), + peers: cfg.Peers, + startedAt: time.Now(), } } From 54d17d2b7a2cf2af0796f669aed7ffc6e874f240 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 16:02:22 -0300 Subject: [PATCH 08/44] Add block announce tests --- dot/sync/warp_sync.go | 13 ++++--- dot/sync/warp_sync_test.go | 78 +++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 57c45c1063..e8dab56625 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -68,19 +68,22 @@ func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { // And peers target block func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnounceMessage) ( repChange *Change, err error) { - blockAnnounceHeader := types.NewHeader(msg.ParentHash, msg.StateRoot, msg.ExtrinsicsRoot, msg.Number, msg.Digest) - blockAnnounceHeaderHash := blockAnnounceHeader.Hash() + + blockAnnounceHeaderHash, err := msg.Hash() + if err != nil { + return nil, err + } logger.Infof("received block announce from %s: #%d (%s) best block: %v", from, - blockAnnounceHeader.Number, + msg.Number, blockAnnounceHeaderHash, msg.BestBlock, ) if slices.Contains(w.badBlocks, blockAnnounceHeaderHash.String()) { logger.Infof("bad block received from %s: #%d (%s) is a bad block", - from, blockAnnounceHeader.Number, blockAnnounceHeaderHash) + from, msg.Number, blockAnnounceHeaderHash) return &Change{ who: from, @@ -92,7 +95,7 @@ func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou } if msg.BestBlock { - w.peers.update(from, blockAnnounceHeaderHash, uint32(blockAnnounceHeader.Number)) //nolint:gosec + w.peers.update(from, blockAnnounceHeaderHash, uint32(msg.Number)) //nolint:gosec } return &Change{ diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index b18ac1cacf..a25dbbd4a8 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -6,13 +6,89 @@ package sync import ( "testing" + "github.com/ChainSafe/gossamer/dot/network" "github.com/ChainSafe/gossamer/dot/network/messages" + "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" + "github.com/ChainSafe/gossamer/lib/common" + "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) -func TestNextActions(t *testing.T) { +func TestWarpSyncBlockAnnounce(t *testing.T) { + peer := peer.ID("peer") + + t.Run("successful_block_announce", func(t *testing.T) { + peersView := NewPeerViewSet() + + strategy := NewWarpSyncStrategy(&WarpSyncConfig{ + Peers: peersView, + }) + + blockAnnounce := &network.BlockAnnounceMessage{ + ParentHash: common.BytesToHash([]byte{0, 1, 2}), + Number: 1024, + StateRoot: common.BytesToHash([]byte{3, 3, 3, 3}), + ExtrinsicsRoot: common.BytesToHash([]byte{4, 4, 4, 4}), + Digest: types.NewDigest(), + BestBlock: true, + } + + expectedRepChange := &Change{ + who: peer, + rep: peerset.ReputationChange{ + Value: peerset.GossipSuccessValue, + Reason: peerset.GossipSuccessReason, + }, + } + + rep, err := strategy.OnBlockAnnounce(peer, blockAnnounce) + require.NoError(t, err) + require.NotNil(t, rep) + require.Equal(t, expectedRepChange, rep) + require.Equal(t, blockAnnounce.Number, uint(peersView.getTarget())) + }) + + t.Run("successful_block_announce", func(t *testing.T) { + peersView := NewPeerViewSet() + + blockAnnounce := &network.BlockAnnounceMessage{ + ParentHash: common.BytesToHash([]byte{0, 1, 2}), + Number: 1024, + StateRoot: common.BytesToHash([]byte{3, 3, 3, 3}), + ExtrinsicsRoot: common.BytesToHash([]byte{4, 4, 4, 4}), + Digest: types.NewDigest(), + BestBlock: true, + } + + blockAnnounceHash, err := blockAnnounce.Hash() + require.NoError(t, err) + + strategy := NewWarpSyncStrategy(&WarpSyncConfig{ + Peers: peersView, + BadBlocks: []string{blockAnnounceHash.String()}, + }) + + expectedRepChange := &Change{ + who: peer, + rep: peerset.ReputationChange{ + Value: peerset.BadBlockAnnouncementValue, + Reason: peerset.BadBlockAnnouncementReason, + }, + } + + rep, err := strategy.OnBlockAnnounce(peer, blockAnnounce) + require.NotNil(t, err) + require.ErrorIs(t, err, errBadBlockReceived) + require.NotNil(t, rep) + require.Equal(t, expectedRepChange, rep) + require.Equal(t, 0, int(peersView.getTarget())) + }) + +} + +func TestWarpSyncNextActions(t *testing.T) { ctrl := gomock.NewController(t) mockBlockState := NewMockBlockState(ctrl) From a78a0432b24a8d20b8cd5ed91dd693269af82365 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 16:20:52 -0300 Subject: [PATCH 09/44] Add block announce handshake tests --- dot/network/block_announce.go | 2 +- dot/sync/warp_sync.go | 1 + dot/sync/warp_sync_test.go | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dot/network/block_announce.go b/dot/network/block_announce.go index a526b2f7f5..51080a501f 100644 --- a/dot/network/block_announce.go +++ b/dot/network/block_announce.go @@ -99,7 +99,7 @@ func decodeBlockAnnounceMessage(in []byte) (NotificationsMessage, error) { // BlockAnnounceHandshake is exchanged by nodes that are beginning the BlockAnnounce protocol type BlockAnnounceHandshake struct { Roles common.NetworkRole - BestBlockNumber uint32 + BestBlockNumber uint32 // TODO: change to uint64 BestBlockHash common.Hash GenesisHash common.Hash } diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index e8dab56625..942cd900f8 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -169,6 +169,7 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( case TargetBlock: var validRes []RequestResponseData + // Reuse same validator than in fullsync repChanges, bans, validRes = validateResults(results, w.badBlocks) // TODO: check if this can cause an issue diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index a25dbbd4a8..f3c4d8080a 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -50,6 +50,24 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { require.Equal(t, blockAnnounce.Number, uint(peersView.getTarget())) }) + t.Run("successful_block_announce_handshake", func(t *testing.T) { + peersView := NewPeerViewSet() + + strategy := NewWarpSyncStrategy(&WarpSyncConfig{ + Peers: peersView, + }) + + handshake := &network.BlockAnnounceHandshake{ + Roles: 1, + BestBlockNumber: 17, + BestBlockHash: common.BytesToHash([]byte{0, 1, 2}), + GenesisHash: common.BytesToHash([]byte{1, 1, 1, 1}), + } + err := strategy.OnBlockAnnounceHandshake(peer, handshake) + require.NoError(t, err) + require.Equal(t, handshake.BestBlockNumber, peersView.getTarget()) + }) + t.Run("successful_block_announce", func(t *testing.T) { peersView := NewPeerViewSet() @@ -85,7 +103,6 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { require.Equal(t, expectedRepChange, rep) require.Equal(t, 0, int(peersView.getTarget())) }) - } func TestWarpSyncNextActions(t *testing.T) { From 43dc2275f3867700205bc13d82e82d21408a161b Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 16:22:34 -0300 Subject: [PATCH 10/44] Change comment --- dot/network/block_announce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/network/block_announce.go b/dot/network/block_announce.go index 51080a501f..f436d05d09 100644 --- a/dot/network/block_announce.go +++ b/dot/network/block_announce.go @@ -99,7 +99,7 @@ func decodeBlockAnnounceMessage(in []byte) (NotificationsMessage, error) { // BlockAnnounceHandshake is exchanged by nodes that are beginning the BlockAnnounce protocol type BlockAnnounceHandshake struct { Roles common.NetworkRole - BestBlockNumber uint32 // TODO: change to uint64 + BestBlockNumber uint32 // TODO: shuldn't we use uint64 here? BestBlockHash common.Hash GenesisHash common.Hash } From 6f4f281838bffc20cdd9e0d8c89bf7db4a65e7ce Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 21:34:06 -0300 Subject: [PATCH 11/44] Fix lint --- dot/sync/message_integration_test.go | 2 +- dot/sync/warp_sync.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dot/sync/message_integration_test.go b/dot/sync/message_integration_test.go index b69e9d7dfd..f597c13789 100644 --- a/dot/sync/message_integration_test.go +++ b/dot/sync/message_integration_test.go @@ -153,7 +153,7 @@ func newFullSyncService(t *testing.T) *SyncService { WithBlockState(stateSrvc.Block), WithNetwork(mockNetwork), WithSlotDuration(6 * time.Second), - WithStrategy(fullSync), + WithFullSyncStrategy(fullSync), } syncLogLvl := log.Info diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 942cd900f8..e6151795a7 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -59,7 +59,6 @@ func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { badBlocks: cfg.BadBlocks, reqMaker: cfg.RequestMaker, peers: cfg.Peers, - startedAt: time.Now(), } } From fd185879265ad74d863e5258ba81c500129cfee6 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 21:47:38 -0300 Subject: [PATCH 12/44] Add CLI flag for sync mode --- chain/kusama/defaults.go | 1 + chain/paseo/defaults.go | 1 + chain/polkadot/defaults.go | 1 + chain/westend-dev/defaults.go | 1 + chain/westend-local/default.go | 1 + chain/westend/defaults.go | 1 + cmd/gossamer/commands/root.go | 8 ++++++++ config/config.go | 9 ++++++++- dot/services.go | 18 ++++++++++++++++++ dot/sync/warp_sync.go | 4 ++-- 10 files changed, 42 insertions(+), 3 deletions(-) diff --git a/chain/kusama/defaults.go b/chain/kusama/defaults.go index 589b666084..26054fa83a 100644 --- a/chain/kusama/defaults.go +++ b/chain/kusama/defaults.go @@ -25,6 +25,7 @@ func DefaultConfig() *cfg.Config { config.Core.GrandpaAuthority = false config.Core.Role = 1 config.Network.NoMDNS = false + config.Core.Sync = "full" return config } diff --git a/chain/paseo/defaults.go b/chain/paseo/defaults.go index aafee6e882..30bdc77e3f 100644 --- a/chain/paseo/defaults.go +++ b/chain/paseo/defaults.go @@ -24,6 +24,7 @@ func DefaultConfig() *cfg.Config { config.Core.GrandpaAuthority = false config.Core.Role = 1 config.Network.NoMDNS = false + config.Core.Sync = "full" return config } diff --git a/chain/polkadot/defaults.go b/chain/polkadot/defaults.go index 48ce349c67..c0e405f69c 100644 --- a/chain/polkadot/defaults.go +++ b/chain/polkadot/defaults.go @@ -24,6 +24,7 @@ func DefaultConfig() *cfg.Config { config.Core.GrandpaAuthority = false config.Core.Role = 1 config.Network.NoMDNS = false + config.Core.Sync = "full" return config } diff --git a/chain/westend-dev/defaults.go b/chain/westend-dev/defaults.go index e171ae3382..912322ba79 100644 --- a/chain/westend-dev/defaults.go +++ b/chain/westend-dev/defaults.go @@ -24,6 +24,7 @@ func DefaultConfig() *cfg.Config { config.RPC.UnsafeRPC = true config.RPC.WSExternal = true config.RPC.UnsafeWSExternal = true + config.Core.Sync = "full" return config } diff --git a/chain/westend-local/default.go b/chain/westend-local/default.go index 0bedec5eae..9e43c5a648 100644 --- a/chain/westend-local/default.go +++ b/chain/westend-local/default.go @@ -29,6 +29,7 @@ func DefaultConfig() *cfg.Config { config.RPC.UnsafeRPC = true config.RPC.WSExternal = true config.RPC.UnsafeWSExternal = true + config.Core.Sync = "full" return config } diff --git a/chain/westend/defaults.go b/chain/westend/defaults.go index 416c30b2a4..1419207084 100644 --- a/chain/westend/defaults.go +++ b/chain/westend/defaults.go @@ -24,6 +24,7 @@ func DefaultConfig() *cfg.Config { config.Core.GrandpaAuthority = false config.Core.Role = 1 config.Network.NoMDNS = false + config.Core.Sync = "full" return config } diff --git a/cmd/gossamer/commands/root.go b/cmd/gossamer/commands/root.go index 0003833ef5..6a8a33416b 100644 --- a/cmd/gossamer/commands/root.go +++ b/cmd/gossamer/commands/root.go @@ -529,6 +529,14 @@ func addCoreFlags(cmd *cobra.Command) error { return fmt.Errorf("failed to add --grandpa-interval flag: %s", err) } + if err := addStringFlagBindViper(cmd, + "sync", + config.Core.Sync, + "sync mode [warp | full]", + "core.sync"); err != nil { + return fmt.Errorf("failed to add --sync flag: %s", err) + } + return nil } diff --git a/config/config.go b/config/config.go index 4c50fe3d67..da1c83f33e 100644 --- a/config/config.go +++ b/config/config.go @@ -61,6 +61,9 @@ const ( DefaultSystemName = "Gossamer" // DefaultSystemVersion is the default system version DefaultSystemVersion = "0.0.0" + + // DefaultSyncMode is the default block sync mode + DefaultSyncMode = "full" ) // DefaultRPCModules the default RPC modules @@ -78,7 +81,7 @@ var DefaultRPCModules = []string{ } // Config defines the configuration for the gossamer node -type Config struct { +type Config struct { BaseConfig `mapstructure:",squash"` Log *LogConfig `mapstructure:"log"` Account *AccountConfig `mapstructure:"account"` @@ -188,6 +191,7 @@ type CoreConfig struct { GrandpaAuthority bool `mapstructure:"grandpa-authority"` WasmInterpreter string `mapstructure:"wasm-interpreter,omitempty"` GrandpaInterval time.Duration `mapstructure:"grandpa-interval,omitempty"` + Sync string `mapstructure:"sync,omitempty"` } // StateConfig contains the configuration for the state. @@ -363,6 +367,7 @@ func DefaultConfig() *Config { GrandpaAuthority: true, WasmInterpreter: DefaultWasmInterpreter, GrandpaInterval: DefaultDiscoveryInterval, + Sync: DefaultSyncMode, }, Network: &NetworkConfig{ Port: DefaultNetworkPort, @@ -444,6 +449,7 @@ func DefaultConfigFromSpec(nodeSpec *genesis.Genesis) *Config { GrandpaAuthority: true, WasmInterpreter: DefaultWasmInterpreter, GrandpaInterval: DefaultDiscoveryInterval, + Sync: DefaultSyncMode, }, Network: &NetworkConfig{ Port: DefaultNetworkPort, @@ -525,6 +531,7 @@ func Copy(c *Config) Config { GrandpaAuthority: c.Core.GrandpaAuthority, WasmInterpreter: c.Core.WasmInterpreter, GrandpaInterval: c.Core.GrandpaInterval, + Sync: c.Core.Sync, }, Network: &NetworkConfig{ Port: c.Network.Port, diff --git a/dot/services.go b/dot/services.go index c7612151a9..7c1d88654a 100644 --- a/dot/services.go +++ b/dot/services.go @@ -529,6 +529,23 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync // Should be shared between all sync strategies peersView := sync.NewPeerViewSet() + var warpSyncStrategy sync.Strategy + + if config.Core.Sync == "warp" { + warpSyncProvider := grandpa.NewWarpSyncProofProvider(st.Block, st.Grandpa) + + warpSyncCfg := &sync.WarpSyncConfig{ + Telemetry: telemetryMailer, + BadBlocks: genesisData.BadBlocks, + WarpSyncProvider: *warpSyncProvider, + RequestMaker: requestMaker, + BlockState: st.Block, + Peers: peersView, + } + + warpSyncStrategy = sync.NewWarpSyncStrategy(warpSyncCfg) + } + syncCfg := &sync.FullSyncConfig{ BlockState: st.Block, StorageState: st.Storage, @@ -548,6 +565,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync sync.WithNetwork(net), sync.WithBlockState(st.Block), sync.WithSlotDuration(slotDuration), + sync.WithWarpSyncStrategy(warpSyncStrategy), sync.WithFullSyncStrategy(fullSync), sync.WithMinPeers(config.Network.MinPeers), ), nil diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index e6151795a7..9a857e6086 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -46,7 +46,7 @@ type WarpSyncConfig struct { Telemetry Telemetry BadBlocks []string RequestMaker network.RequestMaker - warpSyncProvider grandpa.WarpSyncProofProvider + WarpSyncProvider grandpa.WarpSyncProofProvider BlockState BlockState Peers *peerViewSet } @@ -54,7 +54,7 @@ type WarpSyncConfig struct { // NewWarpSyncStrategy returns a new warp sync strategy func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { return &WarpSyncStrategy{ - warpSyncProvider: cfg.warpSyncProvider, + warpSyncProvider: cfg.WarpSyncProvider, blockState: cfg.BlockState, badBlocks: cfg.BadBlocks, reqMaker: cfg.RequestMaker, From 8e26aac229a158fa3118474a2e0cc65df3ab2033 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 22:01:46 -0300 Subject: [PATCH 13/44] Lint --- dot/sync/fullsync_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/dot/sync/fullsync_test.go b/dot/sync/fullsync_test.go index 7d571ffc1b..dc2b7c6e31 100644 --- a/dot/sync/fullsync_test.go +++ b/dot/sync/fullsync_test.go @@ -310,6 +310,7 @@ func TestFullSyncProcess(t *testing.T) { } func TestFullSyncBlockAnnounce(t *testing.T) { + t.Parallel() t.Run("announce_a_far_block_without_any_commom_ancestor", func(t *testing.T) { t.Parallel() From e0963cc5285227ee48c9b2cfc277b8f09ca0994e Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 28 Oct 2024 22:08:09 -0300 Subject: [PATCH 14/44] Lint --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index da1c83f33e..9ff07eb042 100644 --- a/config/config.go +++ b/config/config.go @@ -81,7 +81,7 @@ var DefaultRPCModules = []string{ } // Config defines the configuration for the gossamer node -type Config struct { +type Config struct { BaseConfig `mapstructure:",squash"` Log *LogConfig `mapstructure:"log"` Account *AccountConfig `mapstructure:"account"` From cb029c2e40e3f978f0c9d8c34d7ffdc6b5af577e Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 31 Oct 2024 16:40:59 -0300 Subject: [PATCH 15/44] Use right procotol id for sync --- dot/network/service.go | 16 +++++++++++----- dot/services.go | 15 +++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dot/network/service.go b/dot/network/service.go index f916e18359..41cd4fa3a8 100644 --- a/dot/network/service.go +++ b/dot/network/service.go @@ -259,11 +259,14 @@ func (s *Service) Start() error { s.ctx, s.cancel = context.WithCancel(context.Background()) } - genesisHashProtocolId := protocol.ID(s.cfg.BlockState.GenesisHash().String()) + genesisHash := s.blockState.GenesisHash().String() + genesisHash = strings.TrimPrefix(genesisHash, "0x") + fullSyncProtocolId := fmt.Sprintf("/%s%s", genesisHash, SyncID) + warpSyncProtocolId := fmt.Sprintf("/%s%s", genesisHash, WarpSyncID) - s.host.registerStreamHandler(s.host.protocolID+SyncID, s.handleSyncStream) + s.host.registerStreamHandler(protocol.ID(fullSyncProtocolId), s.handleSyncStream) s.host.registerStreamHandler(s.host.protocolID+lightID, s.handleLightStream) - s.host.registerStreamHandler(genesisHashProtocolId+WarpSyncID, s.handleWarpSyncStream) + s.host.registerStreamHandler(protocol.ID(warpSyncProtocolId), s.handleWarpSyncStream) // register block announce protocol err := s.RegisterNotificationsProtocol( @@ -622,13 +625,16 @@ func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error { func (s *Service) GetRequestResponseProtocol(subprotocol string, requestTimeout time.Duration, maxResponseSize uint64) *RequestResponseProtocol { - protocolID := s.host.protocolID + protocol.ID(subprotocol) + genesisHash := s.blockState.GenesisHash().String() + genesisHash = strings.TrimPrefix(genesisHash, "0x") + protocolId := fmt.Sprintf("/%s%s", genesisHash, subprotocol) + return &RequestResponseProtocol{ ctx: s.ctx, host: s.host, requestTimeout: requestTimeout, maxResponseSize: maxResponseSize, - protocolID: protocolID, + protocolID: protocol.ID(protocolId), responseBuf: make([]byte, maxResponseSize), responseBufMu: sync.Mutex{}, } diff --git a/dot/services.go b/dot/services.go index 7c1d88654a..507eca0ec0 100644 --- a/dot/services.go +++ b/dot/services.go @@ -523,9 +523,6 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync return nil, fmt.Errorf("failed to parse sync log level: %w", err) } - requestMaker := net.GetRequestResponseProtocol(network.SyncID, - blockRequestTimeout, network.MaxBlockResponseSize) - // Should be shared between all sync strategies peersView := sync.NewPeerViewSet() @@ -538,9 +535,10 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync Telemetry: telemetryMailer, BadBlocks: genesisData.BadBlocks, WarpSyncProvider: *warpSyncProvider, - RequestMaker: requestMaker, - BlockState: st.Block, - Peers: peersView, + RequestMaker: net.GetRequestResponseProtocol(network.WarpSyncID, + blockRequestTimeout, network.MaxBlockResponseSize), + BlockState: st.Block, + Peers: peersView, } warpSyncStrategy = sync.NewWarpSyncStrategy(warpSyncCfg) @@ -555,8 +553,9 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync BlockImportHandler: cs, Telemetry: telemetryMailer, BadBlocks: genesisData.BadBlocks, - RequestMaker: requestMaker, - Peers: peersView, + RequestMaker: net.GetRequestResponseProtocol(network.SyncID, + blockRequestTimeout, network.MaxBlockResponseSize), + Peers: peersView, } fullSync := sync.NewFullSyncStrategy(syncCfg) From b82723f6900c929fb7256f94e9d64ec2763a1779 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 31 Oct 2024 16:57:08 -0300 Subject: [PATCH 16/44] Fix comment --- lib/grandpa/warp_sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 0774433aed..9012e75212 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -117,7 +117,7 @@ func (w *WarpSyncProof) verify( currentSetId += 1 currentAuthorities = auths } else if fragmentNumber != len(w.Proofs)-1 || !w.IsFinished { - return nil, fmt.Errorf("Header is missing authority set change digest") + return nil, fmt.Errorf("header is missing authority set change digest") } } } From 1a1cd10ca7f93edcf8a89f1ff14eb013df24307d Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 31 Oct 2024 19:09:32 -0300 Subject: [PATCH 17/44] Add warp sync message decode test --- dot/network/messages/warp_sync_test.go | 23 +++++++++++++++++++++++ lib/grandpa/warp_sync_test.go | 1 + 2 files changed, 24 insertions(+) create mode 100644 dot/network/messages/warp_sync_test.go diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go new file mode 100644 index 0000000000..6deca9493e --- /dev/null +++ b/dot/network/messages/warp_sync_test.go @@ -0,0 +1,23 @@ +package messages + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDecodeWarpSyncProof(t *testing.T) { + // Generated using substrate + expected := []byte{ + 16, 42, 155, 102, 29, 58, 40, 212, 74, 125, 155, 118, 26, 73, 122, 190, 84, 48, 13, 249, 22, 214, 179, 123, 56, 122, 185, 55, 86, 197, 211, 165, 202, 20, 68, 252, 92, 46, 128, 11, 205, 216, 120, 127, 190, 228, 116, 80, 9, 9, 111, 233, 240, 91, 176, 68, 231, 95, 39, 215, 91, 68, 100, 9, 135, 67, 157, 201, 172, 116, 101, 84, 7, 112, 1, 198, 175, 139, 8, 171, 49, 220, 191, 32, 89, 34, 41, 125, 230, 200, 169, 144, 11, 18, 236, 82, 63, 132, 4, 4, 70, 82, 78, 75, 73, 3, 1, 20, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 1, 0, 0, 0, 0, 0, 0, 0, 69, 23, 129, 205, 12, 85, 4, 80, 79, 105, 206, 236, 72, 76, 198, 110, 76, 34, 162, 182, 169, 210, 15, 177, 164, 38, 217, 26, 208, 116, 162, 168, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 222, 184, 227, 254, 253, 47, 253, 127, 8, 0, 21, 180, 100, 121, 185, 202, 98, 243, 6, 146, 192, 169, 5, 136, 125, 66, 118, 111, 10, 67, 251, 31, 5, 0, 0, 0, 0, 0, 0, 0, 4, 222, 184, 227, 254, 253, 47, 253, 127, 8, 0, 21, 180, 100, 121, 185, 202, 98, 243, 6, 146, 192, 169, 5, 136, 125, 66, 118, 111, 10, 67, 251, 31, 5, 0, 0, 0, 0, 0, 0, 0, 29, 199, 174, 147, 44, 90, 15, 89, 180, 4, 8, 109, 71, 59, 202, 156, 3, 113, 4, 194, 14, 201, 252, 50, 246, 3, 209, 88, 222, 255, 152, 86, 191, 149, 96, 174, 143, 133, 70, 30, 96, 220, 47, 119, 16, 134, 137, 128, 1, 241, 185, 250, 10, 44, 200, 140, 108, 50, 192, 28, 197, 44, 178, 8, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 0, 18, 187, 202, 252, 94, 179, 53, 14, 176, 84, 46, 126, 135, 1, 127, 78, 47, 180, 169, 252, 153, 71, 156, 53, 235, 63, 186, 46, 86, 183, 90, 204, 40, 51, 237, 178, 195, 27, 255, 108, 61, 23, 84, 166, 11, 193, 25, 4, 150, 144, 165, 193, 134, 132, 235, 31, 158, 67, 191, 50, 40, 171, 93, 185, 41, 165, 7, 79, 87, 2, 229, 213, 33, 224, 112, 122, 182, 28, 46, 183, 70, 174, 201, 58, 91, 48, 136, 224, 232, 79, 101, 203, 114, 246, 11, 36, 32, 4, 4, 70, 82, 78, 75, 137, 4, 1, 28, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 29, 4, 50, 215, 83, 49, 171, 41, 144, 101, 190, 231, 156, 219, 27, 220, 36, 151, 197, 151, 163, 8, 123, 77, 149, 92, 103, 227, 192, 0, 193, 226, 1, 0, 0, 0, 0, 0, 0, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 1, 0, 0, 0, 0, 0, 0, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 1, 0, 0, 0, 0, 0, 0, 0, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 20, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 130, 183, 122, 23, 144, 235, 99, 87, 104, 168, 98, 150, 159, 8, 27, 217, 140, 45, 137, 193, 131, 252, 86, 96, 169, 209, 201, 126, 34, 21, 3, 53, 18, 181, 72, 167, 183, 60, 219, 75, 28, 116, 220, 135, 252, 202, 219, 146, 116, 80, 75, 90, 204, 37, 254, 253, 162, 196, 68, 117, 142, 172, 57, 10, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 4, 24, 248, 69, 10, 128, 114, 115, 110, 204, 209, 78, 185, 28, 215, 21, 196, 205, 132, 168, 169, 53, 225, 46, 213, 244, 224, 205, 35, 77, 56, 15, 77, 114, 154, 81, 195, 219, 90, 229, 192, 156, 170, 43, 38, 29, 195, 31, 117, 15, 221, 240, 49, 71, 233, 100, 43, 98, 233, 78, 175, 215, 43, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 57, 193, 96, 236, 78, 110, 74, 197, 137, 199, 106, 112, 26, 247, 115, 135, 54, 107, 232, 246, 54, 3, 182, 223, 244, 226, 203, 174, 23, 109, 99, 114, 192, 67, 179, 194, 68, 154, 187, 90, 180, 236, 237, 190, 122, 219, 120, 67, 124, 13, 64, 147, 202, 105, 128, 135, 239, 114, 50, 95, 124, 191, 112, 9, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 168, 174, 111, 72, 225, 211, 70, 235, 140, 155, 144, 105, 138, 45, 82, 242, 67, 52, 98, 176, 112, 188, 202, 104, 14, 82, 1, 88, 161, 117, 223, 179, 54, 198, 42, 110, 18, 133, 133, 142, 192, 246, 148, 152, 114, 101, 146, 128, 119, 147, 224, 235, 100, 221, 216, 150, 139, 18, 188, 235, 140, 210, 212, 4, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 196, 130, 8, 112, 175, 89, 98, 27, 86, 208, 43, 14, 251, 39, 146, 230, 111, 142, 255, 91, 217, 210, 230, 118, 25, 231, 114, 166, 86, 19, 237, 10, 134, 61, 79, 192, 229, 230, 180, 205, 14, 74, 197, 109, 134, 91, 145, 204, 146, 249, 204, 43, 178, 121, 200, 81, 98, 24, 39, 47, 147, 188, 144, 3, 69, 23, 129, 205, 12, 85, 4, 80, 79, 105, 206, 236, 72, 76, 198, 110, 76, 34, 162, 182, 169, 210, 15, 177, 164, 38, 217, 26, 208, 116, 162, 168, 0, 117, 171, 39, 200, 140, 43, 2, 156, 122, 75, 105, 139, 53, 227, 245, 107, 157, 204, 180, 171, 4, 88, 158, 252, 90, 34, 193, 135, 147, 208, 18, 5, 60, 16, 215, 51, 50, 210, 17, 116, 212, 59, 14, 248, 239, 34, 134, 131, 110, 214, 224, 226, 247, 21, 69, 113, 142, 45, 201, 9, 198, 123, 79, 184, 220, 135, 17, 78, 58, 146, 90, 124, 58, 101, 105, 87, 170, 238, 254, 9, 143, 191, 83, 82, 144, 225, 219, 145, 217, 3, 165, 129, 19, 95, 96, 75, 94, 4, 4, 70, 82, 78, 75, 9, 7, 1, 44, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 1, 0, 0, 0, 0, 0, 0, 0, 25, 157, 116, 157, 191, 75, 129, 53, 203, 31, 60, 143, 214, 151, 163, 144, 252, 6, 121, 136, 26, 138, 17, 12, 29, 6, 55, 91, 59, 98, 205, 9, 1, 0, 0, 0, 0, 0, 0, 0, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 1, 0, 0, 0, 0, 0, 0, 0, 41, 38, 132, 171, 187, 40, 222, 246, 56, 7, 197, 246, 232, 78, 158, 134, 137, 118, 158, 179, 123, 26, 177, 48, 215, 157, 191, 191, 27, 154, 13, 68, 1, 0, 0, 0, 0, 0, 0, 0, 86, 140, 180, 165, 116, 198, 209, 120, 254, 179, 156, 39, 223, 200, 179, 247, 137, 229, 245, 66, 62, 25, 199, 22, 51, 199, 72, 185, 172, 240, 134, 181, 1, 0, 0, 0, 0, 0, 0, 0, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 1, 0, 0, 0, 0, 0, 0, 0, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 28, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 116, 245, 244, 106, 194, 23, 18, 3, 173, 241, 49, 32, 205, 92, 108, 211, 21, 223, 122, 230, 37, 81, 44, 115, 166, 220, 14, 144, 153, 231, 77, 121, 211, 221, 215, 70, 20, 74, 44, 131, 5, 118, 77, 234, 136, 90, 229, 180, 66, 186, 221, 202, 1, 35, 233, 39, 142, 103, 214, 83, 92, 93, 252, 12, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 99, 67, 30, 234, 126, 197, 226, 44, 19, 135, 144, 206, 246, 28, 168, 121, 245, 28, 8, 10, 73, 80, 190, 14, 76, 251, 104, 234, 99, 216, 151, 189, 125, 216, 174, 11, 254, 208, 133, 116, 80, 90, 171, 62, 102, 163, 10, 58, 1, 201, 92, 140, 210, 108, 191, 117, 211, 93, 27, 206, 157, 44, 137, 13, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 169, 163, 198, 29, 156, 231, 183, 155, 25, 157, 205, 64, 191, 198, 241, 24, 200, 198, 79, 38, 144, 206, 154, 43, 106, 52, 24, 37, 17, 93, 84, 27, 37, 176, 5, 89, 149, 192, 136, 174, 146, 103, 251, 4, 137, 226, 20, 201, 207, 108, 74, 178, 60, 16, 210, 41, 143, 28, 199, 115, 108, 89, 255, 13, 29, 4, 50, 215, 83, 49, 171, 41, 144, 101, 190, 231, 156, 219, 27, 220, 36, 151, 197, 151, 163, 8, 123, 77, 149, 92, 103, 227, 192, 0, 193, 226, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 216, 168, 238, 43, 2, 73, 29, 120, 165, 152, 72, 101, 226, 190, 55, 54, 6, 116, 200, 172, 232, 161, 139, 220, 46, 214, 252, 222, 173, 175, 43, 84, 208, 249, 117, 204, 236, 66, 137, 157, 198, 40, 46, 100, 150, 215, 196, 151, 178, 50, 247, 200, 28, 181, 126, 237, 234, 83, 149, 91, 56, 67, 140, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 5, 111, 29, 243, 194, 132, 118, 106, 111, 238, 2, 114, 215, 106, 21, 167, 120, 185, 220, 115, 244, 234, 123, 160, 177, 251, 166, 172, 16, 129, 169, 45, 76, 144, 165, 148, 86, 185, 253, 152, 32, 139, 81, 176, 163, 204, 162, 193, 219, 136, 60, 54, 134, 151, 138, 47, 133, 83, 236, 216, 230, 42, 73, 10, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 222, 214, 229, 70, 232, 174, 163, 44, 61, 8, 70, 216, 220, 160, 181, 47, 177, 121, 37, 10, 180, 118, 55, 68, 206, 251, 134, 235, 138, 241, 119, 76, 119, 157, 41, 57, 210, 93, 115, 247, 10, 58, 46, 124, 200, 156, 135, 135, 168, 248, 138, 110, 238, 90, 244, 12, 178, 20, 184, 242, 167, 195, 54, 8, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 175, 41, 93, 232, 245, 75, 128, 55, 65, 85, 188, 173, 236, 120, 175, 159, 235, 18, 149, 206, 102, 155, 115, 12, 55, 209, 92, 218, 239, 205, 147, 210, 101, 71, 135, 163, 73, 2, 50, 137, 35, 179, 165, 17, 131, 21, 234, 25, 176, 93, 228, 158, 90, 224, 110, 236, 49, 242, 98, 120, 206, 193, 95, 15, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 0, 21, 248, 232, 48, 214, 166, 58, 40, 127, 139, 227, 97, 146, 120, 98, 241, 140, 115, 123, 92, 221, 121, 148, 202, 17, 124, 111, 255, 249, 70, 20, 48, 80, 7, 221, 252, 52, 55, 136, 224, 118, 162, 139, 96, 28, 115, 177, 154, 82, 115, 229, 66, 41, 141, 63, 69, 133, 136, 219, 28, 224, 120, 89, 124, 242, 249, 222, 7, 7, 173, 197, 201, 42, 96, 96, 214, 147, 237, 56, 0, 246, 201, 66, 60, 242, 100, 8, 162, 139, 37, 238, 197, 49, 170, 89, 75, 99, 4, 4, 70, 82, 78, 75, 105, 1, 1, 8, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 44, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 72, 197, 176, 166, 176, 29, 13, 202, 12, 103, 90, 122, 101, 70, 18, 65, 156, 245, 204, 134, 252, 130, 26, 79, 162, 172, 100, 31, 10, 154, 46, 66, 118, 178, 175, 201, 251, 69, 101, 112, 155, 237, 245, 176, 225, 9, 223, 228, 130, 105, 96, 122, 167, 101, 202, 168, 206, 69, 122, 195, 63, 163, 54, 2, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 156, 253, 170, 7, 146, 192, 248, 154, 102, 217, 12, 19, 185, 254, 198, 242, 178, 202, 42, 64, 93, 65, 200, 182, 22, 30, 72, 85, 27, 148, 80, 159, 18, 212, 92, 190, 85, 235, 82, 192, 11, 240, 128, 148, 6, 52, 189, 93, 153, 246, 80, 115, 173, 116, 160, 8, 239, 239, 45, 245, 100, 219, 232, 12, 25, 157, 116, 157, 191, 75, 129, 53, 203, 31, 60, 143, 214, 151, 163, 144, 252, 6, 121, 136, 26, 138, 17, 12, 29, 6, 55, 91, 59, 98, 205, 9, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 239, 12, 39, 85, 233, 182, 144, 7, 119, 212, 237, 214, 12, 53, 73, 149, 187, 234, 115, 229, 62, 211, 123, 118, 180, 203, 9, 74, 22, 135, 224, 119, 235, 124, 4, 186, 58, 90, 174, 124, 174, 102, 188, 68, 231, 146, 244, 33, 63, 67, 163, 222, 171, 9, 201, 112, 255, 70, 209, 161, 18, 184, 138, 11, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 116, 193, 98, 32, 118, 52, 48, 117, 7, 132, 160, 176, 170, 153, 102, 35, 164, 230, 139, 62, 36, 176, 222, 33, 250, 220, 52, 85, 206, 3, 145, 185, 0, 161, 70, 182, 16, 40, 161, 78, 16, 31, 127, 7, 100, 117, 31, 198, 63, 243, 247, 244, 254, 225, 217, 189, 102, 191, 195, 154, 180, 161, 143, 1, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 253, 182, 158, 26, 205, 66, 3, 249, 22, 75, 200, 178, 198, 178, 68, 123, 100, 100, 40, 91, 54, 196, 56, 62, 219, 44, 86, 62, 197, 128, 170, 83, 34, 170, 52, 121, 58, 148, 78, 57, 89, 86, 164, 114, 25, 24, 45, 243, 253, 233, 206, 158, 105, 188, 165, 253, 76, 105, 198, 173, 165, 82, 226, 8, 41, 38, 132, 171, 187, 40, 222, 246, 56, 7, 197, 246, 232, 78, 158, 134, 137, 118, 158, 179, 123, 26, 177, 48, 215, 157, 191, 191, 27, 154, 13, 68, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 209, 184, 243, 156, 27, 248, 87, 219, 109, 173, 213, 15, 70, 98, 6, 60, 144, 187, 11, 48, 185, 112, 142, 220, 103, 32, 224, 85, 154, 219, 63, 3, 105, 193, 183, 194, 181, 106, 184, 125, 27, 249, 161, 223, 176, 42, 205, 77, 35, 27, 97, 99, 152, 215, 145, 12, 11, 120, 221, 162, 248, 57, 222, 4, 86, 140, 180, 165, 116, 198, 209, 120, 254, 179, 156, 39, 223, 200, 179, 247, 137, 229, 245, 66, 62, 25, 199, 22, 51, 199, 72, 185, 172, 240, 134, 181, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 161, 243, 14, 58, 230, 158, 140, 119, 85, 57, 174, 66, 42, 57, 40, 38, 95, 177, 17, 221, 57, 27, 19, 246, 201, 28, 75, 206, 171, 22, 219, 153, 175, 85, 166, 214, 23, 150, 197, 241, 126, 4, 0, 56, 94, 250, 124, 219, 22, 13, 91, 239, 49, 120, 86, 142, 188, 105, 9, 180, 252, 59, 218, 7, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 152, 160, 70, 204, 215, 44, 69, 158, 109, 252, 175, 27, 183, 141, 145, 199, 93, 181, 51, 13, 140, 190, 120, 222, 153, 181, 47, 107, 19, 23, 37, 128, 177, 248, 70, 91, 33, 253, 156, 177, 213, 148, 212, 171, 191, 203, 53, 224, 102, 30, 255, 205, 93, 224, 93, 2, 0, 154, 156, 151, 188, 246, 165, 8, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 125, 69, 183, 15, 98, 167, 92, 128, 90, 128, 223, 71, 200, 121, 202, 31, 16, 8, 148, 142, 22, 68, 197, 232, 161, 232, 172, 102, 140, 150, 16, 31, 190, 190, 201, 210, 148, 35, 49, 203, 2, 47, 190, 196, 191, 115, 32, 42, 94, 108, 10, 61, 92, 50, 140, 244, 168, 248, 172, 13, 63, 161, 135, 7, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 123, 33, 231, 71, 138, 31, 247, 32, 10, 19, 145, 205, 106, 205, 104, 1, 159, 88, 167, 107, 171, 128, 32, 108, 171, 65, 115, 195, 204, 89, 249, 82, 103, 201, 24, 188, 172, 179, 90, 243, 194, 6, 212, 74, 55, 246, 0, 36, 249, 248, 237, 180, 109, 41, 138, 172, 26, 150, 172, 106, 36, 83, 8, 6, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 205, 77, 198, 42, 175, 110, 56, 214, 191, 108, 148, 188, 42, 253, 176, 102, 207, 208, 235, 0, 53, 166, 196, 149, 9, 116, 73, 165, 189, 242, 129, 228, 42, 255, 88, 130, 237, 114, 191, 62, 72, 110, 240, 153, 191, 93, 248, 104, 70, 139, 153, 138, 176, 129, 95, 64, 131, 44, 202, 58, 138, 144, 180, 1, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 0, 1, + } + + var proof WarpSyncProof + + err := proof.Decode(expected) + require.NoError(t, err) + + encoded, err := proof.Encode() + require.NoError(t, err) + require.Equal(t, expected, encoded) +} diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warp_sync_test.go index 8f26c2e9a5..4dfd88fc83 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warp_sync_test.go @@ -9,6 +9,7 @@ import ( "slices" "testing" + "github.com/ChainSafe/gossamer/dot/network/messages" "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" ced25519 "github.com/ChainSafe/gossamer/internal/primitives/core/ed25519" From 8a5f3cc6536e340bd046a4dec7339ad3b32bedf2 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 31 Oct 2024 19:11:06 -0300 Subject: [PATCH 18/44] Add missing license --- dot/network/messages/warp_sync_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go index 6deca9493e..7ab330463b 100644 --- a/dot/network/messages/warp_sync_test.go +++ b/dot/network/messages/warp_sync_test.go @@ -1,3 +1,6 @@ +// Copyright 2024 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + package messages import ( From ea6eee9ec0fe5d204b7dba84e8fd22fd0a386762 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 31 Oct 2024 20:46:49 -0300 Subject: [PATCH 19/44] Remove import --- dot/network/messages/warp_sync.go | 4 ++++ dot/sync/warp_sync.go | 8 +++++++- lib/grandpa/warp_sync_test.go | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dot/network/messages/warp_sync.go b/dot/network/messages/warp_sync.go index d73588eb23..7ddde1a7ac 100644 --- a/dot/network/messages/warp_sync.go +++ b/dot/network/messages/warp_sync.go @@ -8,6 +8,7 @@ import ( "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa" + "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/internal/primitives/core/hash" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/pkg/scale" @@ -58,7 +59,10 @@ type WarpSyncProof struct { proofsLength int } +var logger = log.NewFromGlobal(log.AddContext("pkg", "network")) + func (wsp *WarpSyncProof) Decode(in []byte) error { + logger.Infof("decoding WarpSyncProof bytes: %x", in) return scale.Unmarshal(in, wsp) } diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 9a857e6086..d2ded1649a 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -12,6 +12,7 @@ import ( "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" + "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/grandpa" "github.com/libp2p/go-libp2p/core/peer" ) @@ -120,11 +121,16 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { return nil, err } + lastBlockHash := common.Hash([]byte{ + 0x85, 0xa2, 0x97, 0xea, 0xd2, 0x0a, 0xd1, 0x9d, 0x96, 0x6d, 0x87, 0x69, 0xc3, 0x79, 0xc9, 0xf0, 0xc4, 0xa4, 0xe5, 0x16, 0xc8, 0xa3, + 0xd9, 0x7f, 0x6f, 0xf6, 0xba, 0xb3, 0x8a, 0x0e, 0x31, 0xb3, + }) + var task SyncTask switch w.phase { case WarpProof: task = SyncTask{ - request: messages.NewWarpProofRequest(lastBlock.Hash()), + request: messages.NewWarpProofRequest(lastBlockHash), response: &messages.WarpSyncProof{}, requestMaker: w.reqMaker, } diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warp_sync_test.go index 4dfd88fc83..8f26c2e9a5 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warp_sync_test.go @@ -9,7 +9,6 @@ import ( "slices" "testing" - "github.com/ChainSafe/gossamer/dot/network/messages" "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" ced25519 "github.com/ChainSafe/gossamer/internal/primitives/core/ed25519" From 99cae82579541d8d23c6a61afd1f5a7634e6f711 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 01:44:08 -0300 Subject: [PATCH 20/44] Use right justification number for generic --- dot/network/messages/warp_sync.go | 6 ++++- dot/network/messages/warp_sync_test.go | 10 +++++--- dot/sync/peer_view.go | 2 +- dot/sync/service.go | 6 +++-- dot/sync/warp_sync.go | 33 ++++++++++++++++++-------- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/dot/network/messages/warp_sync.go b/dot/network/messages/warp_sync.go index 7ddde1a7ac..cd83f8f703 100644 --- a/dot/network/messages/warp_sync.go +++ b/dot/network/messages/warp_sync.go @@ -49,7 +49,7 @@ func (wpr *WarpProofRequest) String() string { type WarpSyncFragment struct { Header types.Header - Justification grandpa.GrandpaJustification[hash.H256, uint64] + Justification grandpa.GrandpaJustification[hash.H256, uint32] } type WarpSyncProof struct { @@ -63,6 +63,10 @@ var logger = log.NewFromGlobal(log.AddContext("pkg", "network")) func (wsp *WarpSyncProof) Decode(in []byte) error { logger.Infof("decoding WarpSyncProof bytes: %x", in) + + if len(in) == 0 { + return fmt.Errorf("cannot decode empty bytes") + } return scale.Unmarshal(in, wsp) } diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go index 7ab330463b..5f5ff3fdbf 100644 --- a/dot/network/messages/warp_sync_test.go +++ b/dot/network/messages/warp_sync_test.go @@ -4,6 +4,8 @@ package messages import ( + "encoding/hex" + "log" "testing" "github.com/stretchr/testify/require" @@ -11,13 +13,15 @@ import ( func TestDecodeWarpSyncProof(t *testing.T) { // Generated using substrate - expected := []byte{ - 16, 42, 155, 102, 29, 58, 40, 212, 74, 125, 155, 118, 26, 73, 122, 190, 84, 48, 13, 249, 22, 214, 179, 123, 56, 122, 185, 55, 86, 197, 211, 165, 202, 20, 68, 252, 92, 46, 128, 11, 205, 216, 120, 127, 190, 228, 116, 80, 9, 9, 111, 233, 240, 91, 176, 68, 231, 95, 39, 215, 91, 68, 100, 9, 135, 67, 157, 201, 172, 116, 101, 84, 7, 112, 1, 198, 175, 139, 8, 171, 49, 220, 191, 32, 89, 34, 41, 125, 230, 200, 169, 144, 11, 18, 236, 82, 63, 132, 4, 4, 70, 82, 78, 75, 73, 3, 1, 20, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 1, 0, 0, 0, 0, 0, 0, 0, 69, 23, 129, 205, 12, 85, 4, 80, 79, 105, 206, 236, 72, 76, 198, 110, 76, 34, 162, 182, 169, 210, 15, 177, 164, 38, 217, 26, 208, 116, 162, 168, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 222, 184, 227, 254, 253, 47, 253, 127, 8, 0, 21, 180, 100, 121, 185, 202, 98, 243, 6, 146, 192, 169, 5, 136, 125, 66, 118, 111, 10, 67, 251, 31, 5, 0, 0, 0, 0, 0, 0, 0, 4, 222, 184, 227, 254, 253, 47, 253, 127, 8, 0, 21, 180, 100, 121, 185, 202, 98, 243, 6, 146, 192, 169, 5, 136, 125, 66, 118, 111, 10, 67, 251, 31, 5, 0, 0, 0, 0, 0, 0, 0, 29, 199, 174, 147, 44, 90, 15, 89, 180, 4, 8, 109, 71, 59, 202, 156, 3, 113, 4, 194, 14, 201, 252, 50, 246, 3, 209, 88, 222, 255, 152, 86, 191, 149, 96, 174, 143, 133, 70, 30, 96, 220, 47, 119, 16, 134, 137, 128, 1, 241, 185, 250, 10, 44, 200, 140, 108, 50, 192, 28, 197, 44, 178, 8, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 0, 18, 187, 202, 252, 94, 179, 53, 14, 176, 84, 46, 126, 135, 1, 127, 78, 47, 180, 169, 252, 153, 71, 156, 53, 235, 63, 186, 46, 86, 183, 90, 204, 40, 51, 237, 178, 195, 27, 255, 108, 61, 23, 84, 166, 11, 193, 25, 4, 150, 144, 165, 193, 134, 132, 235, 31, 158, 67, 191, 50, 40, 171, 93, 185, 41, 165, 7, 79, 87, 2, 229, 213, 33, 224, 112, 122, 182, 28, 46, 183, 70, 174, 201, 58, 91, 48, 136, 224, 232, 79, 101, 203, 114, 246, 11, 36, 32, 4, 4, 70, 82, 78, 75, 137, 4, 1, 28, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 29, 4, 50, 215, 83, 49, 171, 41, 144, 101, 190, 231, 156, 219, 27, 220, 36, 151, 197, 151, 163, 8, 123, 77, 149, 92, 103, 227, 192, 0, 193, 226, 1, 0, 0, 0, 0, 0, 0, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 1, 0, 0, 0, 0, 0, 0, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 1, 0, 0, 0, 0, 0, 0, 0, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 20, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 130, 183, 122, 23, 144, 235, 99, 87, 104, 168, 98, 150, 159, 8, 27, 217, 140, 45, 137, 193, 131, 252, 86, 96, 169, 209, 201, 126, 34, 21, 3, 53, 18, 181, 72, 167, 183, 60, 219, 75, 28, 116, 220, 135, 252, 202, 219, 146, 116, 80, 75, 90, 204, 37, 254, 253, 162, 196, 68, 117, 142, 172, 57, 10, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 4, 24, 248, 69, 10, 128, 114, 115, 110, 204, 209, 78, 185, 28, 215, 21, 196, 205, 132, 168, 169, 53, 225, 46, 213, 244, 224, 205, 35, 77, 56, 15, 77, 114, 154, 81, 195, 219, 90, 229, 192, 156, 170, 43, 38, 29, 195, 31, 117, 15, 221, 240, 49, 71, 233, 100, 43, 98, 233, 78, 175, 215, 43, 0, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 57, 193, 96, 236, 78, 110, 74, 197, 137, 199, 106, 112, 26, 247, 115, 135, 54, 107, 232, 246, 54, 3, 182, 223, 244, 226, 203, 174, 23, 109, 99, 114, 192, 67, 179, 194, 68, 154, 187, 90, 180, 236, 237, 190, 122, 219, 120, 67, 124, 13, 64, 147, 202, 105, 128, 135, 239, 114, 50, 95, 124, 191, 112, 9, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 168, 174, 111, 72, 225, 211, 70, 235, 140, 155, 144, 105, 138, 45, 82, 242, 67, 52, 98, 176, 112, 188, 202, 104, 14, 82, 1, 88, 161, 117, 223, 179, 54, 198, 42, 110, 18, 133, 133, 142, 192, 246, 148, 152, 114, 101, 146, 128, 119, 147, 224, 235, 100, 221, 216, 150, 139, 18, 188, 235, 140, 210, 212, 4, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 202, 255, 114, 72, 34, 166, 249, 96, 175, 214, 253, 139, 48, 242, 225, 226, 101, 153, 167, 225, 62, 59, 43, 2, 37, 191, 14, 189, 79, 81, 217, 16, 10, 0, 0, 0, 0, 0, 0, 0, 196, 130, 8, 112, 175, 89, 98, 27, 86, 208, 43, 14, 251, 39, 146, 230, 111, 142, 255, 91, 217, 210, 230, 118, 25, 231, 114, 166, 86, 19, 237, 10, 134, 61, 79, 192, 229, 230, 180, 205, 14, 74, 197, 109, 134, 91, 145, 204, 146, 249, 204, 43, 178, 121, 200, 81, 98, 24, 39, 47, 147, 188, 144, 3, 69, 23, 129, 205, 12, 85, 4, 80, 79, 105, 206, 236, 72, 76, 198, 110, 76, 34, 162, 182, 169, 210, 15, 177, 164, 38, 217, 26, 208, 116, 162, 168, 0, 117, 171, 39, 200, 140, 43, 2, 156, 122, 75, 105, 139, 53, 227, 245, 107, 157, 204, 180, 171, 4, 88, 158, 252, 90, 34, 193, 135, 147, 208, 18, 5, 60, 16, 215, 51, 50, 210, 17, 116, 212, 59, 14, 248, 239, 34, 134, 131, 110, 214, 224, 226, 247, 21, 69, 113, 142, 45, 201, 9, 198, 123, 79, 184, 220, 135, 17, 78, 58, 146, 90, 124, 58, 101, 105, 87, 170, 238, 254, 9, 143, 191, 83, 82, 144, 225, 219, 145, 217, 3, 165, 129, 19, 95, 96, 75, 94, 4, 4, 70, 82, 78, 75, 9, 7, 1, 44, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 1, 0, 0, 0, 0, 0, 0, 0, 25, 157, 116, 157, 191, 75, 129, 53, 203, 31, 60, 143, 214, 151, 163, 144, 252, 6, 121, 136, 26, 138, 17, 12, 29, 6, 55, 91, 59, 98, 205, 9, 1, 0, 0, 0, 0, 0, 0, 0, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 1, 0, 0, 0, 0, 0, 0, 0, 41, 38, 132, 171, 187, 40, 222, 246, 56, 7, 197, 246, 232, 78, 158, 134, 137, 118, 158, 179, 123, 26, 177, 48, 215, 157, 191, 191, 27, 154, 13, 68, 1, 0, 0, 0, 0, 0, 0, 0, 86, 140, 180, 165, 116, 198, 209, 120, 254, 179, 156, 39, 223, 200, 179, 247, 137, 229, 245, 66, 62, 25, 199, 22, 51, 199, 72, 185, 172, 240, 134, 181, 1, 0, 0, 0, 0, 0, 0, 0, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 1, 0, 0, 0, 0, 0, 0, 0, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 1, 0, 0, 0, 0, 0, 0, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 1, 0, 0, 0, 0, 0, 0, 0, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 1, 0, 0, 0, 0, 0, 0, 0, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 28, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 116, 245, 244, 106, 194, 23, 18, 3, 173, 241, 49, 32, 205, 92, 108, 211, 21, 223, 122, 230, 37, 81, 44, 115, 166, 220, 14, 144, 153, 231, 77, 121, 211, 221, 215, 70, 20, 74, 44, 131, 5, 118, 77, 234, 136, 90, 229, 180, 66, 186, 221, 202, 1, 35, 233, 39, 142, 103, 214, 83, 92, 93, 252, 12, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 99, 67, 30, 234, 126, 197, 226, 44, 19, 135, 144, 206, 246, 28, 168, 121, 245, 28, 8, 10, 73, 80, 190, 14, 76, 251, 104, 234, 99, 216, 151, 189, 125, 216, 174, 11, 254, 208, 133, 116, 80, 90, 171, 62, 102, 163, 10, 58, 1, 201, 92, 140, 210, 108, 191, 117, 211, 93, 27, 206, 157, 44, 137, 13, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 169, 163, 198, 29, 156, 231, 183, 155, 25, 157, 205, 64, 191, 198, 241, 24, 200, 198, 79, 38, 144, 206, 154, 43, 106, 52, 24, 37, 17, 93, 84, 27, 37, 176, 5, 89, 149, 192, 136, 174, 146, 103, 251, 4, 137, 226, 20, 201, 207, 108, 74, 178, 60, 16, 210, 41, 143, 28, 199, 115, 108, 89, 255, 13, 29, 4, 50, 215, 83, 49, 171, 41, 144, 101, 190, 231, 156, 219, 27, 220, 36, 151, 197, 151, 163, 8, 123, 77, 149, 92, 103, 227, 192, 0, 193, 226, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 216, 168, 238, 43, 2, 73, 29, 120, 165, 152, 72, 101, 226, 190, 55, 54, 6, 116, 200, 172, 232, 161, 139, 220, 46, 214, 252, 222, 173, 175, 43, 84, 208, 249, 117, 204, 236, 66, 137, 157, 198, 40, 46, 100, 150, 215, 196, 151, 178, 50, 247, 200, 28, 181, 126, 237, 234, 83, 149, 91, 56, 67, 140, 0, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 5, 111, 29, 243, 194, 132, 118, 106, 111, 238, 2, 114, 215, 106, 21, 167, 120, 185, 220, 115, 244, 234, 123, 160, 177, 251, 166, 172, 16, 129, 169, 45, 76, 144, 165, 148, 86, 185, 253, 152, 32, 139, 81, 176, 163, 204, 162, 193, 219, 136, 60, 54, 134, 151, 138, 47, 133, 83, 236, 216, 230, 42, 73, 10, 200, 51, 189, 210, 225, 167, 161, 138, 204, 28, 17, 248, 89, 110, 46, 105, 123, 185, 180, 45, 107, 96, 81, 228, 116, 9, 26, 29, 67, 162, 148, 215, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 222, 214, 229, 70, 232, 174, 163, 44, 61, 8, 70, 216, 220, 160, 181, 47, 177, 121, 37, 10, 180, 118, 55, 68, 206, 251, 134, 235, 138, 241, 119, 76, 119, 157, 41, 57, 210, 93, 115, 247, 10, 58, 46, 124, 200, 156, 135, 135, 168, 248, 138, 110, 238, 90, 244, 12, 178, 20, 184, 242, 167, 195, 54, 8, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 83, 146, 197, 225, 162, 181, 29, 105, 191, 226, 73, 217, 135, 239, 81, 168, 166, 160, 168, 61, 176, 64, 114, 7, 41, 49, 71, 101, 46, 232, 79, 51, 15, 0, 0, 0, 0, 0, 0, 0, 175, 41, 93, 232, 245, 75, 128, 55, 65, 85, 188, 173, 236, 120, 175, 159, 235, 18, 149, 206, 102, 155, 115, 12, 55, 209, 92, 218, 239, 205, 147, 210, 101, 71, 135, 163, 73, 2, 50, 137, 35, 179, 165, 17, 131, 21, 234, 25, 176, 93, 228, 158, 90, 224, 110, 236, 49, 242, 98, 120, 206, 193, 95, 15, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 0, 21, 248, 232, 48, 214, 166, 58, 40, 127, 139, 227, 97, 146, 120, 98, 241, 140, 115, 123, 92, 221, 121, 148, 202, 17, 124, 111, 255, 249, 70, 20, 48, 80, 7, 221, 252, 52, 55, 136, 224, 118, 162, 139, 96, 28, 115, 177, 154, 82, 115, 229, 66, 41, 141, 63, 69, 133, 136, 219, 28, 224, 120, 89, 124, 242, 249, 222, 7, 7, 173, 197, 201, 42, 96, 96, 214, 147, 237, 56, 0, 246, 201, 66, 60, 242, 100, 8, 162, 139, 37, 238, 197, 49, 170, 89, 75, 99, 4, 4, 70, 82, 78, 75, 105, 1, 1, 8, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 1, 0, 0, 0, 0, 0, 0, 0, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 44, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 72, 197, 176, 166, 176, 29, 13, 202, 12, 103, 90, 122, 101, 70, 18, 65, 156, 245, 204, 134, 252, 130, 26, 79, 162, 172, 100, 31, 10, 154, 46, 66, 118, 178, 175, 201, 251, 69, 101, 112, 155, 237, 245, 176, 225, 9, 223, 228, 130, 105, 96, 122, 167, 101, 202, 168, 206, 69, 122, 195, 63, 163, 54, 2, 136, 220, 52, 23, 213, 5, 142, 196, 180, 80, 62, 12, 18, 234, 26, 10, 137, 190, 32, 15, 233, 137, 34, 66, 61, 67, 52, 1, 79, 166, 176, 238, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 156, 253, 170, 7, 146, 192, 248, 154, 102, 217, 12, 19, 185, 254, 198, 242, 178, 202, 42, 64, 93, 65, 200, 182, 22, 30, 72, 85, 27, 148, 80, 159, 18, 212, 92, 190, 85, 235, 82, 192, 11, 240, 128, 148, 6, 52, 189, 93, 153, 246, 80, 115, 173, 116, 160, 8, 239, 239, 45, 245, 100, 219, 232, 12, 25, 157, 116, 157, 191, 75, 129, 53, 203, 31, 60, 143, 214, 151, 163, 144, 252, 6, 121, 136, 26, 138, 17, 12, 29, 6, 55, 91, 59, 98, 205, 9, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 239, 12, 39, 85, 233, 182, 144, 7, 119, 212, 237, 214, 12, 53, 73, 149, 187, 234, 115, 229, 62, 211, 123, 118, 180, 203, 9, 74, 22, 135, 224, 119, 235, 124, 4, 186, 58, 90, 174, 124, 174, 102, 188, 68, 231, 146, 244, 33, 63, 67, 163, 222, 171, 9, 201, 112, 255, 70, 209, 161, 18, 184, 138, 11, 209, 124, 45, 120, 35, 235, 242, 96, 253, 19, 143, 45, 126, 39, 209, 20, 192, 20, 93, 150, 139, 95, 245, 0, 97, 37, 242, 65, 79, 173, 174, 105, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 116, 193, 98, 32, 118, 52, 48, 117, 7, 132, 160, 176, 170, 153, 102, 35, 164, 230, 139, 62, 36, 176, 222, 33, 250, 220, 52, 85, 206, 3, 145, 185, 0, 161, 70, 182, 16, 40, 161, 78, 16, 31, 127, 7, 100, 117, 31, 198, 63, 243, 247, 244, 254, 225, 217, 189, 102, 191, 195, 154, 180, 161, 143, 1, 29, 254, 62, 34, 204, 13, 69, 199, 7, 121, 193, 9, 95, 116, 137, 168, 239, 60, 245, 45, 98, 251, 216, 194, 250, 56, 201, 241, 114, 53, 2, 181, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 253, 182, 158, 26, 205, 66, 3, 249, 22, 75, 200, 178, 198, 178, 68, 123, 100, 100, 40, 91, 54, 196, 56, 62, 219, 44, 86, 62, 197, 128, 170, 83, 34, 170, 52, 121, 58, 148, 78, 57, 89, 86, 164, 114, 25, 24, 45, 243, 253, 233, 206, 158, 105, 188, 165, 253, 76, 105, 198, 173, 165, 82, 226, 8, 41, 38, 132, 171, 187, 40, 222, 246, 56, 7, 197, 246, 232, 78, 158, 134, 137, 118, 158, 179, 123, 26, 177, 48, 215, 157, 191, 191, 27, 154, 13, 68, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 209, 184, 243, 156, 27, 248, 87, 219, 109, 173, 213, 15, 70, 98, 6, 60, 144, 187, 11, 48, 185, 112, 142, 220, 103, 32, 224, 85, 154, 219, 63, 3, 105, 193, 183, 194, 181, 106, 184, 125, 27, 249, 161, 223, 176, 42, 205, 77, 35, 27, 97, 99, 152, 215, 145, 12, 11, 120, 221, 162, 248, 57, 222, 4, 86, 140, 180, 165, 116, 198, 209, 120, 254, 179, 156, 39, 223, 200, 179, 247, 137, 229, 245, 66, 62, 25, 199, 22, 51, 199, 72, 185, 172, 240, 134, 181, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 161, 243, 14, 58, 230, 158, 140, 119, 85, 57, 174, 66, 42, 57, 40, 38, 95, 177, 17, 221, 57, 27, 19, 246, 201, 28, 75, 206, 171, 22, 219, 153, 175, 85, 166, 214, 23, 150, 197, 241, 126, 4, 0, 56, 94, 250, 124, 219, 22, 13, 91, 239, 49, 120, 86, 142, 188, 105, 9, 180, 252, 59, 218, 7, 67, 150, 96, 179, 108, 108, 3, 175, 175, 202, 2, 123, 145, 11, 79, 236, 249, 152, 1, 131, 76, 98, 165, 230, 0, 111, 39, 217, 120, 222, 35, 79, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 152, 160, 70, 204, 215, 44, 69, 158, 109, 252, 175, 27, 183, 141, 145, 199, 93, 181, 51, 13, 140, 190, 120, 222, 153, 181, 47, 107, 19, 23, 37, 128, 177, 248, 70, 91, 33, 253, 156, 177, 213, 148, 212, 171, 191, 203, 53, 224, 102, 30, 255, 205, 93, 224, 93, 2, 0, 154, 156, 151, 188, 246, 165, 8, 221, 106, 97, 24, 182, 193, 28, 156, 158, 90, 79, 52, 237, 61, 84, 94, 44, 116, 25, 15, 144, 54, 92, 96, 194, 48, 250, 130, 233, 66, 59, 185, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 125, 69, 183, 15, 98, 167, 92, 128, 90, 128, 223, 71, 200, 121, 202, 31, 16, 8, 148, 142, 22, 68, 197, 232, 161, 232, 172, 102, 140, 150, 16, 31, 190, 190, 201, 210, 148, 35, 49, 203, 2, 47, 190, 196, 191, 115, 32, 42, 94, 108, 10, 61, 92, 50, 140, 244, 168, 248, 172, 13, 63, 161, 135, 7, 22, 249, 112, 22, 187, 234, 143, 123, 69, 174, 103, 87, 180, 158, 252, 16, 128, 172, 204, 23, 93, 143, 1, 143, 155, 167, 25, 182, 11, 8, 21, 228, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 123, 33, 231, 71, 138, 31, 247, 32, 10, 19, 145, 205, 106, 205, 104, 1, 159, 88, 167, 107, 171, 128, 32, 108, 171, 65, 115, 195, 204, 89, 249, 82, 103, 201, 24, 188, 172, 179, 90, 243, 194, 6, 212, 74, 55, 246, 0, 36, 249, 248, 237, 180, 109, 41, 138, 172, 26, 150, 172, 106, 36, 83, 8, 6, 80, 121, 188, 210, 15, 217, 125, 125, 47, 117, 44, 70, 7, 1, 38, 0, 180, 1, 149, 2, 96, 169, 24, 33, 247, 62, 105, 32, 113, 200, 43, 245, 240, 16, 121, 43, 132, 63, 124, 168, 85, 163, 14, 109, 243, 107, 91, 112, 81, 29, 19, 139, 91, 14, 236, 90, 98, 208, 20, 178, 212, 176, 88, 233, 20, 0, 0, 0, 0, 0, 0, 0, 205, 77, 198, 42, 175, 110, 56, 214, 191, 108, 148, 188, 42, 253, 176, 102, 207, 208, 235, 0, 53, 166, 196, 149, 9, 116, 73, 165, 189, 242, 129, 228, 42, 255, 88, 130, 237, 114, 191, 62, 72, 110, 240, 153, 191, 93, 248, 104, 70, 139, 153, 138, 176, 129, 95, 64, 131, 44, 202, 58, 138, 144, 180, 1, 94, 99, 155, 67, 224, 5, 44, 71, 68, 125, 172, 135, 214, 253, 43, 110, 197, 11, 221, 77, 15, 97, 78, 66, 153, 198, 101, 36, 155, 189, 9, 217, 0, 1, + hexString := "04e995dd4dddbdfc54bd8126e0b5b394a47da71ca4a6510e7bd132d103470bf9b9be748b05d4026dd4bd8821893ce9e82a3a8c324ca454dd7510ee9ab05df3df82e87a1eada450bc10f223a562a12962e8914f436fd0991319d662310298fa47e5ff0dffb50c0642414245b501031100000009ba301100000000a6815e866aebee63d23cefa60964fa88b4814264fd35703c0c8a5f8192d8f41aa15bc5d991d1cad65ffccb73dbacd542a32286ec051190166ec00bfb4304b6049a882d0858cdbfb8d37a07269ea01bad1b55fb1174d6dedbfac56787adfa700004424545468403a6c0199af958a3ae8a3928b0802b709589bcbb1ec5b7041cf91644dd696ad99f05424142450101f8b400261b84cc580a8947abe4caf3b4ee51b7aeb26afc9a3bcdd2b3cd634f2df03cda49368e5e56a5b2427f6088cdc4144d75e1985f5e0a7e8f527290f47b8dad10000000000000376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620138376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62015037bddf7847fd40d7e6235c17203c8b70e661ef25aa44cbbaed19d5bb455bec3b20f59a720253b7c536171e1e68a91dcbf6b88fd077e28a2125cc9ea4fb430819b6ba718c28b1078474dc63e9d8a6f4d794da79f661da070fcca13b3bba50e7376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201243478b0465e1c13e9cda8479d42958422ab0acd69a1dbdc8d14fa95d2b15e96e6c1a5e58df7ff148977ba68418a7d6f6cf2ab959056c59cd768e490bc90ea0c1a619f90a9c96ec3e1c57211613247e8c0efe123188263da1dc8796d6a018c16376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620151010e386ecf4cb60e88acf75d7859547584a8e4258af8ca3fcde8d79dedf9ed1b6b0bf7df2704c3dfbc2db4a785833f0a70e30ec3c6ad9f35cae93e6ebd990a1d50350ac619dc36a0fe05cdd7a1654e73858586d55265f3524cc27e005be0f2376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201ca80d95b84408c14cc2c0cca1f3d2e094ebe056b5816959c887ac40b7311edf8c87e0f77a06ed398323b684e09c6d784e5333136dbae5a1d0627bf774e633408229366210b4b20adf7741fb6bc8fa669ea2f7470e1440b38969d2a47d752ffeb376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201bda1ac4056f6e6210d6b2dd8f69323cb7f2729f49ad9d42059ceecdffecebef04ce478a3cfde9bceadaf9be978443f0c3a5aea19d04b538b087cc0ca614e6b0a2bf793d9fb4251da094a2dd33bb0f68a46e60d799b58a78a4a5cc369a92ee2ec376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620156dd1808cb6044b9d6762bbd5a0284b32e51809010300fa8b4a6f2bb3072e9e632041c6ad74ba989c3e18f3874ab4be95c2e8f51ab275d943a839c12d5b73c0a3ab4559bf186773ede8cf3ddc78a93439c8e82ead090de7d3c2fe4e75591fcf1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620176857f28231e3b3a8eaf85eb07b835f5f7f5d379e854debd3f325693118db758b2765fa1c4a959d41f7d0b1650f61cffe1d607eee7fb12de81777cf725cd8e073fee6e433392b821f11c4cf8fe8d17b7c08dbbc32381895955ee27448f8869e1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201688b6d2c8640491fe4db52979dfaa2947ebded2b4ba5e020257fe29ffdb2a6c7017102fa6c9d6f0744bba28a05c34c377108bf73ee04982d6db0656208ec620c7e287589ac74a46b3a74a8ae66c3e2554857419bd00f9bfeb55957fffccd98b9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62012256e07d9c9f3c76356fa7946b8233591a4d9b91ed3e81b2a09b1d3ae6b69c8906a299e8245221c8efd46bc55966f1de6b2b4bd0b2b3256527d59e7b738056009e8adb538dacdd20c86c4eca9a158895cef125dfd118e883cd55454f8d59f3ed376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62011479e687ce7b0594637250707491cbec69a909aad5dab78e00aae8c3d8a530d8de4c6a1faad6ef416aea872988d50227e35e2dfb5b73d4b3b897acaa4cf56f0ea674568468af9fef031f033166880eec9f5ddd05d797d5abf1a9b9a957c77820376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201a0e495db4830b2a4e80d045871b5f0f8541091fdb7707d5e6c8f085bc255f0a5069a0ae153d9a83f6fa3f208cd1d701fbd7e852449f026f8566c7d8826cf5b0aa99c0755eec29f2be753fb701762d1e7cc841323bac49576b9ea2e124c4b7b9f376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62018c4f486b7b87c5735e42249c15f5ec6d7b2b50a16aa0ba3bfbe666f99537e81a6a121659a06d58eacb9594201b6644f18e54c1c6ca457a4fcfa9d15e3bfea201be0bbf54aad305682afc6dc7cd051b5dce154e7d0056e877562407872cdb1242376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201763fba0da4fef393f59f1fd9eb9a646a2a1106f404681840fa846ec56c1a3443223b8a147990c6fd3e2af11300531168be94f091931f6ac07724f3ce75a06600d3ccc285f3c648f34ca9ce476651495b9a6c4aa7607d83737bd871de56a50ed9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201d9b7c0218e498e5930fc4ad9a8c139f774de3fda36ad408008c3957f1e822070ceda5ca810ef3fb7fda2c48576051107235edba92a3be39b38b9ac9aba8c2305f12e7ddae48873b7dcd614b8ccc8ea2e5ec000f3cc398f20801cf9047bc909b20001" + expected, err := hex.DecodeString(hexString) + if err != nil { + log.Fatal(err) } var proof WarpSyncProof - err := proof.Decode(expected) + err = proof.Decode(expected) require.NoError(t, err) encoded, err := proof.Encode() diff --git a/dot/sync/peer_view.go b/dot/sync/peer_view.go index be7dd8b94b..5e60c55b22 100644 --- a/dot/sync/peer_view.go +++ b/dot/sync/peer_view.go @@ -42,7 +42,7 @@ func (p *peerViewSet) update(peerID peer.ID, bestHash common.Hash, bestNumber ui return } - logger.Infof("updating peer %s view to #%d (%s)", peerID.String(), bestNumber, bestHash.Short()) + logger.Debugf("updating peer %s view to #%d (%s)", peerID.String(), bestNumber, bestHash.Short()) p.view[peerID] = newView } diff --git a/dot/sync/service.go b/dot/sync/service.go index a415e37146..c53fc3e555 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -181,7 +181,7 @@ func (s *SyncService) Stop() error { } func (s *SyncService) HandleBlockAnnounceHandshake(from peer.ID, msg *network.BlockAnnounceHandshake) error { - logger.Infof("receiving a block announce handshake from %s", from.String()) + logger.Debugf("receiving a block announce handshake from %s", from.String()) if err := s.workerPool.fromBlockAnnounceHandshake(from); err != nil { return err } @@ -292,6 +292,9 @@ func (s *SyncService) runStrategy() { results := s.workerPool.submitRequests(tasks) done, repChanges, peersToIgnore, err := s.currentStrategy.Process(results) + + logger.Infof("Sync process results: done=%t, repChanges=%d, peersToIgnore=%d", done, len(repChanges), len(peersToIgnore)) + if err != nil { logger.Criticalf("current sync strategy failed with: %s", err.Error()) return @@ -306,7 +309,6 @@ func (s *SyncService) runStrategy() { } s.currentStrategy.ShowMetrics() - logger.Trace("finish process to acquire more blocks") // TODO: why not use s.currentStrategy.IsSynced()? if done { diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index d2ded1649a..a6fb0c291f 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -4,7 +4,9 @@ package sync import ( + "encoding/hex" "slices" + "strings" "time" "github.com/ChainSafe/gossamer/dot/network" @@ -74,7 +76,7 @@ func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou return nil, err } - logger.Infof("received block announce from %s: #%d (%s) best block: %v", + logger.Debugf("received block announce from %s: #%d (%s) best block: %v", from, msg.Number, blockAnnounceHeaderHash, @@ -82,7 +84,7 @@ func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou ) if slices.Contains(w.badBlocks, blockAnnounceHeaderHash.String()) { - logger.Infof("bad block received from %s: #%d (%s) is a bad block", + logger.Debugf("bad block received from %s: #%d (%s) is a bad block", from, msg.Number, blockAnnounceHeaderHash) return &Change{ @@ -121,16 +123,19 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { return nil, err } - lastBlockHash := common.Hash([]byte{ - 0x85, 0xa2, 0x97, 0xea, 0xd2, 0x0a, 0xd1, 0x9d, 0x96, 0x6d, 0x87, 0x69, 0xc3, 0x79, 0xc9, 0xf0, 0xc4, 0xa4, 0xe5, 0x16, 0xc8, 0xa3, - 0xd9, 0x7f, 0x6f, 0xf6, 0xba, 0xb3, 0x8a, 0x0e, 0x31, 0xb3, - }) + hexString := "0xa2a29c0e8089ab43ac20327aecc9015b3a34596c7b2bb7490fa56fd05fe13be7" + hexString = strings.TrimPrefix(hexString, "0x") + + lastBlockHash, err := hex.DecodeString(hexString) + if err != nil { + return nil, err + } var task SyncTask switch w.phase { case WarpProof: task = SyncTask{ - request: messages.NewWarpProofRequest(lastBlockHash), + request: messages.NewWarpProofRequest(common.Hash(lastBlockHash)), response: &messages.WarpSyncProof{}, requestMaker: w.reqMaker, } @@ -157,6 +162,9 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { // Updating our block state func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( done bool, repChanges []Change, bans []peer.ID, err error) { + + logger.Infof("[WARP SYNC] processing %d warp sync results", len(results)) + switch w.phase { case WarpProof: var warpProofResult *network.WarpSyncVerificationResult @@ -182,11 +190,16 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( w.phase = Completed } + logger.Infof("[WARP SYNC] finishing processing") + return w.IsSynced(), repChanges, bans, nil } func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( repChanges []Change, peersToBlock []peer.ID, result *network.WarpSyncVerificationResult) { + + logger.Infof("[WARP SYNC] validating warp sync results") + repChanges = make([]Change, 0) peersToBlock = make([]peer.ID, 0) bestProof := &messages.WarpSyncProof{} @@ -242,9 +255,9 @@ func (w *WarpSyncStrategy) ShowMetrics() { totalSyncSeconds := time.Since(w.startedAt).Seconds() fps := float64(w.syncedFragments) / totalSyncSeconds - logger.Infof("⛓️ synced %d warp sync fragments "+ - "took: %.2f seconds, fps: %.2f fragments/second, target best block number #%d", - w.syncedFragments, totalSyncSeconds, fps, w.lastBlock.Number) + logger.Infof("⏩ Warping, downloading finality proofs, fragments %d, best %x "+ + "took: %.2f seconds, fps: %.2f fragments/second", + w.syncedFragments, w.lastBlock.Number, totalSyncSeconds, fps) } func (w *WarpSyncStrategy) IsSynced() bool { From fa300a8c3e444a6a3bfb102f73b453ea69501698 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 01:45:36 -0300 Subject: [PATCH 21/44] Disable linting lll --- dot/network/messages/warp_sync_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go index 5f5ff3fdbf..46ef402923 100644 --- a/dot/network/messages/warp_sync_test.go +++ b/dot/network/messages/warp_sync_test.go @@ -13,7 +13,7 @@ import ( func TestDecodeWarpSyncProof(t *testing.T) { // Generated using substrate - hexString := "04e995dd4dddbdfc54bd8126e0b5b394a47da71ca4a6510e7bd132d103470bf9b9be748b05d4026dd4bd8821893ce9e82a3a8c324ca454dd7510ee9ab05df3df82e87a1eada450bc10f223a562a12962e8914f436fd0991319d662310298fa47e5ff0dffb50c0642414245b501031100000009ba301100000000a6815e866aebee63d23cefa60964fa88b4814264fd35703c0c8a5f8192d8f41aa15bc5d991d1cad65ffccb73dbacd542a32286ec051190166ec00bfb4304b6049a882d0858cdbfb8d37a07269ea01bad1b55fb1174d6dedbfac56787adfa700004424545468403a6c0199af958a3ae8a3928b0802b709589bcbb1ec5b7041cf91644dd696ad99f05424142450101f8b400261b84cc580a8947abe4caf3b4ee51b7aeb26afc9a3bcdd2b3cd634f2df03cda49368e5e56a5b2427f6088cdc4144d75e1985f5e0a7e8f527290f47b8dad10000000000000376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620138376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62015037bddf7847fd40d7e6235c17203c8b70e661ef25aa44cbbaed19d5bb455bec3b20f59a720253b7c536171e1e68a91dcbf6b88fd077e28a2125cc9ea4fb430819b6ba718c28b1078474dc63e9d8a6f4d794da79f661da070fcca13b3bba50e7376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201243478b0465e1c13e9cda8479d42958422ab0acd69a1dbdc8d14fa95d2b15e96e6c1a5e58df7ff148977ba68418a7d6f6cf2ab959056c59cd768e490bc90ea0c1a619f90a9c96ec3e1c57211613247e8c0efe123188263da1dc8796d6a018c16376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620151010e386ecf4cb60e88acf75d7859547584a8e4258af8ca3fcde8d79dedf9ed1b6b0bf7df2704c3dfbc2db4a785833f0a70e30ec3c6ad9f35cae93e6ebd990a1d50350ac619dc36a0fe05cdd7a1654e73858586d55265f3524cc27e005be0f2376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201ca80d95b84408c14cc2c0cca1f3d2e094ebe056b5816959c887ac40b7311edf8c87e0f77a06ed398323b684e09c6d784e5333136dbae5a1d0627bf774e633408229366210b4b20adf7741fb6bc8fa669ea2f7470e1440b38969d2a47d752ffeb376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201bda1ac4056f6e6210d6b2dd8f69323cb7f2729f49ad9d42059ceecdffecebef04ce478a3cfde9bceadaf9be978443f0c3a5aea19d04b538b087cc0ca614e6b0a2bf793d9fb4251da094a2dd33bb0f68a46e60d799b58a78a4a5cc369a92ee2ec376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620156dd1808cb6044b9d6762bbd5a0284b32e51809010300fa8b4a6f2bb3072e9e632041c6ad74ba989c3e18f3874ab4be95c2e8f51ab275d943a839c12d5b73c0a3ab4559bf186773ede8cf3ddc78a93439c8e82ead090de7d3c2fe4e75591fcf1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620176857f28231e3b3a8eaf85eb07b835f5f7f5d379e854debd3f325693118db758b2765fa1c4a959d41f7d0b1650f61cffe1d607eee7fb12de81777cf725cd8e073fee6e433392b821f11c4cf8fe8d17b7c08dbbc32381895955ee27448f8869e1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201688b6d2c8640491fe4db52979dfaa2947ebded2b4ba5e020257fe29ffdb2a6c7017102fa6c9d6f0744bba28a05c34c377108bf73ee04982d6db0656208ec620c7e287589ac74a46b3a74a8ae66c3e2554857419bd00f9bfeb55957fffccd98b9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62012256e07d9c9f3c76356fa7946b8233591a4d9b91ed3e81b2a09b1d3ae6b69c8906a299e8245221c8efd46bc55966f1de6b2b4bd0b2b3256527d59e7b738056009e8adb538dacdd20c86c4eca9a158895cef125dfd118e883cd55454f8d59f3ed376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62011479e687ce7b0594637250707491cbec69a909aad5dab78e00aae8c3d8a530d8de4c6a1faad6ef416aea872988d50227e35e2dfb5b73d4b3b897acaa4cf56f0ea674568468af9fef031f033166880eec9f5ddd05d797d5abf1a9b9a957c77820376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201a0e495db4830b2a4e80d045871b5f0f8541091fdb7707d5e6c8f085bc255f0a5069a0ae153d9a83f6fa3f208cd1d701fbd7e852449f026f8566c7d8826cf5b0aa99c0755eec29f2be753fb701762d1e7cc841323bac49576b9ea2e124c4b7b9f376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62018c4f486b7b87c5735e42249c15f5ec6d7b2b50a16aa0ba3bfbe666f99537e81a6a121659a06d58eacb9594201b6644f18e54c1c6ca457a4fcfa9d15e3bfea201be0bbf54aad305682afc6dc7cd051b5dce154e7d0056e877562407872cdb1242376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201763fba0da4fef393f59f1fd9eb9a646a2a1106f404681840fa846ec56c1a3443223b8a147990c6fd3e2af11300531168be94f091931f6ac07724f3ce75a06600d3ccc285f3c648f34ca9ce476651495b9a6c4aa7607d83737bd871de56a50ed9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201d9b7c0218e498e5930fc4ad9a8c139f774de3fda36ad408008c3957f1e822070ceda5ca810ef3fb7fda2c48576051107235edba92a3be39b38b9ac9aba8c2305f12e7ddae48873b7dcd614b8ccc8ea2e5ec000f3cc398f20801cf9047bc909b20001" + hexString := "04e995dd4dddbdfc54bd8126e0b5b394a47da71ca4a6510e7bd132d103470bf9b9be748b05d4026dd4bd8821893ce9e82a3a8c324ca454dd7510ee9ab05df3df82e87a1eada450bc10f223a562a12962e8914f436fd0991319d662310298fa47e5ff0dffb50c0642414245b501031100000009ba301100000000a6815e866aebee63d23cefa60964fa88b4814264fd35703c0c8a5f8192d8f41aa15bc5d991d1cad65ffccb73dbacd542a32286ec051190166ec00bfb4304b6049a882d0858cdbfb8d37a07269ea01bad1b55fb1174d6dedbfac56787adfa700004424545468403a6c0199af958a3ae8a3928b0802b709589bcbb1ec5b7041cf91644dd696ad99f05424142450101f8b400261b84cc580a8947abe4caf3b4ee51b7aeb26afc9a3bcdd2b3cd634f2df03cda49368e5e56a5b2427f6088cdc4144d75e1985f5e0a7e8f527290f47b8dad10000000000000376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620138376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62015037bddf7847fd40d7e6235c17203c8b70e661ef25aa44cbbaed19d5bb455bec3b20f59a720253b7c536171e1e68a91dcbf6b88fd077e28a2125cc9ea4fb430819b6ba718c28b1078474dc63e9d8a6f4d794da79f661da070fcca13b3bba50e7376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201243478b0465e1c13e9cda8479d42958422ab0acd69a1dbdc8d14fa95d2b15e96e6c1a5e58df7ff148977ba68418a7d6f6cf2ab959056c59cd768e490bc90ea0c1a619f90a9c96ec3e1c57211613247e8c0efe123188263da1dc8796d6a018c16376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620151010e386ecf4cb60e88acf75d7859547584a8e4258af8ca3fcde8d79dedf9ed1b6b0bf7df2704c3dfbc2db4a785833f0a70e30ec3c6ad9f35cae93e6ebd990a1d50350ac619dc36a0fe05cdd7a1654e73858586d55265f3524cc27e005be0f2376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201ca80d95b84408c14cc2c0cca1f3d2e094ebe056b5816959c887ac40b7311edf8c87e0f77a06ed398323b684e09c6d784e5333136dbae5a1d0627bf774e633408229366210b4b20adf7741fb6bc8fa669ea2f7470e1440b38969d2a47d752ffeb376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201bda1ac4056f6e6210d6b2dd8f69323cb7f2729f49ad9d42059ceecdffecebef04ce478a3cfde9bceadaf9be978443f0c3a5aea19d04b538b087cc0ca614e6b0a2bf793d9fb4251da094a2dd33bb0f68a46e60d799b58a78a4a5cc369a92ee2ec376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620156dd1808cb6044b9d6762bbd5a0284b32e51809010300fa8b4a6f2bb3072e9e632041c6ad74ba989c3e18f3874ab4be95c2e8f51ab275d943a839c12d5b73c0a3ab4559bf186773ede8cf3ddc78a93439c8e82ead090de7d3c2fe4e75591fcf1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620176857f28231e3b3a8eaf85eb07b835f5f7f5d379e854debd3f325693118db758b2765fa1c4a959d41f7d0b1650f61cffe1d607eee7fb12de81777cf725cd8e073fee6e433392b821f11c4cf8fe8d17b7c08dbbc32381895955ee27448f8869e1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201688b6d2c8640491fe4db52979dfaa2947ebded2b4ba5e020257fe29ffdb2a6c7017102fa6c9d6f0744bba28a05c34c377108bf73ee04982d6db0656208ec620c7e287589ac74a46b3a74a8ae66c3e2554857419bd00f9bfeb55957fffccd98b9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62012256e07d9c9f3c76356fa7946b8233591a4d9b91ed3e81b2a09b1d3ae6b69c8906a299e8245221c8efd46bc55966f1de6b2b4bd0b2b3256527d59e7b738056009e8adb538dacdd20c86c4eca9a158895cef125dfd118e883cd55454f8d59f3ed376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62011479e687ce7b0594637250707491cbec69a909aad5dab78e00aae8c3d8a530d8de4c6a1faad6ef416aea872988d50227e35e2dfb5b73d4b3b897acaa4cf56f0ea674568468af9fef031f033166880eec9f5ddd05d797d5abf1a9b9a957c77820376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201a0e495db4830b2a4e80d045871b5f0f8541091fdb7707d5e6c8f085bc255f0a5069a0ae153d9a83f6fa3f208cd1d701fbd7e852449f026f8566c7d8826cf5b0aa99c0755eec29f2be753fb701762d1e7cc841323bac49576b9ea2e124c4b7b9f376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62018c4f486b7b87c5735e42249c15f5ec6d7b2b50a16aa0ba3bfbe666f99537e81a6a121659a06d58eacb9594201b6644f18e54c1c6ca457a4fcfa9d15e3bfea201be0bbf54aad305682afc6dc7cd051b5dce154e7d0056e877562407872cdb1242376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201763fba0da4fef393f59f1fd9eb9a646a2a1106f404681840fa846ec56c1a3443223b8a147990c6fd3e2af11300531168be94f091931f6ac07724f3ce75a06600d3ccc285f3c648f34ca9ce476651495b9a6c4aa7607d83737bd871de56a50ed9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201d9b7c0218e498e5930fc4ad9a8c139f774de3fda36ad408008c3957f1e822070ceda5ca810ef3fb7fda2c48576051107235edba92a3be39b38b9ac9aba8c2305f12e7ddae48873b7dcd614b8ccc8ea2e5ec000f3cc398f20801cf9047bc909b20001" //nolint:lll expected, err := hex.DecodeString(hexString) if err != nil { log.Fatal(err) From 1c66b1b55d500483d163b0336a2fba58cf02474d Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 01:53:59 -0300 Subject: [PATCH 22/44] Fix types --- dot/sync/warp_sync.go | 7 +++++++ lib/grandpa/warp_sync.go | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index a6fb0c291f..75181a6d39 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -170,12 +170,19 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( var warpProofResult *network.WarpSyncVerificationResult repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) + + logger.Infof("[WARP SYNC] validation result repChanges=%v bans=%v result=%v", repChanges, bans, warpProofResult) + if !warpProofResult.Completed { + logger.Infof("[WARP SYNC] partial warp sync", len(results)) + // Partial warp proof w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList w.lastBlock = &warpProofResult.Header } else { + logger.Infof("[WARP SYNC] complete warp sync", len(results)) + w.phase = TargetBlock w.lastBlock = &warpProofResult.Header } diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 9012e75212..580ce9a9a5 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -32,7 +32,7 @@ type WarpSyncFragment struct { Header types.Header // A justification for the header above which proves its finality. In order to validate it the // verifier must be aware of the authorities and set id for which the justification refers to. - Justification consensus_grandpa.GrandpaJustification[hash.H256, uint64] + Justification consensus_grandpa.GrandpaJustification[hash.H256, uint32] } type WarpSyncProof struct { @@ -66,7 +66,7 @@ func (w *WarpSyncProof) addFragment(fragment WarpSyncFragment) (limitReached boo return false, nil } -func (w *WarpSyncProof) lastProofBlockNumber() uint64 { +func (w *WarpSyncProof) lastProofBlockNumber() uint32 { if len(w.Proofs) == 0 { return 0 } @@ -192,7 +192,7 @@ func (p *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) { return nil, err } - justification, err := consensus_grandpa.DecodeJustification[hash.H256, uint64, runtime.BlakeTwo256](encJustification) + justification, err := consensus_grandpa.DecodeJustification[hash.H256, uint32, runtime.BlakeTwo256](encJustification) if err != nil { return nil, err } @@ -227,7 +227,7 @@ func (p *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) { return nil, err } - justification, err := consensus_grandpa.DecodeJustification[hash.H256, uint64, runtime.BlakeTwo256]( + justification, err := consensus_grandpa.DecodeJustification[hash.H256, uint32, runtime.BlakeTwo256]( latestJustification, ) if err != nil { From 7154b0fc014a2d2445885bee0df6d0fadf3495a3 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 02:18:49 -0300 Subject: [PATCH 23/44] Small fixes --- dot/network/messages/warp_sync.go | 8 ------- dot/sync/service.go | 5 +++-- dot/sync/warp_sync.go | 35 +++++++++++++++++++++---------- lib/grandpa/warp_sync.go | 27 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/dot/network/messages/warp_sync.go b/dot/network/messages/warp_sync.go index cd83f8f703..294ef8f194 100644 --- a/dot/network/messages/warp_sync.go +++ b/dot/network/messages/warp_sync.go @@ -8,7 +8,6 @@ import ( "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa" - "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/internal/primitives/core/hash" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/pkg/scale" @@ -59,14 +58,7 @@ type WarpSyncProof struct { proofsLength int } -var logger = log.NewFromGlobal(log.AddContext("pkg", "network")) - func (wsp *WarpSyncProof) Decode(in []byte) error { - logger.Infof("decoding WarpSyncProof bytes: %x", in) - - if len(in) == 0 { - return fmt.Errorf("cannot decode empty bytes") - } return scale.Unmarshal(in, wsp) } diff --git a/dot/sync/service.go b/dot/sync/service.go index c53fc3e555..e9e4aaf535 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -293,8 +293,9 @@ func (s *SyncService) runStrategy() { results := s.workerPool.submitRequests(tasks) done, repChanges, peersToIgnore, err := s.currentStrategy.Process(results) - logger.Infof("Sync process results: done=%t, repChanges=%d, peersToIgnore=%d", done, len(repChanges), len(peersToIgnore)) - + logger.Infof("Sync process results: done=%t, repChanges=%d, peersToIgnore=%d", + done, len(repChanges), len(peersToIgnore)) + if err != nil { logger.Criticalf("current sync strategy failed with: %s", err.Error()) return diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 75181a6d39..06bd414e43 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -56,12 +56,19 @@ type WarpSyncConfig struct { // NewWarpSyncStrategy returns a new warp sync strategy func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { + authorities, err := cfg.WarpSyncProvider.CurrentAuthorities() + if err != nil { + panic("failed to get current authorities") + } + return &WarpSyncStrategy{ warpSyncProvider: cfg.WarpSyncProvider, blockState: cfg.BlockState, badBlocks: cfg.BadBlocks, reqMaker: cfg.RequestMaker, peers: cfg.Peers, + setId: 0, + authorities: authorities, } } @@ -173,19 +180,22 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( logger.Infof("[WARP SYNC] validation result repChanges=%v bans=%v result=%v", repChanges, bans, warpProofResult) - if !warpProofResult.Completed { - logger.Infof("[WARP SYNC] partial warp sync", len(results)) + if warpProofResult != nil { + if !warpProofResult.Completed { + logger.Infof("[WARP SYNC] partial warp sync") - // Partial warp proof - w.setId = warpProofResult.SetId - w.authorities = warpProofResult.AuthorityList - w.lastBlock = &warpProofResult.Header - } else { - logger.Infof("[WARP SYNC] complete warp sync", len(results)) + // Partial warp proof + w.setId = warpProofResult.SetId + w.authorities = warpProofResult.AuthorityList + w.lastBlock = &warpProofResult.Header + } else { + logger.Infof("[WARP SYNC] complete warp sync") - w.phase = TargetBlock - w.lastBlock = &warpProofResult.Header + w.phase = TargetBlock + w.lastBlock = &warpProofResult.Header + } } + case TargetBlock: var validRes []RequestResponseData @@ -210,7 +220,7 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( repChanges = make([]Change, 0) peersToBlock = make([]peer.ID, 0) bestProof := &messages.WarpSyncProof{} - bestResult := &network.WarpSyncVerificationResult{} + var bestResult *network.WarpSyncVerificationResult for _, result := range results { switch response := result.response.(type) { @@ -227,6 +237,7 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( } // Best proof will be the finished proof or the proof with more fragments + logger.Infof("[WARP SYNC] verifying warp proof using authorities %v", w.authorities) res, err := w.warpSyncProvider.Verify(encodedProof, w.setId, w.authorities) if err != nil { @@ -237,6 +248,8 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( Reason: peerset.BadWarpProofReason, }}) peersToBlock = append(peersToBlock, result.who) + + return repChanges, peersToBlock, nil } if response.IsFinished || len(response.Proofs) > len(bestProof.Proofs) { diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 580ce9a9a5..83aec9b679 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -143,6 +143,33 @@ type SetIdAuthorityList struct { grandpa.AuthorityList } +func (p *WarpSyncProofProvider) CurrentAuthorities() (primitives.AuthorityList, error) { + currentSetid, err := p.grandpaState.GetCurrentSetID() + if err != nil { + return nil, err + } + + authorities, err := p.grandpaState.GetAuthorities(currentSetid) + if err != nil { + return nil, err + } + + var authorityList primitives.AuthorityList + for _, auth := range authorities { + key, err := app.NewPublic(auth.Key[:]) + if err != nil { + return nil, err + } + + authorityList = append(authorityList, primitives.AuthorityIDWeight{ + AuthorityID: key, + AuthorityWeight: primitives.AuthorityWeight(auth.ID), + }) + } + + return authorityList, nil +} + // Generate build a warp sync encoded proof starting from the given block hash func (p *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) { // Get and traverse all GRANDPA authorities changes from the given block hash From b62b3fab00da659a67072f853d5dd085dd55ea3a Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 02:51:03 -0300 Subject: [PATCH 24/44] Create warp sync provider interface --- dot/services.go | 2 +- dot/sync/mocks_generate_test.go | 2 +- dot/sync/mocks_test.go | 58 +++++++++++++++++++++++++++++++-- dot/sync/service.go | 3 -- dot/sync/warp_sync.go | 29 ++++++++++++----- dot/sync/warp_sync_test.go | 25 +++++++++++--- lib/grandpa/warp_sync_test.go | 16 ++++----- 7 files changed, 107 insertions(+), 28 deletions(-) diff --git a/dot/services.go b/dot/services.go index 507eca0ec0..cc0bcc6647 100644 --- a/dot/services.go +++ b/dot/services.go @@ -534,7 +534,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync warpSyncCfg := &sync.WarpSyncConfig{ Telemetry: telemetryMailer, BadBlocks: genesisData.BadBlocks, - WarpSyncProvider: *warpSyncProvider, + WarpSyncProvider: warpSyncProvider, RequestMaker: net.GetRequestResponseProtocol(network.WarpSyncID, blockRequestTimeout, network.MaxBlockResponseSize), BlockState: st.Block, diff --git a/dot/sync/mocks_generate_test.go b/dot/sync/mocks_generate_test.go index a8f52d172f..35da5b7961 100644 --- a/dot/sync/mocks_generate_test.go +++ b/dot/sync/mocks_generate_test.go @@ -3,6 +3,6 @@ package sync -//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network +//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network,WarpSyncProofProvider //go:generate mockgen -destination=mock_request_maker.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/network RequestMaker //go:generate mockgen -destination=mock_importer.go -source=fullsync.go -package=sync diff --git a/dot/sync/mocks_test.go b/dot/sync/mocks_test.go index ef04c575d7..228f23533e 100644 --- a/dot/sync/mocks_test.go +++ b/dot/sync/mocks_test.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/ChainSafe/gossamer/dot/sync (interfaces: Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network) +// Source: github.com/ChainSafe/gossamer/dot/sync (interfaces: Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network,WarpSyncProofProvider) // // Generated by this command: // -// mockgen -destination=mocks_test.go -package=sync . Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network +// mockgen -destination=mocks_test.go -package=sync . Telemetry,BlockState,StorageState,TransactionState,BabeVerifier,FinalityGadget,BlockImportHandler,Network,WarpSyncProofProvider // // Package sync is a generated GoMock package. @@ -17,6 +17,7 @@ import ( network "github.com/ChainSafe/gossamer/dot/network" peerset "github.com/ChainSafe/gossamer/dot/peerset" types "github.com/ChainSafe/gossamer/dot/types" + grandpa "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" common "github.com/ChainSafe/gossamer/lib/common" runtime "github.com/ChainSafe/gossamer/lib/runtime" storage "github.com/ChainSafe/gossamer/lib/runtime/storage" @@ -731,3 +732,56 @@ func (mr *MockNetworkMockRecorder) ReportPeer(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportPeer", reflect.TypeOf((*MockNetwork)(nil).ReportPeer), arg0, arg1) } + +// MockWarpSyncProofProvider is a mock of WarpSyncProofProvider interface. +type MockWarpSyncProofProvider struct { + ctrl *gomock.Controller + recorder *MockWarpSyncProofProviderMockRecorder +} + +// MockWarpSyncProofProviderMockRecorder is the mock recorder for MockWarpSyncProofProvider. +type MockWarpSyncProofProviderMockRecorder struct { + mock *MockWarpSyncProofProvider +} + +// NewMockWarpSyncProofProvider creates a new mock instance. +func NewMockWarpSyncProofProvider(ctrl *gomock.Controller) *MockWarpSyncProofProvider { + mock := &MockWarpSyncProofProvider{ctrl: ctrl} + mock.recorder = &MockWarpSyncProofProviderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWarpSyncProofProvider) EXPECT() *MockWarpSyncProofProviderMockRecorder { + return m.recorder +} + +// CurrentAuthorities mocks base method. +func (m *MockWarpSyncProofProvider) CurrentAuthorities() (grandpa.AuthorityList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CurrentAuthorities") + ret0, _ := ret[0].(grandpa.AuthorityList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CurrentAuthorities indicates an expected call of CurrentAuthorities. +func (mr *MockWarpSyncProofProviderMockRecorder) CurrentAuthorities() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentAuthorities", reflect.TypeOf((*MockWarpSyncProofProvider)(nil).CurrentAuthorities)) +} + +// Verify mocks base method. +func (m *MockWarpSyncProofProvider) Verify(arg0 []byte, arg1 grandpa.SetID, arg2 grandpa.AuthorityList) (*network.WarpSyncVerificationResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Verify", arg0, arg1, arg2) + ret0, _ := ret[0].(*network.WarpSyncVerificationResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Verify indicates an expected call of Verify. +func (mr *MockWarpSyncProofProviderMockRecorder) Verify(arg0, arg1, arg2 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*MockWarpSyncProofProvider)(nil).Verify), arg0, arg1, arg2) +} diff --git a/dot/sync/service.go b/dot/sync/service.go index e9e4aaf535..94e8970b65 100644 --- a/dot/sync/service.go +++ b/dot/sync/service.go @@ -293,9 +293,6 @@ func (s *SyncService) runStrategy() { results := s.workerPool.submitRequests(tasks) done, repChanges, peersToIgnore, err := s.currentStrategy.Process(results) - logger.Infof("Sync process results: done=%t, repChanges=%d, peersToIgnore=%d", - done, len(repChanges), len(peersToIgnore)) - if err != nil { logger.Criticalf("current sync strategy failed with: %s", err.Error()) return diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 06bd414e43..2774c55489 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -15,7 +15,6 @@ import ( "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" "github.com/ChainSafe/gossamer/lib/common" - "github.com/ChainSafe/gossamer/lib/grandpa" "github.com/libp2p/go-libp2p/core/peer" ) @@ -27,12 +26,18 @@ const ( Completed ) +type WarpSyncProofProvider interface { + CurrentAuthorities() (primitives.AuthorityList, error) + Verify(encodedProof []byte, setId primitives.SetID, authorities primitives.AuthorityList) ( + *network.WarpSyncVerificationResult, error) +} + type WarpSyncStrategy struct { // Strategy dependencies and config peers *peerViewSet badBlocks []string reqMaker network.RequestMaker - warpSyncProvider grandpa.WarpSyncProofProvider + warpSyncProvider WarpSyncProofProvider blockState BlockState // Warp sync state @@ -49,7 +54,7 @@ type WarpSyncConfig struct { Telemetry Telemetry BadBlocks []string RequestMaker network.RequestMaker - WarpSyncProvider grandpa.WarpSyncProofProvider + WarpSyncProvider WarpSyncProofProvider BlockState BlockState Peers *peerViewSet } @@ -170,16 +175,12 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( done bool, repChanges []Change, bans []peer.ID, err error) { - logger.Infof("[WARP SYNC] processing %d warp sync results", len(results)) - switch w.phase { case WarpProof: var warpProofResult *network.WarpSyncVerificationResult repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) - logger.Infof("[WARP SYNC] validation result repChanges=%v bans=%v result=%v", repChanges, bans, warpProofResult) - if warpProofResult != nil { if !warpProofResult.Completed { logger.Infof("[WARP SYNC] partial warp sync") @@ -223,6 +224,17 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( var bestResult *network.WarpSyncVerificationResult for _, result := range results { + if !result.completed { + repChanges = append(repChanges, Change{ + who: result.who, + rep: peerset.ReputationChange{ + Value: peerset.UnexpectedResponseValue, + Reason: peerset.UnexpectedResponseReason, + }}) + peersToBlock = append(peersToBlock, result.who) + continue + } + switch response := result.response.(type) { case *messages.WarpSyncProof: if !result.completed { @@ -237,10 +249,11 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( } // Best proof will be the finished proof or the proof with more fragments - logger.Infof("[WARP SYNC] verifying warp proof using authorities %v", w.authorities) res, err := w.warpSyncProvider.Verify(encodedProof, w.setId, w.authorities) if err != nil { + logger.Errorf("[WARP SYNC] bad warp proof: %s", err) + repChanges = append(repChanges, Change{ who: result.who, rep: peerset.ReputationChange{ diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index f3c4d8080a..ba8a2fb557 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -17,13 +17,22 @@ import ( ) func TestWarpSyncBlockAnnounce(t *testing.T) { + t.Parallel() + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + warpSyncProvider := NewMockWarpSyncProofProvider(ctrl) + warpSyncProvider.EXPECT().CurrentAuthorities().Return(nil, nil).AnyTimes() + peer := peer.ID("peer") t.Run("successful_block_announce", func(t *testing.T) { peersView := NewPeerViewSet() strategy := NewWarpSyncStrategy(&WarpSyncConfig{ - Peers: peersView, + Peers: peersView, + WarpSyncProvider: warpSyncProvider, }) blockAnnounce := &network.BlockAnnounceMessage{ @@ -54,7 +63,8 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { peersView := NewPeerViewSet() strategy := NewWarpSyncStrategy(&WarpSyncConfig{ - Peers: peersView, + Peers: peersView, + WarpSyncProvider: warpSyncProvider, }) handshake := &network.BlockAnnounceHandshake{ @@ -84,8 +94,9 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { require.NoError(t, err) strategy := NewWarpSyncStrategy(&WarpSyncConfig{ - Peers: peersView, - BadBlocks: []string{blockAnnounceHash.String()}, + Peers: peersView, + WarpSyncProvider: warpSyncProvider, + BadBlocks: []string{blockAnnounceHash.String()}, }) expectedRepChange := &Change{ @@ -109,6 +120,9 @@ func TestWarpSyncNextActions(t *testing.T) { ctrl := gomock.NewController(t) mockBlockState := NewMockBlockState(ctrl) + warpSyncProvider := NewMockWarpSyncProofProvider(ctrl) + warpSyncProvider.EXPECT().CurrentAuthorities().Return(nil, nil).AnyTimes() + genesisHeader := &types.Header{ Number: 1, } @@ -135,7 +149,8 @@ func TestWarpSyncNextActions(t *testing.T) { for name, c := range tc { t.Run(name, func(t *testing.T) { strategy := NewWarpSyncStrategy(&WarpSyncConfig{ - BlockState: mockBlockState, + BlockState: mockBlockState, + WarpSyncProvider: warpSyncProvider, }) strategy.phase = c.phase diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warp_sync_test.go index 8f26c2e9a5..be8692fb07 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warp_sync_test.go @@ -81,8 +81,8 @@ func TestGenerateWarpSyncProofBlockNotFinalized(t *testing.T) { func TestGenerateAndVerifyWarpSyncProofOk(t *testing.T) { t.Parallel() - type signedPrecommit = grandpa.SignedPrecommit[hash.H256, uint64, primitives.AuthoritySignature, primitives.AuthorityID] - type preCommit = grandpa.Precommit[hash.H256, uint64] + type signedPrecommit = grandpa.SignedPrecommit[hash.H256, uint32, primitives.AuthoritySignature, primitives.AuthorityID] + type preCommit = grandpa.Precommit[hash.H256, uint32] // Initialize mocks ctrl := gomock.NewController(t) @@ -169,7 +169,7 @@ func TestGenerateAndVerifyWarpSyncProofOk(t *testing.T) { // If we have an authority set change, create a justification if len(newAuthorities) > 0 { targetHash := hash.H256(string(header.Hash().ToBytes())) - targetNumber := uint64(header.Number) + targetNumber := uint32(header.Number) // Create precommits for current voters precommits := []signedPrecommit{} @@ -179,7 +179,7 @@ func TestGenerateAndVerifyWarpSyncProofOk(t *testing.T) { TargetNumber: targetNumber, } - msg := grandpa.NewMessage[hash.H256, uint64, preCommit](precommit) + msg := grandpa.NewMessage[hash.H256, uint32, preCommit](precommit) encoded := primitives.NewLocalizedPayload(1, currentSetId, msg) signature := voter.Sign(encoded) @@ -196,9 +196,9 @@ func TestGenerateAndVerifyWarpSyncProofOk(t *testing.T) { } // Create justification - justification := primitives.GrandpaJustification[hash.H256, uint64]{ + justification := primitives.GrandpaJustification[hash.H256, uint32]{ Round: 1, - Commit: primitives.Commit[hash.H256, uint64]{ + Commit: primitives.Commit[hash.H256, uint32]{ TargetHash: targetHash, TargetNumber: targetNumber, Precommits: precommits, @@ -299,10 +299,10 @@ func createGRANDPAConsensusDigest(t *testing.T, digestData any) types.ConsensusD } } -func genericHeadersList(t *testing.T, headers []*types.Header) []runtime.Header[uint64, hash.H256] { +func genericHeadersList(t *testing.T, headers []*types.Header) []runtime.Header[uint32, hash.H256] { t.Helper() - headerList := []runtime.Header[uint64, hash.H256]{} + headerList := []runtime.Header[uint32, hash.H256]{} for _, header := range headers { if header == nil { continue From 0b212acb81783ea056f6265d5e5f3aa6731a62cf Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 02:52:54 -0300 Subject: [PATCH 25/44] Remove unnecesary logs --- dot/sync/warp_sync.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 2774c55489..490390188e 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -208,16 +208,12 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( w.phase = Completed } - logger.Infof("[WARP SYNC] finishing processing") - return w.IsSynced(), repChanges, bans, nil } func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( repChanges []Change, peersToBlock []peer.ID, result *network.WarpSyncVerificationResult) { - logger.Infof("[WARP SYNC] validating warp sync results") - repChanges = make([]Change, 0) peersToBlock = make([]peer.ID, 0) bestProof := &messages.WarpSyncProof{} From 439dc21278bea8928637cb2cee9bf4879506797d Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 03:58:35 -0300 Subject: [PATCH 26/44] Clean up, remove logs and local tests --- dot/sync/warp_sync.go | 13 +------------ lib/common/hash.go | 2 +- lib/grandpa/warp_sync.go | 9 +++++++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 490390188e..5ed8ca4bdf 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -4,9 +4,7 @@ package sync import ( - "encoding/hex" "slices" - "strings" "time" "github.com/ChainSafe/gossamer/dot/network" @@ -14,7 +12,6 @@ import ( "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" - "github.com/ChainSafe/gossamer/lib/common" "github.com/libp2p/go-libp2p/core/peer" ) @@ -135,19 +132,11 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { return nil, err } - hexString := "0xa2a29c0e8089ab43ac20327aecc9015b3a34596c7b2bb7490fa56fd05fe13be7" - hexString = strings.TrimPrefix(hexString, "0x") - - lastBlockHash, err := hex.DecodeString(hexString) - if err != nil { - return nil, err - } - var task SyncTask switch w.phase { case WarpProof: task = SyncTask{ - request: messages.NewWarpProofRequest(common.Hash(lastBlockHash)), + request: messages.NewWarpProofRequest(lastBlock.Hash()), response: &messages.WarpSyncProof{}, requestMaker: w.reqMaker, } diff --git a/lib/common/hash.go b/lib/common/hash.go index 28798afb46..2c07485b5e 100644 --- a/lib/common/hash.go +++ b/lib/common/hash.go @@ -62,7 +62,7 @@ func (h Hash) String() string { //skipcq: GO-W1029 // Short returns the first 4 bytes and the last 4 bytes of the hex string for the hash func (h Hash) Short() string { //skipcq: GO-W1029 - const nBytes = 4 + const nBytes = 2 return fmt.Sprintf("0x%x...%x", h[:nBytes], h[len(h)-nBytes:]) } diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 83aec9b679..5e52400921 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -96,6 +96,7 @@ func (w *WarpSyncProof) verify( } else { err := proof.Justification.Verify(uint64(currentSetId), currentAuthorities) if err != nil { + logger.Debugf("failed to verify justification %s", err) return nil, err } @@ -162,7 +163,7 @@ func (p *WarpSyncProofProvider) CurrentAuthorities() (primitives.AuthorityList, } authorityList = append(authorityList, primitives.AuthorityIDWeight{ - AuthorityID: key, + AuthorityID: primitives.AuthorityID(key), AuthorityWeight: primitives.AuthorityWeight(auth.ID), }) } @@ -331,7 +332,11 @@ func findScheduledChange( return nil, err } - parsedScheduledChange, _ := scheduledChange.(types.GrandpaScheduledChange) + parsedScheduledChange, ok := scheduledChange.(types.GrandpaScheduledChange) + if !ok { + return nil, nil + } + return &parsedScheduledChange, nil } } From ff292177b1efb6a3f55dab6be34b92155a542e5c Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 14:05:34 -0300 Subject: [PATCH 27/44] Lint --- dot/sync/warp_sync_test.go | 6 ++++++ lib/grandpa/warp_sync.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index ba8a2fb557..7d011d83b5 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -28,6 +28,8 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { peer := peer.ID("peer") t.Run("successful_block_announce", func(t *testing.T) { + t.Parallel() + peersView := NewPeerViewSet() strategy := NewWarpSyncStrategy(&WarpSyncConfig{ @@ -60,6 +62,8 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { }) t.Run("successful_block_announce_handshake", func(t *testing.T) { + t.Parallel() + peersView := NewPeerViewSet() strategy := NewWarpSyncStrategy(&WarpSyncConfig{ @@ -79,6 +83,8 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { }) t.Run("successful_block_announce", func(t *testing.T) { + t.Parallel() + peersView := NewPeerViewSet() blockAnnounce := &network.BlockAnnounceMessage{ diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 5e52400921..ceaaa432b4 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -163,7 +163,7 @@ func (p *WarpSyncProofProvider) CurrentAuthorities() (primitives.AuthorityList, } authorityList = append(authorityList, primitives.AuthorityIDWeight{ - AuthorityID: primitives.AuthorityID(key), + AuthorityID: key, AuthorityWeight: primitives.AuthorityWeight(auth.ID), }) } From bad09355ced46dae1da8d9045dc86ada74e3e0c1 Mon Sep 17 00:00:00 2001 From: Diego Date: Fri, 1 Nov 2024 14:10:23 -0300 Subject: [PATCH 28/44] Lint --- dot/sync/warp_sync_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index 7d011d83b5..1d55d34aac 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -20,7 +20,7 @@ func TestWarpSyncBlockAnnounce(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Cleanup(ctrl.Finish) warpSyncProvider := NewMockWarpSyncProofProvider(ctrl) warpSyncProvider.EXPECT().CurrentAuthorities().Return(nil, nil).AnyTimes() From d73af92d352d48b5663dabb67d45d22187a94534 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 4 Nov 2024 10:35:15 -0300 Subject: [PATCH 29/44] Fix Test_PeerSupportsProtocol test --- dot/network/host_integration_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dot/network/host_integration_test.go b/dot/network/host_integration_test.go index 17ac938226..2f93c5c25e 100644 --- a/dot/network/host_integration_test.go +++ b/dot/network/host_integration_test.go @@ -7,6 +7,7 @@ package network import ( "fmt" + "strings" "testing" "time" @@ -396,12 +397,21 @@ func Test_PeerSupportsProtocol(t *testing.T) { } require.NoError(t, err) + genesisHash := nodeA.blockState.GenesisHash().String() + genesisHash = strings.TrimPrefix(genesisHash, "0x") + fullSyncProtocolId := fmt.Sprintf("/%s%s", genesisHash, SyncID) + warpSyncProtocolId := fmt.Sprintf("/%s%s", genesisHash, WarpSyncID) + tests := []struct { protocol protocol.ID expect bool }{ { - protocol: protocol.ID("/gossamer/test/0/sync/2"), + protocol: protocol.ID(fullSyncProtocolId), + expect: true, + }, + { + protocol: protocol.ID(warpSyncProtocolId), expect: true, }, { From 840a3405f655bdd2b770bb0f251e9494b6a8354b Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 4 Nov 2024 10:39:12 -0300 Subject: [PATCH 30/44] Remove TODO --- dot/network/block_announce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/network/block_announce.go b/dot/network/block_announce.go index f436d05d09..a526b2f7f5 100644 --- a/dot/network/block_announce.go +++ b/dot/network/block_announce.go @@ -99,7 +99,7 @@ func decodeBlockAnnounceMessage(in []byte) (NotificationsMessage, error) { // BlockAnnounceHandshake is exchanged by nodes that are beginning the BlockAnnounce protocol type BlockAnnounceHandshake struct { Roles common.NetworkRole - BestBlockNumber uint32 // TODO: shuldn't we use uint64 here? + BestBlockNumber uint32 BestBlockHash common.Hash GenesisHash common.Hash } From 484a28dc4262a36ec808b77465e60a66143003b7 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 4 Nov 2024 13:01:18 -0300 Subject: [PATCH 31/44] Fix findScheduledChange --- dot/sync/warp_sync.go | 36 ++++++++++++++++------------------- lib/grandpa/warp_sync.go | 25 ++++++++++++------------ lib/grandpa/warp_sync_test.go | 1 + 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 5ed8ca4bdf..bc2cd472ff 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -172,14 +172,14 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( if warpProofResult != nil { if !warpProofResult.Completed { - logger.Infof("[WARP SYNC] partial warp sync") + logger.Infof("[WARP SYNC] partial warp sync received") // Partial warp proof w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList w.lastBlock = &warpProofResult.Header } else { - logger.Infof("[WARP SYNC] complete warp sync") + logger.Infof("[WARP SYNC] complete warp sync received") w.phase = TargetBlock w.lastBlock = &warpProofResult.Header @@ -209,17 +209,6 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( var bestResult *network.WarpSyncVerificationResult for _, result := range results { - if !result.completed { - repChanges = append(repChanges, Change{ - who: result.who, - rep: peerset.ReputationChange{ - Value: peerset.UnexpectedResponseValue, - Reason: peerset.UnexpectedResponseReason, - }}) - peersToBlock = append(peersToBlock, result.who) - continue - } - switch response := result.response.(type) { case *messages.WarpSyncProof: if !result.completed { @@ -246,8 +235,7 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( Reason: peerset.BadWarpProofReason, }}) peersToBlock = append(peersToBlock, result.who) - - return repChanges, peersToBlock, nil + continue } if response.IsFinished || len(response.Proofs) > len(bestProof.Proofs) { @@ -266,16 +254,24 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( } } + w.syncedFragments += len(bestProof.Proofs) + return repChanges, peersToBlock, bestResult } func (w *WarpSyncStrategy) ShowMetrics() { - totalSyncSeconds := time.Since(w.startedAt).Seconds() + switch w.phase { + case WarpProof: + totalSyncSeconds := time.Since(w.startedAt).Seconds() + + logger.Infof("⏩ Warping, downloading finality proofs, fragments %d, best #%d (%s) "+ + "took: %.2f seconds", + w.syncedFragments, w.lastBlock.Number, w.lastBlock.Hash().String(), totalSyncSeconds) + case TargetBlock: + logger.Infof("⏩ Warping, downloading target block #%d (%x)", + w.lastBlock.Number, w.lastBlock.Hash().String()) + } - fps := float64(w.syncedFragments) / totalSyncSeconds - logger.Infof("⏩ Warping, downloading finality proofs, fragments %d, best %x "+ - "took: %.2f seconds, fps: %.2f fragments/second", - w.syncedFragments, w.lastBlock.Number, totalSyncSeconds, fps) } func (w *WarpSyncStrategy) IsSynced() bool { diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index ceaaa432b4..8dc197b363 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -82,8 +82,10 @@ func (w *WarpSyncProof) verify( authorities grandpa.AuthorityList, hardForks map[string]SetIdAuthorityList, ) (*SetIdAuthorityList, error) { - currentSetId := setId - currentAuthorities := authorities + setIdAuth := &SetIdAuthorityList{ + SetID: setId, + AuthorityList: authorities, + } for fragmentNumber, proof := range w.Proofs { headerHash := proof.Header.Hash() @@ -91,10 +93,10 @@ func (w *WarpSyncProof) verify( hardForkKey := fmt.Sprintf("%v-%v", headerHash, number) if fork, ok := hardForks[hardForkKey]; ok { - currentSetId = fork.SetID - currentAuthorities = fork.AuthorityList + setIdAuth.SetID = fork.SetID + setIdAuth.AuthorityList = fork.AuthorityList } else { - err := proof.Justification.Verify(uint64(currentSetId), currentAuthorities) + err := proof.Justification.Verify(uint64(setIdAuth.SetID), setIdAuth.AuthorityList) if err != nil { logger.Debugf("failed to verify justification %s", err) return nil, err @@ -115,15 +117,16 @@ func (w *WarpSyncProof) verify( return nil, fmt.Errorf("cannot parse GRANPDA raw authorities: %w", err) } - currentSetId += 1 - currentAuthorities = auths + setIdAuth.SetID += 1 + setIdAuth.AuthorityList = auths } else if fragmentNumber != len(w.Proofs)-1 || !w.IsFinished { + logger.Errorf("missing scheduled change in fragment %d, for proof with fragments %d, block %d, finished %v", fragmentNumber, len(w.Proofs), proof.Header.Number, w.IsFinished) return nil, fmt.Errorf("header is missing authority set change digest") } } } - return &SetIdAuthorityList{currentSetId, currentAuthorities}, nil + return setIdAuth, nil } type WarpSyncProofProvider struct { @@ -333,11 +336,9 @@ func findScheduledChange( } parsedScheduledChange, ok := scheduledChange.(types.GrandpaScheduledChange) - if !ok { - return nil, nil + if ok { + return &parsedScheduledChange, nil } - - return &parsedScheduledChange, nil } } } diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warp_sync_test.go index be8692fb07..db2f92a5cd 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warp_sync_test.go @@ -4,6 +4,7 @@ package grandpa import ( + "encoding/hex" "errors" "math/rand" "slices" From d0aa461f17fcf471c0acb87a390e8d4f3ff6999a Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 4 Nov 2024 13:43:34 -0300 Subject: [PATCH 32/44] Improve logs and remove tests --- dot/sync/warp_sync.go | 10 +++++----- lib/grandpa/warp_sync_test.go | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index bc2cd472ff..7223bc95eb 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -172,14 +172,14 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( if warpProofResult != nil { if !warpProofResult.Completed { - logger.Infof("[WARP SYNC] partial warp sync received") + logger.Debug("partial warp sync received") // Partial warp proof w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList w.lastBlock = &warpProofResult.Header } else { - logger.Infof("[WARP SYNC] complete warp sync received") + logger.Debug("complete warp sync received") w.phase = TargetBlock w.lastBlock = &warpProofResult.Header @@ -226,7 +226,7 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( res, err := w.warpSyncProvider.Verify(encodedProof, w.setId, w.authorities) if err != nil { - logger.Errorf("[WARP SYNC] bad warp proof: %s", err) + logger.Warnf("bad warp proof response: %s", err) repChanges = append(repChanges, Change{ who: result.who, @@ -266,9 +266,9 @@ func (w *WarpSyncStrategy) ShowMetrics() { logger.Infof("⏩ Warping, downloading finality proofs, fragments %d, best #%d (%s) "+ "took: %.2f seconds", - w.syncedFragments, w.lastBlock.Number, w.lastBlock.Hash().String(), totalSyncSeconds) + w.syncedFragments, w.lastBlock.Number, w.lastBlock.Hash().Short(), totalSyncSeconds) case TargetBlock: - logger.Infof("⏩ Warping, downloading target block #%d (%x)", + logger.Infof("⏩ Warping, downloading target block #%d (%s)", w.lastBlock.Number, w.lastBlock.Hash().String()) } diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warp_sync_test.go index db2f92a5cd..be8692fb07 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warp_sync_test.go @@ -4,7 +4,6 @@ package grandpa import ( - "encoding/hex" "errors" "math/rand" "slices" From 3dfbe2e3947f3079e73dafa6af5295bc2df08133 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 4 Nov 2024 13:44:21 -0300 Subject: [PATCH 33/44] Improve logs --- lib/grandpa/warp_sync.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warp_sync.go index 8dc197b363..8eb84446b6 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warp_sync.go @@ -120,7 +120,6 @@ func (w *WarpSyncProof) verify( setIdAuth.SetID += 1 setIdAuth.AuthorityList = auths } else if fragmentNumber != len(w.Proofs)-1 || !w.IsFinished { - logger.Errorf("missing scheduled change in fragment %d, for proof with fragments %d, block %d, finished %v", fragmentNumber, len(w.Proofs), proof.Header.Number, w.IsFinished) return nil, fmt.Errorf("header is missing authority set change digest") } } From 2e5fdfa2a5e9d22fa008cac4c51bb17509f6ae1a Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 10:33:09 -0300 Subject: [PATCH 34/44] Fix get target block --- dot/sync/warp_sync.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 7223bc95eb..7297b3fbfb 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -187,14 +187,17 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( } case TargetBlock: + logger.Debug("getting target block") + var validRes []RequestResponseData // Reuse same validator than in fullsync repChanges, bans, validRes = validateResults(results, w.badBlocks) - // TODO: check if this can cause an issue - w.result = *validRes[0].responseData[0] - w.phase = Completed + if len(validRes) > 0 && len(validRes[0].responseData) > 0 { + w.result = *validRes[0].responseData[0] + w.phase = Completed + } } return w.IsSynced(), repChanges, bans, nil From b878685dbd24f0484ddadc4d7397e72f7fdcae46 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 13:25:48 -0300 Subject: [PATCH 35/44] Update comment --- lib/common/hash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/hash.go b/lib/common/hash.go index 2c07485b5e..6603d7bfec 100644 --- a/lib/common/hash.go +++ b/lib/common/hash.go @@ -60,7 +60,7 @@ func (h Hash) String() string { //skipcq: GO-W1029 return fmt.Sprintf("0x%x", h[:]) } -// Short returns the first 4 bytes and the last 4 bytes of the hex string for the hash +// Short returns the first 2 bytes and the last 2 bytes of the hex string for the hash func (h Hash) Short() string { //skipcq: GO-W1029 const nBytes = 2 return fmt.Sprintf("0x%x...%x", h[:nBytes], h[len(h)-nBytes:]) From ddedb34f36719bd6067816131b255a518361fb0f Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 13:26:42 -0300 Subject: [PATCH 36/44] Remove comment --- dot/sync/warp_sync.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 7297b3fbfb..5f313901ab 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -187,17 +187,14 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( } case TargetBlock: - logger.Debug("getting target block") - var validRes []RequestResponseData // Reuse same validator than in fullsync repChanges, bans, validRes = validateResults(results, w.badBlocks) - if len(validRes) > 0 && len(validRes[0].responseData) > 0 { - w.result = *validRes[0].responseData[0] - w.phase = Completed - } + // TODO: check if this can cause an issue + w.result = *validRes[0].responseData[0] + w.phase = Completed } return w.IsSynced(), repChanges, bans, nil @@ -225,7 +222,6 @@ func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( panic("fail to encode warp proof") } - // Best proof will be the finished proof or the proof with more fragments res, err := w.warpSyncProvider.Verify(encodedProof, w.setId, w.authorities) if err != nil { From 514d3bb7da451c8e3d0fcf42c57e05dab96ef9f0 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 13:29:18 -0300 Subject: [PATCH 37/44] Refactor --- dot/sync/warp_sync.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 5f313901ab..35ca197a5d 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -171,18 +171,16 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) if warpProofResult != nil { + w.lastBlock = &warpProofResult.Header + if !warpProofResult.Completed { logger.Debug("partial warp sync received") - // Partial warp proof w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList - w.lastBlock = &warpProofResult.Header } else { logger.Debug("complete warp sync received") - w.phase = TargetBlock - w.lastBlock = &warpProofResult.Header } } From c74429337dddfccf0ab34e571d2ee9062663160a Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 13:30:05 -0300 Subject: [PATCH 38/44] Update comment --- dot/sync/warp_sync.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 35ca197a5d..28b1519558 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -74,9 +74,9 @@ func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { } } -// OnBlockAnnounce on every new block announce received -// Synce it is a warp sync strategy, we are going to only update the peerset reputation -// And peers target block +// OnBlockAnnounce on every new block announce received. +// Since it is a warp sync strategy, we are going to only update the peerset reputation +// And peers target block. func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnounceMessage) ( repChange *Change, err error) { From 676e7c7020350861ea5ce2efc171ae3c3689fe26 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 5 Nov 2024 13:31:16 -0300 Subject: [PATCH 39/44] Add error message in panic --- dot/sync/warp_sync.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 28b1519558..18e25bbb58 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -4,6 +4,7 @@ package sync import ( + "fmt" "slices" "time" @@ -60,7 +61,7 @@ type WarpSyncConfig struct { func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { authorities, err := cfg.WarpSyncProvider.CurrentAuthorities() if err != nil { - panic("failed to get current authorities") + panic(fmt.Sprintf("failed to get current authorities %s", err)) } return &WarpSyncStrategy{ From d4a5d8eee30cf14e06351cec07c0b76733cb01d2 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 9 Nov 2024 14:35:12 +0700 Subject: [PATCH 40/44] Fix get target block --- dot/services.go | 4 +++- dot/sync/warp_sync.go | 34 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/dot/services.go b/dot/services.go index cc0bcc6647..c1c775a43b 100644 --- a/dot/services.go +++ b/dot/services.go @@ -535,7 +535,9 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync Telemetry: telemetryMailer, BadBlocks: genesisData.BadBlocks, WarpSyncProvider: warpSyncProvider, - RequestMaker: net.GetRequestResponseProtocol(network.WarpSyncID, + WarpSyncRequestMaker: net.GetRequestResponseProtocol(network.WarpSyncID, + blockRequestTimeout, network.MaxBlockResponseSize), + SyncRequestMaker: net.GetRequestResponseProtocol(network.SyncID, blockRequestTimeout, network.MaxBlockResponseSize), BlockState: st.Block, Peers: peersView, diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 18e25bbb58..30de7ddaf6 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -34,7 +34,8 @@ type WarpSyncStrategy struct { // Strategy dependencies and config peers *peerViewSet badBlocks []string - reqMaker network.RequestMaker + warpSyncReqMaker network.RequestMaker + syncReqMaker network.RequestMaker warpSyncProvider WarpSyncProofProvider blockState BlockState @@ -49,12 +50,13 @@ type WarpSyncStrategy struct { } type WarpSyncConfig struct { - Telemetry Telemetry - BadBlocks []string - RequestMaker network.RequestMaker - WarpSyncProvider WarpSyncProofProvider - BlockState BlockState - Peers *peerViewSet + Telemetry Telemetry + BadBlocks []string + WarpSyncRequestMaker network.RequestMaker + SyncRequestMaker network.RequestMaker + WarpSyncProvider WarpSyncProofProvider + BlockState BlockState + Peers *peerViewSet } // NewWarpSyncStrategy returns a new warp sync strategy @@ -68,7 +70,8 @@ func NewWarpSyncStrategy(cfg *WarpSyncConfig) *WarpSyncStrategy { warpSyncProvider: cfg.WarpSyncProvider, blockState: cfg.BlockState, badBlocks: cfg.BadBlocks, - reqMaker: cfg.RequestMaker, + warpSyncReqMaker: cfg.WarpSyncRequestMaker, + syncReqMaker: cfg.SyncRequestMaker, peers: cfg.Peers, setId: 0, authorities: authorities, @@ -139,7 +142,7 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { task = SyncTask{ request: messages.NewWarpProofRequest(lastBlock.Hash()), response: &messages.WarpSyncProof{}, - requestMaker: w.reqMaker, + requestMaker: w.warpSyncReqMaker, } case TargetBlock: req := messages.NewBlockRequest( @@ -153,7 +156,7 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { task = SyncTask{ request: req, response: &messages.BlockResponseMessage{}, - requestMaker: w.reqMaker, + requestMaker: w.syncReqMaker, } } @@ -167,6 +170,8 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( switch w.phase { case WarpProof: + logger.Debug("processing warp sync proof results") + var warpProofResult *network.WarpSyncVerificationResult repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) @@ -186,14 +191,17 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( } case TargetBlock: + logger.Debug("processing warp sync target block results") + var validRes []RequestResponseData // Reuse same validator than in fullsync repChanges, bans, validRes = validateResults(results, w.badBlocks) - // TODO: check if this can cause an issue - w.result = *validRes[0].responseData[0] - w.phase = Completed + if len(validRes) > 0 && validRes[0].responseData != nil && len(validRes[0].responseData) > 0 { + w.result = *validRes[0].responseData[0] + w.phase = Completed + } } return w.IsSynced(), repChanges, bans, nil From bfbc17d8ca5bce1cb45afd8c83d7b52bba773449 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 5 Dec 2024 18:21:15 +0900 Subject: [PATCH 41/44] Add warp sync proof fixture --- .../messages/testdata/warp_sync_proofs.yaml | 1 + dot/network/messages/warp_sync_test.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 dot/network/messages/testdata/warp_sync_proofs.yaml diff --git a/dot/network/messages/testdata/warp_sync_proofs.yaml b/dot/network/messages/testdata/warp_sync_proofs.yaml new file mode 100644 index 0000000000..16a7058823 --- /dev/null +++ b/dot/network/messages/testdata/warp_sync_proofs.yaml @@ -0,0 +1 @@ +substrate_warp_sync_proof_1: 0x04e995dd4dddbdfc54bd8126e0b5b394a47da71ca4a6510e7bd132d103470bf9b9be748b05d4026dd4bd8821893ce9e82a3a8c324ca454dd7510ee9ab05df3df82e87a1eada450bc10f223a562a12962e8914f436fd0991319d662310298fa47e5ff0dffb50c0642414245b501031100000009ba301100000000a6815e866aebee63d23cefa60964fa88b4814264fd35703c0c8a5f8192d8f41aa15bc5d991d1cad65ffccb73dbacd542a32286ec051190166ec00bfb4304b6049a882d0858cdbfb8d37a07269ea01bad1b55fb1174d6dedbfac56787adfa700004424545468403a6c0199af958a3ae8a3928b0802b709589bcbb1ec5b7041cf91644dd696ad99f05424142450101f8b400261b84cc580a8947abe4caf3b4ee51b7aeb26afc9a3bcdd2b3cd634f2df03cda49368e5e56a5b2427f6088cdc4144d75e1985f5e0a7e8f527290f47b8dad10000000000000376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620138376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62015037bddf7847fd40d7e6235c17203c8b70e661ef25aa44cbbaed19d5bb455bec3b20f59a720253b7c536171e1e68a91dcbf6b88fd077e28a2125cc9ea4fb430819b6ba718c28b1078474dc63e9d8a6f4d794da79f661da070fcca13b3bba50e7376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201243478b0465e1c13e9cda8479d42958422ab0acd69a1dbdc8d14fa95d2b15e96e6c1a5e58df7ff148977ba68418a7d6f6cf2ab959056c59cd768e490bc90ea0c1a619f90a9c96ec3e1c57211613247e8c0efe123188263da1dc8796d6a018c16376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620151010e386ecf4cb60e88acf75d7859547584a8e4258af8ca3fcde8d79dedf9ed1b6b0bf7df2704c3dfbc2db4a785833f0a70e30ec3c6ad9f35cae93e6ebd990a1d50350ac619dc36a0fe05cdd7a1654e73858586d55265f3524cc27e005be0f2376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201ca80d95b84408c14cc2c0cca1f3d2e094ebe056b5816959c887ac40b7311edf8c87e0f77a06ed398323b684e09c6d784e5333136dbae5a1d0627bf774e633408229366210b4b20adf7741fb6bc8fa669ea2f7470e1440b38969d2a47d752ffeb376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201bda1ac4056f6e6210d6b2dd8f69323cb7f2729f49ad9d42059ceecdffecebef04ce478a3cfde9bceadaf9be978443f0c3a5aea19d04b538b087cc0ca614e6b0a2bf793d9fb4251da094a2dd33bb0f68a46e60d799b58a78a4a5cc369a92ee2ec376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620156dd1808cb6044b9d6762bbd5a0284b32e51809010300fa8b4a6f2bb3072e9e632041c6ad74ba989c3e18f3874ab4be95c2e8f51ab275d943a839c12d5b73c0a3ab4559bf186773ede8cf3ddc78a93439c8e82ead090de7d3c2fe4e75591fcf1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620176857f28231e3b3a8eaf85eb07b835f5f7f5d379e854debd3f325693118db758b2765fa1c4a959d41f7d0b1650f61cffe1d607eee7fb12de81777cf725cd8e073fee6e433392b821f11c4cf8fe8d17b7c08dbbc32381895955ee27448f8869e1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201688b6d2c8640491fe4db52979dfaa2947ebded2b4ba5e020257fe29ffdb2a6c7017102fa6c9d6f0744bba28a05c34c377108bf73ee04982d6db0656208ec620c7e287589ac74a46b3a74a8ae66c3e2554857419bd00f9bfeb55957fffccd98b9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62012256e07d9c9f3c76356fa7946b8233591a4d9b91ed3e81b2a09b1d3ae6b69c8906a299e8245221c8efd46bc55966f1de6b2b4bd0b2b3256527d59e7b738056009e8adb538dacdd20c86c4eca9a158895cef125dfd118e883cd55454f8d59f3ed376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62011479e687ce7b0594637250707491cbec69a909aad5dab78e00aae8c3d8a530d8de4c6a1faad6ef416aea872988d50227e35e2dfb5b73d4b3b897acaa4cf56f0ea674568468af9fef031f033166880eec9f5ddd05d797d5abf1a9b9a957c77820376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201a0e495db4830b2a4e80d045871b5f0f8541091fdb7707d5e6c8f085bc255f0a5069a0ae153d9a83f6fa3f208cd1d701fbd7e852449f026f8566c7d8826cf5b0aa99c0755eec29f2be753fb701762d1e7cc841323bac49576b9ea2e124c4b7b9f376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62018c4f486b7b87c5735e42249c15f5ec6d7b2b50a16aa0ba3bfbe666f99537e81a6a121659a06d58eacb9594201b6644f18e54c1c6ca457a4fcfa9d15e3bfea201be0bbf54aad305682afc6dc7cd051b5dce154e7d0056e877562407872cdb1242376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201763fba0da4fef393f59f1fd9eb9a646a2a1106f404681840fa846ec56c1a3443223b8a147990c6fd3e2af11300531168be94f091931f6ac07724f3ce75a06600d3ccc285f3c648f34ca9ce476651495b9a6c4aa7607d83737bd871de56a50ed9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201d9b7c0218e498e5930fc4ad9a8c139f774de3fda36ad408008c3957f1e822070ceda5ca810ef3fb7fda2c48576051107235edba92a3be39b38b9ac9aba8c2305f12e7ddae48873b7dcd614b8ccc8ea2e5ec000f3cc398f20801cf9047bc909b20001 \ No newline at end of file diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go index 46ef402923..744b8702f5 100644 --- a/dot/network/messages/warp_sync_test.go +++ b/dot/network/messages/warp_sync_test.go @@ -4,17 +4,30 @@ package messages import ( - "encoding/hex" "log" "testing" + _ "embed" + + "github.com/ChainSafe/gossamer/lib/common" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" ) +//go:embed testdata/warp_sync_proofs.yaml +var rawWarpSyncProofs []byte + +type WarpSyncProofs struct { + SubstrateWarpSyncProof1 string `yaml:"substrate_warp_sync_proof_1"` +} + func TestDecodeWarpSyncProof(t *testing.T) { + warpSyncProofs := &WarpSyncProofs{} + err := yaml.Unmarshal(rawWarpSyncProofs, warpSyncProofs) + require.NoError(t, err) + // Generated using substrate - hexString := "04e995dd4dddbdfc54bd8126e0b5b394a47da71ca4a6510e7bd132d103470bf9b9be748b05d4026dd4bd8821893ce9e82a3a8c324ca454dd7510ee9ab05df3df82e87a1eada450bc10f223a562a12962e8914f436fd0991319d662310298fa47e5ff0dffb50c0642414245b501031100000009ba301100000000a6815e866aebee63d23cefa60964fa88b4814264fd35703c0c8a5f8192d8f41aa15bc5d991d1cad65ffccb73dbacd542a32286ec051190166ec00bfb4304b6049a882d0858cdbfb8d37a07269ea01bad1b55fb1174d6dedbfac56787adfa700004424545468403a6c0199af958a3ae8a3928b0802b709589bcbb1ec5b7041cf91644dd696ad99f05424142450101f8b400261b84cc580a8947abe4caf3b4ee51b7aeb26afc9a3bcdd2b3cd634f2df03cda49368e5e56a5b2427f6088cdc4144d75e1985f5e0a7e8f527290f47b8dad10000000000000376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620138376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62015037bddf7847fd40d7e6235c17203c8b70e661ef25aa44cbbaed19d5bb455bec3b20f59a720253b7c536171e1e68a91dcbf6b88fd077e28a2125cc9ea4fb430819b6ba718c28b1078474dc63e9d8a6f4d794da79f661da070fcca13b3bba50e7376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201243478b0465e1c13e9cda8479d42958422ab0acd69a1dbdc8d14fa95d2b15e96e6c1a5e58df7ff148977ba68418a7d6f6cf2ab959056c59cd768e490bc90ea0c1a619f90a9c96ec3e1c57211613247e8c0efe123188263da1dc8796d6a018c16376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620151010e386ecf4cb60e88acf75d7859547584a8e4258af8ca3fcde8d79dedf9ed1b6b0bf7df2704c3dfbc2db4a785833f0a70e30ec3c6ad9f35cae93e6ebd990a1d50350ac619dc36a0fe05cdd7a1654e73858586d55265f3524cc27e005be0f2376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201ca80d95b84408c14cc2c0cca1f3d2e094ebe056b5816959c887ac40b7311edf8c87e0f77a06ed398323b684e09c6d784e5333136dbae5a1d0627bf774e633408229366210b4b20adf7741fb6bc8fa669ea2f7470e1440b38969d2a47d752ffeb376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201bda1ac4056f6e6210d6b2dd8f69323cb7f2729f49ad9d42059ceecdffecebef04ce478a3cfde9bceadaf9be978443f0c3a5aea19d04b538b087cc0ca614e6b0a2bf793d9fb4251da094a2dd33bb0f68a46e60d799b58a78a4a5cc369a92ee2ec376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620156dd1808cb6044b9d6762bbd5a0284b32e51809010300fa8b4a6f2bb3072e9e632041c6ad74ba989c3e18f3874ab4be95c2e8f51ab275d943a839c12d5b73c0a3ab4559bf186773ede8cf3ddc78a93439c8e82ead090de7d3c2fe4e75591fcf1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd620176857f28231e3b3a8eaf85eb07b835f5f7f5d379e854debd3f325693118db758b2765fa1c4a959d41f7d0b1650f61cffe1d607eee7fb12de81777cf725cd8e073fee6e433392b821f11c4cf8fe8d17b7c08dbbc32381895955ee27448f8869e1376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201688b6d2c8640491fe4db52979dfaa2947ebded2b4ba5e020257fe29ffdb2a6c7017102fa6c9d6f0744bba28a05c34c377108bf73ee04982d6db0656208ec620c7e287589ac74a46b3a74a8ae66c3e2554857419bd00f9bfeb55957fffccd98b9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62012256e07d9c9f3c76356fa7946b8233591a4d9b91ed3e81b2a09b1d3ae6b69c8906a299e8245221c8efd46bc55966f1de6b2b4bd0b2b3256527d59e7b738056009e8adb538dacdd20c86c4eca9a158895cef125dfd118e883cd55454f8d59f3ed376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62011479e687ce7b0594637250707491cbec69a909aad5dab78e00aae8c3d8a530d8de4c6a1faad6ef416aea872988d50227e35e2dfb5b73d4b3b897acaa4cf56f0ea674568468af9fef031f033166880eec9f5ddd05d797d5abf1a9b9a957c77820376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201a0e495db4830b2a4e80d045871b5f0f8541091fdb7707d5e6c8f085bc255f0a5069a0ae153d9a83f6fa3f208cd1d701fbd7e852449f026f8566c7d8826cf5b0aa99c0755eec29f2be753fb701762d1e7cc841323bac49576b9ea2e124c4b7b9f376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd62018c4f486b7b87c5735e42249c15f5ec6d7b2b50a16aa0ba3bfbe666f99537e81a6a121659a06d58eacb9594201b6644f18e54c1c6ca457a4fcfa9d15e3bfea201be0bbf54aad305682afc6dc7cd051b5dce154e7d0056e877562407872cdb1242376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201763fba0da4fef393f59f1fd9eb9a646a2a1106f404681840fa846ec56c1a3443223b8a147990c6fd3e2af11300531168be94f091931f6ac07724f3ce75a06600d3ccc285f3c648f34ca9ce476651495b9a6c4aa7607d83737bd871de56a50ed9376d697522a9a42b9c6952e771fd74be9cb19fe6dd0d41c362f753ae2686547a2fdd6201d9b7c0218e498e5930fc4ad9a8c139f774de3fda36ad408008c3957f1e822070ceda5ca810ef3fb7fda2c48576051107235edba92a3be39b38b9ac9aba8c2305f12e7ddae48873b7dcd614b8ccc8ea2e5ec000f3cc398f20801cf9047bc909b20001" //nolint:lll - expected, err := hex.DecodeString(hexString) + expected := common.MustHexToBytes(warpSyncProofs.SubstrateWarpSyncProof1) if err != nil { log.Fatal(err) } From 20b303d2220f332cd1d423713d75d78c539d3735 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 5 Dec 2024 18:38:45 +0900 Subject: [PATCH 42/44] Move types to warpsync package --- dot/network/messages/warp_sync.go | 36 ---- dot/network/messages/warp_sync_test.go | 43 ----- dot/network/mock_warp_sync_provider_test.go | 5 +- dot/network/warp_sync.go | 11 +- dot/services.go | 5 +- dot/sync/mocks_test.go | 5 +- dot/sync/warp_sync.go | 15 +- dot/sync/warp_sync_test.go | 3 +- lib/grandpa/warpsync/mocks_generate_test.go | 6 + lib/grandpa/warpsync/mocks_test.go | 169 ++++++++++++++++++ .../warpsync}/testdata/warp_sync_proofs.yaml | 0 lib/grandpa/{ => warpsync}/warp_sync.go | 50 +++++- lib/grandpa/{ => warpsync}/warp_sync_test.go | 33 +++- 13 files changed, 274 insertions(+), 107 deletions(-) delete mode 100644 dot/network/messages/warp_sync_test.go create mode 100644 lib/grandpa/warpsync/mocks_generate_test.go create mode 100644 lib/grandpa/warpsync/mocks_test.go rename {dot/network/messages => lib/grandpa/warpsync}/testdata/warp_sync_proofs.yaml (100%) rename lib/grandpa/{ => warpsync}/warp_sync.go (89%) rename lib/grandpa/{ => warpsync}/warp_sync_test.go (93%) diff --git a/dot/network/messages/warp_sync.go b/dot/network/messages/warp_sync.go index 294ef8f194..4307161fb0 100644 --- a/dot/network/messages/warp_sync.go +++ b/dot/network/messages/warp_sync.go @@ -6,9 +6,6 @@ package messages import ( "fmt" - "github.com/ChainSafe/gossamer/dot/types" - "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa" - "github.com/ChainSafe/gossamer/internal/primitives/core/hash" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/pkg/scale" ) @@ -46,37 +43,4 @@ func (wpr *WarpProofRequest) String() string { return fmt.Sprintf("WarpProofRequest begin=%v", wpr.Begin) } -type WarpSyncFragment struct { - Header types.Header - Justification grandpa.GrandpaJustification[hash.H256, uint32] -} - -type WarpSyncProof struct { - Proofs []WarpSyncFragment - // indicates whether the warp sync has been completed - IsFinished bool - proofsLength int -} - -func (wsp *WarpSyncProof) Decode(in []byte) error { - return scale.Unmarshal(in, wsp) -} - -func (wsp *WarpSyncProof) Encode() ([]byte, error) { - if wsp == nil { - return nil, fmt.Errorf("cannot encode nil WarpSyncProof") - } - return scale.Marshal(*wsp) -} - -func (wsp *WarpSyncProof) String() string { - if wsp == nil { - return "WarpSyncProof=nil" - } - - return fmt.Sprintf("WarpSyncProof proofs=%v isFinished=%v proofsLength=%v", - wsp.Proofs, wsp.IsFinished, wsp.proofsLength) -} - -var _ P2PMessage = (*WarpSyncProof)(nil) var _ P2PMessage = (*WarpProofRequest)(nil) diff --git a/dot/network/messages/warp_sync_test.go b/dot/network/messages/warp_sync_test.go deleted file mode 100644 index 744b8702f5..0000000000 --- a/dot/network/messages/warp_sync_test.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2024 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package messages - -import ( - "log" - "testing" - - _ "embed" - - "github.com/ChainSafe/gossamer/lib/common" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" -) - -//go:embed testdata/warp_sync_proofs.yaml -var rawWarpSyncProofs []byte - -type WarpSyncProofs struct { - SubstrateWarpSyncProof1 string `yaml:"substrate_warp_sync_proof_1"` -} - -func TestDecodeWarpSyncProof(t *testing.T) { - warpSyncProofs := &WarpSyncProofs{} - err := yaml.Unmarshal(rawWarpSyncProofs, warpSyncProofs) - require.NoError(t, err) - - // Generated using substrate - expected := common.MustHexToBytes(warpSyncProofs.SubstrateWarpSyncProof1) - if err != nil { - log.Fatal(err) - } - - var proof WarpSyncProof - - err = proof.Decode(expected) - require.NoError(t, err) - - encoded, err := proof.Encode() - require.NoError(t, err) - require.Equal(t, expected, encoded) -} diff --git a/dot/network/mock_warp_sync_provider_test.go b/dot/network/mock_warp_sync_provider_test.go index 04280930e7..4425377b94 100644 --- a/dot/network/mock_warp_sync_provider_test.go +++ b/dot/network/mock_warp_sync_provider_test.go @@ -14,6 +14,7 @@ import ( grandpa "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" common "github.com/ChainSafe/gossamer/lib/common" + warpsync "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" gomock "go.uber.org/mock/gomock" ) @@ -56,10 +57,10 @@ func (mr *MockWarpSyncProviderMockRecorder) Generate(arg0 any) *gomock.Call { } // Verify mocks base method. -func (m *MockWarpSyncProvider) Verify(arg0 []byte, arg1 grandpa.SetID, arg2 grandpa.AuthorityList) (*WarpSyncVerificationResult, error) { +func (m *MockWarpSyncProvider) Verify(arg0 []byte, arg1 grandpa.SetID, arg2 grandpa.AuthorityList) (*warpsync.WarpSyncVerificationResult, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Verify", arg0, arg1, arg2) - ret0, _ := ret[0].(*WarpSyncVerificationResult) + ret0, _ := ret[0].(*warpsync.WarpSyncVerificationResult) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/dot/network/warp_sync.go b/dot/network/warp_sync.go index 5e5e7b85b5..c72c8333ea 100644 --- a/dot/network/warp_sync.go +++ b/dot/network/warp_sync.go @@ -8,23 +8,16 @@ 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" + "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" libp2pnetwork "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" ) const MaxAllowedSameRequestPerPeer = 5 -type WarpSyncVerificationResult struct { - 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 @@ -34,7 +27,7 @@ type WarpSyncProvider interface { encodedProof []byte, setId grandpa.SetID, authorities primitives.AuthorityList, - ) (*WarpSyncVerificationResult, error) + ) (*warpsync.WarpSyncVerificationResult, error) } func (s *Service) handleWarpSyncRequest(req messages.WarpProofRequest) ([]byte, error) { diff --git a/dot/services.go b/dot/services.go index c1c775a43b..c9dc92169d 100644 --- a/dot/services.go +++ b/dot/services.go @@ -31,6 +31,7 @@ import ( "github.com/ChainSafe/gossamer/lib/crypto/sr25519" "github.com/ChainSafe/gossamer/lib/genesis" "github.com/ChainSafe/gossamer/lib/grandpa" + "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" "github.com/ChainSafe/gossamer/lib/keystore" "github.com/ChainSafe/gossamer/lib/runtime" rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" @@ -349,7 +350,7 @@ func (nodeBuilder) createNetworkService(config *cfg.Config, stateSrvc *state.Ser return nil, fmt.Errorf("failed to parse network log level: %w", err) } - warpSyncProvider := grandpa.NewWarpSyncProofProvider( + warpSyncProvider := warpsync.NewWarpSyncProofProvider( stateSrvc.Block, stateSrvc.Grandpa, ) @@ -529,7 +530,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync var warpSyncStrategy sync.Strategy if config.Core.Sync == "warp" { - warpSyncProvider := grandpa.NewWarpSyncProofProvider(st.Block, st.Grandpa) + warpSyncProvider := warpsync.NewWarpSyncProofProvider(st.Block, st.Grandpa) warpSyncCfg := &sync.WarpSyncConfig{ Telemetry: telemetryMailer, diff --git a/dot/sync/mocks_test.go b/dot/sync/mocks_test.go index 228f23533e..88b694a70d 100644 --- a/dot/sync/mocks_test.go +++ b/dot/sync/mocks_test.go @@ -19,6 +19,7 @@ import ( types "github.com/ChainSafe/gossamer/dot/types" grandpa "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" common "github.com/ChainSafe/gossamer/lib/common" + warpsync "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" runtime "github.com/ChainSafe/gossamer/lib/runtime" storage "github.com/ChainSafe/gossamer/lib/runtime/storage" peer "github.com/libp2p/go-libp2p/core/peer" @@ -772,10 +773,10 @@ func (mr *MockWarpSyncProofProviderMockRecorder) CurrentAuthorities() *gomock.Ca } // Verify mocks base method. -func (m *MockWarpSyncProofProvider) Verify(arg0 []byte, arg1 grandpa.SetID, arg2 grandpa.AuthorityList) (*network.WarpSyncVerificationResult, error) { +func (m *MockWarpSyncProofProvider) Verify(arg0 []byte, arg1 grandpa.SetID, arg2 grandpa.AuthorityList) (*warpsync.WarpSyncVerificationResult, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Verify", arg0, arg1, arg2) - ret0, _ := ret[0].(*network.WarpSyncVerificationResult) + ret0, _ := ret[0].(*warpsync.WarpSyncVerificationResult) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 30de7ddaf6..96a18e7667 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -13,6 +13,7 @@ import ( "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" primitives "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" + "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" "github.com/libp2p/go-libp2p/core/peer" ) @@ -27,7 +28,7 @@ const ( type WarpSyncProofProvider interface { CurrentAuthorities() (primitives.AuthorityList, error) Verify(encodedProof []byte, setId primitives.SetID, authorities primitives.AuthorityList) ( - *network.WarpSyncVerificationResult, error) + *warpsync.WarpSyncVerificationResult, error) } type WarpSyncStrategy struct { @@ -141,7 +142,7 @@ func (w *WarpSyncStrategy) NextActions() ([]*SyncTask, error) { case WarpProof: task = SyncTask{ request: messages.NewWarpProofRequest(lastBlock.Hash()), - response: &messages.WarpSyncProof{}, + response: &warpsync.WarpSyncProof{}, requestMaker: w.warpSyncReqMaker, } case TargetBlock: @@ -172,7 +173,7 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( case WarpProof: logger.Debug("processing warp sync proof results") - var warpProofResult *network.WarpSyncVerificationResult + var warpProofResult *warpsync.WarpSyncVerificationResult repChanges, bans, warpProofResult = w.validateWarpSyncResults(results) @@ -208,16 +209,16 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( } func (w *WarpSyncStrategy) validateWarpSyncResults(results []*SyncTaskResult) ( - repChanges []Change, peersToBlock []peer.ID, result *network.WarpSyncVerificationResult) { + repChanges []Change, peersToBlock []peer.ID, result *warpsync.WarpSyncVerificationResult) { repChanges = make([]Change, 0) peersToBlock = make([]peer.ID, 0) - bestProof := &messages.WarpSyncProof{} - var bestResult *network.WarpSyncVerificationResult + bestProof := &warpsync.WarpSyncProof{} + var bestResult *warpsync.WarpSyncVerificationResult for _, result := range results { switch response := result.response.(type) { - case *messages.WarpSyncProof: + case *warpsync.WarpSyncProof: if !result.completed { continue } diff --git a/dot/sync/warp_sync_test.go b/dot/sync/warp_sync_test.go index 1d55d34aac..e3d704a11b 100644 --- a/dot/sync/warp_sync_test.go +++ b/dot/sync/warp_sync_test.go @@ -11,6 +11,7 @@ import ( "github.com/ChainSafe/gossamer/dot/peerset" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/common" + "github.com/ChainSafe/gossamer/lib/grandpa/warpsync" "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -143,7 +144,7 @@ func TestWarpSyncNextActions(t *testing.T) { "warp_sync_phase": { phase: WarpProof, expectedRequestType: &messages.WarpProofRequest{}, - expectedResponseType: &messages.WarpSyncProof{}, + expectedResponseType: &warpsync.WarpSyncProof{}, }, "target_block_phase": { phase: TargetBlock, diff --git a/lib/grandpa/warpsync/mocks_generate_test.go b/lib/grandpa/warpsync/mocks_generate_test.go new file mode 100644 index 0000000000..82185f8d08 --- /dev/null +++ b/lib/grandpa/warpsync/mocks_generate_test.go @@ -0,0 +1,6 @@ +// Copyright 2021 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package warpsync + +//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . BlockState,GrandpaState diff --git a/lib/grandpa/warpsync/mocks_test.go b/lib/grandpa/warpsync/mocks_test.go new file mode 100644 index 0000000000..5d3ed95394 --- /dev/null +++ b/lib/grandpa/warpsync/mocks_test.go @@ -0,0 +1,169 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/ChainSafe/gossamer/lib/grandpa/warpsync (interfaces: BlockState,GrandpaState) +// +// Generated by this command: +// +// mockgen -destination=mocks_test.go -package warpsync . BlockState,GrandpaState +// + +// Package warpsync is a generated GoMock package. +package warpsync + +import ( + reflect "reflect" + + types "github.com/ChainSafe/gossamer/dot/types" + common "github.com/ChainSafe/gossamer/lib/common" + gomock "go.uber.org/mock/gomock" +) + +// MockBlockState is a mock of BlockState interface. +type MockBlockState struct { + ctrl *gomock.Controller + recorder *MockBlockStateMockRecorder +} + +// MockBlockStateMockRecorder is the mock recorder for MockBlockState. +type MockBlockStateMockRecorder struct { + mock *MockBlockState +} + +// NewMockBlockState creates a new mock instance. +func NewMockBlockState(ctrl *gomock.Controller) *MockBlockState { + mock := &MockBlockState{ctrl: ctrl} + mock.recorder = &MockBlockStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBlockState) EXPECT() *MockBlockStateMockRecorder { + return m.recorder +} + +// GetHeader mocks base method. +func (m *MockBlockState) GetHeader(arg0 common.Hash) (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHeader", arg0) + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHeader indicates an expected call of GetHeader. +func (mr *MockBlockStateMockRecorder) GetHeader(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHeader", reflect.TypeOf((*MockBlockState)(nil).GetHeader), arg0) +} + +// GetHeaderByNumber mocks base method. +func (m *MockBlockState) GetHeaderByNumber(arg0 uint) (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHeaderByNumber", arg0) + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHeaderByNumber indicates an expected call of GetHeaderByNumber. +func (mr *MockBlockStateMockRecorder) GetHeaderByNumber(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHeaderByNumber", reflect.TypeOf((*MockBlockState)(nil).GetHeaderByNumber), arg0) +} + +// GetHighestFinalisedHeader mocks base method. +func (m *MockBlockState) GetHighestFinalisedHeader() (*types.Header, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHighestFinalisedHeader") + ret0, _ := ret[0].(*types.Header) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHighestFinalisedHeader indicates an expected call of GetHighestFinalisedHeader. +func (mr *MockBlockStateMockRecorder) GetHighestFinalisedHeader() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHighestFinalisedHeader", reflect.TypeOf((*MockBlockState)(nil).GetHighestFinalisedHeader)) +} + +// GetJustification mocks base method. +func (m *MockBlockState) GetJustification(arg0 common.Hash) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetJustification", arg0) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetJustification indicates an expected call of GetJustification. +func (mr *MockBlockStateMockRecorder) GetJustification(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetJustification", reflect.TypeOf((*MockBlockState)(nil).GetJustification), arg0) +} + +// MockGrandpaState is a mock of GrandpaState interface. +type MockGrandpaState struct { + ctrl *gomock.Controller + recorder *MockGrandpaStateMockRecorder +} + +// MockGrandpaStateMockRecorder is the mock recorder for MockGrandpaState. +type MockGrandpaStateMockRecorder struct { + mock *MockGrandpaState +} + +// NewMockGrandpaState creates a new mock instance. +func NewMockGrandpaState(ctrl *gomock.Controller) *MockGrandpaState { + mock := &MockGrandpaState{ctrl: ctrl} + mock.recorder = &MockGrandpaStateMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGrandpaState) EXPECT() *MockGrandpaStateMockRecorder { + return m.recorder +} + +// GetAuthorities mocks base method. +func (m *MockGrandpaState) GetAuthorities(arg0 uint64) ([]types.GrandpaVoter, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAuthorities", arg0) + ret0, _ := ret[0].([]types.GrandpaVoter) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAuthorities indicates an expected call of GetAuthorities. +func (mr *MockGrandpaStateMockRecorder) GetAuthorities(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthorities", reflect.TypeOf((*MockGrandpaState)(nil).GetAuthorities), arg0) +} + +// GetAuthoritiesChangesFromBlock mocks base method. +func (m *MockGrandpaState) GetAuthoritiesChangesFromBlock(arg0 uint) ([]uint, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAuthoritiesChangesFromBlock", arg0) + ret0, _ := ret[0].([]uint) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAuthoritiesChangesFromBlock indicates an expected call of GetAuthoritiesChangesFromBlock. +func (mr *MockGrandpaStateMockRecorder) GetAuthoritiesChangesFromBlock(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthoritiesChangesFromBlock", reflect.TypeOf((*MockGrandpaState)(nil).GetAuthoritiesChangesFromBlock), arg0) +} + +// GetCurrentSetID mocks base method. +func (m *MockGrandpaState) GetCurrentSetID() (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCurrentSetID") + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCurrentSetID indicates an expected call of GetCurrentSetID. +func (mr *MockGrandpaStateMockRecorder) GetCurrentSetID() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentSetID", reflect.TypeOf((*MockGrandpaState)(nil).GetCurrentSetID)) +} diff --git a/dot/network/messages/testdata/warp_sync_proofs.yaml b/lib/grandpa/warpsync/testdata/warp_sync_proofs.yaml similarity index 100% rename from dot/network/messages/testdata/warp_sync_proofs.yaml rename to lib/grandpa/warpsync/testdata/warp_sync_proofs.yaml diff --git a/lib/grandpa/warp_sync.go b/lib/grandpa/warpsync/warp_sync.go similarity index 89% rename from lib/grandpa/warp_sync.go rename to lib/grandpa/warpsync/warp_sync.go index 8eb84446b6..3c8b45fd11 100644 --- a/lib/grandpa/warp_sync.go +++ b/lib/grandpa/warpsync/warp_sync.go @@ -1,15 +1,15 @@ // Copyright 2024 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only -package grandpa +package warpsync import ( "bytes" "fmt" - "github.com/ChainSafe/gossamer/dot/network" "github.com/ChainSafe/gossamer/dot/types" consensus_grandpa "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa" + "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa" "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa/app" "github.com/ChainSafe/gossamer/internal/primitives/core/hash" @@ -22,10 +22,32 @@ import ( const MaxWarpSyncProofSize = 8 * 1024 * 1024 var ( + logger = log.NewFromGlobal(log.AddContext("pkg", "warpsync")) + errMissingStartBlock = fmt.Errorf("missing start block") errStartBlockNotFinalized = fmt.Errorf("start block is not finalized") ) +type BlockState interface { + GetHeader(common.Hash) (*types.Header, error) + GetHeaderByNumber(uint) (*types.Header, error) + GetJustification(common.Hash) ([]byte, error) + GetHighestFinalisedHeader() (*types.Header, error) +} + +type GrandpaState interface { + GetCurrentSetID() (uint64, error) + GetAuthorities(uint64) ([]types.GrandpaVoter, error) + GetAuthoritiesChangesFromBlock(uint) ([]uint, error) +} + +type WarpSyncVerificationResult struct { + SetId grandpa.SetID + AuthorityList primitives.AuthorityList + Header types.Header + Completed bool +} + type WarpSyncFragment struct { // The last block that the given authority set finalized. This block should contain a digest // signalling an authority set change from which we can fetch the next authority set. @@ -50,6 +72,26 @@ func NewWarpSyncProof() WarpSyncProof { } } +func (wsp *WarpSyncProof) Decode(in []byte) error { + return scale.Unmarshal(in, wsp) +} + +func (wsp *WarpSyncProof) Encode() ([]byte, error) { + if wsp == nil { + return nil, fmt.Errorf("cannot encode nil WarpSyncProof") + } + return scale.Marshal(*wsp) +} + +func (wsp *WarpSyncProof) String() string { + if wsp == nil { + return "WarpSyncProof=nil" + } + + return fmt.Sprintf("WarpSyncProof proofs=%v isFinished=%v proofsLength=%v", + wsp.Proofs, wsp.IsFinished, wsp.proofsLength) +} + func (w *WarpSyncProof) addFragment(fragment WarpSyncFragment) (limitReached bool, err error) { encodedFragment, err := scale.Marshal(fragment) if err != nil { @@ -284,7 +326,7 @@ func (p *WarpSyncProofProvider) Verify( encodedProof []byte, setId grandpa.SetID, authorities grandpa.AuthorityList, -) (*network.WarpSyncVerificationResult, error) { +) (*WarpSyncVerificationResult, error) { var proof WarpSyncProof err := scale.Unmarshal(encodedProof, &proof) if err != nil { @@ -303,7 +345,7 @@ func (p *WarpSyncProofProvider) Verify( return nil, fmt.Errorf("verifying warp sync proof: %w", err) } - return &network.WarpSyncVerificationResult{ + return &WarpSyncVerificationResult{ SetId: nextSetAndAuthorities.SetID, AuthorityList: nextSetAndAuthorities.AuthorityList, Header: lastHeader, diff --git a/lib/grandpa/warp_sync_test.go b/lib/grandpa/warpsync/warp_sync_test.go similarity index 93% rename from lib/grandpa/warp_sync_test.go rename to lib/grandpa/warpsync/warp_sync_test.go index be8692fb07..86212f256c 100644 --- a/lib/grandpa/warp_sync_test.go +++ b/lib/grandpa/warpsync/warp_sync_test.go @@ -1,10 +1,11 @@ // Copyright 2024 ChainSafe Systems (ON) // SPDX-License-Identifier: LGPL-3.0-only -package grandpa +package warpsync import ( "errors" + "log" "math/rand" "slices" "testing" @@ -21,8 +22,38 @@ import ( "github.com/ChainSafe/gossamer/pkg/scale" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" + "gopkg.in/yaml.v3" + + _ "embed" ) +//go:embed testdata/warp_sync_proofs.yaml +var rawWarpSyncProofs []byte + +type WarpSyncProofs struct { + SubstrateWarpSyncProof1 string `yaml:"substrate_warp_sync_proof_1"` +} + +func TestDecodeWarpSyncProof(t *testing.T) { + warpSyncProofs := &WarpSyncProofs{} + err := yaml.Unmarshal(rawWarpSyncProofs, warpSyncProofs) + require.NoError(t, err) + + // Generated using substrate + expected := common.MustHexToBytes(warpSyncProofs.SubstrateWarpSyncProof1) + if err != nil { + log.Fatal(err) + } + + var proof WarpSyncProof + + err = proof.Decode(expected) + require.NoError(t, err) + + encoded, err := proof.Encode() + require.NoError(t, err) + require.Equal(t, expected, encoded) +} func TestGenerateWarpSyncProofBlockNotFound(t *testing.T) { t.Parallel() From 8743d1fa98f953bfec0e010387d3262eb69a46dd Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 16 Dec 2024 17:54:23 +0700 Subject: [PATCH 43/44] Remove unnused linter comment --- dot/sync/warp_sync.go | 2 +- lib/grandpa/warpsync/warp_sync.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 96a18e7667..1715eaf22c 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -111,7 +111,7 @@ func (w *WarpSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou } if msg.BestBlock { - w.peers.update(from, blockAnnounceHeaderHash, uint32(msg.Number)) //nolint:gosec + w.peers.update(from, blockAnnounceHeaderHash, uint32(msg.Number)) } return &Change{ diff --git a/lib/grandpa/warpsync/warp_sync.go b/lib/grandpa/warpsync/warp_sync.go index 3c8b45fd11..9759556b8e 100644 --- a/lib/grandpa/warpsync/warp_sync.go +++ b/lib/grandpa/warpsync/warp_sync.go @@ -43,7 +43,7 @@ type GrandpaState interface { type WarpSyncVerificationResult struct { SetId grandpa.SetID - AuthorityList primitives.AuthorityList + AuthorityList grandpa.AuthorityList Header types.Header Completed bool } @@ -188,7 +188,7 @@ type SetIdAuthorityList struct { grandpa.AuthorityList } -func (p *WarpSyncProofProvider) CurrentAuthorities() (primitives.AuthorityList, error) { +func (p *WarpSyncProofProvider) CurrentAuthorities() (grandpa.AuthorityList, error) { currentSetid, err := p.grandpaState.GetCurrentSetID() if err != nil { return nil, err @@ -199,16 +199,16 @@ func (p *WarpSyncProofProvider) CurrentAuthorities() (primitives.AuthorityList, return nil, err } - var authorityList primitives.AuthorityList + var authorityList grandpa.AuthorityList for _, auth := range authorities { key, err := app.NewPublic(auth.Key[:]) if err != nil { return nil, err } - authorityList = append(authorityList, primitives.AuthorityIDWeight{ + authorityList = append(authorityList, grandpa.AuthorityIDWeight{ AuthorityID: key, - AuthorityWeight: primitives.AuthorityWeight(auth.ID), + AuthorityWeight: grandpa.AuthorityWeight(auth.ID), }) } From c5d6815af58c94f24fbcbe428967c471efa4e187 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 7 Jan 2025 14:41:06 -0300 Subject: [PATCH 44/44] Improve logs --- dot/sync/warp_sync.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dot/sync/warp_sync.go b/dot/sync/warp_sync.go index 1715eaf22c..b886b5e817 100644 --- a/dot/sync/warp_sync.go +++ b/dot/sync/warp_sync.go @@ -181,12 +181,13 @@ func (w *WarpSyncStrategy) Process(results []*SyncTaskResult) ( w.lastBlock = &warpProofResult.Header if !warpProofResult.Completed { - logger.Debug("partial warp sync received") + logger.Debug("partial warp sync proof received") w.setId = warpProofResult.SetId w.authorities = warpProofResult.AuthorityList } else { - logger.Debug("complete warp sync received") + logger.Debugf("⏩ Warping, finish processing proofs, downloading target block #%d (%s)", + w.lastBlock.Number, w.lastBlock.Hash().String()) w.phase = TargetBlock } }