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

Client/Block: Clique PoA fixes #1088

Merged
merged 18 commits into from
Feb 11, 2021
Merged

Client/Block: Clique PoA fixes #1088

merged 18 commits into from
Feb 11, 2021

Conversation

holgerd77
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Feb 8, 2021

Codecov Report

Merging #1088 (c23f006) into master (4cb7fae) will increase coverage by 1.20%.
The diff coverage is 73.49%.

Impacted file tree graph

Flag Coverage Δ
block ?
blockchain ?
client 87.29% <73.68%> (+0.02%) ⬆️
common ?
devp2p ?
ethash ?
tx ?
vm 82.32% <73.33%> (-1.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@holgerd77
Copy link
Member Author

I am as close as one can get: 😄

Bildschirmfoto 2021-02-08 um 16 25 51

@holgerd77
Copy link
Member Author

Yeah, yeah, yeah

client_goerli_ruzn.mov

🎉 🎉 🎉 🥳

@holgerd77
Copy link
Member Author

Got it, client is now syncing with the Goerli network. 😄

This is now ready for review, change summary can be taken from the commit messages.

@@ -56,8 +56,6 @@ const messages: Message[] = [
name: 'BlockHeaders',
code: 0x04,
encode: (headers: BlockHeader[]) => headers.map((h) => h.raw()),
decode: (headers: BlockHeaderBuffer[]) =>
headers.map((h) => BlockHeader.fromValuesArray(h, {})),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just add common here instead of removing the decode function?

headers.map((h) => BlockHeader.fromValuesArray(h, { common: this.chain._common }))

This commit (2ca45cd) feels like it's moving around and adding code to handle the buffers that was otherwise nicely handled here.

Copy link
Member Author

@holgerd77 holgerd77 Feb 8, 2021

Choose a reason for hiding this comment

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

I had this implemented before (as announced here #1086 (comment)) but then reverted it because I had to pass config along every single decode method due to typing and then add another round of //es-lint-ignore comments since it wasn't used in most of the other decode functions. So I decided that this would at the end be the cleaner way, especially since this was in an inconsistent state anyhow with the Block decoding also working without a decode method like now done here for the BlockHeader decoding. Wouldn't be a big fan of reverting, but if you have got a cleaner way of doing this feel free to push here, no emotional connections to this code 😋 , just would want this to work "somehow".

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe this can be readded (then also together with the Block decoding) along some refactor at some point towards some more type friendly handling of this whole ETH/LES message call handling?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh yeah passing common into decode would be a lot of passing around. can't we use the common from chain in EthProtocolOptions?

Maybe this can be readded (then also together with the Block decoding) along some refactor at some point towards some more type friendly handling of this whole ETH/LES message call handling?

yes for sure, I will start thinking about this. I think if we inline the messages const into methods on the actual class then it would allow for seamless type info without needing to define the additional type helper EthProtocolMethods.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, you are so right, I didn't see the option that messages could be relatively easily inlined into the Protocol classes. Have removed the old commits via rebase and done this now in 08ffcd8. I had to add a no-invalid-this lint ignore rule here since eslint was complaining, but I checked with a console.log() in the decode message and this is properly resolved and the common object is present and not set to undefined or something.

This is really much nicer now. 😄

@holgerd77
Copy link
Member Author

holgerd77 commented Feb 8, 2021

First time sync stops on Goerli is with Error: invalid clique difficulty (block number=5281 hash=cca147be20ed1c416cfc8b533d15827764a216eef5d2c67f472ee9d143538926), so there still seems to be something wrong with this difficulty-in-turn, difficulty-out-turn check in BlockHeader.validateCliqueDifficulty(), difficulty of the respective block 5281 is 1.

Update:

Some numbers from within the library:
Signer length: 2
Signer index: 1
inTurn: true

Can't spot what's wrong on first sight.

Another update:

Ah, there seems to be a new signer 0x000000568b9b5a365eaa767d42e74ed88915c204 added around that block, so generally an interesting spot for testing PoA mechanics.

Maybe it's the order in blockchain of the validate call and the signer updates? 🤔

@holgerd77
Copy link
Member Author

(side question: so what do you guys think? I would love to add such additional information as in the error message above (with the block number and hash) also to the other block/header error messages (and also expand to other libraries), for now I just kept it to the new error messages to not change anything existing here. Do you think this is acceptable?)

@ryanio
Copy link
Contributor

ryanio commented Feb 8, 2021

yeah I love the additional context for the error messages, I wonder if we can stick it in some meta field on the error object to not disturb the prior messages, but then I'm not sure if it would output on a toString(). another idea could be to make some kind of error factory that would try to insert this data so we don't have to add it to each error individually.

in general i think the more we use enums for error messages gives us more flexibility to not worry about disturbing the string content. it would also free us to more easily fix typos or improve wording/clarity incrementally. perhaps we could do a sprint to swap error strings for enums in v6. i found geth's code base also does a really good job of defining and documenting their error enums (example 1, example 2).

@ryanio
Copy link
Contributor

ryanio commented Feb 8, 2021

Maybe it's the order in blockchain of the validate call and the signer updates? 🤔

That could definitely be it, it looks like validate is run before cliqueUpdateVotes and cliqueUpdateLatestBlockSigners in _putBlockOrHeader.

@holgerd77
Copy link
Member Author

(side note for reviewers: the clique error from above is independent from this PR - just noted it down for convenience since I looked a bit further - so this remains open for review)

@holgerd77
Copy link
Member Author

@ryanio that's a great idea with the error sprint, have added this to #1024. 😄

@holgerd77
Copy link
Member Author

@ryanio regarding error annotation this should already be better I guess a738424 ? I think we should be safe to at least already update the already-dynamic error messages which add custom data to a static prefix message (like the invalid transactions: ... error from the Block class.

@holgerd77
Copy link
Member Author

This still needs a review as well.

@holgerd77
Copy link
Member Author

(@ryanio thanks for reviewing #1089)

@holgerd77
Copy link
Member Author

Guys, I will do an admin merge here, otherwise this will get bloated up too much and more and more difficult to review, and I need these changes for continued work this morning. I did a self-review of the remaining changes, I think all are local and unproblematic, the fixed clique hash function change has already be confirmed by the geth team, and the reactivated total difficulty is also obvious if looking at e.g. an Etherscan block where the total difficulty is still present. The common addition to the ETH/LES protocols respectively the block creations has already been reviewed and discussed with @ryanio.

Fee free to do a post-merge review if you are not satisfied with something, I'll happily integrate into a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants