-
Notifications
You must be signed in to change notification settings - Fork 651
Simple engine API versioning and simplified message version validation #5157
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
Merged
MarekM25
merged 11 commits into
feature/shanghai-engine-failure-unify
from
feature/engine-api-simple-versioning
Jan 18, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
db05f6c
Simple versioning and simplified transparent message version validation
LukaszRozmej 500352d
remove redundant code
LukaszRozmej 43b8761
fix
LukaszRozmej 4dac228
fix v2
LukaszRozmej 4d95b5d
fix searching for ReleaseSpec, prioritizing TImeStamp if not null
LukaszRozmej 0a7af25
More refactors
LukaszRozmej ce0f314
revert change in ForkInfo
LukaszRozmej a58b393
revert changes
LukaszRozmej 06afdb5
fix
LukaszRozmej 9363cc6
Refactor
LukaszRozmej d008455
Add comment
LukaszRozmej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs
This file contains hidden or 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,102 @@ | ||
| // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Nethermind.Consensus.Producers; | ||
| using Nethermind.Core.Crypto; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.JsonRpc; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Merge.Plugin.Data; | ||
| using Nethermind.Merge.Plugin.Handlers; | ||
|
|
||
| namespace Nethermind.Merge.Plugin | ||
| { | ||
| public partial class EngineRpcModule : IEngineRpcModule | ||
| { | ||
| private readonly IAsyncHandler<byte[], ExecutionPayload?> _getPayloadHandlerV1; | ||
| private readonly IAsyncHandler<ExecutionPayload, PayloadStatusV1> _newPayloadV1Handler; | ||
| private readonly IForkchoiceUpdatedHandler _forkchoiceUpdatedV1Handler; | ||
| private readonly IHandler<TransitionConfigurationV1, TransitionConfigurationV1> _transitionConfigurationHandler; | ||
| private readonly SemaphoreSlim _locker = new(1, 1); | ||
| private readonly TimeSpan _timeout = TimeSpan.FromSeconds(8); | ||
|
Comment on lines
+24
to
+25
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be here or in |
||
|
|
||
| public Task<ResultWrapper<ExecutionPayload?>> engine_getPayloadV1(byte[] payloadId) => | ||
| _getPayloadHandlerV1.HandleAsync(payloadId); | ||
|
|
||
| public async Task<ResultWrapper<PayloadStatusV1>> engine_newPayloadV1(ExecutionPayload executionPayload) | ||
| => await NewPayload(executionPayload, 1); | ||
|
|
||
| public async Task<ResultWrapper<ForkchoiceUpdatedV1Result>> engine_forkchoiceUpdatedV1(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) | ||
| => await ForkchoiceUpdated(forkchoiceState, payloadAttributes, 1); | ||
|
|
||
| public ResultWrapper<TransitionConfigurationV1> engine_exchangeTransitionConfigurationV1( | ||
| TransitionConfigurationV1 beaconTransitionConfiguration) => _transitionConfigurationHandler.Handle(beaconTransitionConfiguration); | ||
|
|
||
| private async Task<ResultWrapper<ForkchoiceUpdatedV1Result>> ForkchoiceUpdated(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes, int version) | ||
| { | ||
| if (payloadAttributes?.Validate(_specProvider, version, out string? error) == false) | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn(error); | ||
| return ResultWrapper<ForkchoiceUpdatedV1Result>.Fail(error, ErrorCodes.InvalidParams); | ||
| } | ||
|
|
||
| if (await _locker.WaitAsync(_timeout)) | ||
| { | ||
| Stopwatch watch = Stopwatch.StartNew(); | ||
| try | ||
| { | ||
| return await _forkchoiceUpdatedV1Handler.Handle(forkchoiceState, payloadAttributes); | ||
| } | ||
| finally | ||
| { | ||
| watch.Stop(); | ||
| Metrics.ForkchoiceUpdedExecutionTime = watch.ElapsedMilliseconds; | ||
| _locker.Release(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"engine_forkchoiceUpdated{version} timed out"); | ||
| return ResultWrapper<ForkchoiceUpdatedV1Result>.Fail("Timed out", ErrorCodes.Timeout); | ||
| } | ||
| } | ||
|
|
||
| private async Task<ResultWrapper<PayloadStatusV1>> NewPayload(ExecutionPayload executionPayload, int version) | ||
| { | ||
| if (!executionPayload.Validate(_specProvider, version, out string? error)) | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn(error); | ||
| return ResultWrapper<PayloadStatusV1>.Fail(error, ErrorCodes.InvalidParams); | ||
| } | ||
|
|
||
| if (await _locker.WaitAsync(_timeout)) | ||
| { | ||
| Stopwatch watch = Stopwatch.StartNew(); | ||
| try | ||
| { | ||
| return await _newPayloadV1Handler.HandleAsync(executionPayload); | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| if (_logger.IsError) _logger.Error($"engine_newPayloadV{version} failed: {exception}"); | ||
| return ResultWrapper<PayloadStatusV1>.Fail(exception.Message); | ||
| } | ||
| finally | ||
| { | ||
| watch.Stop(); | ||
| Metrics.NewPayloadExecutionTime = watch.ElapsedMilliseconds; | ||
| _locker.Release(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"engine_newPayloadV{version} timed out"); | ||
| return ResultWrapper<PayloadStatusV1>.Fail("Timed out", ErrorCodes.Timeout); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+39
to
+101
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be here or in |
||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs
This file contains hidden or 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,31 @@ | ||
| // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Nethermind.Consensus.Producers; | ||
| using Nethermind.Core.Crypto; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.JsonRpc; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Merge.Plugin.Data; | ||
| using Nethermind.Merge.Plugin.Handlers; | ||
|
|
||
| namespace Nethermind.Merge.Plugin | ||
| { | ||
| public partial class EngineRpcModule : IEngineRpcModule | ||
| { | ||
| private readonly IAsyncHandler<byte[], GetPayloadV2Result?> _getPayloadHandlerV2; | ||
|
|
||
| public async Task<ResultWrapper<GetPayloadV2Result?>> engine_getPayloadV2(byte[] payloadId) => | ||
| await _getPayloadHandlerV2.HandleAsync(payloadId); | ||
|
|
||
| public Task<ResultWrapper<PayloadStatusV1>> engine_newPayloadV2(ExecutionPayload executionPayload) | ||
| => NewPayload(executionPayload, 2); | ||
|
|
||
| public Task<ResultWrapper<ForkchoiceUpdatedV1Result>> engine_forkchoiceUpdatedV2(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) | ||
| => ForkchoiceUpdated(forkchoiceState, payloadAttributes, 2); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be here or in
EngineRpcModule.cs?