-
Notifications
You must be signed in to change notification settings - Fork 130
Conversation
recId = v.subtract(REPLAY_UNPROTECTED_V_BASE).byteValue(); | ||
} else if (v.compareTo(REPLAY_PROTECTED_V_MIN) > 0) { | ||
chainId = v.subtract(REPLAY_PROTECTED_V_BASE).divide(TWO); | ||
recId = v.subtract(TWO.multiply(chainId).add(REPLAY_PROTECTED_V_BASE)).byteValue(); |
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.
Probably should use byteValueExact
instead of byteValue
here and line 96.
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.
done
} else if (v > REPLAY_PROTECTED_V_MIN) { | ||
chainId = (v - REPLAY_PROTECTED_V_BASE) / 2; | ||
recId = (byte) (v - (2 * chainId + REPLAY_PROTECTED_V_BASE)); | ||
BigInteger chainId = BigInteger.valueOf(-1); |
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.
This probably shouldn't be using -1
as a sentinel value now that we're not using a primitive. Probably should be Optional<BigInteger> chainId = Optional.empty();
and that can flow through to Builder.chainId
.
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.
done
@@ -426,9 +429,9 @@ public String toString() { | |||
|
|||
protected Address sender; | |||
|
|||
protected int chainId = -1; | |||
protected BigInteger chainId = BigInteger.valueOf(-1); |
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.
protected BigInteger chainId = BigInteger.valueOf(-1); | |
protected Optional<BigInteger> chainId = Optional.empty(); |
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.
done
|
||
public Builder chainId(final int chainId) { | ||
public Builder chainId(final BigInteger chainId) { | ||
this.chainId = chainId; |
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.
Two possible approaches here, either public Builder chainId(final Optional<BigInteger> chainId)
which is just directly assigned or public Builder chainId(final BigInteger chainId)
which is wrapped with Optional.of
- if you don't have a chain ID don't call chainId
on the builder.
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.
done. used approach of defaulting to Optional.empty only calling chainId on builder if you have a chainId
final OptionalInt optionalChainId = | ||
chainId > 0 ? OptionalInt.of(chainId) : OptionalInt.empty(); | ||
final Optional<BigInteger> optionalChainId = | ||
chainId.signum() == 1 ? Optional.of(chainId) : Optional.empty(); |
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.
With the changes above you then don't need this and can just use chainId
directly since it's already an optional.
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.
done
@@ -37,7 +38,7 @@ | |||
*/ | |||
public class MainnetTransactionValidator implements TransactionValidator { | |||
|
|||
public static final int NO_CHAIN_ID = -1; | |||
public static final BigInteger NO_CHAIN_ID = BigInteger.valueOf(-1); |
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.
Shouldn't be using a sentinel value here - I suspect this constant can just go away and Optional.empty()
used in its place.
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.
done
this.gasCalculator = gasCalculator; | ||
this.disallowSignatureMalleability = checkSignatureMalleability; | ||
this.chainId = chainId > 0 ? OptionalInt.of(chainId) : OptionalInt.empty(); | ||
this.chainId = chainId.signum() == 1 ? Optional.of(chainId) : Optional.empty(); |
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.
Just pass in Optional<BigInteger>
and avoid the sentinel check here too.
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.
done
throw new ParameterException( | ||
this.commandLine, | ||
"No networkId specified and chainId in " | ||
+ "genesis file is too large to be used as a networkId"); |
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.
ugh, this is quite unfortunate but probably better to bail out with an error than to default to something else silently.
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.
yeah it's not nice, but I think it's the best thing to do
@@ -22,4 +23,15 @@ public static OptionalLong getOptionalLong(final JsonObject jsonObject, final St | |||
? OptionalLong.of(jsonObject.getLong(key)) | |||
: OptionalLong.empty(); | |||
} | |||
|
|||
public static BigInteger getBigInteger(final JsonObject jsonObject, final String key) { |
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.
Optional<BigInteger>
for consistency with the other method in this class
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.
done
this.chainId = chainId; | ||
return this; | ||
} | ||
|
||
public Builder chainId(final BigInteger chainId) { |
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.
did you end up with 2 'chainId' setters on purpose?
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.
just removed actually. don't think it's necessary afterall
Updated so make chainId optional in ProtocolSchedule as well. This allows having no chainId when using FixedDifficultyProtocolSchedule without the need to special -1 chainId value being used. |
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.
LGTM.
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.
LGTM
(cherry-picked from ac53e3d)
PR description
This updates chainId to be a BigInteger so that large values for a chainId can be used. Decided on using BigInteger as Geth currently using BigInt.
Fixed Issue(s)