From 26840ffb7591212e14ab6cc529148f483f0e2e6f Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Tue, 28 Mar 2023 17:59:24 +0530 Subject: [PATCH 1/2] eth/downloader/whitelist: skip future chain validation --- eth/downloader/whitelist/service.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/eth/downloader/whitelist/service.go b/eth/downloader/whitelist/service.go index 3cb402c442..a2edcfb797 100644 --- a/eth/downloader/whitelist/service.go +++ b/eth/downloader/whitelist/service.go @@ -100,18 +100,20 @@ func (w *Service) IsValidChain(currentHeader *types.Header, chain []*types.Heade } // Split the chain into past and future chain - pastChain, futureChain := splitChain(current, chain) + pastChain, _ := splitChain(current, chain) + + // Note: Do not act on future chain and allow importing all kinds of future chains. // Add an offset to future chain if it's not in continuity - offset := 0 - if len(futureChain) != 0 { - offset += int(futureChain[0].Number.Uint64()-currentHeader.Number.Uint64()) - 1 - } + // offset := 0 + // if len(futureChain) != 0 { + // offset += int(futureChain[0].Number.Uint64()-currentHeader.Number.Uint64()) - 1 + // } // Don't accept future chain of unacceptable length (from current block) - if len(futureChain)+offset > int(w.checkpointInterval) { - return false, ErrLongFutureChain - } + // if len(futureChain)+offset > int(w.checkpointInterval) { + // return false, ErrLongFutureChain + // } // Iterate over the chain and validate against the last checkpoint // It will handle all cases where the incoming chain has atleast one checkpoint From f8c3dd9620045b0ed590fad8c6ab82fa2f57b126 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 29 Mar 2023 11:14:09 +0530 Subject: [PATCH 2/2] eth/downloader/whitelist: fix tests for future chain import --- eth/downloader/whitelist/service_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eth/downloader/whitelist/service_test.go b/eth/downloader/whitelist/service_test.go index df23df2fc9..a91148c761 100644 --- a/eth/downloader/whitelist/service_test.go +++ b/eth/downloader/whitelist/service_test.go @@ -166,7 +166,7 @@ func TestIsValidChain(t *testing.T) { // create a future chain to be imported of length <= `checkpointInterval` chainB := createMockChain(21, 30) // B21->B22...B29->B30 - // case5: Try importing a future chain of acceptable length + // case5: Try importing a future chain (1) res, err = s.IsValidChain(chainA[len(chainA)-1], chainB) require.Equal(t, res, true, "expected chain to be valid") require.Equal(t, err, nil, "expected error to be nil") @@ -174,10 +174,13 @@ func TestIsValidChain(t *testing.T) { // create a future chain to be imported of length > `checkpointInterval` chainB = createMockChain(21, 40) // C21->C22...C39->C40 - // case5: Try importing a future chain of unacceptable length + // Note: Earlier, it used to reject future chains longer than some threshold. + // That check is removed for now. + + // case6: Try importing a future chain (2) res, err = s.IsValidChain(chainA[len(chainA)-1], chainB) - require.Equal(t, res, false, "expected chain to be invalid") - require.Equal(t, err, ErrLongFutureChain, "expected error") + require.Equal(t, res, true, "expected chain to be valid") + require.Equal(t, err, nil, "expected error to be nil") } func TestSplitChain(t *testing.T) {