Skip to content

Comments

Simple engine API versioning and simplified message version validation#5157

Merged
MarekM25 merged 11 commits intofeature/shanghai-engine-failure-unifyfrom
feature/engine-api-simple-versioning
Jan 18, 2023
Merged

Simple engine API versioning and simplified message version validation#5157
MarekM25 merged 11 commits intofeature/shanghai-engine-failure-unifyfrom
feature/engine-api-simple-versioning

Conversation

@LukaszRozmej
Copy link
Member

No description provided.

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);
}

Copy link
Member Author

@LukaszRozmej LukaszRozmej Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fixes with CompareActivation might take care of that?

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);
}
}
}
Copy link
Member Author

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?

Comment on lines +21 to +22
private readonly IAsyncHandler<ExecutionPayload, PayloadStatusV1> _newPayloadV1Handler;
private readonly IForkchoiceUpdatedHandler _forkchoiceUpdatedV1Handler;
Copy link
Member Author

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?

Comment on lines +24 to +25
private readonly SemaphoreSlim _locker = new(1, 1);
private readonly TimeSpan _timeout = TimeSpan.FromSeconds(8);
Copy link
Member Author

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?

@LukaszRozmej LukaszRozmej changed the title Simple versioning and simplified transparent message version validation Simple engine API versioning and simplified message version validation Jan 18, 2023
@MarekM25 MarekM25 merged commit 919df0d into feature/shanghai-engine-failure-unify Jan 18, 2023
@MarekM25 MarekM25 deleted the feature/engine-api-simple-versioning branch January 18, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants