Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Cache extra data #1389

Merged
merged 32 commits into from
May 14, 2019
Merged

Cache extra data #1389

merged 32 commits into from
May 14, 2019

Conversation

ajsutton
Copy link
Contributor

@ajsutton ajsutton commented May 2, 2019

PR description

Parse extra data into a consensus protocol specific type when creating a block header. Avoids reprising the extra data all the time and gives a hook to cache things like the proposer seal which are expensive to compute.

Copy link
Contributor

@rain-on rain-on left a comment

Choose a reason for hiding this comment

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

more comments when I have done a real review...

@@ -40,8 +40,7 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

off topic - but this should be renamed to something not containing "Interface"

if (inputExtraData instanceof CliqueExtraData) {
return (CliqueExtraData) inputExtraData;
}
LOG.warn(
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 a warning? Or is it expected that someone MUST call decodeRaw quite early in the reception (why not force the call during blockimporter?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would expect to never see this message because the extra data should only ever be parsed to the right type. But the nice thing about this approach is that if somehow we get that wrong, things we still work, just with a performance penalty (and this warning is intended to make that situation visible).

@ajsutton ajsutton marked this pull request as ready for review May 8, 2019 02:25
final CliqueExtraData extraData = new CliqueExtraData(vanityDataToInsert, null, validators);

return extraData.encode();
return new CliqueExtraData(vanityDataToInsert, null, validators, null).encode();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding a static encode() method, so you don't have to pass a null header? Then you can run checkNotNull on header in the CliqueExtraData constructor.

@@ -47,9 +57,28 @@ public CliqueExtraData(
this.vanityData = vanityData;
this.proposerSeal = Optional.ofNullable(proposerSeal);
this.validators = validators;
proposerAddress =
Suppliers.memoize(() -> CliqueBlockHashing.recoverProposerAddress(header, this));
Copy link
Contributor

Choose a reason for hiding this comment

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

When header is null, looks like getProposerAddress() will throw an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So all these nulls are required because when you're mining a block you need to have something for the extra data before you can calculate the hash and sign it. Except for one slightly contrived case in test setup, whenever header is null, proposerSeal is also null or empty - so in either case you can't recover the proposer address because there isn't one.

But I like the idea of a static encode function and it fits in quite well so have done that. You can still wind up with a CliqueExtraData instance with an invalid principal seal but we need to handle that because that's what the genesis block has.

@ajsutton ajsutton merged commit d95eb2c into PegaSysEng:master May 14, 2019
@ajsutton ajsutton deleted the cache-extra-data branch May 14, 2019 20:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants