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