Skip to content

Commit

Permalink
Add endpoint to support rBuilder payload (#8160)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit authored Feb 6, 2025
1 parent 337c6ca commit 3c3c117
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 22 deletions.
50 changes: 32 additions & 18 deletions src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,37 @@

namespace Nethermind.Flashbots.Data;

public class BidTrace(
ulong slot,
Hash256 blockHash,
PublicKey builderPublicKey,
PublicKey proposerPublicKey,
Address proposerFeeRecipient,
long gasLimit,
long gasUsed,
UInt256 value)
public class BidTrace
{
public ulong Slot { get; } = slot;
public required Hash256 ParentHash { get; set; }
public Hash256 BlockHash { get; } = blockHash;
public PublicKey BuilderPublicKey { get; } = builderPublicKey;
public PublicKey ProposerPublicKey { get; } = proposerPublicKey;
public Address ProposerFeeRecipient { get; } = proposerFeeRecipient;
public long GasLimit { get; } = gasLimit;
public long GasUsed { get; } = gasUsed;
public UInt256 Value { get; } = value;
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; }

public BidTrace(
ulong slot,
Hash256 parentHash,
Hash256 blockHash,
PublicKey builderPublicKey,
PublicKey proposerPublicKey,
Address proposerFeeRecipient,
long gasLimit,
long gasUsed,
UInt256 value)
{
Slot = slot;
ParentHash = parentHash;
BlockHash = blockHash;
BuilderPublicKey = builderPublicKey;
ProposerPublicKey = proposerPublicKey;
ProposerFeeRecipient = proposerFeeRecipient;
GasLimit = gasLimit;
GasUsed = gasUsed;
Value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ namespace Nethermind.Flashbots.Data;

public class BuilderBlockValidationRequest
{
public BuilderBlockValidationRequest(Hash256 parentBeaconBlockRoot, long registerGasLimit, SubmitBlockRequest blockRequest)
{
ParentBeaconBlockRoot = parentBeaconBlockRoot;
RegisterGasLimit = registerGasLimit;
BlockRequest = blockRequest;
}

/// <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>
[JsonRequired]
public required Hash256 ParentBeaconBlockRoot { get; set; }
public Hash256 ParentBeaconBlockRoot { get; set; }

[JsonRequired]
public long RegisterGasLimit { get; set; }

[JsonRequired]
public required SubmitBlockRequest BlockRequest { get; set; }
public SubmitBlockRequest BlockRequest { get; set; }
}
46 changes: 46 additions & 0 deletions src/Nethermind/Nethermind.Flashbots/Data/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.Flashbots.Data;

public class Message(
ulong slot,
Hash256 parent_hash,
Hash256 block_hash,
PublicKey builder_pubkey,
PublicKey proposer_pubkey,
Address proposer_fee_recipient,
long gas_limit,
long gas_used,
UInt256 value)
{
public ulong slot { get; } = slot;
public required Hash256 parent_hash { get; set; } = parent_hash;
public Hash256 block_hash { get; } = block_hash;
public PublicKey builder_pubkey { get; } = builder_pubkey;
public PublicKey proposer_pubkey { get; } = proposer_pubkey;
public Address proposer_fee_recipient { get; } = proposer_fee_recipient;
public long gas_limit { get; } = gas_limit;
public long gas_used { get; } = gas_used;
public UInt256 value { get; } = value;

public BidTrace ToBidTrace()
{
return new BidTrace(
slot,
parent_hash,
block_hash,
builder_pubkey,
proposer_pubkey,
proposer_fee_recipient,
gas_limit,
gas_used,
value
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Text.Json.Serialization;
using Nethermind.Core.Crypto;
using Nethermind.Merge.Plugin.Data;

namespace Nethermind.Flashbots.Data;

public class RBuilderBlockValidationRequest
{
public RBuilderBlockValidationRequest(
Message message,
RExecutionPayloadV3 execution_payload,
BlobsBundleV1 blobs_bundle,
byte[] signature,
long registered_gas_limit,
Hash256 withdrawals_root,
Hash256 parent_beacon_block_root)
{
this.message = message;
this.execution_payload = execution_payload;
this.blobs_bundle = blobs_bundle;
this.signature = signature;
this.registered_gas_limit = registered_gas_limit;
this.withdrawals_root = withdrawals_root;
this.parent_beacon_block_root = parent_beacon_block_root;
}

[JsonRequired]
public Message message { get; set; }

[JsonRequired]
public RExecutionPayloadV3 execution_payload { get; set; }

[JsonRequired]
public BlobsBundleV1 blobs_bundle { get; set; }

[JsonRequired]
public byte[] signature { get; set; }

[JsonRequired]
public long registered_gas_limit { get; set; }

[JsonRequired]
public Hash256 withdrawals_root { get; set; }

[JsonRequired]
public Hash256 parent_beacon_block_root { get; set; }
}
91 changes: 91 additions & 0 deletions src/Nethermind/Nethermind.Flashbots/Data/RExecutionPayloadV3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

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

public class RExecutionPayloadV3
{
public Hash256 parent_hash { get; set; }
public Address fee_recipient { get; set; }
public Hash256 state_root { get; set; }
public Hash256 receipts_root { get; set; }
public Bloom logs_bloom { get; set; }
public Hash256 prev_randao { get; set; }
public long block_number { get; set; }
public long gas_limit { get; set; }
public long gas_used { get; set; }
public ulong timestamp { get; set; }
public byte[] extra_data { get; set; }
public UInt256 base_fee_per_gas { get; set; }
public Hash256 block_hash { get; set; }
public byte[][] transactions { get; set; }
public Withdrawal[]? withdrawals { get; set; }
public ulong? blob_gas_used { get; set; }
public ulong? excess_blob_gas { get; set; }

public ExecutionPayloadV3 ToExecutionPayloadV3()
{
return new ExecutionPayloadV3
{
ParentHash = parent_hash,
FeeRecipient = fee_recipient,
StateRoot = state_root,
ReceiptsRoot = receipts_root,
LogsBloom = logs_bloom,
PrevRandao = prev_randao,
BlockNumber = block_number,
GasLimit = gas_limit,
GasUsed = gas_used,
Timestamp = timestamp,
ExtraData = extra_data,
BaseFeePerGas = base_fee_per_gas,
BlockHash = block_hash,
Transactions = transactions,
Withdrawals = withdrawals,
BlobGasUsed = blob_gas_used,
ExcessBlobGas = excess_blob_gas
};
}

public RExecutionPayloadV3(
Hash256 parent_hash,
Address fee_recipient,
Hash256 state_root,
Hash256 receipts_root,
Bloom logs_bloom,
Hash256 prev_randao,
long block_number,
long gas_limit,
long gas_used,
ulong timestamp,
byte[] extra_data,
UInt256 base_fee_per_gas,
Hash256 block_hash,
byte[][] transactions,
Withdrawal[]? withdrawals,
ulong? blob_gas_used,
ulong? excess_blob_gas
)
{
this.parent_hash = parent_hash;
this.fee_recipient = fee_recipient;
this.state_root = state_root;
this.receipts_root = receipts_root;
this.logs_bloom = logs_bloom;
this.prev_randao = prev_randao;
this.block_number = block_number;
this.gas_limit = gas_limit;
this.gas_used = gas_used;
this.timestamp = timestamp;
this.extra_data = extra_data;
this.base_fee_per_gas = base_fee_per_gas;
this.block_hash = block_hash;
this.transactions = transactions;
this.withdrawals = withdrawals;
this.blob_gas_used = blob_gas_used;
this.excess_blob_gas = excess_blob_gas;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public class SubmitBlockRequest
private readonly ExecutionPayloadV3 _executionPayload;
private readonly BlobsBundleV1 _blobsBundle;

public SubmitBlockRequest(ExecutionPayloadV3 executionPayload, BlobsBundleV1 blobsBundle, BidTrace message)
public SubmitBlockRequest(ExecutionPayloadV3 executionPayload, BlobsBundleV1 blobsBundle, BidTrace message, byte[] signature)
{
_executionPayload = executionPayload;
_blobsBundle = blobsBundle;
Message = message;
Signature = signature;
}
public ExecutionPayloadV3 ExecutionPayload => _executionPayload;
public BlobsBundleV1 BlobsBundle => _blobsBundle;
public BidTrace Message { get; }
public byte[] Signature { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Threading.Tasks;
using Nethermind.Core.Crypto;
using Nethermind.Flashbots.Data;
using Nethermind.Flashbots.Handlers;
using Nethermind.JsonRpc;
using Nethermind.Merge.Plugin.Data;

namespace Nethermind.Flashbots.Modules.Flashbots;

Expand All @@ -21,4 +21,19 @@ public FlashbotsRpcModule(ValidateSubmissionHandler validateSubmissionHandler)
Task<ResultWrapper<FlashbotsResult>> IFlashbotsRpcModule.flashbots_validateBuilderSubmissionV3(BuilderBlockValidationRequest @params) =>
_validateSubmissionHandler.ValidateSubmission(@params);

Task<ResultWrapper<FlashbotsResult>> IFlashbotsRpcModule.flashbots_validateRBuilderSubmissionV3(RBuilderBlockValidationRequest @params)
{
ExecutionPayloadV3 executionPayload = @params.execution_payload.ToExecutionPayloadV3();
BuilderBlockValidationRequest builderBlockValidationRequest = new BuilderBlockValidationRequest(
@params.parent_beacon_block_root,
@params.registered_gas_limit,
new SubmitBlockRequest(
executionPayload,
@params.blobs_bundle,
@params.message.ToBidTrace(),
@params.signature
)
);
return _validateSubmissionHandler.ValidateSubmission(builderBlockValidationRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public interface IFlashbotsRpcModule : IRpcModule
IsSharable = false,
IsImplemented = true)]
Task<ResultWrapper<FlashbotsResult>> flashbots_validateBuilderSubmissionV3(BuilderBlockValidationRequest @params);

[JsonRpcMethod(
Description = " validate the builder submissions as received by a relay",
IsSharable = false,
IsImplemented = true)]
Task<ResultWrapper<FlashbotsResult>> flashbots_validateRBuilderSubmissionV3(RBuilderBlockValidationRequest @params);
}

0 comments on commit 3c3c117

Please sign in to comment.