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

*: support extra dBFT stage #118

Merged
merged 16 commits into from
Aug 1, 2024
Merged

*: support extra dBFT stage #118

merged 16 commits into from
Aug 1, 2024

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Jul 12, 2024

WIP, just something I have on hands right now, need to test it and integrate with NeoGo/NeoX nodes.

TODO:

  • Add CommitAck messages to recovery
  • Add more unit-tests for CommitAk stage
  • ...

Ref. #112.

@AnnaShaleva AnnaShaleva force-pushed the add-postblock-handling branch 2 times, most recently from a2d89af to 01f9e6c Compare July 16, 2024 17:15
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 38.91892% with 226 lines in your changes missing coverage. Please review.

Project coverage is 59.35%. Comparing base (de50c7b) to head (2fca051).
Report is 4 commits behind head on master.

Files Patch % Lines
internal/consensus/amev_block.go 0.00% 49 Missing ⚠️
dbft.go 56.31% 36 Missing and 9 partials ⚠️
internal/consensus/amev_preBlock.go 0.00% 30 Missing ⚠️
config.go 45.45% 12 Missing and 6 partials ⚠️
internal/consensus/amev_preCommit.go 0.00% 14 Missing ⚠️
internal/consensus/amev_commit.go 0.00% 12 Missing ⚠️
internal/consensus/recovery_message.go 0.00% 12 Missing ⚠️
internal/consensus/transaction.go 0.00% 12 Missing ⚠️
internal/consensus/constructors.go 0.00% 8 Missing ⚠️
send.go 63.15% 5 Missing and 2 partials ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #118      +/-   ##
==========================================
- Coverage   63.31%   59.35%   -3.96%     
==========================================
  Files          27       32       +5     
  Lines        1510     1823     +313     
==========================================
+ Hits          956     1082     +126     
- Misses        489      661     +172     
- Partials       65       80      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AnnaShaleva AnnaShaleva force-pushed the add-postblock-handling branch 3 times, most recently from 3460b23 to 942dd05 Compare July 16, 2024 17:44
It will be reused by anti-MEV related dBFT interfaces implementations.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva AnnaShaleva force-pushed the add-postblock-handling branch 3 times, most recently from 890c324 to 7d7004b Compare July 17, 2024 18:05
pre_block.go Outdated
Data() []byte // required
// SetData generates and sets PreBlock's data CNs need to exchange during Commit
// phase.
SetData(key PrivateKey) error // required
Copy link
Member

Choose a reason for hiding this comment

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

Getters/setters?

Copy link
Member Author

Choose a reason for hiding this comment

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

What exactly do you want? GetData instead of Data?

Copy link
Member

Choose a reason for hiding this comment

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

Usually getters/setters mean that something is wrong with the interface. Likely SetData can be avoided.

Copy link
Member Author

@AnnaShaleva AnnaShaleva Jul 18, 2024

Choose a reason for hiding this comment

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

Then it’s wrong with the old implementation because the logic is the same as for our old Commit.SetSignature() and Commit.Signature(). Need to check, maybe we can pass signature directly to the Commit constructor.

@AnnaShaleva AnnaShaleva force-pushed the add-postblock-handling branch 2 times, most recently from 1966e0a to 659de52 Compare July 18, 2024 16:31
@AnnaShaleva AnnaShaleva requested a review from roman-khimov July 18, 2024 16:36
Ref. #112.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@roman-khimov roman-khimov force-pushed the add-postblock-handling branch 2 times, most recently from 438f9df to d5baa08 Compare July 31, 2024 20:44
AnnaShaleva and others added 12 commits July 31, 2024 23:53
Add custom PreBlock and Block interfaces implementation, custom Commit
and CommitAck, adjust testing logic.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Technically, this is implied by d.ResponseSent(), but we still have BlockSent()
check as well, so these don't hurt.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
It's done at the start of OnReceive() and it's even more strict there.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
It's a security event, this should never happen and we better know if it does.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
It's useless, we log tx number down below anyway.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
Commit payloads can't be checked with PrepareRequest data only in AMEV case,
we don't yet have a complete header. So check them after we have enough
PreCommit payloads.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
Be a bit more optimistic about the message (similar to how onPrepareResponse()
works).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
Supposedly AMEV code will do its magic here and it doesn't need to do it twice.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
For a single height/view there is a single proper hash and it's not a final
block hash, likely logging it won't help much. Can be done in future if needed,
but let's have view number for now.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
start() was designed to be called at every view change, but looks like it
_never_ worked this way. Which means two things:
 * on every view change Primary doesn't send PrepareRequest during
   initialization (which is mostly OK, OnTimeout() will be triggered
   immediately with 0 timeout)
 * our future message caching system has never really worked since start() is
   the only place where messages can be picked up from it

Just drop start(), make caches work and add a test for them.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
@roman-khimov roman-khimov force-pushed the add-postblock-handling branch from d5baa08 to 2fca051 Compare July 31, 2024 20:53
@roman-khimov roman-khimov marked this pull request as ready for review July 31, 2024 20:55
@roman-khimov roman-khimov merged commit eddbd6d into master Aug 1, 2024
10 of 12 checks passed
@roman-khimov roman-khimov deleted the add-postblock-handling branch August 1, 2024 14:56
Copy link
Member Author

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

I didn't find anything suspicious here, LGTM.

@AnnaShaleva AnnaShaleva mentioned this pull request Aug 8, 2024
AnnaShaleva added a commit that referenced this pull request Dec 5, 2024
Problem:

Inappropriate message in the WatchOnly node logs with NeoXAMEV extension
enabled:
```
2024-12-05T15:15:54.366+0300	INFO	dbft@v0.3.1/dbft.go:545	received PreCommit	{"validator": 5}
2024-12-05T15:15:54.366+0300	DEBUG	dbft@v0.3.1/check.go:90	can't send commit since self preCommit not yet sent
```

Based on these logs it may seem that WatchOnly is trying (or will try)
to send Commit. It must never happen, hence I dived into the library
code and discovered the condition that was added mostly for safety and
that was planned to be removed in future:
https://github.com/nspcc-dev/dbft/blob/7c005d93e4b47106b679e3cc55d182f8167e0e56/check.go#L82-L84

Ref. #118 (comment).

So the problem is in the invalid documentaiton and in improper log
message.

It should be noted that for non-WatchOnly CNs we also need to keep
and check PreCommitSent requirement because node's Commit must be
confirmed by previousely sent PreCommit.

Solution:

Strictly speaking, this commit almost doesn't change the dBFT behaviour
because WatchOnly node is not allowed to send Commit thanks to the
condition outlined above. But we'd better adjust the comment and don't
confuse the library users with inappropriate message.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit that referenced this pull request Dec 5, 2024
Problem:

Inappropriate message in the WatchOnly node logs with NeoXAMEV extension
enabled:
```
2024-12-05T15:15:54.366+0300	INFO	dbft@v0.3.1/dbft.go:545	received PreCommit	{"validator": 5}
2024-12-05T15:15:54.366+0300	DEBUG	dbft@v0.3.1/check.go:90	can't send commit since self preCommit not yet sent
```

Based on these logs it may seem that WatchOnly is trying (or will try)
to send Commit. It must never happen, hence I dived into the library
code and discovered the condition that was added mostly for safety and
that was planned to be removed in future:
https://github.com/nspcc-dev/dbft/blob/7c005d93e4b47106b679e3cc55d182f8167e0e56/check.go#L82-L84

Ref. #118 (comment).

So the problem is in the invalid documentaiton and in improper log
message.

It should be noted that for non-WatchOnly CNs we also need to keep
and check PreCommitSent requirement because node's Commit must be
confirmed by previousely sent PreCommit.

Solution:

Strictly speaking, this commit almost doesn't change the dBFT behaviour
because WatchOnly node is not allowed to send Commit thanks to the
condition outlined above. But we'd better adjust the comment and don't
confuse the library users with inappropriate message.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit that referenced this pull request Dec 5, 2024
Problem:

Inappropriate message in the WatchOnly node logs with NeoXAMEV extension
enabled:
```
2024-12-05T15:15:54.366+0300	INFO	dbft@v0.3.1/dbft.go:545	received PreCommit	{"validator": 5}
2024-12-05T15:15:54.366+0300	DEBUG	dbft@v0.3.1/check.go:90	can't send commit since self preCommit not yet sent
```

Based on these logs it may seem that WatchOnly is trying (or will try)
to send Commit. It must never happen, hence I dived into the library
code and discovered the condition that was added mostly for safety and
that was planned to be removed in future:
https://github.com/nspcc-dev/dbft/blob/7c005d93e4b47106b679e3cc55d182f8167e0e56/check.go#L82-L84

Ref. #118 (comment).

So the problem is in the invalid documentaiton and in improper log
message.

It should be noted that for non-WatchOnly CNs we also need to keep
and check PreCommitSent requirement because node's Commit must be
confirmed by previousely sent PreCommit.

Solution:

Strictly speaking, this commit almost doesn't change the dBFT behaviour
because WatchOnly node is not allowed to send Commit thanks to the
condition outlined above. But we'd better adjust the comment and don't
confuse the library users with inappropriate message.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants