-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add support to builder validator registration using ssz #9065
Merged
lucassaldanha
merged 6 commits into
Consensys:master
from
lucassaldanha:ssz-registerValidator
Feb 3, 2025
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46b6c2f
Add support to builder validator registration using ssz
lucassaldanha b405e1f
Changelog
lucassaldanha 92ed432
small nits
lucassaldanha 1a7c28e
Added tests for timeout and non-http errors
lucassaldanha f13dbd6
Fix final
lucassaldanha 3fb8850
Merge branch 'master' into ssz-registerValidator
lucassaldanha 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 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 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 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 |
---|---|---|
|
@@ -24,7 +24,10 @@ | |
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.bls.BLSPublicKey; | ||
import tech.pegasys.teku.ethereum.executionclient.BuilderApiMethod; | ||
|
@@ -35,6 +38,7 @@ | |
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; | ||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.time.TimeProvider; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.infrastructure.version.VersionProvider; | ||
import tech.pegasys.teku.spec.Spec; | ||
|
@@ -50,6 +54,8 @@ | |
|
||
public class RestBuilderClient implements BuilderClient { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private static final Map.Entry<String, String> USER_AGENT_HEADER = | ||
Map.entry( | ||
"User-Agent", | ||
|
@@ -72,13 +78,23 @@ public class RestBuilderClient implements BuilderClient { | |
private final Map<SpecMilestone, ResponseSchemaAndDeserializableTypeDefinition<SignedBuilderBid>> | ||
cachedBuilderApiSignedBuilderBidResponseType = new ConcurrentHashMap<>(); | ||
|
||
public static final UInt64 REGISTER_VALIDATOR_SSZ_BACKOFF_TIME_MILLIS = | ||
UInt64.valueOf(TimeUnit.DAYS.toMillis(1)); | ||
|
||
private final RestClient restClient; | ||
private final TimeProvider timeProvider; | ||
private final Spec spec; | ||
private final boolean setUserAgentHeader; | ||
|
||
private UInt64 nextSszRegisterValidatorsTryMillis = UInt64.ZERO; | ||
|
||
public RestBuilderClient( | ||
final RestClient restClient, final Spec spec, final boolean setUserAgentHeader) { | ||
final RestClient restClient, | ||
final TimeProvider timeProvider, | ||
final Spec spec, | ||
final boolean setUserAgentHeader) { | ||
this.restClient = restClient; | ||
this.timeProvider = timeProvider; | ||
this.spec = spec; | ||
this.setUserAgentHeader = setUserAgentHeader; | ||
} | ||
|
@@ -98,12 +114,43 @@ public SafeFuture<Response<Void>> registerValidators( | |
return SafeFuture.completedFuture(Response.fromNullPayload()); | ||
} | ||
|
||
return restClient | ||
.postAsync( | ||
BuilderApiMethod.REGISTER_VALIDATOR.getPath(), signedValidatorRegistrations, false) | ||
if (nextSszRegisterValidatorsTryMillis.isGreaterThan(timeProvider.getTimeInMillis())) { | ||
return registerValidatorsUsingJson(signedValidatorRegistrations) | ||
.orTimeout(BUILDER_REGISTER_VALIDATOR_TIMEOUT); | ||
} | ||
|
||
return registerValidatorsUsingSsz(signedValidatorRegistrations) | ||
.thenCompose( | ||
response -> { | ||
// Any failure will trigger a retry, not only Unsupported Media Type (415) | ||
if (response.isFailure()) { | ||
LOG.debug( | ||
"Failed to register validator using SSZ. Will retry using JSON (error: {})", | ||
response.errorMessage()); | ||
|
||
nextSszRegisterValidatorsTryMillis = | ||
timeProvider.getTimeInMillis().plus(REGISTER_VALIDATOR_SSZ_BACKOFF_TIME_MILLIS); | ||
|
||
return registerValidatorsUsingJson(signedValidatorRegistrations); | ||
} else { | ||
return SafeFuture.completedFuture(response); | ||
} | ||
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. you could avoid |
||
}) | ||
.orTimeout(BUILDER_REGISTER_VALIDATOR_TIMEOUT); | ||
} | ||
|
||
private SafeFuture<Response<Void>> registerValidatorsUsingJson( | ||
final SszList<SignedValidatorRegistration> signedValidatorRegistrations) { | ||
return restClient.postAsync( | ||
BuilderApiMethod.REGISTER_VALIDATOR.getPath(), signedValidatorRegistrations, false); | ||
} | ||
|
||
private SafeFuture<Response<Void>> registerValidatorsUsingSsz( | ||
final SszList<SignedValidatorRegistration> signedValidatorRegistrations) { | ||
return restClient.postAsync( | ||
BuilderApiMethod.REGISTER_VALIDATOR.getPath(), signedValidatorRegistrations, true); | ||
} | ||
|
||
@Override | ||
public SafeFuture<Response<Optional<SignedBuilderBid>>> getHeader( | ||
final UInt64 slot, final BLSPublicKey pubKey, final Bytes32 parentHash) { | ||
|
@@ -203,6 +250,7 @@ private SchemaDefinitionsBellatrix getSchemaDefinitionsBellatrix(final SpecVersi | |
() -> | ||
new IllegalArgumentException( | ||
specVersion.getMilestone() | ||
+ " is not a supported milestone for the builder rest api. Milestones >= Bellatrix are supported.")); | ||
+ " is not a supported milestone for the builder rest api. Milestones >= Bellatrix are " | ||
+ "supported.")); | ||
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. could be unchanged really... |
||
} | ||
} |
This file contains 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
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.
nit: we should probably make a tiny change here to show that the first set are verified and the second set is just the ssz call... we basically show that with the asserts above but it'd be clearer if this last check is just seeing 1 request, and just ssz.
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.
I guess I can move the early assertions closer to where we exercise the request to make them a bit more "sequential".