Skip to content

Commit

Permalink
Merge pull request #556 from NethermindEth/rc7fix
Browse files Browse the repository at this point in the history
fix for rc7 corrupted receipts db
  • Loading branch information
tkstanczak authored Jun 25, 2019
2 parents 7bb1e10 + b019e87 commit 8cb2bdb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task Can_process_mined_blocks()
MemDb receiptsDb = new MemDb();
MemDb traceDb = new MemDb();
TxPool txPool = new TxPool(NullTxStorage.Instance, Timestamp.Default, ecdsa, specProvider, new TxPoolConfig(), logManager);
IReceiptStorage receiptStorage = new PersistentReceiptStorage(receiptsDb, specProvider, logManager);
IReceiptStorage receiptStorage = new PersistentReceiptStorage(receiptsDb, NullDb.Instance, specProvider, logManager);
BlockTree blockTree = new BlockTree(new MemDb(), new MemDb(), new MemDb(), specProvider, txPool, logManager);
Timestamp timestamp = new Timestamp();
DifficultyCalculator difficultyCalculator = new DifficultyCalculator(specProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void should_add_and_fetch_receipt_from_in_memory_storage()

[Test]
public void should_add_and_fetch_receipt_from_persistent_storage()
=> TestAddAndGetReceipt(new PersistentReceiptStorage(new MemDb(), _specProvider, LimboLogs.Instance));
=> TestAddAndGetReceipt(new PersistentReceiptStorage(new MemDb(), NullDb.Instance, _specProvider, LimboLogs.Instance));

private void TestAddAndGetReceipt(IReceiptStorage storage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace Nethermind.Blockchain.Receipts
public class PersistentReceiptStorage : IReceiptStorage
{
private readonly IDb _database;
private readonly IDb _headersFixDb;
private readonly ISpecProvider _specProvider;
private readonly ILogger _logger;

public PersistentReceiptStorage(IDb database, ISpecProvider specProvider, ILogManager logManager)
public PersistentReceiptStorage(IDb receiptsDb, IDb headersFixDb, ISpecProvider specProvider, ILogManager logManager)
{
_logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
_database = database ?? throw new ArgumentNullException(nameof(database));
_database = receiptsDb ?? throw new ArgumentNullException(nameof(receiptsDb));
_headersFixDb = headersFixDb ?? throw new ArgumentNullException(nameof(headersFixDb));
_specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider));

byte[] lowestBytes = _database.Get(Keccak.Zero);
Expand All @@ -45,6 +47,10 @@ public PersistentReceiptStorage(IDb database, ISpecProvider specProvider, ILogMa
public TxReceipt Find(Keccak hash)
{
var receiptData = _database.Get(hash);
if (receiptData == null)
{
receiptData = _headersFixDb.Get(hash);
}

return receiptData == null
? null
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Runner/Config/IInitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,7 @@ public interface IInitConfig : IConfig

[ConfigItem(Description = "If set to 'false' then transaction receipts will not be stored in the database.", DefaultValue = "true")]
bool StoreReceipts { get; set; }

bool EnableRc7Fix { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Runner/Config/InitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public class InitConfig : IInitConfig
public bool StoreTraces { get; set; } = false;
public bool StoreReceipts { get; set; } = false;

public bool EnableRc7Fix { get; set; } = false;
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Runner/Runners/EthereumRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ private async Task InitBlockchain()
_ethereumEcdsa,
_specProvider,
_txPoolConfig, _logManager);
_receiptStorage = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider, _logManager);
var _rc7FixDb = _initConfig.EnableRc7Fix ? _dbProvider.HeadersDb : NullDb.Instance;
_receiptStorage = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _rc7FixDb, _specProvider, _logManager);

// IDbProvider debugRecorder = new RocksDbProvider(Path.Combine(_dbBasePath, "debug"), dbConfig);
// _dbProvider = new RpcDbProvider(_jsonSerializer, new BasicJsonRpcClient(KnownRpcUris.NethVm1, _jsonSerializer, _logManager), _logManager, debugRecorder);
Expand Down

0 comments on commit 8cb2bdb

Please sign in to comment.