This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Limit ibft msg queues #704
Merged
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4fa3284
move evicting map into it's own class
jframe fa03a32
use evicting map for future msgs in ibftController and roundChangeMan…
jframe 593b7ca
add generics on evict map eviction method
jframe bb6532e
config for message buffer size
jframe 968e758
test that MaxSizeEvictingMap evicts records when at capacity
jframe cf639a7
rename map type
jframe 11be71c
Merge branch 'master' into limit_ibft_msg_queues
jframe aa3e2d6
use SizeLimitedMap in the UniqueMessageMulticaster
jframe 16467b8
set event queue limit from the ibft message buffer size config
jframe d385a15
Merge branch 'master' into limit_ibft_msg_queues
jframe 3695c51
revert map and queue changes to future messages and round change and …
jframe 901a331
spotless
jframe 13e3388
fix test context after config changes
jframe 363f507
update config names
jframe b64829e
update config names
jframe f5b1e2e
Update gossiped history limit to 1000
jframe 4afd709
Update gossiped history limit to 1000 - test
jframe 08b79fe
comment on why default gossipped history limit was chosen
jframe 97af876
update field names to match new config names
jframe be0bd99
Merge branch 'master' into limit_ibft_msg_queues
jframe d32c128
Merge branch 'master' into limit_ibft_msg_queues
CjHare 96a3ab7
Merge branch 'master' into limit_ibft_msg_queues
jframe 14ab492
Merge branch 'master' into limit_ibft_msg_queues
jframe 66a5279
Merge branch 'master' into limit_ibft_msg_queues
jframe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ public EventMultiplexer getEventMultiplexer() { | |
public static final int EPOCH_LENGTH = 10_000; | ||
public static final int BLOCK_TIMER_SEC = 3; | ||
public static final int ROUND_TIMER_SEC = 12; | ||
public static final int MESSAGE_BUFFER_SIZE = 10_000; | ||
|
||
private Clock clock = Clock.fixed(Instant.MIN, ZoneId.of("UTC")); | ||
private IbftEventQueue ibftEventQueue = new IbftEventQueue(); | ||
|
@@ -158,7 +159,8 @@ public TestContext build() { | |
// Use a stubbed version of the multicaster, to prevent creating PeerConnections etc. | ||
final StubValidatorMulticaster multicaster = new StubValidatorMulticaster(); | ||
|
||
final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster); | ||
final UniqueMessageMulticaster uniqueMulticaster = | ||
new UniqueMessageMulticaster(multicaster, MESSAGE_BUFFER_SIZE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should Multicaster be updated as part of this change? Or is that a separate problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The multicaster should be updated to have a limited size buffer. Would be better to have a seperate config option though. |
||
|
||
final Gossiper gossiper = useGossip ? new IbftGossip(uniqueMulticaster) : mock(Gossiper.class); | ||
|
||
|
@@ -301,7 +303,8 @@ private static ControllerAndState createControllerAndFinalState( | |
finalState, | ||
new IbftRoundFactory( | ||
finalState, protocolContext, protocolSchedule, minedBlockObservers), | ||
messageValidatorFactory), | ||
messageValidatorFactory, | ||
MESSAGE_BUFFER_SIZE), | ||
gossiper, | ||
new HashMap<>()); | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/SizeLimitedMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.consensus.ibft; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map.Entry; | ||
|
||
/** | ||
* Map that is limited to a specified size and will evict oldest entries when the size limit is | ||
* reached. | ||
*/ | ||
public class SizeLimitedMap<K, V> extends LinkedHashMap<K, V> { | ||
private final int maxEntries; | ||
|
||
public SizeLimitedMap(final int maxEntries) { | ||
this.maxEntries = maxEntries; | ||
} | ||
|
||
@Override | ||
protected boolean removeEldestEntry(final Entry<K, V> ignored) { | ||
return size() > maxEntries; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import tech.pegasys.pantheon.consensus.ibft.BlockTimer; | ||
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; | ||
import tech.pegasys.pantheon.consensus.ibft.RoundTimer; | ||
import tech.pegasys.pantheon.consensus.ibft.SizeLimitedMap; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftevent.RoundExpiry; | ||
import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; | ||
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; | ||
|
@@ -43,7 +44,6 @@ | |
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
import com.google.common.collect.Maps; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
|
@@ -64,7 +64,7 @@ public class IbftBlockHeightManager implements BlockHeightManager { | |
private final BlockTimer blockTimer; | ||
private final IbftMessageTransmitter transmitter; | ||
private final MessageFactory messageFactory; | ||
private final Map<Integer, RoundState> futureRoundStateBuffer = Maps.newHashMap(); | ||
private final Map<Integer, RoundState> futureRoundStateBuffer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this related to the incoming event queue size? |
||
private final NewRoundMessageValidator newRoundMessageValidator; | ||
private final Clock clock; | ||
private final Function<ConsensusRoundIdentifier, RoundState> roundStateCreator; | ||
|
@@ -80,7 +80,8 @@ public IbftBlockHeightManager( | |
final RoundChangeManager roundChangeManager, | ||
final IbftRoundFactory ibftRoundFactory, | ||
final Clock clock, | ||
final MessageValidatorFactory messageValidatorFactory) { | ||
final MessageValidatorFactory messageValidatorFactory, | ||
final int maxFutureRoundStateBufferSize) { | ||
this.parentHeader = parentHeader; | ||
this.roundFactory = ibftRoundFactory; | ||
this.roundTimer = finalState.getRoundTimer(); | ||
|
@@ -91,6 +92,7 @@ public IbftBlockHeightManager( | |
this.roundChangeManager = roundChangeManager; | ||
this.finalState = finalState; | ||
|
||
futureRoundStateBuffer = new SizeLimitedMap<>(maxFutureRoundStateBufferSize); | ||
newRoundMessageValidator = messageValidatorFactory.createNewRoundValidator(parentHeader); | ||
|
||
roundStateCreator = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/SizeLimitedMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.consensus.ibft; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class SizeLimitedMapTest { | ||
|
||
@Test | ||
public void evictMessageRecordAtCapacity() { | ||
SizeLimitedMap<String, Boolean> map = new SizeLimitedMap<>(5); | ||
|
||
map.put("message1", true); | ||
assertThat(map).hasSize(1); | ||
|
||
// add messages so map is at capacity | ||
for (int i = 2; i <= 5; i++) { | ||
map.put("message" + i, true); | ||
} | ||
assertThat(map).hasSize(5); | ||
|
||
map.put("message6", false); | ||
assertThat(map).hasSize(5); | ||
assertThat(map.keySet()).doesNotContain("message1"); | ||
assertThat(map.keySet()).contains("message2", "message3", "message4", "message5", "message6"); | ||
|
||
map.put("message7", true); | ||
assertThat(map).hasSize(5); | ||
assertThat(map.keySet()).doesNotContain("message1", "message2"); | ||
assertThat(map.keySet()).contains("message3", "message4", "message5", "message6", "message7"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these oddly named? I.e. what does "EXPECTED_" indicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are bit oddly named I guess. The "EXPECTED_" indicates this expected values for the assertion. These values are used to assert the default values are correct in the tests. It's existing test code so I just followed the existing pattern.