Simple engine API versioning and simplified message version validation#5157
Merged
MarekM25 merged 11 commits intofeature/shanghai-engine-failure-unifyfrom Jan 18, 2023
Merged
Conversation
12 tasks
LukaszRozmej
commented
Jan 17, 2023
Comment on lines
-238
to
-257
| var spec = _specProvider.GetSpec(newHeadBlock.Number + 1, payloadAttributes.Timestamp); | ||
|
|
||
| if (spec.WithdrawalsEnabled && payloadAttributes.Withdrawals is null) | ||
| { | ||
| var error = "PayloadAttributesV2 expected"; | ||
|
|
||
| if (_logger.IsInfo) _logger.Warn($"Invalid payload attributes: {error}"); | ||
|
|
||
| return ForkchoiceUpdatedV1Result.Error(error, ErrorCodes.InvalidParams); | ||
| } | ||
|
|
||
| if (!spec.WithdrawalsEnabled && payloadAttributes.Withdrawals is not null) | ||
| { | ||
| var error = "PayloadAttributesV1 expected"; | ||
|
|
||
| if (_logger.IsInfo) _logger.Warn($"Invalid payload attributes: {error}"); | ||
|
|
||
| return ForkchoiceUpdatedV1Result.Error(error, ErrorCodes.InvalidParams); | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
Is this fine to do this validation outside the handler? Or should the handler still run up to this point even if this would fail?
Member
Author
There was a problem hiding this comment.
I think fixes with CompareActivation might take care of that?
LukaszRozmej
commented
Jan 17, 2023
Comment on lines
+39
to
+101
| 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); | ||
| } | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
Should this be here or in EngineRpcModule.cs?
Comment on lines
+21
to
+22
| private readonly IAsyncHandler<ExecutionPayload, PayloadStatusV1> _newPayloadV1Handler; | ||
| private readonly IForkchoiceUpdatedHandler _forkchoiceUpdatedV1Handler; |
Member
Author
There was a problem hiding this comment.
Should this be here or in EngineRpcModule.cs?
Comment on lines
+24
to
+25
| private readonly SemaphoreSlim _locker = new(1, 1); | ||
| private readonly TimeSpan _timeout = TimeSpan.FromSeconds(8); |
Member
Author
There was a problem hiding this comment.
Should this be here or in EngineRpcModule.cs?
MarekM25
approved these changes
Jan 18, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.