Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full pruning #3096

Merged
merged 80 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
e06b879
Add HighestPersistedState to BlockTree
LukaszRozmej May 20, 2021
c61f779
RocksDbSettings cloning
LukaszRozmej May 21, 2021
6b24404
MemDbFactoryAdapter to use IRocksDbFactory
LukaszRozmej May 21, 2021
5edf619
Pruning Triggers
LukaszRozmej May 21, 2021
265cab3
Add StateDbDuplicateWrites metrics
LukaszRozmej May 21, 2021
903630a
Add FullPruningDb
LukaszRozmej May 21, 2021
1e02ad7
Add FullPruner and CopyTreeVisitor
LukaszRozmej May 21, 2021
d67c0c2
CopyTreeVisitor add logs
LukaszRozmej May 25, 2021
d879f97
CopyTreeVisitor add tests
LukaszRozmej May 25, 2021
f4e13b2
Rename RocksDbSizePruningTrigger to PathSizePruningTrigger
LukaszRozmej May 25, 2021
5ad5cf0
add tests for PathSizePruningTrigger
LukaszRozmej May 25, 2021
12948ef
Move test projects to c# 9
LukaszRozmej May 25, 2021
c5c9b7c
Add DiskFreeSpacePruningTrigger Tests
LukaszRozmej May 25, 2021
8c7c8ec
Add Build.A.Trie and TrieBuilder
LukaszRozmej May 25, 2021
432471c
Move PruningConfig add PruningMode
LukaszRozmej May 25, 2021
ee9df91
FullPruningInnerDbFactory to correctly read db index
LukaszRozmej May 25, 2021
6e97196
Add RocksDbSettings clone test
LukaszRozmej May 25, 2021
0825f42
Change FullPruningDb, add tests for it
LukaszRozmej May 25, 2021
3afc8f6
Rename MemDbFactoryToRocksDbAdapter
LukaszRozmej May 25, 2021
5e7b467
Change StandardDbInitializer to support full pruning
LukaszRozmej May 25, 2021
b5e66e9
Add FullPruner tests
LukaszRozmej May 25, 2021
9f9ec28
Add TrieStoreBondryWatcher to encapsulate and reuse connection betwee…
LukaszRozmej May 26, 2021
40cd8b3
Fix HighestPersistedState null serialization
LukaszRozmej May 26, 2021
5edb1f6
Fix DbOnTheRocks Clear by delete (needed dispose first) and special p…
LukaszRozmej May 26, 2021
9cdde84
Add FullPruningDiskTest
LukaszRozmej May 26, 2021
c486b31
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej May 26, 2021
37e256c
Add PruningConfig.FullPruningThresholdMb and PruningConfig.FullPrunin…
LukaszRozmej May 26, 2021
e9d127a
Add IFullPruningDb.GetPath
LukaszRozmej May 26, 2021
0987fb1
Initialize FullPruner
LukaszRozmej May 26, 2021
99461de
Better metrics
LukaszRozmej May 26, 2021
612359f
BlockTree highest persisted state fix
LukaszRozmej May 26, 2021
f8722b7
fixes
LukaszRozmej Jun 4, 2021
23a8c15
Duplicate batches in pruning, start full pruning only between blocks,…
LukaszRozmej Jun 6, 2021
3d64580
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej Jun 8, 2021
de80437
Fix FullPruningDb canellation
LukaszRozmej Jun 10, 2021
96cf067
Fix indexing db in PathSizePruningTrigger
LukaszRozmej Jun 10, 2021
66c42bd
Fix FullPruner, use head.StateRoot
LukaszRozmej Jun 10, 2021
db7f3ee
fix delete database
LukaszRozmej Jun 21, 2021
af91f1f
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej Jun 22, 2021
c0d110c
fix tests
LukaszRozmej Jun 22, 2021
c3097bb
fix tests
LukaszRozmej Jun 22, 2021
51882f6
Change config a bit
LukaszRozmej Jun 22, 2021
0cb7237
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej Jun 25, 2021
0caeb24
Make CopyTreeVisitor parallel
LukaszRozmej Jun 25, 2021
2a8fbc7
Move to VisitingOptions
LukaszRozmej Jun 25, 2021
000561f
add FullPruningMaxDegreeOfParallelism config option
LukaszRozmej Jun 25, 2021
9c51de9
Remove SupportsParallelVisits
LukaszRozmej Jun 25, 2021
e177d2c
changes
LukaszRozmej Jul 1, 2021
3de599a
Merge remote-tracking branch 'origin/master' into FullPruning2
LukaszRozmej Oct 5, 2021
270c714
Add full pruned configs
jmederosalvarado Dec 3, 2021
4e14e9f
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej Dec 27, 2021
b26bfe2
Fix issues with TrieStore with both archive and mem pruning modes.
LukaszRozmej Dec 28, 2021
92bae42
Refactor + comments
LukaszRozmej Dec 28, 2021
515b80f
FIx initialize pruning trigger when only Manual pruning is enabled
LukaszRozmej Dec 30, 2021
08a0be3
Move parallelism to be based on Semaphore
LukaszRozmej Dec 30, 2021
1b0d37d
PruningTriggerPersistenceStrategy experiment
LukaszRozmej Dec 31, 2021
02c50ee
Add description how Full Pruning works
LukaszRozmej Dec 31, 2021
a2237a5
Merge remote-tracking branch 'origin/master' into FullPrunning-trigger
LukaszRozmej Jan 18, 2022
55163c8
Fix issues with hybrid pruning
LukaszRozmej Jan 24, 2022
7ef8b55
fix resolving storage root
LukaszRozmej Jan 24, 2022
9dc7bfc
Merge remote-tracking branch 'origin/master' into FullPrunning-trigger
LukaszRozmej Jan 26, 2022
49e5800
Merge branch 'FullPrunning-trigger' into FullPruning
LukaszRozmej Jan 26, 2022
b508446
refactor merge
LukaszRozmej Jan 26, 2022
366943e
Add pruning delay to make sure we won't break ssds
LukaszRozmej Jan 26, 2022
b9fbc2d
optimize ShouldPersist
LukaszRozmej Jan 26, 2022
cab11d4
Add TrieStats Levels
LukaszRozmej Jan 28, 2022
e8e634d
Make TrieStats collecting parallel
LukaszRozmej Jan 28, 2022
1ae5cac
Make Trie Stats collecting in the background
LukaszRozmej Jan 28, 2022
0ed890f
Hide PruningConfig.Enabled from docs
LukaszRozmej Jan 28, 2022
b73598c
Merge remote-tracking branch 'origin/FullPrunning-trigger' into FullP…
LukaszRozmej Jan 28, 2022
b80d8aa
Log Exception when collecting trie stats
dceleda Jan 30, 2022
05d3902
Always register FullPruningDb if someone disables it in the future
LukaszRozmej Jan 31, 2022
37b95b8
small refactor
LukaszRozmej Feb 1, 2022
d8d1b97
Merge branch 'FullPrunning-trigger' into FullPruning
LukaszRozmej Feb 1, 2022
382ecae
Set VisitContext.MaxDegreeOfParallelism default to 1
LukaszRozmej Feb 1, 2022
3af5453
Remove IDb.Innermost
LukaszRozmej Feb 1, 2022
7ed8b08
Remove non-default module types
LukaszRozmej Feb 1, 2022
23d5f53
fix tests
LukaszRozmej Feb 2, 2022
5476935
review comments
LukaszRozmej Feb 4, 2022
be4e38c
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej Feb 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Nethermind.Blockchain;
using Nethermind.Blockchain.Comparers;
using Nethermind.Blockchain.Filters;
using Nethermind.Blockchain.FullPruning;
using Nethermind.Blockchain.Processing;
using Nethermind.Blockchain.Producers;
using Nethermind.Blockchain.Rewards;
Expand Down Expand Up @@ -96,5 +97,7 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory
IGasPriceOracle? GasPriceOracle { get; set; }

IEthSyncingInfo? EthSyncingInfo { get; set; }

CompositePruningTrigger PruningTrigger { get; }
Copy link
Member

@tkstanczak tkstanczak Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an API that can be used by externally written plugins. In order to minimize disruption to external plugins in the future this class should be replaced with an interface, possibly a simple one called ITrigger or IPruningTrigger if it requires some data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that there can be multiple triggers, but we need a central place to collect them, hence the class that can handle multiple interface items via Add.

}
}
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Nethermind.Blockchain.Comparers;
using Nethermind.Blockchain.Filters;
using Nethermind.Blockchain.Find;
using Nethermind.Blockchain.FullPruning;
using Nethermind.Blockchain.Processing;
using Nethermind.Blockchain.Producers;
using Nethermind.Blockchain.Receipts;
Expand Down Expand Up @@ -90,8 +91,7 @@ public IBlockchainBridge CreateBlockchainBridge()
LogManager);

IMiningConfig miningConfig = ConfigProvider.GetConfig<IMiningConfig>();
ISyncConfig syncConfig = ConfigProvider.GetConfig<ISyncConfig>();


return new BlockchainBridge(
readOnlyTxProcessingEnv,
TxPool,
Expand Down Expand Up @@ -201,5 +201,6 @@ public IBlockchainBridge CreateBlockchainBridge()
public DisposableStack DisposeStack { get; } = new();
public IReadOnlyList<INethermindPlugin> Plugins { get; } = new List<INethermindPlugin>();
public IList<IPublisher> Publishers { get; } = new List<IPublisher>(); // this should be called publishers
public CompositePruningTrigger PruningTrigger { get; } = new();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Nethermind.Blockchain.FullPruning;
using Nethermind.Core.Test.Builders;
using Nethermind.Db;
using Nethermind.Db.FullPruning;
using Nethermind.Logging;
using Nethermind.State;
using Nethermind.Trie;
using Nethermind.Trie.Pruning;
using NSubstitute;
using NUnit.Framework;

namespace Nethermind.Blockchain.Test.FullPruning
{
[Parallelizable(ParallelScope.All)]
public class CopyTreeVisitorTests
{
[Test]
public void copies_state_between_dbs()
{
MemDb trieDb = new();
MemDb clonedDb = new();
CopyDb(StartPruning(trieDb, clonedDb), trieDb, clonedDb);

clonedDb.Count.Should().Be(132);
clonedDb.Keys.Should().BeEquivalentTo(trieDb.Keys);
clonedDb.Values.Should().BeEquivalentTo(trieDb.Values);
}

[Test]
public async Task cancel_coping_state_between_dbs()
{
MemDb trieDb = new();
MemDb clonedDb = new();
IPruningContext pruningContext = StartPruning(trieDb, clonedDb);
Task task = Task.Run(() => CopyDb(pruningContext, trieDb, clonedDb));

pruningContext?.CancellationTokenSource.Cancel();

await task;

clonedDb.Count.Should().BeLessThan(trieDb.Count);
}

private static IPruningContext CopyDb(IPruningContext pruningContext, MemDb trieDb, MemDb clonedDb)
{
LimboLogs logManager = LimboLogs.Instance;
PatriciaTree trie = Build.A.Trie(trieDb).WithAccountsByIndex(0, 100).TestObject;
IStateReader stateReader = new StateReader(new TrieStore(trieDb, logManager), new MemDb(), logManager);

using CopyTreeVisitor copyTreeVisitor = new(pruningContext, logManager);
stateReader.RunTreeVisitor(copyTreeVisitor, trie.RootHash);
return pruningContext;
}

private static IPruningContext StartPruning(MemDb trieDb, MemDb clonedDb)
{
IRocksDbFactory rocksDbFactory = Substitute.For<IRocksDbFactory>();
rocksDbFactory.CreateDb(Arg.Any<RocksDbSettings>()).Returns(trieDb, clonedDb);

FullPruningDb fullPruningDb = new(new RocksDbSettings("Test", "Test"), rocksDbFactory);
fullPruningDb.TryStartPruning(out IPruningContext pruningContext);
return pruningContext;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.IO.Abstractions;
using FluentAssertions;
using MathGmp.Native;
using Nethermind.Blockchain.FullPruning;
using Nethermind.Core.Timers;
using NSubstitute;
using NUnit.Framework;

namespace Nethermind.Blockchain.Test.FullPruning
{
[Parallelizable(ParallelScope.All)]
public class DiskFreeSpacePruningTriggerTests
{
[TestCase(999, ExpectedResult = true)]
[TestCase(1000, ExpectedResult = false)]
public bool triggers_on_low_free_space(int availableFreeSpace)
{
ITimerFactory timerFactory = Substitute.For<ITimerFactory>();
ITimer timer = Substitute.For<ITimer>();
timerFactory.CreateTimer(Arg.Any<TimeSpan>()).Returns(timer);

string path = "path";
IFileSystem fileSystem = Substitute.For<IFileSystem>();
fileSystem.Path.GetFullPath(path).Returns(path);
fileSystem.Path.GetPathRoot(path).Returns(path);
fileSystem.DriveInfo.FromDriveName(path).AvailableFreeSpace.Returns(availableFreeSpace);

bool triggered = false;

DiskFreeSpacePruningTrigger trigger = new(path, 1000, timerFactory, fileSystem);
trigger.Prune += (o, e) => triggered = true;

timer.Elapsed += Raise.Event();
return triggered;
}
}
}
Loading