Skip to content

Commit

Permalink
Fixed conflicts from merge, implemented suggested changes, reverted g…
Browse files Browse the repository at this point in the history
…radle props.

Signed-off-by: amsmota <amsmota@gmail.com>
  • Loading branch information
amsmota committed Sep 20, 2024
1 parent a093d81 commit 0c6fc85
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BftFork implements Fork {
public static final String BLOCK_PERIOD_SECONDS_KEY = "blockperiodseconds";

/** The constant EMPTY_BLOCK_PERIOD_SECONDS_KEY. */
public static final String EMPTY_BLOCK_PERIOD_SECONDS_KEY = "emptyblockperiodseconds";
public static final String EMPTY_BLOCK_PERIOD_SECONDS_KEY = "xemptyblockperiodseconds";

/** The constant BLOCK_PERIOD_MILLISECONDS_KEY. */
public static final String BLOCK_PERIOD_MILLISECONDS_KEY = "xblockperiodmilliseconds";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int getBlockPeriodSeconds() {
@Override
public int getEmptyBlockPeriodSeconds() {
return JsonUtil.getInt(
bftConfigRoot, "emptyblockperiodseconds", DEFAULT_EMPTY_BLOCK_PERIOD_SECONDS);
bftConfigRoot, "xemptyblockperiodseconds", DEFAULT_EMPTY_BLOCK_PERIOD_SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void shouldGetBlockPeriodFromConfig() {

@Test
public void shouldGetEmptyBlockPeriodFromConfig() {
final BftConfigOptions config = fromConfigOptions(singletonMap("emptyblockperiodseconds", 60));
final BftConfigOptions config = fromConfigOptions(singletonMap("xemptyblockperiodseconds", 60));
assertThat(config.getEmptyBlockPeriodSeconds()).isEqualTo(60);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,32 @@ public synchronized boolean isRunning() {
*/
public synchronized void startTimer(
final ConsensusRoundIdentifier round, final BlockHeader chainHeadHeader) {
cancelTimer();

final long now = clock.millis();
final long expiryTime;
// cancelTimer();
//
// final long now = clock.millis();
// final long expiryTime;

// Experimental option for test scenarios only. Not for production use.
final long blockPeriodMilliseconds =
forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodMilliseconds();

if (blockPeriodMilliseconds > 0) {
// Experimental mode for setting < 1 second block periods e.g. for CI/CD pipelines
// running tests against Besu
expiryTime = clock.millis() + blockPeriodMilliseconds;
LOG.warn(
"Test-mode only xblockperiodmilliseconds has been set to {} millisecond blocks. Do not use in a production system.",
blockPeriodMilliseconds);
} else {
// absolute time when the timer is supposed to expire
final int blockPeriodSeconds =
forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodSeconds();
final long minimumTimeBetweenBlocksMillis = blockPeriodSeconds * 1000L;
expiryTime = chainHeadHeader.getTimestamp() * 1_000 + minimumTimeBetweenBlocksMillis;
}
// final long blockPeriodMilliseconds =
//
// forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodMilliseconds();
//
// if (blockPeriodMilliseconds > 0) {
// // Experimental mode for setting < 1 second block periods e.g. for CI/CD pipelines
// // running tests against Besu
// expiryTime = clock.millis() + blockPeriodMilliseconds;
// LOG.warn(
// "Test-mode only xblockperiodmilliseconds has been set to {} millisecond blocks. Do
// not use in a production system.",
// blockPeriodMilliseconds);
// } else {
// // absolute time when the timer is supposed to expire
// final int blockPeriodSeconds =
// forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodSeconds();
// final long minimumTimeBetweenBlocksMillis = blockPeriodSeconds * 1000L;
// expiryTime = chainHeadHeader.getTimestamp() * 1_000 + minimumTimeBetweenBlocksMillis;
// }

// absolute time when the timer is supposed to expire
final int currentBlockPeriodSeconds =
forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodSeconds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void buildBlockAndMaybePropose(
LOG.trace(
"Block has transactions and this node is a proposer so it will send a proposal: "
+ roundIdentifier);
qbftRound.sendProposalMessage(block);
qbftRound.updateStateWithProposalAndTransmit(block);

} else {
// handle the block times period
Expand All @@ -172,7 +172,7 @@ private void buildBlockAndMaybePropose(
LOG.trace(
"Block has no transactions and this node is a proposer so it will send a proposal: "
+ roundIdentifier);
qbftRound.sendProposalMessage(block);
qbftRound.updateStateWithProposalAndTransmit(block);
} else {
LOG.trace(
"Block has no transactions but emptyBlockPeriodSeconds did not expired yet: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,19 @@ public Block createBlock(final long headerTimeStampSeconds) {
return blockCreator.createBlock(headerTimeStampSeconds, this.parentHeader).getBlock();
}

/**
* Send proposal message.
*
* @param block to send
*/
public void sendProposalMessage(final Block block) {
LOG.trace("Creating proposed block blockHeader={}", block.getHeader());
updateStateWithProposalAndTransmit(block);
}

/**
* Create and send proposal message.
*
* @param headerTimeStampSeconds the header time stamp seconds
*/
public void createAndSendProposalMessage(final long headerTimeStampSeconds) {
LOG.debug("Creating proposed block. round={}", roundState.getRoundIdentifier());
final Block block =
blockCreator.createBlock(headerTimeStampSeconds, this.parentHeader).getBlock();

LOG.trace("Creating proposed block blockHeader={}", block.getHeader());
updateStateWithProposalAndTransmit(block, emptyList(), emptyList());
}
// public void createAndSendProposalMessage(final long headerTimeStampSeconds) {
// LOG.debug("Creating proposed block. round={}", roundState.getRoundIdentifier());
// final Block block =
// blockCreator.createBlock(headerTimeStampSeconds, this.parentHeader).getBlock();
//
// LOG.trace("Creating proposed block blockHeader={}", block.getHeader());
// updateStateWithProposalAndTransmit(block, emptyList(), emptyList());
// }

/**
* Start round with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.consensus.common.bft.BftBlockHashing;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
Expand All @@ -48,7 +47,6 @@
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreationTiming;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
Expand Down Expand Up @@ -196,89 +194,90 @@ public void onReceptionOfValidProposalSendsAPrepareToNetworkPeers() {
verify(transmitter, never()).multicastCommit(any(), any(), any());
}

@Test
public void sendsAProposalAndPrepareWhenSendProposalRequested() {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
final QbftRound round =
new QbftRound(
roundState,
blockCreator,
protocolContext,
protocolSchedule,
subscribers,
nodeKey,
messageFactory,
transmitter,
roundTimer,
bftExtraDataCodec,
parentHeader);

round.createAndSendProposalMessage(15);
verify(transmitter, times(1))
.multicastProposal(
roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList());
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, never()).multicastCommit(any(), any(), any());
}

@Test
public void singleValidatorImportBlocksImmediatelyOnProposalCreation() {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final QbftRound round =
new QbftRound(
roundState,
blockCreator,
protocolContext,
protocolSchedule,
subscribers,
nodeKey,
messageFactory,
transmitter,
roundTimer,
bftExtraDataCodec,
parentHeader);
round.createAndSendProposalMessage(15);
verify(transmitter, times(1))
.multicastProposal(
roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList());
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, times(1)).multicastCommit(any(), any(), any());
}

@Test
public void localNodeProposesToNetworkOfTwoValidatorsImportsOnReceptionOfCommitFromPeer() {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final QbftRound round =
new QbftRound(
roundState,
blockCreator,
protocolContext,
protocolSchedule,
subscribers,
nodeKey,
messageFactory,
transmitter,
roundTimer,
bftExtraDataCodec,
parentHeader);

final Hash commitSealHash =
new BftBlockHashing(new QbftExtraDataCodec())
.calculateDataHashForCommittedSeal(proposedBlock.getHeader(), proposedExtraData);
final SECPSignature localCommitSeal = nodeKey.sign(commitSealHash);

round.createAndSendProposalMessage(15);
verify(transmitter, never()).multicastCommit(any(), any(), any());

round.handlePrepareMessage(
messageFactory2.createPrepare(roundIdentifier, proposedBlock.getHash()));

verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);

round.handleCommitMessage(
messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
}
// @Test
// public void sendsAProposalAndPrepareWhenSendProposalRequested() {
// final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
// final QbftRound round =
// new QbftRound(
// roundState,
// blockCreator,
// protocolContext,
// protocolSchedule,
// subscribers,
// nodeKey,
// messageFactory,
// transmitter,
// roundTimer,
// bftExtraDataCodec,
// parentHeader);
//
// round.createAndSendProposalMessage(15);
// verify(transmitter, times(1))
// .multicastProposal(
// roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList());
// verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
// verify(transmitter, never()).multicastCommit(any(), any(), any());
// }

// @Test
// public void singleValidatorImportBlocksImmediatelyOnProposalCreation() {
// final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
// final QbftRound round =
// new QbftRound(
// roundState,
// blockCreator,
// protocolContext,
// protocolSchedule,
// subscribers,
// nodeKey,
// messageFactory,
// transmitter,
// roundTimer,
// bftExtraDataCodec,
// parentHeader);
// round.createAndSendProposalMessage(15);
// verify(transmitter, times(1))
// .multicastProposal(
// roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList());
// verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
// verify(transmitter, times(1)).multicastCommit(any(), any(), any());
// }

// @Test
// public void localNodeProposesToNetworkOfTwoValidatorsImportsOnReceptionOfCommitFromPeer() {
// final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
// final QbftRound round =
// new QbftRound(
// roundState,
// blockCreator,
// protocolContext,
// protocolSchedule,
// subscribers,
// nodeKey,
// messageFactory,
// transmitter,
// roundTimer,
// bftExtraDataCodec,
// parentHeader);
//
// final Hash commitSealHash =
// new BftBlockHashing(new QbftExtraDataCodec())
// .calculateDataHashForCommittedSeal(proposedBlock.getHeader(), proposedExtraData);
// final SECPSignature localCommitSeal = nodeKey.sign(commitSealHash);
//
// round.createAndSendProposalMessage(15);
// verify(transmitter, never()).multicastCommit(any(), any(), any());
//
// round.handlePrepareMessage(
// messageFactory2.createPrepare(roundIdentifier, proposedBlock.getHash()));
//
// verify(transmitter, times(1))
// .multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
//
// round.handleCommitMessage(
// messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(),
// remoteCommitSeal));
// }

@Test
public void aProposalWithAnewBlockIsSentUponReceptionOfARoundChangeWithNoCertificate() {
Expand Down Expand Up @@ -393,25 +392,25 @@ public void creatingNewBlockFromEmptyPreparedCertificateUpdatesInternalState() {
assertThat(roundState.isPrepared()).isTrue();
}

@Test
public void creatingNewBlockNotifiesBlockMiningObservers() {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final QbftRound round =
new QbftRound(
roundState,
blockCreator,
protocolContext,
protocolSchedule,
subscribers,
nodeKey,
messageFactory,
transmitter,
roundTimer,
bftExtraDataCodec,
parentHeader);
round.createAndSendProposalMessage(15);
verify(minedBlockObserver).blockMined(any());
}
// @Test
// public void creatingNewBlockNotifiesBlockMiningObservers() {
// final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
// final QbftRound round =
// new QbftRound(
// roundState,
// blockCreator,
// protocolContext,
// protocolSchedule,
// subscribers,
// nodeKey,
// messageFactory,
// transmitter,
// roundTimer,
// bftExtraDataCodec,
// parentHeader);
// round.createAndSendProposalMessage(15);
// verify(minedBlockObserver).blockMined(any());
// }

@Test
public void blockIsOnlyImportedOnceWhenCommitsAreReceivedBeforeProposal() {
Expand Down
9 changes: 2 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ org.gradle.welcome=never
# version=24.5.6-acme
# versionappendcommit=true

test.maxParallelForks = 1
test.forkEvery = 100


# Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396)
org.gradle.jvmargs=-Xmx3g \
org.gradle.jvmargs=-Xmx4g \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
Expand All @@ -22,5 +18,4 @@ org.gradle.jvmargs=-Xmx3g \
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
# Could be moved to sonar properties after https://sonarsource.atlassian.net/browse/SONARGRADL-134
systemProp.sonar.gradle.skipCompile=true
#sonar.gradle.skipCompile=true
systemProp.sonar.gradle.skipCompile=true

0 comments on commit 0c6fc85

Please sign in to comment.