-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
443 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Autofac; | ||
using Nethermind.Core; | ||
|
||
namespace Nethermind.Db; | ||
|
||
public class DbModule : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
base.Load(builder); | ||
builder.AddSingleton(this); | ||
|
||
// TODO: Have hooks that automatically get these | ||
string[] dbNames = [ | ||
DbNames.State, | ||
DbNames.Code, | ||
DbNames.Metadata, | ||
DbNames.Blocks, | ||
DbNames.Headers, | ||
DbNames.BlockInfos, | ||
DbNames.BadBlocks, | ||
DbNames.Bloom, | ||
DbNames.Metadata, | ||
]; | ||
foreach (string dbName in dbNames) | ||
{ | ||
ConfigureDb(builder, dbName); | ||
} | ||
|
||
ConfigureColumnDb<ReceiptsColumns>(builder, DbNames.Receipts); | ||
} | ||
|
||
private static void ConfigureDb(ContainerBuilder builder, string dbName) | ||
{ | ||
builder.Register((ctx) => | ||
{ | ||
IDbProvider dbProvider = ctx.Resolve<IDbProvider>(); | ||
IDb db = dbProvider.GetDb<IDb>(dbName); | ||
return db; | ||
}) | ||
.ExternallyOwned() | ||
.Named<IDb>(dbName) | ||
.Named<IDbMeta>(dbName); | ||
|
||
builder.Register((ctx) => | ||
{ | ||
IDbProvider dbProvider = ctx.Resolve<IDbProvider>(); | ||
IDb db = dbProvider.GetDb<IDb>(dbName); | ||
return db as ITunableDb ?? new NoopTunableDb(); | ||
}) | ||
.ExternallyOwned() | ||
.Named<ITunableDb>(dbName); | ||
} | ||
|
||
|
||
private static void ConfigureColumnDb<TColumn>(ContainerBuilder builder, string dbName) | ||
{ | ||
builder.Register((ctx) => | ||
{ | ||
IDbProvider dbProvider = ctx.Resolve<IDbProvider>(); | ||
IColumnsDb<TColumn> db = dbProvider.GetColumnDb<TColumn>(dbName); | ||
return db; | ||
}) | ||
.ExternallyOwned() | ||
.As<IColumnsDb<TColumn>>(); | ||
|
||
builder.Register((ctx) => | ||
{ | ||
IDbProvider dbProvider = ctx.Resolve<IDbProvider>(); | ||
IColumnsDb<TColumn> db = dbProvider.GetColumnDb<TColumn>(dbName); | ||
return db as ITunableDb ?? new NoopTunableDb(); | ||
}) | ||
.ExternallyOwned() | ||
.Named<ITunableDb>(dbName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.