|
17 | 17 | using Nethermind.Core.Test;
|
18 | 18 | using Nethermind.Core.Test.Builders;
|
19 | 19 | using Nethermind.Logging;
|
| 20 | +using Nethermind.State.Repositories; |
20 | 21 | using Nethermind.Stats.Model;
|
21 | 22 | using Nethermind.Synchronization.FastBlocks;
|
22 | 23 | using Nethermind.Synchronization.ParallelSync;
|
23 | 24 | using Nethermind.Synchronization.Peers;
|
24 | 25 | using Nethermind.Synchronization.Reporting;
|
| 26 | +using Nethermind.Synchronization.SyncLimits; |
25 | 27 | using NSubstitute;
|
26 | 28 | using NUnit.Framework;
|
27 | 29 | using BlockTree = Nethermind.Blockchain.BlockTree;
|
@@ -74,6 +76,7 @@ public async Task Can_prepare_3_requests_in_a_row()
|
74 | 76 |
|
75 | 77 | [Test]
|
76 | 78 | public async Task Can_handle_forks_with_persisted_headers()
|
| 79 | + |
77 | 80 | {
|
78 | 81 | IBlockTree remoteBlockTree = CachedBlockTreeBuilder.OfLength(1000);
|
79 | 82 | IBlockTree forkedBlockTree = Build.A.BlockTree().WithStateRoot(Keccak.Compute("1245")).OfChainLength(1000).TestObject;
|
@@ -461,7 +464,7 @@ public async Task Can_insert_all_good_headers_from_dependent_batch_with_missing_
|
461 | 464 | report.FastBlocksHeaders.Returns(new MeasuredProgress());
|
462 | 465 |
|
463 | 466 | ISyncPeerPool syncPeerPool = Substitute.For<ISyncPeerPool>();
|
464 |
| - using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, new TestLogManager(LogLevel.Trace)); |
| 467 | + using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, LimboLogs.Instance); |
465 | 468 | feed.InitializeFeed();
|
466 | 469 | using HeadersSyncBatch? firstBatch = await feed.PrepareRequest();
|
467 | 470 | using HeadersSyncBatch? dependentBatch = await feed.PrepareRequest();
|
@@ -522,7 +525,7 @@ public async Task Does_not_download_persisted_header()
|
522 | 525 | ISyncReport report = Substitute.For<ISyncReport>();
|
523 | 526 | report.HeadersInQueue.Returns(new MeasuredProgress());
|
524 | 527 | report.FastBlocksHeaders.Returns(new MeasuredProgress());
|
525 |
| - using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, new TestLogManager(LogLevel.Trace)); |
| 528 | + using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, LimboLogs.Instance); |
526 | 529 | feed.InitializeFeed();
|
527 | 530 |
|
528 | 531 | void FillBatch(HeadersSyncBatch batch)
|
@@ -583,13 +586,52 @@ public async Task Limits_persisted_headers_dependency()
|
583 | 586 | ISyncReport report = Substitute.For<ISyncReport>();
|
584 | 587 | report.HeadersInQueue.Returns(new MeasuredProgress());
|
585 | 588 | report.FastBlocksHeaders.Returns(new MeasuredProgress());
|
586 |
| - using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, new TestLogManager(LogLevel.Trace)); |
| 589 | + using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, LimboLogs.Instance); |
587 | 590 | feed.InitializeFeed();
|
588 | 591 |
|
589 | 592 | (await feed.PrepareRequest()).Should().NotBe(null);
|
590 | 593 | (await feed.PrepareRequest()).Should().Be(null);
|
591 | 594 | }
|
592 | 595 |
|
| 596 | + [Test] |
| 597 | + public async Task Can_use_persisted_header_without_total_difficulty() |
| 598 | + { |
| 599 | + var peerChain = CachedBlockTreeBuilder.OfLength(1000); |
| 600 | + var pivotHeader = peerChain.FindHeader(700)!; |
| 601 | + var syncConfig = new TestSyncConfig |
| 602 | + { |
| 603 | + FastSync = true, |
| 604 | + PivotNumber = pivotHeader.Number.ToString(), |
| 605 | + PivotHash = pivotHeader.Hash!.ToString(), |
| 606 | + PivotTotalDifficulty = pivotHeader.TotalDifficulty.ToString()! |
| 607 | + }; |
| 608 | + |
| 609 | + IChainLevelInfoRepository levelInfoRepository = new ChainLevelInfoRepository(new TestMemDb()); |
| 610 | + IBlockTree localBlockTree = Build.A.BlockTree(peerChain.FindBlock(0, BlockTreeLookupOptions.None)!, null) |
| 611 | + .WithChainLevelInfoRepository(levelInfoRepository) |
| 612 | + .WithSyncConfig(syncConfig).TestObject; |
| 613 | + |
| 614 | + long firstCheckedHeader = pivotHeader.Number - GethSyncLimits.MaxHeaderFetch; |
| 615 | + for (long i = firstCheckedHeader - 1; i <= firstCheckedHeader; i++) |
| 616 | + { |
| 617 | + BlockHeader header = peerChain.FindHeader(i)!; |
| 618 | + header.TotalDifficulty = null; |
| 619 | + localBlockTree.Insert(header, BlockTreeInsertHeaderOptions.TotalDifficultyNotNeeded).Should().Be(AddBlockResult.Added); |
| 620 | + } |
| 621 | + levelInfoRepository.Delete(firstCheckedHeader - 1); |
| 622 | + |
| 623 | + ISyncPeerPool syncPeerPool = Substitute.For<ISyncPeerPool>(); |
| 624 | + ISyncReport report = Substitute.For<ISyncReport>(); |
| 625 | + report.HeadersInQueue.Returns(new MeasuredProgress()); |
| 626 | + report.FastBlocksHeaders.Returns(new MeasuredProgress()); |
| 627 | + using HeadersSyncFeed feed = new(localBlockTree, syncPeerPool, syncConfig, report, LimboLogs.Instance); |
| 628 | + feed.InitializeFeed(); |
| 629 | + |
| 630 | + (await feed.PrepareRequest()).Should().NotBe(null); |
| 631 | + (await feed.PrepareRequest()).Should().NotBe(null); |
| 632 | + (await feed.PrepareRequest()).Should().NotBe(null); |
| 633 | + } |
| 634 | + |
593 | 635 | [Test]
|
594 | 636 | public async Task Will_never_lose_batch_on_invalid_batch()
|
595 | 637 | {
|
|
0 commit comments