Skip to content

Commit

Permalink
Use istanbul 100 subprotocol in QBFT (hyperledger#2076)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Frame jasonwframe@gmail.com
  • Loading branch information
jframe authored Mar 25, 2021
1 parent e230a44 commit 36ef9e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.hyperledger.besu.consensus.qbft.QbftGossip;
import org.hyperledger.besu.consensus.qbft.jsonrpc.QbftJsonRpcMethods;
import org.hyperledger.besu.consensus.qbft.payload.MessageFactory;
import org.hyperledger.besu.consensus.qbft.protocol.QbftSubProtocol;
import org.hyperledger.besu.consensus.qbft.protocol.Istanbul100SubProtocol;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftController;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory;
Expand Down Expand Up @@ -108,9 +108,12 @@ protected SubProtocolConfiguration createSubProtocolConfiguration(
return new SubProtocolConfiguration()
.withSubProtocol(EthProtocol.get(), ethProtocolManager)
.withSubProtocol(
QbftSubProtocol.get(),
Istanbul100SubProtocol.get(),
new BftProtocolManager(
bftEventQueue, peers, QbftSubProtocol.QBFV1, QbftSubProtocol.get().getName()));
bftEventQueue,
peers,
Istanbul100SubProtocol.ISTANBUL_100,
Istanbul100SubProtocol.get().getName()));
}

@Override
Expand Down Expand Up @@ -144,7 +147,7 @@ protected MiningCoordinator createMiningCoordinator(

// NOTE: peers should not be used for accessing the network as it does not enforce the
// "only send once" filter applied by the UniqueMessageMulticaster.
peers = new ValidatorPeers(voteTallyCache, QbftSubProtocol.NAME);
peers = new ValidatorPeers(voteTallyCache, Istanbul100SubProtocol.NAME);

final UniqueMessageMulticaster uniqueMessageMulticaster =
new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.SubProtocol;

public class QbftSubProtocol implements SubProtocol {
public class Istanbul100SubProtocol implements SubProtocol {

public static String NAME = "QBF";
public static final Capability QBFV1 = Capability.create(NAME, 1);
public static String NAME = "istanbul";
public static final Capability ISTANBUL_100 = Capability.create(NAME, 100);

private static final QbftSubProtocol INSTANCE = new QbftSubProtocol();
private static final Istanbul100SubProtocol INSTANCE = new Istanbul100SubProtocol();

public static QbftSubProtocol get() {
public static Istanbul100SubProtocol get() {
return INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import org.junit.Test;

public class QbftSubProtocolTest {
public class Istanbul100SubProtocolTest {

@Test
public void messageSpaceReportsCorrectly() {
final QbftSubProtocol subProt = new QbftSubProtocol();
final Istanbul100SubProtocol subProt = new Istanbul100SubProtocol();

assertThat(subProt.messageSpace(1)).isEqualTo(0x16);
}

@Test
public void allIbftMessageTypesAreRecognisedAsValidByTheSubProtocol() {
final QbftSubProtocol subProt = new QbftSubProtocol();
final Istanbul100SubProtocol subProt = new Istanbul100SubProtocol();

assertThat(subProt.isValidMessageCode(1, 0x12)).isTrue();
assertThat(subProt.isValidMessageCode(1, 0x13)).isTrue();
Expand All @@ -39,7 +39,7 @@ public void allIbftMessageTypesAreRecognisedAsValidByTheSubProtocol() {

@Test
public void invalidMessageTypesAreNotAcceptedByTheSubprotocol() {
final QbftSubProtocol subProt = new QbftSubProtocol();
final Istanbul100SubProtocol subProt = new Istanbul100SubProtocol();

assertThat(subProt.isValidMessageCode(1, 0x16)).isFalse();
}
Expand Down

0 comments on commit 36ef9e7

Please sign in to comment.