Skip to content

Commit

Permalink
Commit Boost Acceptance Test for List Pub Keys (#1040)
Browse files Browse the repository at this point in the history
* Add commit boost acceptance test for list pub keys API. Also fix the public key identifiers used by commit boost API by introducing K256ArtifactSigner.
* Refactor SignerForIdentifier and removed signAndGetArtifactSignature. Derive SignatureData from existing SecpArtifactSignature builder method
  • Loading branch information
usmansaleem authored Nov 26, 2024
1 parent e7840a1 commit f27d7ea
Show file tree
Hide file tree
Showing 20 changed files with 705 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.Ethereum;
import org.web3j.protocol.core.JsonRpc2_0Web3j;
Expand Down Expand Up @@ -187,6 +188,34 @@ public Response callApiPublicKeys(final KeyType keyType) {
return given().baseUri(getUrl()).get(publicKeysPath(keyType));
}

public Response callCommitBoostGetPubKeys() {
return given().baseUri(getUrl()).get("/signer/v1/get_pubkeys");
}

public Response callCommitBoostGenerateProxyKey(final String pubkey, final String scheme) {
return given()
.baseUri(getUrl())
.contentType(ContentType.JSON)
.body(new JsonObject().put("pubkey", pubkey).put("scheme", scheme).toString())
.post("/signer/v1/generate_proxy_key");
}

public Response callCommitBoostRequestForSignature(
final String signRequestType, final String pubkey, final Bytes32 objectRoot) {
return given()
.baseUri(getUrl())
.contentType(ContentType.JSON)
.log()
.all()
.body(
new JsonObject()
.put("type", signRequestType)
.put("pubkey", pubkey)
.put("object_root", objectRoot.toHexString())
.toString())
.post("/signer/v1/request_signature");
}

public List<String> listPublicKeys(final KeyType keyType) {
return callApiPublicKeys(keyType).as(new TypeRef<>() {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.Level;

public class SignerConfiguration {
Expand Down Expand Up @@ -81,6 +82,7 @@ public class SignerConfiguration {
private final Optional<KeystoresParameters> v3KeystoresBulkloadParameters;

private final boolean signingExtEnabled;
private Optional<Pair<Path, Path>> commitBoostParameters;

public SignerConfiguration(
final String hostname,
Expand Down Expand Up @@ -128,7 +130,8 @@ public SignerConfiguration(
final Optional<ClientTlsOptions> downstreamTlsOptions,
final ChainIdProvider chainIdProvider,
final Optional<KeystoresParameters> v3KeystoresBulkloadParameters,
final boolean signingExtEnabled) {
final boolean signingExtEnabled,
final Optional<Pair<Path, Path>> commitBoostParameters) {
this.hostname = hostname;
this.logLevel = logLevel;
this.httpRpcPort = httpRpcPort;
Expand Down Expand Up @@ -175,6 +178,7 @@ public SignerConfiguration(
this.chainIdProvider = chainIdProvider;
this.v3KeystoresBulkloadParameters = v3KeystoresBulkloadParameters;
this.signingExtEnabled = signingExtEnabled;
this.commitBoostParameters = commitBoostParameters;
}

public String hostname() {
Expand Down Expand Up @@ -368,4 +372,8 @@ public Optional<KeystoresParameters> getV3KeystoresBulkloadParameters() {
public boolean isSigningExtEnabled() {
return signingExtEnabled;
}

public Optional<Pair<Path, Path>> getCommitBoostParameters() {
return commitBoostParameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.Level;

public class SignerConfigurationBuilder {
Expand Down Expand Up @@ -85,6 +86,7 @@ public class SignerConfigurationBuilder {
private KeystoresParameters v3KeystoresBulkloadParameters;

private boolean signingExtEnabled;
private Pair<Path, Path> commitBoostParameters;

public SignerConfigurationBuilder withLogLevel(final Level logLevel) {
this.logLevel = logLevel;
Expand Down Expand Up @@ -331,6 +333,12 @@ public SignerConfigurationBuilder withSigningExtEnabled(final boolean signingExt
return this;
}

public SignerConfigurationBuilder withCommitBoostParameters(
final Pair<Path, Path> commitBoostParameters) {
this.commitBoostParameters = commitBoostParameters;
return this;
}

public SignerConfiguration build() {
if (mode == null) {
throw new IllegalArgumentException("Mode cannot be null");
Expand Down Expand Up @@ -381,6 +389,7 @@ public SignerConfiguration build() {
Optional.ofNullable(downstreamTlsOptions),
chainIdProvider,
Optional.ofNullable(v3KeystoresBulkloadParameters),
signingExtEnabled);
signingExtEnabled,
Optional.ofNullable(commitBoostParameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.function.Consumer;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.tuple.Pair;

public class CmdLineParamsConfigFileImpl implements CmdLineParamsBuilder {
private final SignerConfiguration signerConfig;
Expand Down Expand Up @@ -163,6 +164,12 @@ public List<String> createCmdLineParams() {
String.format(YAML_BOOLEAN_FMT, "eth2.Xsigning-ext-enabled", Boolean.TRUE));
}

signerConfig
.getCommitBoostParameters()
.ifPresent(
commitBoostParameters ->
appendCommitBoostParameters(commitBoostParameters, yamlConfig));

final CommandArgs subCommandArgs = createSubCommandArgs();
params.addAll(subCommandArgs.params);
yamlConfig.append(subCommandArgs.yamlConfig);
Expand Down Expand Up @@ -204,6 +211,22 @@ public List<String> createCmdLineParams() {
return params;
}

private static void appendCommitBoostParameters(
final Pair<Path, Path> commitBoostParameters, final StringBuilder yamlConfig) {
yamlConfig.append(
String.format(YAML_BOOLEAN_FMT, "eth2.commit-boost-api-enabled", Boolean.TRUE));
yamlConfig.append(
String.format(
YAML_STRING_FMT,
"eth2.proxy-keystores-path",
commitBoostParameters.getLeft().toAbsolutePath()));
yamlConfig.append(
String.format(
YAML_STRING_FMT,
"eth2.proxy-keystores-password-file",
commitBoostParameters.getRight().toAbsolutePath()));
}

private Consumer<? super KeystoresParameters> setV3KeystoresBulkloadParameters(
final StringBuilder yamlConfig) {
return keystoresParameters -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.function.Consumer;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.tuple.Pair;

public class CmdLineParamsDefaultImpl implements CmdLineParamsBuilder {
private final SignerConfiguration signerConfig;
Expand Down Expand Up @@ -138,6 +139,12 @@ public List<String> createCmdLineParams() {
if (signerConfig.isSigningExtEnabled()) {
params.add("--Xsigning-ext-enabled=true");
}

signerConfig
.getCommitBoostParameters()
.ifPresent(
commitBoostParameters -> params.addAll(commitBoostOptions(commitBoostParameters)));

} else if (signerConfig.getMode().equals("eth1")) {
params.add("--downstream-http-port");
params.add(Integer.toString(signerConfig.getDownstreamHttpPort()));
Expand All @@ -160,6 +167,15 @@ public List<String> createCmdLineParams() {
return params;
}

private static List<String> commitBoostOptions(final Pair<Path, Path> commitBoostParameters) {
return List.of(
"--commit-boost-api-enabled=true",
"--proxy-keystores-path",
commitBoostParameters.getLeft().toAbsolutePath().toString(),
"--proxy-keystores-password-file",
commitBoostParameters.getRight().toAbsolutePath().toString());
}

private static Consumer<KeystoresParameters> setV3KeystoresBulkloadParameters(
final List<String> params) {
return keystoresParameters -> {
Expand Down
Loading

0 comments on commit f27d7ea

Please sign in to comment.