diff --git a/internal/client/consensus/grandpa/warp_sync.go b/internal/client/consensus/grandpa/warp_sync.go index a2a60d4d36..23710fc362 100644 --- a/internal/client/consensus/grandpa/warp_sync.go +++ b/internal/client/consensus/grandpa/warp_sync.go @@ -120,6 +120,10 @@ func (np *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) { // If the limit is not reached then retrieve the latest (best) justification // and append in the proofs if !limitReached { + // the existing best justification must be for a block higher than the + // last authority set change. if we didn't prove any authority set + // change then we fallback to make sure it's higher or equal to the + // initial warp sync block. bestLastBlockHeader, err := np.blockState.BestBlockHeader() if err != nil { return nil, err @@ -134,8 +138,13 @@ func (np *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) { return nil, err } - fragment := WarpSyncFragment{Header: *bestLastBlockHeader, Justification: *justification} - proofs = append(proofs, fragment) + limit := proofs[len(proofs)-1].Justification.Justification.Commit.TargetNumber + 1 + + if justification.Justification.Commit.TargetNumber >= limit { + fragment := WarpSyncFragment{Header: *bestLastBlockHeader, Justification: *justification} + proofs = append(proofs, fragment) + } + isFinished = true } diff --git a/internal/client/consensus/grandpa/warp_sync_test.go b/internal/client/consensus/grandpa/warp_sync_test.go index c218b4cefc..165d073073 100644 --- a/internal/client/consensus/grandpa/warp_sync_test.go +++ b/internal/client/consensus/grandpa/warp_sync_test.go @@ -69,7 +69,6 @@ func TestGenerateWarpSyncProofOk(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - const blocksAmount = 10 encodedJustification1 := []byte{42, 0, 0, 0, 0, 0, 0, 0, 236, 148, 26, 228, 225, 134, 98, 140, 150, 154, 23, 185, 43, 231, 172, 194, 69, 150, 27, 191, 202, 50, 108, 91, 220, 57, 214, 47, 202, 62, 70, 238, 10, 0, 0, 0, 0, 0, 0, 0, 4, 236, 148, 26, 228, 225, 134, 98, 140, 150, 154, 23, 185, 43, 231, 172, 194, 69, 150, 27, 191, 202, 50, 108, 91, 220, 57, 214, 47, 202, 62, 70, 238, 10, 0, 0, 0, 0, 0, 0, 0, 201, 232, 26, 136, 31, 77, 15, 194, 34, 200, 248, 43, 219, 148, 207, 56, 240, 171, 208, 221, 162, 202, 153, 209, 150, 27, 71, 207, 227, 102, 133, 32, 206, 74, 78, 26, 148, 166, 18, 67, 188, 76, 163, 200, 68, 249, 134, 28, 122, 74, 182, 69, 135, 90, 199, 52, 72, 109, 41, 12, 37, 18, 161, 4, 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} encodedJustification2 := []byte{50, 0, 0, 0, 0, 0, 0, 0, 236, 148, 26, 228, 225, 134, 98, 140, 150, 154, 23, 185, 43, 231, 172, 194, 69, 150, 27, 191, 202, 50, 108, 91, 220, 57, 214, 47, 202, 62, 70, 238, 10, 0, 0, 0, 0, 0, 0, 0, 4, 236, 148, 26, 228, 225, 134, 98, 140, 150, 154, 23, 185, 43, 231, 172, 194, 69, 150, 27, 191, 202, 50, 108, 91, 220, 57, 214, 47, 202, 62, 70, 238, 10, 0, 0, 0, 0, 0, 0, 0, 201, 232, 26, 136, 31, 77, 15, 194, 34, 200, 248, 43, 219, 148, 207, 56, 240, 171, 208, 221, 162, 202, 153, 209, 150, 27, 71, 207, 227, 102, 133, 32, 206, 74, 78, 26, 148, 166, 18, 67, 188, 76, 163, 200, 68, 249, 134, 28, 122, 74, 182, 69, 135, 90, 199, 52, 72, 109, 41, 12, 37, 18, 161, 4, 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} blockHeaders := []*types.Header{} @@ -77,7 +76,7 @@ func TestGenerateWarpSyncProofOk(t *testing.T) { blockStateMock := NewMockBlockState(ctrl) grandpaStateMock := NewMockGrandpaState(ctrl) - for blockNumber := uint(1); blockNumber <= blocksAmount; blockNumber++ { + for blockNumber := uint(1); blockNumber <= 10; blockNumber++ { // Create block header var header *types.Header parentHash := common.Hash{0x00} @@ -121,7 +120,7 @@ func TestGenerateWarpSyncProofOk(t *testing.T) { assert.NoError(t, err) expectedProof := []byte{ - 0x8, 0x1c, 0xa4, 0x2, 0x25, 0x71, 0x86, 0xee, 0x43, 0x46, 0xfd, 0x2c, 0x9, 0xfe, 0xeb, 0x91, 0x17, 0x10, 0xe5, 0x88, 0x41, 0x89, 0xc3, 0xc7, 0x5f, 0xb5, 0x1, 0x1a, 0x75, 0x21, 0x37, 0x2f, 0xf9, 0x14, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xec, 0x94, 0x1a, 0xe4, 0xe1, 0x86, 0x62, 0x8c, 0x96, 0x9a, 0x17, 0xb9, 0x2b, 0xe7, 0xac, 0xc2, 0x45, 0x96, 0x1b, 0xbf, 0xca, 0x32, 0x6c, 0x5b, 0xdc, 0x39, 0xd6, 0x2f, 0xca, 0x3e, 0x46, 0xee, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0xec, 0x94, 0x1a, 0xe4, 0xe1, 0x86, 0x62, 0x8c, 0x96, 0x9a, 0x17, 0xb9, 0x2b, 0xe7, 0xac, 0xc2, 0x45, 0x96, 0x1b, 0xbf, 0xca, 0x32, 0x6c, 0x5b, 0xdc, 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