Skip to content
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

Implementation of Issue #3810 QBFT no empty block #6944

Closed
wants to merge 179 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
cd8c857
Mining Parameters Metrics (#6587)
Brindrajsinh-Chauhan Feb 20, 2024
0ca261d
Implementing support for emptyBlockPeriodSeconds in QBFT (Issue #3810)
amsmota Feb 21, 2024
4bd2f5f
Implementing support for emptyBlockPeriodSeconds in QBFT (Issue #3810)
amsmota Mar 12, 2024
beb2756
Implementing support for emptyBlockPeriodSeconds in QBFT (Issue #3810)
amsmota Mar 27, 2024
40202b6
PR Template updates (#6598)
jflo Feb 21, 2024
8eb3564
Restrict downgrade (#6307)
matthew1001 Feb 21, 2024
c8bbfe2
Move account warming from gas calculator to call operations (#6557)
shemnon Feb 21, 2024
4c5dd07
Gha docker pull (#6600)
jflo Feb 21, 2024
326979b
Pass the exceptionHaltReason of the frame if the operation reason is …
Gabriel-Trintinalia Feb 22, 2024
bd56ef3
Use Invalid payload attributes error code (#6582)
macfarla Feb 22, 2024
0e6e2e2
During version check, create data dir if it doesn't exist (#6605)
matthew1001 Feb 22, 2024
28bf551
Extend Blockchain service (#6592)
fab-10 Feb 26, 2024
6e27fe3
Database metadata refactor (#6555)
fab-10 Feb 26, 2024
397e4c2
Abstracts out which container registry (#6606)
jflo Feb 26, 2024
bbb6af8
remove unnecessary PoS checkpoint methods and variables (#6603)
gfukushima Feb 26, 2024
1cfeee5
[MINOR] Rotate changelog since 24.2.0-RC has been cut (#6604)
siladu Feb 27, 2024
642b5b0
Fix NPE when running revert variable subcommand (#6616)
jframe Feb 27, 2024
6c01e84
Fixing conflicts and merge and sign
fab-10 Feb 27, 2024
74a56c2
Make layered txpool aware of minGasPrice and minPriorityFeePerGas dyn…
fab-10 Feb 27, 2024
305762e
Cleanup after refactoring TransactionSelectionService (#6618)
fab-10 Feb 27, 2024
213170b
Acceptance tests to use bonsai (#6619)
macfarla Feb 28, 2024
0201b84
Fixing conflict, merge and sign
siladu Feb 28, 2024
00ca00a
revert 6499 flat-db-healing-enabled false by default (#6642)
macfarla Feb 29, 2024
f2f4b1c
prevent startup if PoA and snap/checkpoint (#6625)
macfarla Feb 29, 2024
ee2dc51
refactored some BesuCommandTests into separate test classes (#6644)
macfarla Feb 29, 2024
d359ad5
Update commons-compress to 1.26.0 (#6648)
fab-10 Mar 1, 2024
bf17f06
Remove an unnecessary persist during the backwardsync (#6570)
matkt Mar 2, 2024
b0dda34
allow snap with clique (#6667)
macfarla Mar 3, 2024
80c44f6
Clique createemptyblocks transition (#6608)
siladu Mar 4, 2024
ea16ab7
[#6301] Track bad block cause (#6622)
mbaxter Mar 4, 2024
498b78c
Revert "Acceptance tests to use bonsai (#6619)" (#6677)
RoboCopsGoneSock Mar 4, 2024
096d1f4
adjust help message for --genesis-file (#6654)
macfarla Mar 5, 2024
911b8a7
Add blobs to `eth_feeHistory` (#6679)
Gabriel-Trintinalia Mar 5, 2024
35682e4
Eth call with 4844 params (#6661)
macfarla Mar 5, 2024
3a82cf2
[MINOR] Remove todo override genesis config (#6659)
macfarla Mar 5, 2024
aa5a829
Refactor and extend PluginTransactionPoolValidatorService (#6636)
fab-10 Mar 5, 2024
5064c2b
Bugfix - only track intrinsically bad blocks (#6678)
mbaxter Mar 5, 2024
4fdfc6e
silence the vertx counterpart to the tuweni dns errors (#6684)
garyschulte Mar 5, 2024
fe97322
Remove isChainPruneEnabled from MergeContext interface (#6672)
gfukushima Mar 6, 2024
447e595
[build] - Update gradle build to make assemble invoke integration tes…
usmansaleem Mar 7, 2024
982a795
Update Vert.x to 4.5.4 (#6666)
fab-10 Mar 7, 2024
ffd1cab
fix for txpool inSync listener to honor initial sync state (#6696)
garyschulte Mar 7, 2024
c7f4d09
Add logging for newer FCU payload parameter details (#6693)
siladu Mar 8, 2024
3ebbac0
worldstate refactor (#6209)
matkt Mar 8, 2024
f6a438a
[MINOR] Remove unused method (#6713)
siladu Mar 12, 2024
c7df577
Add privacy and permissioning services to thread plugin context (#6711)
Gabriel-Trintinalia Mar 12, 2024
80e0a34
Transaction call object to accept both input and data field if equal …
friedemannf Mar 12, 2024
28c3bde
eth_call with blobs - added more spec tests (#6687)
macfarla Mar 12, 2024
1b2503e
Fixing conflicts, merge and sign
fab-10 Mar 12, 2024
1dcee43
Don't start the BFT mining coordinator when it is created, just enabl…
matthew1001 Mar 12, 2024
1512b8b
Gha updates (#6705)
jflo Mar 12, 2024
edf58a5
Support pruned chain history in peer validators (#6698)
garyschulte Mar 13, 2024
23f1089
edits to changelog for 24.3.0 (#6712)
macfarla Mar 13, 2024
fcd4ef8
Refactor BadBlockReason enum out of BadBlockCause (#6716)
usmansaleem Mar 13, 2024
95fe3fa
verify syncing false (#6720)
macfarla Mar 13, 2024
4d4ba28
Fix txpool dump/restore race condition (#6665)
fab-10 Mar 13, 2024
6395eb4
Transaction simulation service (#6686)
fab-10 Mar 13, 2024
86943c7
proposed "develop" build versions (#6699)
garyschulte Mar 13, 2024
4c4e68a
Refactor PluginPrivacyController (#6725)
usmansaleem Mar 14, 2024
e0d7357
Move potentially spammy peer discovery warn log to debug (#6728)
siladu Mar 14, 2024
4aeca81
Change`txpool_beusPendingTransactions`:`numResults` from a required …
MASDXI Mar 14, 2024
d99e888
chore: remove repetitive words (#6730)
wellweek Mar 15, 2024
c3e5c28
Add comments to a couple of the the EthPeer methods to clarify their …
matthew1001 Mar 15, 2024
2f097c9
Refactor StorageRangeDataRequest to fix nodes saved variable (#6726)
usmansaleem Mar 15, 2024
a74189c
Fix permissioning plugin test (#6737)
Gabriel-Trintinalia Mar 15, 2024
74d052b
PR Annotations removed (#6735)
jflo Mar 15, 2024
b161ad6
feat: add fixed basefee options (#6562)
suraneti Mar 16, 2024
aa9606a
Artifactory publish (#6746)
jflo Mar 16, 2024
9b2c1a4
ignore flaky test (#6748)
macfarla Mar 18, 2024
e42e6bd
chore: fix some typos (#6741)
standstaff Mar 18, 2024
387ead7
fix(build): docker git ref (#6744)
Savid Mar 18, 2024
50d7100
Suppress ComparisonOutOfRange error-prone warning in AbstractGasLimit…
usmansaleem Mar 18, 2024
492da9d
disable not ignore (#6754)
macfarla Mar 18, 2024
f60f849
uprevved kzg library dependency, aligns version num with upstream (#6…
jflo Mar 19, 2024
a33ed33
allow empty maxFeePerBlobGas for eth_call (#6731)
macfarla Mar 19, 2024
159838d
Log an info message on startup to indicate if IPv6 peer connectivity …
matthew1001 Mar 19, 2024
86f0bfe
Log blob count (#6761)
shemnon Mar 19, 2024
7f28ff7
Extend error handling of plugin RPC methods (#6759)
fab-10 Mar 20, 2024
e5b62f8
get value for sonar options from vars (#6767)
jflo Mar 21, 2024
cf06645
Fix for `Method input parameters must be final` compilation error (#6…
fab-10 Mar 21, 2024
3529370
GraphQL serializes BlobVersionedHashes (#6769)
shemnon Mar 21, 2024
ed2184a
Artifactory publish (#6781)
jflo Mar 21, 2024
1e8700c
typo in env var (#6780)
jflo Mar 21, 2024
0621a5b
for fcu v2 use correct invalid params error code (#6766)
macfarla Mar 21, 2024
751f6d1
Cleanup dev releases (#6782)
jflo Mar 21, 2024
073034e
extra check for syncing (#6771)
macfarla Mar 22, 2024
982ea96
updated PR template (#6773)
macfarla Mar 22, 2024
2e40543
Fix "Backward sync stuck in a loop" #6749 (#6756)
pinges Mar 22, 2024
6177f86
ci: Fix Publish GH workflow Artifactory secrets (#6788)
usmansaleem Mar 22, 2024
ce4c617
Improve PluginRpcEndpointException log (#6789)
fab-10 Mar 22, 2024
6e77599
Adding engine_getPayloadV4 and engine_newPayloadV4 (#6783)
lucassaldanha Mar 23, 2024
51176e1
Refactor BackwardsSyncAlgorithm.pickNextStep for readability (#6775)
siladu Mar 25, 2024
5ff0c3a
Reduce receipt size (#6602)
jframe Mar 26, 2024
228bd1e
Remove draft config from develop release action (#6807)
siladu Mar 26, 2024
6fe8722
Set noisy TransactionLogBloomCacher debug log to trace (#6808)
siladu Mar 26, 2024
7f10960
Support running executable Gradle tasks on Windows with WSL (#6803)
fab-10 Mar 26, 2024
fe63654
Fix issues during snap sync (#6802)
matkt Mar 26, 2024
e4db0fa
Modify the message when the selection of transactions is interrupted …
ahamlat Mar 26, 2024
cc81a34
Block on skipped matrix (#6818)
jflo Mar 26, 2024
d452127
build - Refactor Besu custom error prone dependency (#6692)
usmansaleem Mar 26, 2024
914c952
Expose `v` field in JSON-RPC in some transaction types (#6819)
shemnon Mar 26, 2024
c4c560a
Add holesky DNS server (#6824)
gfukushima Mar 27, 2024
aba1670
Support running acceptance tests on Windows (#6820)
fab-10 Mar 27, 2024
3922b75
storage format refactor for preparing verkle trie integration (#6721)
matkt Mar 27, 2024
8e66290
Ensure empty withdrawal lists are set in BFT blocks when the protocol…
matthew1001 Mar 27, 2024
f7dc25d
Fix two flacky acceptance tests (#6837)
fab-10 Mar 28, 2024
bbeb83e
Fix to avoid broadcasting full blob txs (#6835)
fab-10 Mar 28, 2024
c0d9d14
logging fix for historical queries (#6830)
non-fungible-nelson Mar 28, 2024
65fc035
refactor to check for null peer (#6841)
macfarla Mar 29, 2024
298340c
update broken link, issue template (#6829)
non-fungible-nelson Mar 29, 2024
ced9302
Prevent startup with privacy and bonsai enabled (#6809)
macfarla Mar 29, 2024
cdfbb32
Dedicated log marker for invalid txs removed from the txpool (#6826)
fab-10 Mar 29, 2024
f51dd2a
resolving conflicts, merge and sign
fab-10 Mar 29, 2024
b392118
fix account copy issue (#6845)
matkt Mar 29, 2024
2feade0
increase timeout (#6852)
macfarla Mar 29, 2024
fa6814e
disable flaky test - LegacyFeeMarketBlockTransactionSelectorTest (#6851)
macfarla Mar 29, 2024
cc20c23
Snap client fixes (#6847)
garyschulte Mar 30, 2024
6ef9e2a
Snap server rebase (#6640)
garyschulte Mar 30, 2024
c9cd5eb
workaround for broken publishing of buildinfo (#6856)
jflo Apr 1, 2024
e17ab77
Upgrade reference tests to 13.2 (#6854)
shemnon Apr 2, 2024
75b81bb
build: Remove incomplete artifactory task (#6857)
usmansaleem Apr 2, 2024
ea59aa2
Log at debug the first error when adding a tx for the sender fails (#…
fab-10 Apr 2, 2024
b3cd32e
Update Web3j dependencies (#6811)
fab-10 Apr 2, 2024
e9e923b
Remove some dead code (#6861)
fab-10 Apr 2, 2024
525d0e5
[MINOR] Use 7 chars instead of 10 for source build hash (#6858)
siladu Apr 2, 2024
094c0ed
Remove develop prelease workflow (#6860)
siladu Apr 2, 2024
c90cdf8
add prefix to dns (#6867)
gfukushima Apr 3, 2024
51aea4c
removed extra ... (#6849)
macfarla Apr 3, 2024
7eb3ff2
make test use threshold values explicitly (#6843)
macfarla Apr 3, 2024
9fa125e
Fix besu-untuned start script (#6871)
fab-10 Apr 3, 2024
b824ba8
[MINOR] nuke those extra ellipses (#6870)
macfarla Apr 3, 2024
4581586
Move log entry to specific places where it is useful (#6873)
matthew1001 Apr 3, 2024
2dda177
use event name instead of ref, which may be non-deterministic (#6866)
jflo Apr 3, 2024
9feb430
Add debug logs for when transaction processing halts or reverts (#6875)
matthew1001 Apr 3, 2024
f204715
Blob transaction replacement rule (#6874)
fab-10 Apr 3, 2024
fab8e00
remove check for snap server in controller builder (#6876)
garyschulte Apr 3, 2024
ee2e4ef
align PeerReputation timout threshold with peer max outstanding reque…
garyschulte Apr 3, 2024
67e8cda
Bws internal error fix (#6806)
jframe Apr 4, 2024
517120e
EIP-7002: Add exits/exits_root to block/block_header (#6801)
lucassaldanha Apr 4, 2024
63ee7bc
fix: Use HttpRequest authority instead of host (#6879)
usmansaleem Apr 5, 2024
de2d283
Add debug logging to see why we stop downloading from peer (#6885)
siladu Apr 5, 2024
7e98ea5
Improve logging of peer disconnects due to subprotocol triggered reas…
jframe Apr 5, 2024
adac964
One JDK to rule them all (#6865)
jflo Apr 6, 2024
872f8fd
added richness to useless peer disconnect reasons (#6899)
macfarla Apr 8, 2024
8def976
Correctly initialize the txpool as disabled on creation (#6890)
fab-10 Apr 8, 2024
8f3023c
filtered out the noisy Invalid Trace log messages (#6825)
macfarla Apr 8, 2024
dde934e
Log detailed timing of block creation steps (#6880)
fab-10 Apr 8, 2024
604e117
Expose transaction count by type metrics for the layered txpool (#6903)
fab-10 Apr 8, 2024
c78d44a
marks flaky test as such (#6906)
jflo Apr 9, 2024
df2424c
Fixing conflicts, merge, sign
shemnon Apr 9, 2024
d08ff67
Added waitTime option on engine ATs (#6907)
lucassaldanha Apr 9, 2024
fe2e308
add peer count (#6911)
macfarla Apr 9, 2024
f45ddad
disable the two tests that fail on Mac (#6912)
macfarla Apr 9, 2024
5693024
Fix and reformat produced block timing log (#6916)
fab-10 Apr 9, 2024
b902895
[Issue-6301] Add bad block events (#6848)
mbaxter Apr 9, 2024
f3fe241
Fix flaky test (#6917)
macfarla Apr 9, 2024
b516861
Add RPC errors metric (#6919)
ahamlat Apr 9, 2024
b4f2cb6
feat: add --genesis-state-hash-cache-enabled paramater (#6758)
lyfsn Apr 10, 2024
306bd66
follow up improvement in ordering to fix flakiness (#6922)
macfarla Apr 10, 2024
3cbb807
richness for breach of protocol reasons (#6925)
macfarla Apr 10, 2024
40c6bab
Refactor Gas Calculator Create methods (#6905)
shemnon Apr 10, 2024
e6f53bf
add rlp decode subcommand (#6895)
Brindrajsinh-Chauhan Apr 10, 2024
c983928
added an else and extra logging (#6931)
macfarla Apr 11, 2024
72f30f9
Fixed issues after merge (Issue #3810)
amsmota Apr 12, 2024
e56987e
Fix permissions publish and gradle issue for publishArtifactory (#6930)
siladu Apr 11, 2024
65a4eda
fix npe on trace msg (#6934)
gfukushima Apr 12, 2024
3abbb55
Add Paris Support to tests (#6933)
shemnon Apr 12, 2024
50faf1e
Fix Flaky test permv2 (#6936)
macfarla Apr 12, 2024
76f63f0
Consistent nonce handling (#6941)
shemnon Apr 12, 2024
f977740
Fix named network default disabled for downgrade protection (#6943)
garyschulte Apr 14, 2024
b449145
check for empty in disconnect reason bytes (#6938)
macfarla Apr 15, 2024
4f23808
Docker develop publishing task (#6893)
garyschulte Apr 15, 2024
6460a35
Change block miner log to include all the performance number on one l…
ahamlat Apr 15, 2024
3825681
Revert 7e46889 which slowed down ATs (#6948)
siladu Apr 16, 2024
03c0503
Split acceptance tests by time (#6953)
fab-10 Apr 16, 2024
aa7e38f
Corrections from review comments
amsmota Apr 16, 2024
46d5859
Merge branch 'main' into #3810-qbft-no-empty-block
amsmota Apr 16, 2024
5faf5c9
Corrections from review comments
amsmota Apr 17, 2024
38be820
UPLOADED NETWORK FOR TESTING ONLY -- TO REMOVE BEFORE THE FINAL DRAFT…
amsmota Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ private static MinedBlockObserver blockLogger(
return block ->
LOG.info(
String.format(
"%s #%,d / %d tx / %d pending / %,d (%01.1f%%) gas / (%s)",
"%s %s #%,d / %d tx / %d pending / %,d (%01.1f%%) gas / (%s)",
block.getHeader().getCoinbase().equals(localAddress) ? "Produced" : "Imported",
block.getBody().getTransactions().size() == 0 ? "empty block" : "block",
block.getHeader().getNumber(),
block.getBody().getTransactions().size(),
transactionPool.count(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ public abstract class CommandTestAbstract {
private static final Logger TEST_LOGGER = LoggerFactory.getLogger(CommandTestAbstract.class);

protected static final int POA_BLOCK_PERIOD_SECONDS = 5;
protected static final int POA_EMPTY_BLOCK_PERIOD_SECONDS = 50;
protected static final JsonObject VALID_GENESIS_QBFT_POST_LONDON =
(new JsonObject())
.put(
"config",
new JsonObject()
.put("londonBlock", 0)
.put("qbft", new JsonObject().put("blockperiodseconds", POA_BLOCK_PERIOD_SECONDS))
.put(
"qbft",
new JsonObject().put("blockperiodseconds", POA_BLOCK_PERIOD_SECONDS)));
new JsonObject()
.put("emptyblockperiodseconds", POA_EMPTY_BLOCK_PERIOD_SECONDS)));
protected static final JsonObject VALID_GENESIS_IBFT2_POST_LONDON =
(new JsonObject())
.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void posBlockCreationMaxTimeOption() {
@Test
public void posBlockCreationMaxTimeOutOfAllowedRange() {
internalTestFailure(
"--Xpos-block-creation-max-time must be positive and 12000",
"--Xpos-block-creation-max-time must be positive and less or equal 12000",
"--Xpos-block-creation-max-time",
"17000");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public interface BftConfigOptions {
*/
int getBlockPeriodSeconds();

/**
* Gets empty block period seconds.
*
* @return the empty block period seconds
*/
int getEmptyBlockPeriodSeconds();

/**
* Gets request timeout seconds.
*
Expand Down
13 changes: 13 additions & 0 deletions config/src/main/java/org/hyperledger/besu/config/BftFork.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class BftFork implements Fork {
/** The constant BLOCK_PERIOD_SECONDS_KEY. */
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";

/** The constant BLOCK_REWARD_KEY. */
public static final String BLOCK_REWARD_KEY = "blockreward";

Expand Down Expand Up @@ -82,6 +85,16 @@ public OptionalInt getBlockPeriodSeconds() {
return JsonUtil.getPositiveInt(forkConfigRoot, BLOCK_PERIOD_SECONDS_KEY);
}

/**
* Gets empty block period seconds.
*
* @return the empty block period seconds
*/
public OptionalInt getEmptyBlockPeriodSeconds() {
// It can be 0 to disable custom empty block periods
return JsonUtil.getInt(forkConfigRoot, EMPTY_BLOCK_PERIOD_SECONDS_KEY);
}

/**
* Gets block reward wei.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class JsonBftConfigOptions implements BftConfigOptions {

private static final long DEFAULT_EPOCH_LENGTH = 30_000;
private static final int DEFAULT_BLOCK_PERIOD_SECONDS = 1;
private static final int DEFAULT_EMPTY_BLOCK_PERIOD_SECONDS = 0;
// 0 keeps working as before, increase to activate it
private static final int DEFAULT_ROUND_EXPIRY_SECONDS = 1;
// In a healthy network this can be very small. This default limit will allow for suitable
// protection for on a typical 20 node validator network with multiple rounds
Expand Down Expand Up @@ -66,6 +68,12 @@ public int getBlockPeriodSeconds() {
bftConfigRoot, "blockperiodseconds", DEFAULT_BLOCK_PERIOD_SECONDS);
}

@Override
public int getEmptyBlockPeriodSeconds() {
return JsonUtil.getInt(
bftConfigRoot, "emptyblockperiodseconds", DEFAULT_EMPTY_BLOCK_PERIOD_SECONDS);
}

@Override
public int getRequestTimeoutSeconds() {
return JsonUtil.getInt(bftConfigRoot, "requesttimeoutseconds", DEFAULT_ROUND_EXPIRY_SECONDS);
Expand Down Expand Up @@ -133,6 +141,9 @@ public Map<String, Object> asMap() {
if (bftConfigRoot.has("blockperiodseconds")) {
builder.put("blockPeriodSeconds", getBlockPeriodSeconds());
}
if (bftConfigRoot.has("emptyblockperiodseconds")) {
builder.put("emptyblockperiodseconds", getEmptyBlockPeriodSeconds());
}
if (bftConfigRoot.has("requesttimeoutseconds")) {
builder.put("requestTimeoutSeconds", getRequestTimeoutSeconds());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.hyperledger.besu.datatypes.Address;
Expand All @@ -30,6 +31,7 @@ public class JsonBftConfigOptionsTest {

private static final int EXPECTED_DEFAULT_EPOCH_LENGTH = 30_000;
private static final int EXPECTED_DEFAULT_BLOCK_PERIOD = 1;
private static final int EXPECTED_EMPTY_DEFAULT_BLOCK_PERIOD = 0;
private static final int EXPECTED_DEFAULT_REQUEST_TIMEOUT = 1;
private static final int EXPECTED_DEFAULT_GOSSIPED_HISTORY_LIMIT = 1000;
private static final int EXPECTED_DEFAULT_MESSAGE_QUEUE_LIMIT = 1000;
Expand Down Expand Up @@ -61,25 +63,51 @@ public void shouldGetBlockPeriodFromConfig() {
assertThat(config.getBlockPeriodSeconds()).isEqualTo(5);
}

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

@Test
public void shouldFallbackToDefaultBlockPeriod() {
final BftConfigOptions config = fromConfigOptions(emptyMap());
assertThat(config.getBlockPeriodSeconds()).isEqualTo(EXPECTED_DEFAULT_BLOCK_PERIOD);
}

@Test
public void shouldFallbackToEmptyDefaultBlockPeriod() {
final BftConfigOptions config = fromConfigOptions(emptyMap());
assertThat(config.getEmptyBlockPeriodSeconds()).isEqualTo(EXPECTED_EMPTY_DEFAULT_BLOCK_PERIOD);
}

@Test
public void shouldGetDefaultBlockPeriodFromDefaultConfig() {
assertThat(JsonBftConfigOptions.DEFAULT.getBlockPeriodSeconds())
.isEqualTo(EXPECTED_DEFAULT_BLOCK_PERIOD);
}

@Test
public void shouldGetDefaultEmptyBlockPeriodFromDefaultConfig() {

assertThat(JsonBftConfigOptions.DEFAULT.getEmptyBlockPeriodSeconds())
.isEqualTo(EXPECTED_EMPTY_DEFAULT_BLOCK_PERIOD);
}

@Test
public void shouldThrowOnNonPositiveBlockPeriod() {
final BftConfigOptions config = fromConfigOptions(singletonMap("blockperiodseconds", -1));
assertThatThrownBy(() -> config.getBlockPeriodSeconds())
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void shouldNotThrowOnNonPositiveEmptyBlockPeriod() {
// can be 0 to be compatible with older versions
final BftConfigOptions config = fromConfigOptions(singletonMap("emptyblockperiodseconds", 0));
assertThatCode(() -> config.getEmptyBlockPeriodSeconds()).doesNotThrowAnyException();
}

@Test
public void shouldGetRequestTimeoutFromConfig() {
final BftConfigOptions config = fromConfigOptions(singletonMap("requesttimeoutseconds", 5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Class for starting and keeping organised block timers */
public class BlockTimer {

private static final Logger LOG = LoggerFactory.getLogger(BlockTimer.class);
private final ForksSchedule<? extends BftConfigOptions> forksSchedule;
private final BftExecutors bftExecutors;
private Optional<ScheduledFuture<?>> currentTimerTask;
private final BftEventQueue queue;
private final Clock clock;
private long blockPeriodSeconds;
private long emptyBlockPeriodSeconds;

/**
* Construct a BlockTimer with primed executor service ready to start timers
Expand All @@ -51,6 +57,8 @@ public BlockTimer(
this.bftExecutors = bftExecutors;
this.currentTimerTask = Optional.empty();
this.clock = clock;
this.blockPeriodSeconds = forksSchedule.getFork(0).getValue().getBlockPeriodSeconds();
this.emptyBlockPeriodSeconds = forksSchedule.getFork(0).getValue().getEmptyBlockPeriodSeconds();
amsmota marked this conversation as resolved.
Show resolved Hide resolved
}

/** Cancels the current running round timer if there is one */
Expand All @@ -76,16 +84,36 @@ public synchronized boolean isRunning() {
*/
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 =
final int currentBlockPeriodSeconds =
forksSchedule.getFork(round.getSequenceNumber()).getValue().getBlockPeriodSeconds();
final long minimumTimeBetweenBlocksMillis = blockPeriodSeconds * 1000L;
final long minimumTimeBetweenBlocksMillis = currentBlockPeriodSeconds * 1000L;
final long expiryTime = chainHeadHeader.getTimestamp() * 1_000 + minimumTimeBetweenBlocksMillis;

setBlockTimes(round, false);

startTimer(round, expiryTime);
}

public synchronized void startEmptyBlockTimer(
final ConsensusRoundIdentifier round, final BlockHeader chainHeadHeader) {

// absolute time when the timer is supposed to expire
final int currentBlockPeriodSeconds =
forksSchedule.getFork(round.getSequenceNumber()).getValue().getEmptyBlockPeriodSeconds();
final long minimumTimeBetweenBlocksMillis = currentBlockPeriodSeconds * 1000L;
final long expiryTime = chainHeadHeader.getTimestamp() * 1_000 + minimumTimeBetweenBlocksMillis;

setBlockTimes(round, true);

startTimer(round, expiryTime);
}

private synchronized void startTimer(final ConsensusRoundIdentifier round, final long expiryTime) {
cancelTimer();
final long now = clock.millis();

if (expiryTime > now) {
final long delay = expiryTime - now;

Expand All @@ -98,4 +126,27 @@ public synchronized void startTimer(
queue.add(new BlockTimerExpiry(round));
}
}

private synchronized void setBlockTimes(final ConsensusRoundIdentifier round, final boolean isEmpty) {
final BftConfigOptions currentConfigOptions = forksSchedule.getFork(round.getSequenceNumber()).getValue();
this.blockPeriodSeconds = currentConfigOptions.getBlockPeriodSeconds();
this.emptyBlockPeriodSeconds = currentConfigOptions.getEmptyBlockPeriodSeconds();

long currentBlockPeriodSeconds = isEmpty && this.emptyBlockPeriodSeconds > 0
? this.emptyBlockPeriodSeconds
: this.blockPeriodSeconds;

LOG.debug(
"NEW CURRENTBLOCKPERIODSECONDS SET TO {}: {}"
, isEmpty?"EMPTYBLOCKPERIODSECONDS":"BLOCKPERIODSECONDS"
, currentBlockPeriodSeconds);
}

public synchronized long getBlockPeriodSeconds(){
return blockPeriodSeconds;
}

public synchronized long getEmptyBlockPeriodSeconds(){
return emptyBlockPeriodSeconds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
import java.util.Map;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A mutable {@link BftConfigOptions} that is used for building config for transitions in the {@link
* ForksSchedule}*.
*/
public class MutableBftConfigOptions implements BftConfigOptions {

private static final Logger LOG = LoggerFactory.getLogger(MutableBftConfigOptions.class);
private long epochLength;
private int blockPeriodSeconds;
private int emptyBlockPeriodSeconds;
private int requestTimeoutSeconds;
private int gossipedHistoryLimit;
private int messageQueueLimit;
Expand All @@ -48,6 +54,7 @@ public class MutableBftConfigOptions implements BftConfigOptions {
public MutableBftConfigOptions(final BftConfigOptions bftConfigOptions) {
this.epochLength = bftConfigOptions.getEpochLength();
this.blockPeriodSeconds = bftConfigOptions.getBlockPeriodSeconds();
this.emptyBlockPeriodSeconds = bftConfigOptions.getEmptyBlockPeriodSeconds();
this.requestTimeoutSeconds = bftConfigOptions.getRequestTimeoutSeconds();
this.gossipedHistoryLimit = bftConfigOptions.getGossipedHistoryLimit();
this.messageQueueLimit = bftConfigOptions.getMessageQueueLimit();
Expand All @@ -65,9 +72,16 @@ public long getEpochLength() {

@Override
public int getBlockPeriodSeconds() {
LOG.debug("GET BLOCKPERIODSECONDS: " + blockPeriodSeconds);
return blockPeriodSeconds;
}

@Override
public int getEmptyBlockPeriodSeconds() {
LOG.debug("GET EMPTYBLOCKPERIODSECONDS: " + emptyBlockPeriodSeconds);
return emptyBlockPeriodSeconds;
}

@Override
public int getRequestTimeoutSeconds() {
return requestTimeoutSeconds;
Expand Down Expand Up @@ -128,9 +142,20 @@ public void setEpochLength(final long epochLength) {
* @param blockPeriodSeconds the block period seconds
*/
public void setBlockPeriodSeconds(final int blockPeriodSeconds) {
LOG.info("SET BLOCKPERIODSECONDS: " + blockPeriodSeconds);
this.blockPeriodSeconds = blockPeriodSeconds;
}

/**
* Sets empty block period seconds.
*
* @param emptyBlockPeriodSeconds the empty block period seconds
*/
public void setEmptyBlockPeriodSeconds(final int emptyBlockPeriodSeconds) {
LOG.info("SET EMPTYBLOCKPERIODSECONDS: " + emptyBlockPeriodSeconds);
this.emptyBlockPeriodSeconds = emptyBlockPeriodSeconds;
}

/**
* Sets request timeout seconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ForksScheduleFactoryTest {
@SuppressWarnings("unchecked")
public void throwsErrorIfHasForkForGenesisBlock() {
final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
final BftFork fork = createFork(0, 10);
final BftFork fork = createFork(0, 10, 30);
final SpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(SpecCreator.class);

assertThatThrownBy(
Expand All @@ -49,9 +49,9 @@ public void throwsErrorIfHasForkForGenesisBlock() {
@SuppressWarnings("unchecked")
public void throwsErrorIfHasForksWithDuplicateBlock() {
final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
final BftFork fork1 = createFork(1, 10);
final BftFork fork2 = createFork(1, 20);
final BftFork fork3 = createFork(2, 30);
final BftFork fork1 = createFork(1, 10, 30);
final BftFork fork2 = createFork(1, 20, 60);
final BftFork fork3 = createFork(2, 30, 90);
final SpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(SpecCreator.class);

assertThatThrownBy(
Expand Down Expand Up @@ -82,18 +82,20 @@ public void createsScheduleUsingSpecCreator() {
assertThat(schedule.getFork(2)).isEqualTo(new ForkSpec<>(2, configOptions2));
}

private MutableBftConfigOptions createBftConfigOptions(final int blockPeriodSeconds) {
private MutableBftConfigOptions createBftConfigOptions(final int blockPeriodSeconds, final int emptyBlockPeriodSeconds) {
final MutableBftConfigOptions bftConfigOptions =
new MutableBftConfigOptions(JsonBftConfigOptions.DEFAULT);
bftConfigOptions.setBlockPeriodSeconds(blockPeriodSeconds);
bftConfigOptions.setEmptyBlockPeriodSeconds(emptyBlockPeriodSeconds);
return bftConfigOptions;
}

private BftFork createFork(final long block, final long blockPeriodSeconds) {
private BftFork createFork(final long block, final long blockPeriodSeconds, final long emptyBlockPeriodSeconds) {
return new BftFork(
JsonUtil.objectNodeFromMap(
Map.of(
BftFork.FORK_BLOCK_KEY, block,
BftFork.BLOCK_PERIOD_SECONDS_KEY, blockPeriodSeconds)));
BftFork.BLOCK_PERIOD_SECONDS_KEY, blockPeriodSeconds,
BftFork.EMPTY_BLOCK_PERIOD_SECONDS_KEY, emptyBlockPeriodSeconds)));
}
}
Loading