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

fix AuRa pre-warmer issues #7277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Nethermind/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Copyright>Demerzel Solutions Limited</Copyright>
<Product>Nethermind</Product>
<SourceRevisionId Condition="'$(Commit)' != ''">$(Commit)</SourceRevisionId>
<VersionPrefix>1.27.0</VersionPrefix>
<VersionPrefix>1.27.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public AuRaBlockProcessor(
IAuRaValidator? auRaValidator,
ITxFilter? txFilter = null,
AuRaContractGasLimitOverride? gasLimitOverride = null,
ContractRewriter? contractRewriter = null)
ContractRewriter? contractRewriter = null,
IBlockCachePreWarmer? preWarmer = null)
: base(
specProvider,
blockValidator,
Expand All @@ -55,7 +56,8 @@ public AuRaBlockProcessor(
receiptStorage,
new BlockhashStore(blockTree, specProvider, stateProvider),
logManager,
withdrawalProcessor)
withdrawalProcessor,
preWarmer: preWarmer)
{
_specProvider = specProvider;
_blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected override async Task InitBlockchain()
}
}

protected override BlockProcessor CreateBlockProcessor()
protected override BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWarmer)
{
if (_api.SpecProvider is null) throw new StepDependencyException(nameof(_api.SpecProvider));
if (_api.ChainHeadStateProvider is null) throw new StepDependencyException(nameof(_api.ChainHeadStateProvider));
Expand All @@ -89,10 +89,10 @@ protected override BlockProcessor CreateBlockProcessor()
_api,
new ServiceTxFilter(_api.SpecProvider));

return NewAuraBlockProcessor(auRaTxFilter);
return NewAuraBlockProcessor(auRaTxFilter, preWarmer);
}

protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter)
protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, BlockCachePreWarmer? preWarmer)
{
IDictionary<long, IDictionary<Address, byte[]>> rewriteBytecode = _api.ChainSpec.AuRa.RewriteBytecode;
ContractRewriter? contractRewriter = rewriteBytecode?.Count > 0 ? new ContractRewriter(rewriteBytecode) : null;
Expand All @@ -112,7 +112,8 @@ protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter)
CreateAuRaValidator(),
txFilter,
GetGasLimitCalculator(),
contractRewriter
contractRewriter,
preWarmer: preWarmer
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ the previous head state.*/
}

using CancellationTokenSource cancellationTokenSource = new();
Task? preWarmTask = suggestedBlock.Transactions.Length < 3 ?
null :
_preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token);
Task? preWarmTask = suggestedBlock.Transactions.Length < 3
? null
: _preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token);
(Block processedBlock, TxReceipt[] receipts) = ProcessOne(suggestedBlock, options, blockTracer);
cancellationTokenSource.Cancel();
preWarmTask?.GetAwaiter().GetResult();
Expand Down Expand Up @@ -159,9 +159,12 @@ the previous head state.*/
{
_logger.Trace($"Encountered exception {ex} while processing blocks.");
RestoreBranch(previousBranchStateRoot);
_preWarmer?.ClearCaches();
throw;
}
finally
{
_preWarmer?.ClearCaches();
}
}

public event EventHandler<BlocksProcessingEventArgs>? BlocksProcessing;
Expand Down
14 changes: 6 additions & 8 deletions src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ protected virtual Task InitBlockchain()

setApi.TxPoolInfoProvider = new TxPoolInfoProvider(chainHeadInfoProvider.AccountStateProvider, txPool);
setApi.GasPriceOracle = new GasPriceOracle(getApi.BlockTree!, getApi.SpecProvider, _api.LogManager, blocksConfig.MinGasPrice);
IBlockProcessor mainBlockProcessor = setApi.MainBlockProcessor = CreateBlockProcessor();
PreBlockCaches? preBlockCaches = (_api.WorldState as IPreBlockCaches)?.Caches;
BlockCachePreWarmer? preWarmer = blocksConfig.PreWarmStateOnBlockProcessing
? new(new(_api.WorldStateManager!, _api.BlockTree!, _api.SpecProvider, _api.LogManager, preBlockCaches), _api.SpecProvider, _api.LogManager, preBlockCaches)
: null;
IBlockProcessor mainBlockProcessor = setApi.MainBlockProcessor = CreateBlockProcessor(preWarmer);

BlockchainProcessor blockchainProcessor = new(
getApi.BlockTree,
Expand Down Expand Up @@ -212,7 +216,7 @@ protected virtual TxPool.TxPool CreateTxPool() =>
_api.LogManager);

// TODO: remove from here - move to consensus?
protected virtual BlockProcessor CreateBlockProcessor()
protected virtual BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWarmer)
{
if (_api.DbProvider is null) throw new StepDependencyException(nameof(_api.DbProvider));
if (_api.RewardCalculatorSource is null) throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
Expand All @@ -221,13 +225,7 @@ protected virtual BlockProcessor CreateBlockProcessor()
if (_api.WorldStateManager is null) throw new StepDependencyException(nameof(_api.WorldStateManager));
if (_api.SpecProvider is null) throw new StepDependencyException(nameof(_api.SpecProvider));

IBlocksConfig blocksConfig = _api.Config<IBlocksConfig>();
IWorldState worldState = _api.WorldState!;

PreBlockCaches? preBlockCaches = (worldState as IPreBlockCaches)?.Caches;
BlockCachePreWarmer? preWarmer = blocksConfig.PreWarmStateOnBlockProcessing
? new(new(_api.WorldStateManager, _api.BlockTree, _api.SpecProvider, _api.LogManager, preBlockCaches), _api.SpecProvider, _api.LogManager, preBlockCaches)
: null;
return new BlockProcessor(
_api.SpecProvider,
_api.BlockValidator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public AuRaMergeBlockProcessor(
IAuRaValidator? validator,
ITxFilter? txFilter = null,
AuRaContractGasLimitOverride? gasLimitOverride = null,
ContractRewriter? contractRewriter = null
ContractRewriter? contractRewriter = null,
IBlockCachePreWarmer? preWarmer = null
) : base(
specProvider,
blockValidator,
Expand All @@ -47,7 +48,8 @@ public AuRaMergeBlockProcessor(
validator,
txFilter,
gasLimitOverride,
contractRewriter
contractRewriter,
preWarmer
)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public InitializeBlockchainAuRaMerge(AuRaNethermindApi api) : base(api)
_api = api;
}

protected override AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter)
protected override AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, BlockCachePreWarmer? preWarmer)
{
IDictionary<long, IDictionary<Address, byte[]>> rewriteBytecode = _api.ChainSpec.AuRa.RewriteBytecode;
ContractRewriter? contractRewriter = rewriteBytecode?.Count > 0 ? new ContractRewriter(rewriteBytecode) : null;
Expand All @@ -47,7 +47,8 @@ protected override AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter)
CreateAuRaValidator(),
txFilter,
GetGasLimitCalculator(),
contractRewriter
contractRewriter,
preWarmer: preWarmer
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using Nethermind.Blockchain.Blocks;
using Nethermind.Blockchain.Services;
using Nethermind.Config;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Producers;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Evm;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Init.Steps;
Expand Down Expand Up @@ -82,7 +84,7 @@ protected override IBlockValidator CreateBlockValidator()
return new InvalidBlockInterceptor(blockValidator, _api.InvalidChainTracker, _api.LogManager);
}

protected override BlockProcessor CreateBlockProcessor()
protected override BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWarmer)
{
if (_api.DbProvider is null) throw new StepDependencyException(nameof(_api.DbProvider));
if (_api.RewardCalculatorSource is null) throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
Expand All @@ -105,7 +107,9 @@ protected override BlockProcessor CreateBlockProcessor()
new BlockhashStore(_api.BlockTree, _api.SpecProvider, _api.WorldState),
_api.LogManager,
_api.SpecHelper,
contractRewriter);
contractRewriter,
new BlockProductionWithdrawalProcessor(new NullWithdrawalProcessor()),
preWarmer: preWarmer);
}

protected override IUnclesValidator CreateUnclesValidator() => Always.Valid;
Expand Down
6 changes: 4 additions & 2 deletions src/Nethermind/Nethermind.Optimism/OptimismBlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public OptimismBlockProcessor(
ILogManager? logManager,
IOPConfigHelper opConfigHelper,
Create2DeployerContractRewriter contractRewriter,
IWithdrawalProcessor? withdrawalProcessor = null)
IWithdrawalProcessor? withdrawalProcessor = null,
IBlockCachePreWarmer? preWarmer = null)
: base(specProvider, blockValidator, rewardCalculator, blockTransactionsExecutor,
stateProvider, receiptStorage, blockhashStore, logManager, withdrawalProcessor, ReceiptsRootCalculator.Instance)
stateProvider, receiptStorage, blockhashStore, logManager, withdrawalProcessor,
ReceiptsRootCalculator.Instance, preWarmer)
{
ArgumentNullException.ThrowIfNull(stateProvider);
_contractRewriter = contractRewriter;
Expand Down
Loading