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

Create Qbft Statemachine #1761

Merged
merged 9 commits into from
Jan 8, 2021
Merged

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Jan 8, 2021

Extracts commonality from IBFT classes into consensus/common, then copies IBFT statemachine classes into the Qbft package, an realigns messages to use qbft (rather than ibft) messages.

@rain-on rain-on force-pushed the bft_controller branch 2 times, most recently from 863e456 to 8f8fbdb Compare January 8, 2021 00:12
Trent Mohay added 2 commits January 8, 2021 11:18
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>

protected <P extends BftMessage<?>> void consumeMessage(
final Message message, final P ibftMessage, final Consumer<P> handleMessage) {
LOG.trace("Received IBFT {} message", ibftMessage.getClass().getSimpleName());
Copy link
Member

Choose a reason for hiding this comment

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

nit: trace log refers to IBFT. As well as method arg name is ibftMessage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch.

Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;

public class IbftRoundFactory {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this class rename to QbftRoundFactory as it is in qbft package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Override
public void handleBlockTimerExpiry(final ConsensusRoundIdentifier roundIdentifier) {
if (roundIdentifier.equals(currentRound.getRoundIdentifier())) {
currentRound.createAndSendProposalMessage(clock.millis() / 1000);
Copy link
Member

Choose a reason for hiding this comment

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

nit: divide by 1000L as millis returns a long value.

Copy link
Member

Choose a reason for hiding this comment

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

line 236 is more readable way to convert to seconds I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

private <P extends Payload, M extends BftMessage<P>> void actionOrBufferMessage(
final M ibftMessage,
Copy link
Member

Choose a reason for hiding this comment

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

nit: variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


protected <P extends BftMessage<?>> void consumeMessage(
final Message message, final P ibftMessage, final Consumer<P> handleMessage) {
LOG.trace("Received IBFT {} message", ibftMessage.getClass().getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

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

update log "Received BFT"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

protected abstract void handleMessage(final Message message);

protected <P extends BftMessage<?>> void consumeMessage(
final Message message, final P ibftMessage, final Consumer<P> handleMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to bftMessage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

msgRoundIdentifier.getSequenceNumber() - 1L, rawMsg.getConnection());
} else {
LOG.trace(
"IBFT message discarded as it is from a previous block height messageType={} chainHeight={} eventHeight={}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Update log "BFT message"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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

public class QbftMessageTransmitter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for this. There is one for IbftMessageTransmitter that can be copied and tweaked.

final BlockHeader parentHeader,
final BftFinalState finalState,
final RoundChangeManager roundChangeManager,
final IbftRoundFactory ibftRoundFactory,
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 IbftRoundFactory to be moved to common and become a BftRoundFactory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because it needs the messagefactory and messagevalidators which are both specific to the implementation :(

}

private <P extends Payload, M extends BftMessage<P>> void actionOrBufferMessage(
final M ibftMessage,
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to bftMessage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;

public class IbftRoundFactory {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to QbftRoundFactory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

default:
throw new IllegalArgumentException(
String.format(
"Received message with messageCode=%d does not conform to any recognised IBFT message structure",
Copy link
Contributor

Choose a reason for hiding this comment

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

change pare of log message from "IBFT message" to "QBFT message"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

final RoundChangeMetadata roundChangeMetadata, final long headerTimestamp) {
final Optional<Block> bestBlockFromRoundChange = roundChangeMetadata.getBlock();
Block blockToPublish;
if (!bestBlockFromRoundChange.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can simplify to bestBlockFromRoundChange.isEmpty()

Copy link
Contributor 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: Trent Mohay <trent.mohay@consensys.net>
Trent Mohay added 2 commits January 8, 2021 14:48
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
private final MessageFactory messageFactory = new MessageFactory(nodeKey);

private Block proposedBlock;
private BftExtraData proposedExtraData;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be a local variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@rain-on rain-on merged commit 16cc4d8 into hyperledger:master Jan 8, 2021
@rain-on rain-on deleted the bft_controller branch January 8, 2021 05:59
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
Qbft Statemachine classes copied over from ibft, and specialised.

Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
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.

3 participants