Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Ibft transmitted packets are logged by gossiper #652

Merged
merged 36 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f1116a0
Ibft transmitted packets are logged by gossiper
Jan 24, 2019
f52c616
touch ups after review
Jan 24, 2019
cbd5a4b
[NC-1970] Added handling in admin_addPeer for when p2p is disabled (#…
Errorific Jan 24, 2019
cbd8f7d
Refactoring for more readable IBFT IT (#614)
CjHare Jan 24, 2019
a0bccde
[NC-1970] admin_addPeer acceptance test (#651)
Errorific Jan 25, 2019
f39db51
add description to automatic benchmarks (#646)
shemnon Jan 25, 2019
eb71f3e
Additional logging details for IBFT (#650)
jframe Jan 25, 2019
ebbde8c
Nc 2026 network option (#645)
NicolasMassart Jan 25, 2019
016e002
Enable CLI config for privacy precompiled contract address (#653)
Puneetha17 Jan 25, 2019
949755d
NC-2120 --discovery-enabled option refactoring (#661)
NicolasMassart Jan 25, 2019
66ce6ee
[NC-1344] Create a simple WorldStateDownloader (#657)
mbaxter Jan 26, 2019
424c91b
Added p2p enabled (#654)
MadelineMurray Jan 26, 2019
a0f8089
Update WorldStateDownloader run() interface to accept header (#677)
mbaxter Jan 28, 2019
a68e22e
Added reference to changelog for CLI changes mapping (#673)
MadelineMurray Jan 28, 2019
ce7e034
Removed available from vX.X notes (#672)
MadelineMurray Jan 28, 2019
8940854
[NC-2137] Add world state and chain download into fast sync workflow …
ajsutton Jan 28, 2019
05a449f
Updated Quickstart docs link (#681)
Errorific Jan 28, 2019
1242930
[NC-2138] Extract out generic parts of Downloader (#659)
ajsutton Jan 28, 2019
9ba5cd0
IBFT available in v1.0 note added (#667)
MadelineMurray Jan 29, 2019
238b4e4
wip
Jan 29, 2019
fa2b1c6
wip
Jan 29, 2019
1c3c240
spotless
Jan 29, 2019
3fa447d
repairs
Jan 29, 2019
ba458d4
post review spotless
Jan 29, 2019
0f4d871
Revert dirty files
Jan 29, 2019
2fd69bd
Merge remote-tracking branch 'upstream/master' into goss_packets
Jan 29, 2019
28ef575
revert more files
Jan 29, 2019
c5275dc
update testcontext to use unique msg multiplexer
Jan 29, 2019
130c6ec
spotless
Jan 29, 2019
4206af1
change to int uniqueID
Jan 29, 2019
441e97e
Merge remote-tracking branch 'upstream/master' into goss_packets
Jan 29, 2019
4e0a094
repair to Integer
Jan 29, 2019
85b6c10
Merge branch 'master' into goss_packets
rain-on Jan 29, 2019
70428c1
Merge branch 'master' into goss_packets
rain-on Jan 29, 2019
f11d4a0
rename gossipMessage to send
Jan 29, 2019
cb103e0
Merge branch 'master' into goss_packets
rain-on Jan 29, 2019
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 @@ -25,6 +25,7 @@
import tech.pegasys.pantheon.consensus.common.VoteTallyUpdater;
import tech.pegasys.pantheon.consensus.ibft.BlockTimer;
import tech.pegasys.pantheon.consensus.ibft.EventMultiplexer;
import tech.pegasys.pantheon.consensus.ibft.Gossiper;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockInterface;
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
Expand All @@ -34,6 +35,7 @@
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.IbftProtocolSchedule;
import tech.pegasys.pantheon.consensus.ibft.RoundTimer;
import tech.pegasys.pantheon.consensus.ibft.UniqueMessageMulticaster;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreatorFactory;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.ProposerSelector;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
Expand Down Expand Up @@ -156,7 +158,9 @@ public TestContext build() {
// Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();

final IbftGossip gossiper = useGossip ? new IbftGossip(multicaster) : mock(IbftGossip.class);
final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster);

final Gossiper gossiper = useGossip ? new IbftGossip(uniqueMulticaster) : mock(Gossiper.class);

final ControllerAndState controllerAndState =
createControllerAndFinalState(
Expand Down Expand Up @@ -219,11 +223,11 @@ private static Block createGenesisBlock(final Set<Address> validators) {

private static ControllerAndState createControllerAndFinalState(
final MutableBlockchain blockChain,
final StubValidatorMulticaster stubbedMulticaster,
final StubValidatorMulticaster multicaster,
final KeyPair nodeKeys,
final Clock clock,
final IbftEventQueue ibftEventQueue,
final IbftGossip gossiper) {
final Gossiper gossiper) {

final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();

Expand Down Expand Up @@ -272,7 +276,7 @@ private static ControllerAndState createControllerAndFinalState(
nodeKeys,
Util.publicKeyToAddress(nodeKeys.getPublicKey()),
proposerSelector,
stubbedMulticaster,
multicaster,
new RoundTimer(
ibftEventQueue, ROUND_TIMER_SEC * 1000, Executors.newScheduledThreadPool(1)),
new BlockTimer(
Expand All @@ -298,8 +302,8 @@ private static ControllerAndState createControllerAndFinalState(
new IbftRoundFactory(
finalState, protocolContext, protocolSchedule, minedBlockObservers),
messageValidatorFactory),
new HashMap<>(),
gossiper);
gossiper,
new HashMap<>());

final EventMultiplexer eventMultiplexer = new EventMultiplexer(ibftController);
//////////////////////////// END IBFT PantheonController ////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 tech.pegasys.pantheon.ethereum.p2p.api.Message;

public interface Gossiper {

void send(Message message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,35 @@
import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData;
import tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.p2p.api.Message;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Lists;

/** Class responsible for rebroadcasting IBFT messages to known validators */
public class IbftGossip {
private final ValidatorMulticaster multicaster;

// Size of the seenMessages cache, should end up utilising 65bytes * this number + some meta data
private final int maxSeenMessages;

// Set that starts evicting members when it hits capacity
private final Set<Signature> seenMessages =
Collections.newSetFromMap(
new LinkedHashMap<Signature, Boolean>() {
@Override
protected boolean removeEldestEntry(final Map.Entry<Signature, Boolean> eldest) {
return size() > maxSeenMessages;
}
});
public class IbftGossip implements Gossiper {

IbftGossip(final ValidatorMulticaster multicaster, final int maxSeenMessages) {
this.maxSeenMessages = maxSeenMessages;
this.multicaster = multicaster;
}
private final ValidatorMulticaster multicaster;

/**
* Constructor that attaches gossip logic to a set of multicaster
*
* @param multicaster Network connections to the remote validators
*/
public IbftGossip(final ValidatorMulticaster multicaster) {
this(multicaster, 10_000);
this.multicaster = multicaster;
}

/**
* Retransmit a given IBFT message to other known validators nodes
*
* @param message The raw message to be gossiped
* @return Whether the message was rebroadcast or has been ignored as a repeat
*/
public boolean gossipMessage(final Message message) {
@Override
public void send(final Message message) {
final MessageData messageData = message.getData();
final SignedData<?> signedData;
switch (messageData.getCode()) {
Expand All @@ -93,16 +71,9 @@ public boolean gossipMessage(final Message message) {
throw new IllegalArgumentException(
"Received message does not conform to any recognised IBFT message structure.");
}
final Signature signature = signedData.getSignature();
if (seenMessages.contains(signature)) {
return false;
} else {
final List<Address> excludeAddressesList =
Lists.newArrayList(
message.getConnection().getPeer().getAddress(), signedData.getSender());
multicaster.send(messageData, excludeAddressesList);
seenMessages.add(signature);
return true;
}
final List<Address> excludeAddressesList =
Lists.newArrayList(message.getConnection().getPeer().getAddress(), signedData.getSender());

multicaster.send(messageData, excludeAddressesList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class UniqueMessageMulticaster implements ValidatorMulticaster {

private final int maxSeenMessages;
private final ValidatorMulticaster multicaster;

UniqueMessageMulticaster(final ValidatorMulticaster multicaster, final int maxSeenMessages) {
this.maxSeenMessages = maxSeenMessages;
this.multicaster = multicaster;
}

/**
* Constructor that attaches gossip logic to a set of multicaster
*
* @param multicaster Network connections to the remote validators
*/
public UniqueMessageMulticaster(final ValidatorMulticaster multicaster) {
this(multicaster, 10_000);
}

// Set that starts evicting members when it hits capacity
private final Set<Integer> seenMessages =
Collections.newSetFromMap(
new LinkedHashMap<Integer, Boolean>() {
@Override
protected boolean removeEldestEntry(final Map.Entry<Integer, Boolean> eldest) {
return size() > maxSeenMessages;
}
});

@Override
public void send(final MessageData message) {
send(message, Collections.emptyList());
}

@Override
public void send(final MessageData message, final Collection<Address> blackList) {
final int uniqueID = message.hashCode();
if (seenMessages.contains(uniqueID)) {
return;
}
multicaster.send(message, blackList);
seenMessages.add(uniqueID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static java.util.Collections.emptyList;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.Gossiper;
import tech.pegasys.pantheon.consensus.ibft.IbftGossip;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.IbftReceivedMessageEvent;
Expand Down Expand Up @@ -51,27 +52,23 @@ public class IbftController {
private final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory;
private final Map<Long, List<Message>> futureMessages;
private BlockHeightManager currentHeightManager;
private final IbftGossip gossiper;
private final Gossiper gossiper;

public IbftController(
final Blockchain blockchain,
final IbftFinalState ibftFinalState,
final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory) {
this(
blockchain,
ibftFinalState,
ibftBlockHeightManagerFactory,
Maps.newHashMap(),
new IbftGossip(ibftFinalState.getValidatorMulticaster()));
final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory,
final IbftGossip gossiper) {
this(blockchain, ibftFinalState, ibftBlockHeightManagerFactory, gossiper, Maps.newHashMap());
}

@VisibleForTesting
public IbftController(
final Blockchain blockchain,
final IbftFinalState ibftFinalState,
final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory,
final Map<Long, List<Message>> futureMessages,
final IbftGossip gossiper) {
final Gossiper gossiper,
final Map<Long, List<Message>> futureMessages) {
this.blockchain = blockchain;
this.ibftFinalState = ibftFinalState;
this.ibftBlockHeightManagerFactory = ibftBlockHeightManagerFactory;
Expand Down Expand Up @@ -142,7 +139,7 @@ private <P extends Payload> void consumeMessage(
signedPayload.getPayload().getMessageType(),
signedPayload);
if (processMessage(signedPayload, message)) {
gossiper.gossipMessage(message);
gossiper.send(message);
handleMessage.accept(signedPayload);
}
}
Expand Down
Loading