-
Notifications
You must be signed in to change notification settings - Fork 864
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
Create Qbft Statemachine #1761
Conversation
863e456
to
8f8fbdb
Compare
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
8f8fbdb
to
de36de8
Compare
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: variable name
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update log "Received BFT"
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to bftMessage
There was a problem hiding this comment.
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={}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update log "BFT message"
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
...t/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManager.java
Show resolved
Hide resolved
final BlockHeader parentHeader, | ||
final BftFinalState finalState, | ||
final RoundChangeManager roundChangeManager, | ||
final IbftRoundFactory ibftRoundFactory, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to bftMessage
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to QbftRoundFactory
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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>
0396ffc
to
140348d
Compare
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
Qbft Statemachine classes copied over from ibft, and specialised. Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
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.