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

feature: Add support for block validation (flashbots_validateBuilderSubmissionV3) #7335

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d33add6
add init code for block validation
rjnrohit Aug 16, 2024
9eb6f70
format files
rjnrohit Aug 16, 2024
ae4357f
verify blobs
rjnrohit Aug 27, 2024
346330d
create block processor
rjnrohit Sep 2, 2024
b802039
add modal validate payload
rjnrohit Sep 4, 2024
6ad5909
format files
rjnrohit Sep 4, 2024
3cf82fe
Merge branch 'master' into feature/flashbots_endpoints
rjnrohit Sep 4, 2024
256da82
add hook step
rjnrohit Sep 5, 2024
a749b8e
Merge branch 'master' into feature/flashbots_endpoints
rjnrohit Sep 5, 2024
09b46b4
add config
rjnrohit Sep 5, 2024
621e297
format files
rjnrohit Sep 5, 2024
ffc25f0
address PR comments
rjnrohit Sep 12, 2024
1bebf60
Hookup BlockValidation plugin in Nethermind.Runner
LukaszRozmej Sep 12, 2024
570dce0
Update Fast Sync configuration in Nethermind repository (#7401)
core-repository-dispatch-app[bot] Sep 8, 2024
bec7a5d
Feature/geth like system tx (#7252)
LukaszRozmej Sep 9, 2024
8b8cd01
Heuristic tx censorship detection (#7259)
Arindam2407 Sep 10, 2024
69e36dd
Refactor `TxValidator` (#7386)
emlautarom1 Sep 10, 2024
17533eb
Moved BlockProductionTimeout to config, increased BlockProductionTime…
MarekM25 Sep 10, 2024
c1f9455
Reduce memory use during Archive Sync (#7407)
benaadams Sep 11, 2024
5aebe9b
Update Supported Networks in Readme (#7412)
MarekM25 Sep 11, 2024
37b9fb4
Change Windows native Allocator (#7418)
benaadams Sep 11, 2024
4a17264
Fast address equals (#7417)
benaadams Sep 11, 2024
413a5b3
Reduce backlog threshold for GC (#7415)
benaadams Sep 11, 2024
bb3753d
Bump unstable to 1.29.0 (#7416)
kamilchodola Sep 11, 2024
4373e5a
enable flashBots module
rjnrohit Sep 12, 2024
a73b41a
format files
rjnrohit Sep 12, 2024
cfe14f2
Merge branch 'master' into feature/flashbots_endpoints
rjnrohit Sep 12, 2024
71e03eb
rename blockValidation -> flashbots
rjnrohit Sep 13, 2024
9f1bf85
rename params
rjnrohit Sep 13, 2024
d203d5e
revert holesky.cfg
rjnrohit Sep 13, 2024
1d7c272
add json required
rjnrohit Sep 19, 2024
2e4775c
Merge branch 'master' into feature/flashbots_endpoints
rjnrohit Sep 19, 2024
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
53 changes: 53 additions & 0 deletions src/Nethermind/Nethermind.BlockValidation/BlockValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Threading.Tasks;
using Nethermind.Api;
using Nethermind.Api.Extensions;
using Nethermind.BlockValidation.Handlers;
using Nethermind.Consensus.Processing;
using Nethermind.JsonRpc.Modules;

namespace Nethermind.BlockValidation;

public class BlockValidation : INethermindPlugin
{
private INethermindApi _api = null!;

private IBlockValidationConfig _blockValidationConfig = null!;

public virtual string Name => "BlockValidation";
public virtual string Description => "BlockValidation";
public string Author => "Nethermind";
public Task InitRpcModules()
{
ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv(
_api.WorldStateManager ?? throw new ArgumentNullException(nameof(_api.WorldStateManager)),
_api.BlockTree ?? throw new ArgumentNullException(nameof(_api.BlockTree)),
_api.SpecProvider,
_api.LogManager
);
ValidateSubmissionHandler validateSubmissionHandler = new ValidateSubmissionHandler(
_api.BlockValidator ?? throw new ArgumentNullException(nameof(_api.BlockValidator)),
readOnlyTxProcessingEnv,
_api.GasLimitCalculator ?? throw new ArgumentNullException(nameof(_api.GasLimitCalculator)),
_blockValidationConfig
);
IFlashbotsRpcModule flashbotsRpcModule = new FlashbotsRpcModule(validateSubmissionHandler);

ArgumentNullException.ThrowIfNull(_api.RpcModuleProvider);
_api.RpcModuleProvider.RegisterSingle(flashbotsRpcModule);
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved

return Task.CompletedTask;
}

public Task Init(INethermindApi api)
{
_api = api;
_blockValidationConfig = api.Config<IBlockValidationConfig>();
return Task.CompletedTask;
}

public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
13 changes: 13 additions & 0 deletions src/Nethermind/Nethermind.BlockValidation/BlockValidationConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Config;

namespace Nethermind.BlockValidation;

public class BlockValidationConfig: IBlockValidationConfig
{
public bool UseBalanceDiffProfit { get; set; } = false ;

public bool ExcludeWithdrawals { get; set; } = false;
}
21 changes: 21 additions & 0 deletions src/Nethermind/Nethermind.BlockValidation/Data/BidTrace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Int256;

namespace Nethermind.BlockValidation.Data;

public readonly struct BidTrace
{
public ulong Slot { get; }
public Hash256 ParentHash { get; }
public Hash256 BlockHash { get; }
public PublicKey BuilderPublicKey { get; }
public PublicKey ProposerPublicKey { get; }
public Address ProposerFeeRecipient { get; }
public long GasLimit { get; }
public long GasUsed { get; }
public UInt256 Value { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Text.Json.Serialization;
using Nethermind.JsonRpc;

namespace Nethermind.BlockValidation.Data;

/// <summary>
/// Represents the result of a block validation.
/// </summary>
public class BlockValidationResult
{

public static ResultWrapper<BlockValidationResult> Invalid(string error)
{
return ResultWrapper<BlockValidationResult>.Success(new BlockValidationResult
{
Status = BlockValidationStatus.Invalid,
ValidationError = error
});
}

public static ResultWrapper<BlockValidationResult> Valid()
{
return ResultWrapper<BlockValidationResult>.Success(new BlockValidationResult
{
Status = BlockValidationStatus.Valid
});
}

public static ResultWrapper<BlockValidationResult> Error(string error)
{
return ResultWrapper<BlockValidationResult>.Fail(error);
}

/// <summary>
/// The status of the validation of the builder submissions
/// </summary>
public string Status { get; set; } = BlockValidationStatus.Invalid;

/// <summary>
/// Message providing additional details on the validation error if the payload is classified as <see cref="ValidationStatus.Invalid"/>.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public string? ValidationError { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.BlockValidation.Data;

public static class BlockValidationStatus
{
/// <summary>
/// The submissions are invalid.
/// </summary>
public const string Invalid = "Invalid";

/// <summary>
/// The submissions are valid.
/// </summary>
public const string Valid = "Valid";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core.Crypto;

namespace Nethermind.BlockValidation.Data;

public class BuilderBlockValidationRequest
{
/// <summary>
/// The block hash of the parent beacon block.
/// <see cref=https://github.com/flashbots/builder/blob/df9c765067d57ab4b2d0ad39dbb156cbe4965778/eth/block-validation/api.go#L198"/>
/// </summary>
public Hash256 ParentBeaconBlockRoot { get; set; } = Keccak.Zero;

public long RegisterGasLimit { get; set; }

public SubmitBlockRequest BlockRequest { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core.Crypto;
using Nethermind.Merge.Plugin.Data;

namespace Nethermind.BlockValidation.Data;

public readonly struct SubmitBlockRequest
{
private readonly ExecutionPayload _executionPayload;
private readonly BlobsBundleV1 _blobsBundle;

public SubmitBlockRequest(ExecutionPayload executionPayload, BlobsBundleV1 blobsBundle, BidTrace message)
{
_executionPayload = executionPayload;
_blobsBundle = blobsBundle;
Message = message;
}
public readonly ExecutionPayload ExecutionPayload => _executionPayload;
public readonly BlobsBundleV1 BlobsBundle => _blobsBundle;
public BidTrace Message { get; }
}
23 changes: 23 additions & 0 deletions src/Nethermind/Nethermind.BlockValidation/FlashbotsRpcModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Threading.Tasks;
using Nethermind.BlockValidation.Data;
using Nethermind.BlockValidation.Handlers;
using Nethermind.JsonRpc;

namespace Nethermind.BlockValidation;

public class FlashbotsRpcModule : IFlashbotsRpcModule
{
private readonly ValidateSubmissionHandler _validateSubmissionHandler;

public FlashbotsRpcModule(ValidateSubmissionHandler validateSubmissionHandler)
{
_validateSubmissionHandler = validateSubmissionHandler;
}

Task<ResultWrapper<BlockValidationResult>> IFlashbotsRpcModule.flashbots_validateBuilderSubmissionV3(BuilderBlockValidationRequest @params) =>
_validateSubmissionHandler.ValidateSubmission(@params);

}
Loading
Loading