-
Notifications
You must be signed in to change notification settings - Fork 130
Fix estimate gas RPC failing for clique when no blocks have been created #1528
Fix estimate gas RPC failing for clique when no blocks have been created #1528
Conversation
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.
@@ -23,6 +23,7 @@ | |||
import java.util.function.Supplier; | |||
|
|||
public class CliqueBlockHashing { | |||
private static final Address ADDRESS_ZERO = Address.extract(Hash.ZERO); |
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 suspect we should just introduce Address.ZERO = Address.fromHexString('0x0')
in the Address
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
@@ -48,6 +49,9 @@ public static Hash calculateDataHashForProposerSeal( | |||
*/ | |||
public static Address recoverProposerAddress( | |||
final BlockHeader header, final CliqueExtraData cliqueExtraData) { | |||
if (header.getNumber() == 0) { |
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.
if (header.getNumber() == 0) { | |
if (header.getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) { |
Please don't ever hard code 0 as the genesis block number. One day we're going to have to support variable genesis block numbers.
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
@@ -48,6 +47,9 @@ public static Hash calculateDataHashForProposerSeal( | |||
*/ | |||
public static Address recoverProposerAddress( | |||
final BlockHeader header, final CliqueExtraData cliqueExtraData) { | |||
if (header.getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) { |
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: Personally, I'd move this inside the "isPresent" check - just to minimise the conditionals executed on every check ... its probably a minor benefit at best.
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
PR description
Fixes issue when using Clique, if the chain height is still at 0 then the estimateGas rpc fails with a internal server error.
This change special cases block 0 so we return address 0 for the proposer in this case instead of failing with an IllegalArgumentException as the genesis block does not have proposer seals.
Fixed Issue(s)