Skip to content
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

sign type block_v2 to support Altair and future forks #422

Merged
merged 20 commits into from
Sep 2, 2021

Conversation

usmansaleem
Copy link
Contributor

Block signing request for Altair fork uses different block than phase 0. Introduce new sign type BLOCK_V2 which will allow Altair and future forks block signing requests. Keep BLOCK for phase 0 backward compatibility.

@ajsutton ajsutton mentioned this pull request Aug 26, 2021
@usmansaleem usmansaleem added the TeamCerberus Under active development by TeamCerberus @Consensys label Aug 27, 2021
@usmansaleem usmansaleem self-assigned this Aug 27, 2021
@usmansaleem usmansaleem marked this pull request as ready for review August 30, 2021 00:00
Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
@usmansaleem usmansaleem requested a review from jframe August 31, 2021 04:22
@@ -77,7 +72,7 @@ void signAndVerifyBlockV2Signature(final SpecMilestone specMilestone) throws Exc
@Test
void signAndVerifyLegacyBlockSignature() throws Exception {
final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.PHASE0);
setupSigner("eth2", null, "minimal", Optional.empty());
setupSigner("eth2", null, "minimal", null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be overkill in this case, but could avoid passing the null into the Optional with another overloaded setupSigner method which doesn't call withAltairForkEpoch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are correct, its technically only for legacy block signing that we need to start web3signer without altair fork. Rest of signing types works with altair fork.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rather we didn't pass in null as well, even an optional altair block would be nicer. Might be nit picking though.

Signed-off-by: Usman Saleem <[email protected]>
@@ -196,8 +197,13 @@ public SignerConfigurationBuilder withUseConfigFile(final boolean useConfigFile)
return this;
}

public SignerConfigurationBuilder withAltairForkEpoch(final long altairForkEpoch) {
this.altairForkEpoch = altairForkEpoch;
public SignerConfigurationBuilder withAltairForkEpoch(final Long altairForkEpoch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Be nicer to use the primitive long

public SignerConfigurationBuilder withAltairForkEpoch(final long altairForkEpoch) {
this.altairForkEpoch = altairForkEpoch;
public SignerConfigurationBuilder withAltairForkEpoch(final Long altairForkEpoch) {
this.altairForkEpoch = Optional.ofNullable(altairForkEpoch);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ofNullable because null is being passed into the builder somewhere? Rather didn't do that

signingRoot = signingRootUtil.signingRootForSignBlock(beaconBlock, tekuForkInfo);
}

public Eth2SigningRequestBody createRandomBlockV2Request() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually random? Looks like dataStructureUtil creates deterministic data keyed off the slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is deterministic ... I think createCanned.... naming makes more sense.

null);
}

public Eth2SigningRequestBody createRandomLegacyBlockRequest() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any benefit in having this method and the one in Eth2RequestUtils?

@@ -59,7 +59,7 @@
private static final BLSPublicKey publicKey = keyPair.getPublicKey();

@ParameterizedTest
@EnumSource
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = "BLOCK_V2")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to exclude BLOCK_V2? It would good to include the block v2 in these tests for completeness.

@@ -77,7 +72,7 @@ void signAndVerifyBlockV2Signature(final SpecMilestone specMilestone) throws Exc
@Test
void signAndVerifyLegacyBlockSignature() throws Exception {
final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.PHASE0);
setupSigner("eth2", null, "minimal", Optional.empty());
setupSigner("eth2", null, "minimal", null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather we didn't pass in null as well, even an optional altair block would be nicer. Might be nit picking though.

@@ -44,6 +45,7 @@ public Eth2SigningRequestBody(
@JsonProperty("signingRoot") final Bytes signingRoot,
@JsonProperty("fork_info") final ForkInfo fork_info,
@JsonProperty("block") final BeaconBlock block,
@JsonProperty("beacon_block") final BlockRequest blockRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a bit confusing having block and beacon_block in the request. Not sure there is much we can do about now that Teku has implemented this though

}

@Override
public BlockRequest deserialize(final JsonParser p, final DeserializationContext ctxt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a test? We do have AT though, so maybe that is enough

import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;

public class SigningJsonProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

The way we are using this doing new SigningJsonProvider().getObjectMapper() perhaps a factory would be would be better?

@usmansaleem usmansaleem requested review from siladu and jframe September 1, 2021 07:23
@siladu siladu closed this Sep 1, 2021
@siladu siladu reopened this Sep 1, 2021
Copy link
Contributor

@jframe jframe left a comment

Choose a reason for hiding this comment

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

LGTM

@usmansaleem usmansaleem merged commit 15fc5c5 into Consensys:master Sep 2, 2021
@usmansaleem usmansaleem deleted the altair_block_signing branch September 2, 2021 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TeamCerberus Under active development by TeamCerberus @Consensys
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants