use of org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry in project besu by hyperledger.
the class BlockTimer method startTimer.
/**
* Starts a timer for the supplied round cancelling any previously active block timer
*
* @param round The round identifier which this timer is tracking
* @param chainHeadHeader The header of the chain head
*/
public synchronized void startTimer(final ConsensusRoundIdentifier round, final BlockHeader chainHeadHeader) {
cancelTimer();
final long now = clock.millis();
// absolute time when the timer is supposed to expire
final int blockPeriodSeconds = forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodSeconds();
final long minimumTimeBetweenBlocksMillis = blockPeriodSeconds * 1000L;
final long expiryTime = chainHeadHeader.getTimestamp() * 1_000 + minimumTimeBetweenBlocksMillis;
if (expiryTime > now) {
final long delay = expiryTime - now;
final Runnable newTimerRunnable = () -> queue.add(new BlockTimerExpiry(round));
final ScheduledFuture<?> newTimerTask = bftExecutors.scheduleTask(newTimerRunnable, delay, TimeUnit.MILLISECONDS);
currentTimerTask = Optional.of(newTimerTask);
} else {
queue.add(new BlockTimerExpiry(round));
}
}
use of org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry in project besu by hyperledger.
the class ValidatorContractTest method createNewBlockAsProposer.
private void createNewBlockAsProposer(final TestContext context, final long blockNumber) {
ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(blockNumber, 0);
// trigger proposal
context.getController().handleBlockTimerExpiry(new BlockTimerExpiry(roundId));
// peers commit proposed block
Block proposedBlock = context.createBlockForProposalFromChainHead(clock.instant().getEpochSecond());
RoundSpecificPeers peers = context.roundSpecificPeers(roundId);
peers.commitForNonProposing(roundId, proposedBlock);
assertThat(context.getCurrentChainHeight()).isEqualTo(blockNumber);
context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
}
use of org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry in project besu by hyperledger.
the class LocalNodeIsProposerTest method setup.
@BeforeEach
public void setup() {
expectedProposedBlock = context.createBlockForProposalFromChainHead(blockTimeStamp);
expectedTxProposal = localNodeMessageFactory.createProposal(roundId, expectedProposedBlock, Collections.emptyList(), Collections.emptyList());
expectedTxPrepare = localNodeMessageFactory.createPrepare(roundId, expectedProposedBlock.getHash());
expectedTxCommit = new Commit(createSignedCommitPayload(roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKey()));
// Trigger "block timer" to send proposal.
context.getController().handleBlockTimerExpiry(new BlockTimerExpiry(roundId));
}
use of org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry in project besu by hyperledger.
the class IbftControllerTest method handlesBlockTimerExpiry.
@Test
public void handlesBlockTimerExpiry() {
final BlockTimerExpiry blockTimerExpiry = new BlockTimerExpiry(roundIdentifier);
constructIbftController();
ibftController.start();
ibftController.handleBlockTimerExpiry(blockTimerExpiry);
verify(blockHeightManager).handleBlockTimerExpiry(roundIdentifier);
}
use of org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry in project besu by hyperledger.
the class BlockTimerTest method eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsEqualToNow.
@Test
public void eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsEqualToNow() {
final int MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15;
final long NOW_MILLIS = 515_000L;
final long BLOCK_TIME_STAMP = 500;
when(mockForksSchedule.getFork(anyLong())).thenReturn(new ForkSpec<>(0, createBftFork(MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS)));
final BlockTimer timer = new BlockTimer(mockQueue, mockForksSchedule, bftExecutors, mockClock);
when(mockClock.millis()).thenReturn(NOW_MILLIS);
final BlockHeader header = new BlockHeaderTestFixture().timestamp(BLOCK_TIME_STAMP).buildHeader();
final ConsensusRoundIdentifier round = new ConsensusRoundIdentifier(0xFEDBCA9876543210L, 0x12345678);
timer.startTimer(round, header);
verify(bftExecutors, never()).scheduleTask(any(Runnable.class), anyLong(), any());
final ArgumentCaptor<BftEvent> bftEventCaptor = ArgumentCaptor.forClass(BftEvent.class);
verify(mockQueue).add(bftEventCaptor.capture());
assertThat(bftEventCaptor.getValue() instanceof BlockTimerExpiry).isTrue();
assertThat(((BlockTimerExpiry) bftEventCaptor.getValue()).getRoundIndentifier()).usingRecursiveComparison().isEqualTo(round);
}
Aggregations