|
|
|
@ -84,8 +84,13 @@ public class IbftRound { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void createAndSendProposalMessage(final long headerTimeStampSeconds) { |
|
|
|
|
LOG.info("Creating proposed block."); |
|
|
|
|
final Block block = blockCreator.createBlock(headerTimeStampSeconds); |
|
|
|
|
final IbftExtraData extraData = IbftExtraData.decode(block.getHeader().getExtraData()); |
|
|
|
|
LOG.info( |
|
|
|
|
"Creating proposed block. round={} extraData={} blockHeader={}", |
|
|
|
|
roundState.getRoundIdentifier(), |
|
|
|
|
extraData, |
|
|
|
|
block.getHeader()); |
|
|
|
|
transmitter.multicastProposal(roundState.getRoundIdentifier(), block); |
|
|
|
|
|
|
|
|
|
updateStateWithProposedBlock( |
|
|
|
@ -99,11 +104,13 @@ public class IbftRound { |
|
|
|
|
|
|
|
|
|
SignedData<ProposalPayload> proposal; |
|
|
|
|
if (!latestCertificate.isPresent()) { |
|
|
|
|
LOG.info("Multicasting NewRound with new block."); |
|
|
|
|
LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier()); |
|
|
|
|
final Block block = blockCreator.createBlock(headerTimestamp); |
|
|
|
|
proposal = messageFactory.createSignedProposalPayload(getRoundIdentifier(), block); |
|
|
|
|
} else { |
|
|
|
|
LOG.info("Multicasting NewRound from PreparedCertificate."); |
|
|
|
|
LOG.trace( |
|
|
|
|
"Multicasting NewRound from PreparedCertificate. round={}", |
|
|
|
|
roundState.getRoundIdentifier()); |
|
|
|
|
proposal = createProposalFromPreparedCertificate(latestCertificate.get()); |
|
|
|
|
} |
|
|
|
|
transmitter.multicastNewRound(getRoundIdentifier(), roundChangeCertificate, proposal); |
|
|
|
@ -132,6 +139,10 @@ public class IbftRound { |
|
|
|
|
blockHeader, extraDataToPublish)); |
|
|
|
|
final BlockHeader newHeader = headerBuilder.buildBlockHeader(); |
|
|
|
|
final Block newBlock = new Block(newHeader, block.getBody()); |
|
|
|
|
LOG.debug( |
|
|
|
|
"Created proposal from prepared certificate blockHeader={} extraData={}", |
|
|
|
|
block.getHeader(), |
|
|
|
|
extraDataToPublish); |
|
|
|
|
return messageFactory.createSignedProposalPayload(getRoundIdentifier(), newBlock); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,7 +150,7 @@ public class IbftRound { |
|
|
|
|
LOG.info("Handling a Proposal message."); |
|
|
|
|
|
|
|
|
|
if (getRoundIdentifier().getRoundNumber() != 0) { |
|
|
|
|
LOG.info("Illegally received a Proposal message when not in Round 0."); |
|
|
|
|
LOG.error("Illegally received a Proposal message when not in Round 0."); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
actionReceivedProposal(msg); |
|
|
|
@ -149,7 +160,7 @@ public class IbftRound { |
|
|
|
|
LOG.info("Handling a New Round Proposal."); |
|
|
|
|
|
|
|
|
|
if (getRoundIdentifier().getRoundNumber() == 0) { |
|
|
|
|
LOG.info("Illegally received a NewRound message when in Round 0."); |
|
|
|
|
LOG.error("Illegally received a NewRound message when in Round 0."); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
actionReceivedProposal(msg.getPayload().getProposalPayload()); |
|
|
|
@ -169,12 +180,12 @@ public class IbftRound { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void handlePrepareMessage(final SignedData<PreparePayload> msg) { |
|
|
|
|
LOG.info("Received a prepare message."); |
|
|
|
|
LOG.debug("Received a prepare message. round={}", roundState.getRoundIdentifier()); |
|
|
|
|
peerIsPrepared(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void handleCommitMessage(final SignedData<CommitPayload> msg) { |
|
|
|
|
LOG.info("Received a commit message."); |
|
|
|
|
LOG.debug("Received a commit message. round={}", roundState.getRoundIdentifier()); |
|
|
|
|
peerIsCommitted(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -189,7 +200,7 @@ public class IbftRound { |
|
|
|
|
if (blockAccepted) { |
|
|
|
|
// There are times handling a proposed block is enough to enter prepared.
|
|
|
|
|
if (wasPrepared != roundState.isPrepared()) { |
|
|
|
|
LOG.info("Sending commit message."); |
|
|
|
|
LOG.debug("Sending commit message. round={}", roundState.getRoundIdentifier()); |
|
|
|
|
final Block block = roundState.getProposedBlock().get(); |
|
|
|
|
transmitter.multicastCommit(getRoundIdentifier(), block.getHash(), createCommitSeal(block)); |
|
|
|
|
} |
|
|
|
@ -212,7 +223,7 @@ public class IbftRound { |
|
|
|
|
final boolean wasPrepared = roundState.isPrepared(); |
|
|
|
|
roundState.addPrepareMessage(msg); |
|
|
|
|
if (wasPrepared != roundState.isPrepared()) { |
|
|
|
|
LOG.info("Sending commit message."); |
|
|
|
|
LOG.debug("Sending commit message. round={}", roundState.getRoundIdentifier()); |
|
|
|
|
final Block block = roundState.getProposedBlock().get(); |
|
|
|
|
transmitter.multicastCommit(getRoundIdentifier(), block.getHash(), createCommitSeal(block)); |
|
|
|
|
} |
|
|
|
@ -231,11 +242,17 @@ public class IbftRound { |
|
|
|
|
IbftHelpers.createSealedBlock( |
|
|
|
|
roundState.getProposedBlock().get(), roundState.getCommitSeals()); |
|
|
|
|
|
|
|
|
|
LOG.info("Importing block to chain."); |
|
|
|
|
boolean result = |
|
|
|
|
final long blockNumber = blockToImport.getHeader().getNumber(); |
|
|
|
|
final IbftExtraData extraData = IbftExtraData.decode(blockToImport.getHeader().getExtraData()); |
|
|
|
|
LOG.info("Importing block to chain. block={} extraData={}", blockNumber, extraData); |
|
|
|
|
final boolean result = |
|
|
|
|
blockImporter.importBlock(protocolContext, blockToImport, HeaderValidationMode.FULL); |
|
|
|
|
if (!result) { |
|
|
|
|
LOG.info("Failed to import block to chain."); |
|
|
|
|
LOG.error( |
|
|
|
|
"Failed to import block to chain. block={} extraData={} blockHeader={}", |
|
|
|
|
blockNumber, |
|
|
|
|
extraData, |
|
|
|
|
blockToImport.getHeader()); |
|
|
|
|
} else { |
|
|
|
|
notifyNewBlockListeners(blockToImport); |
|
|
|
|
} |
|
|
|
|