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

Added log for validator selection mode transition #2909

Merged
merged 3 commits into from
Oct 18, 2021

Conversation

lucassaldanha
Copy link
Member

@lucassaldanha lucassaldanha commented Oct 15, 2021

PR description

  • Add a log message when validator selection mode changes between blocks
  • Notification logic implemented on QbftTransitionNotifier
  • Check happens upon creation of a new QbftBlockHeighManager in the corresponding factory. That means that we notify before the transition actually happens, to help diagnose any issues with the transition that is about to happen (e.g. wrong address for the validator contract).

Example messages:

Transitioning validator selection mode from blockheader to contract (address: 0x0000000000000000000000000000000000008888)

Transitioning validator selection mode from contract (address: 0x0000000000000000000000000000000000008888) to blockheader

Transitioning validator selection mode from contract (address: 0x0000000000000000000000000000000000008888) to contract (address: 0x0000000000000000000000000000000000007777)

Fixed Issue(s)

fixes #2784

Changelog

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class QbftTransitionNotifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more specific than ordinary transitions, perhaps QbftValidatorSelectionTransitionLogger? Though is rather a long name

Copy link
Contributor

@siladu siladu Oct 15, 2021

Choose a reason for hiding this comment

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

Since it's already in the qbft package, can we drop the Qbft?

Another suggestion: ValidatorModeTransitionLogger...'mode' has been used elsewhere

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with ValidatorModeTransitionLogger

this.msgConsumer = msgConsumer;
}

public void checkTransitionChange(final BlockHeader parentHeader) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not really checking anything it doesn't return a value. Maybe just logTransitionChange?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!


private String parseConfigToLog(final QbftConfigOptions configOptions) {
if (configOptions.getValidatorContractAddress().isPresent()) {
return String.format("ADDRESS(%s)", configOptions.getValidatorContractAddress().get());
Copy link
Contributor

Choose a reason for hiding this comment

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

contract mode (%s) instead of ADDRESS?

Copy link
Contributor

Choose a reason for hiding this comment

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

should we make this clear it's the validator contract address? In case someone who doesn't know the detail of how this feature works may read the log.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we can expect that operators (people running Besu nodes) have a fair bit of knowledge. If they are using a feature that requires smart contracts etc. they need to know what they are doing.

if (configOptions.getValidatorContractAddress().isPresent()) {
return String.format("ADDRESS(%s)", configOptions.getValidatorContractAddress().get());
} else {
return "BLOCKHEADER";
Copy link
Contributor

Choose a reason for hiding this comment

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

blockheader mode instead of BLOCKHEADER in caps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

Choose a reason for hiding this comment

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

btw we already have the word mode in the phrase.


return !currentConfig
.getValidatorContractAddress()
.equals(nextConfig.getValidatorContractAddress());
Copy link
Member

Choose a reason for hiding this comment

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

nit: equalsignorecase??

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it make more sense to normalize this inside QbftConfigOptions?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be better actually

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

}

@VisibleForTesting
public QbftTransitionNotifier(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could be package-private

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

private static final Logger LOG = LogManager.getLogger();

private final BftForksSchedule<QbftConfigOptions> bftForksSchedule;
private final Consumer<String> msgConsumer;
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this pattern as a way of testing logging 👍

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
this.roundFactory = roundFactory;
this.finalState = finalState;
this.messageValidatorFactory = messageValidatorFactory;
this.messageFactory = messageFactory;
this.qbftTransitionNotifier = validatorModeTransitionLogger;
Copy link
Contributor

Choose a reason for hiding this comment

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

can the field name be updated to match the constructor arg

Copy link
Member Author

Choose a reason for hiding this comment

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

ops!

Comment on lines 52 to 54
BftForkSpec<BftConfigOptions> forkSpecA =
new BftForkSpec<>(0, createQbftConfigOptionsForBlockHeader());
BftForkSpec<BftConfigOptions> forkSpecB =
Copy link
Contributor

Choose a reason for hiding this comment

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

these can be made final in all the tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
@lucassaldanha lucassaldanha enabled auto-merge (squash) October 18, 2021 02:48
@lucassaldanha lucassaldanha merged commit 6be1ed5 into hyperledger:main Oct 18, 2021
@lucassaldanha lucassaldanha deleted the besu-2794 branch October 18, 2021 03:23
garyschulte pushed a commit to garyschulte/besu that referenced this pull request Oct 22, 2021
* Added log for validator selection mode transition

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* Added log for validator selection mode transition

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
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