Skip to content

Commit

Permalink
remove protocol name (#7922)
Browse files Browse the repository at this point in the history
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
  • Loading branch information
pinges authored Nov 27, 2024
1 parent 58fbbe3 commit 126debb
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ public BesuController build() {
ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled());
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
currentProtocolSpecSupplier,
clock,
metricsSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability;
Expand Down Expand Up @@ -52,7 +53,7 @@ static PeerResult fromEthPeer(final EthPeer peer) {
connection.inboundInitiated()))
.port(Quantity.create(peerInfo.getPort()))
.id(peerInfo.getNodeId().toString())
.protocols(Map.of(peer.getProtocolName(), ProtocolsResult.fromEthPeer(peer)))
.protocols(Map.of(EthProtocol.NAME, ProtocolsResult.fromEthPeer(peer)))
.enode(connection.getRemoteEnode().toString())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void getPeers() throws Exception {
peerList.add(
new EthPeer(
MockPeerConnection.create(info1, addr60301, addr30302),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand All @@ -84,7 +83,6 @@ public void getPeers() throws Exception {
peerList.add(
new EthPeer(
MockPeerConnection.create(info2, addr30301, addr60302),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand All @@ -94,7 +92,6 @@ public void getPeers() throws Exception {
peerList.add(
new EthPeer(
MockPeerConnection.create(info3, addr30301, addr60303),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private Collection<EthPeer> peerList() {
final EthPeer ethPeer =
new EthPeer(
p,
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected boolean removeEldestEntry(final Map.Entry<Hash, Boolean> eldest) {

private Optional<BlockHeader> checkpointHeader = Optional.empty();

private final String protocolName;
private final int maxMessageSize;
private final Clock clock;
private final List<NodeMessagePermissioningProvider> permissioningProviders;
Expand Down Expand Up @@ -124,15 +123,13 @@ protected boolean removeEldestEntry(final Map.Entry<Hash, Boolean> eldest) {
@VisibleForTesting
public EthPeer(
final PeerConnection connection,
final String protocolName,
final Consumer<EthPeer> onStatusesExchanged,
final List<PeerValidator> peerValidators,
final int maxMessageSize,
final Clock clock,
final List<NodeMessagePermissioningProvider> permissioningProviders,
final Bytes localNodeId) {
this.connection = connection;
this.protocolName = protocolName;
this.maxMessageSize = maxMessageSize;
this.clock = clock;
this.permissioningProviders = permissioningProviders;
Expand All @@ -153,21 +150,23 @@ private void initEthRequestManagers() {
getAgreedCapabilities().stream().anyMatch(EthProtocol::isEth66Compatible);
// eth protocol
requestManagers.put(
protocolName,
EthProtocol.NAME,
Map.ofEntries(
Map.entry(
EthPV62.GET_BLOCK_HEADERS,
new RequestManager(this, supportsRequestId, protocolName)),
new RequestManager(this, supportsRequestId, EthProtocol.NAME)),
Map.entry(
EthPV62.GET_BLOCK_BODIES,
new RequestManager(this, supportsRequestId, protocolName)),
new RequestManager(this, supportsRequestId, EthProtocol.NAME)),
Map.entry(
EthPV63.GET_RECEIPTS, new RequestManager(this, supportsRequestId, protocolName)),
EthPV63.GET_RECEIPTS,
new RequestManager(this, supportsRequestId, EthProtocol.NAME)),
Map.entry(
EthPV63.GET_NODE_DATA, new RequestManager(this, supportsRequestId, protocolName)),
EthPV63.GET_NODE_DATA,
new RequestManager(this, supportsRequestId, EthProtocol.NAME)),
Map.entry(
EthPV65.GET_POOLED_TRANSACTIONS,
new RequestManager(this, supportsRequestId, protocolName))));
new RequestManager(this, supportsRequestId, EthProtocol.NAME))));
}

private void initSnapRequestManagers() {
Expand Down Expand Up @@ -237,7 +236,7 @@ public void disconnect(final DisconnectReason reason) {
}

public RequestManager.ResponseStream send(final MessageData messageData) throws PeerNotConnected {
return send(messageData, this.protocolName);
return send(messageData, EthProtocol.NAME);
}

public RequestManager.ResponseStream send(
Expand Down Expand Up @@ -317,7 +316,7 @@ public RequestManager.ResponseStream getHeadersByHash(
final GetBlockHeadersMessage message =
GetBlockHeadersMessage.create(hash, maxHeaders, skip, reverse);
final RequestManager requestManager =
requestManagers.get(protocolName).get(EthPV62.GET_BLOCK_HEADERS);
requestManagers.get(EthProtocol.NAME).get(EthPV62.GET_BLOCK_HEADERS);
return sendRequest(requestManager, message);
}

Expand All @@ -326,32 +325,34 @@ public RequestManager.ResponseStream getHeadersByNumber(
throws PeerNotConnected {
final GetBlockHeadersMessage message =
GetBlockHeadersMessage.create(blockNumber, maxHeaders, skip, reverse);
return sendRequest(requestManagers.get(protocolName).get(EthPV62.GET_BLOCK_HEADERS), message);
return sendRequest(
requestManagers.get(EthProtocol.NAME).get(EthPV62.GET_BLOCK_HEADERS), message);
}

public RequestManager.ResponseStream getBodies(final List<Hash> blockHashes)
throws PeerNotConnected {
final GetBlockBodiesMessage message = GetBlockBodiesMessage.create(blockHashes);
return sendRequest(requestManagers.get(protocolName).get(EthPV62.GET_BLOCK_BODIES), message);
return sendRequest(
requestManagers.get(EthProtocol.NAME).get(EthPV62.GET_BLOCK_BODIES), message);
}

public RequestManager.ResponseStream getReceipts(final List<Hash> blockHashes)
throws PeerNotConnected {
final GetReceiptsMessage message = GetReceiptsMessage.create(blockHashes);
return sendRequest(requestManagers.get(protocolName).get(EthPV63.GET_RECEIPTS), message);
return sendRequest(requestManagers.get(EthProtocol.NAME).get(EthPV63.GET_RECEIPTS), message);
}

public RequestManager.ResponseStream getNodeData(final Iterable<Hash> nodeHashes)
throws PeerNotConnected {
final GetNodeDataMessage message = GetNodeDataMessage.create(nodeHashes);
return sendRequest(requestManagers.get(protocolName).get(EthPV63.GET_NODE_DATA), message);
return sendRequest(requestManagers.get(EthProtocol.NAME).get(EthPV63.GET_NODE_DATA), message);
}

public RequestManager.ResponseStream getPooledTransactions(final List<Hash> hashes)
throws PeerNotConnected {
final GetPooledTransactionsMessage message = GetPooledTransactionsMessage.create(hashes);
return sendRequest(
requestManagers.get(protocolName).get(EthPV65.GET_POOLED_TRANSACTIONS), message);
requestManagers.get(EthProtocol.NAME).get(EthPV65.GET_POOLED_TRANSACTIONS), message);
}

public RequestManager.ResponseStream getSnapAccountRange(
Expand Down Expand Up @@ -461,7 +462,7 @@ Optional<RequestManager> dispatch(final EthMessage ethMessage, final String prot
* @param ethMessage the Eth message to dispatch
*/
void dispatch(final EthMessage ethMessage) {
dispatch(ethMessage, protocolName);
dispatch(ethMessage, EthProtocol.NAME);
}

/**
Expand Down Expand Up @@ -587,10 +588,6 @@ public int getLastProtocolVersion() {
return lastProtocolVersion.get();
}

public String getProtocolName() {
return protocolName;
}

/**
* Return A read-only snapshot of this peer's current {@code chainState}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.eth.manager;

import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.SnapProtocol;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer.DisconnectCallback;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerSelector;
Expand Down Expand Up @@ -92,7 +93,6 @@ public class EthPeers implements PeerSelector {
.concurrencyLevel(1)
.removalListener(this::onCacheRemoval)
.build();
private final String protocolName;
private final Clock clock;
private final List<NodeMessagePermissioningProvider> permissioningProviders;
private final int maxMessageSize;
Expand Down Expand Up @@ -122,7 +122,6 @@ public class EthPeers implements PeerSelector {
() -> TrailingPeerRequirements.UNRESTRICTED;

public EthPeers(
final String protocolName,
final Supplier<ProtocolSpec> currentProtocolSpecSupplier,
final Clock clock,
final MetricsSystem metricsSystem,
Expand All @@ -134,7 +133,6 @@ public EthPeers(
final Boolean randomPeerPriority,
final SyncMode syncMode,
final ForkIdManager forkIdManager) {
this.protocolName = protocolName;
this.currentProtocolSpecSupplier = currentProtocolSpecSupplier;
this.clock = clock;
this.permissioningProviders = permissioningProviders;
Expand Down Expand Up @@ -191,7 +189,6 @@ public void registerNewConnection(
peerInList.orElse(
new EthPeer(
newConnection,
protocolName,
this::ethPeerStatusExchanged,
peerValidators,
maxMessageSize,
Expand Down Expand Up @@ -294,7 +291,7 @@ public void dispatchMessage(
}

public void dispatchMessage(final EthPeer peer, final EthMessage ethMessage) {
dispatchMessage(peer, ethMessage, protocolName);
dispatchMessage(peer, ethMessage, EthProtocol.NAME);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ public Map<BlockHeader, List<TransactionReceipt>> processResponse(final MessageD
@Override
public Predicate<EthPeer> getPeerRequirementFilter() {
return (ethPeer) ->
ethPeer.getProtocolName().equals(getSubProtocol().getName())
&& (protocolSchedule.anyMatch((ps) -> ps.spec().isPoS())
|| ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight);
(protocolSchedule.anyMatch((ps) -> ps.spec().isPoS())
|| ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ private EthPeer createPeerWithPeerInfo(final Bytes nodeId) {
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
"foo",
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down Expand Up @@ -513,7 +512,6 @@ private EthPeer createPeer(
// that extend the sub-protocol work correctly
return new EthPeer(
peerConnection,
"foo",
onPeerReady,
peerValidators,
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static EthProtocolManager create(

final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
Expand Down Expand Up @@ -211,7 +210,6 @@ public static EthProtocolManager create(

final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
Expand Down Expand Up @@ -262,7 +260,6 @@ public static EthProtocolManager create(

final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
Expand Down Expand Up @@ -294,7 +291,6 @@ public static EthProtocolManager create(
final EthScheduler ethScheduler) {
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ private EthPeer createPeer() {
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
EthProtocol.NAME,
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthMessages;
Expand Down Expand Up @@ -114,7 +113,6 @@ public void setupTest() {
ethPeers =
spy(
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ protected EthPeer createPeer() {
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
EthProtocol.NAME,
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ public void testGetPeerRequirementFilter() {
new GetReceiptsFromPeerTask(
List.of(blockHeader1, blockHeader2, blockHeader3), protocolSchedule);

EthPeer failForIncorrectProtocol = mockPeer("incorrectProtocol", 5);
EthPeer failForShortChainHeight = mockPeer("incorrectProtocol", 1);
EthPeer successfulCandidate = mockPeer(EthProtocol.NAME, 5);
EthPeer failForShortChainHeight = mockPeer(1);
EthPeer successfulCandidate = mockPeer(5);

Assertions.assertFalse(task.getPeerRequirementFilter().test(failForIncorrectProtocol));
Assertions.assertFalse(task.getPeerRequirementFilter().test(failForShortChainHeight));
Assertions.assertTrue(task.getPeerRequirementFilter().test(successfulCandidate));
}
Expand Down Expand Up @@ -251,11 +249,10 @@ private BlockHeader mockBlockHeader(final long blockNumber) {
return blockHeader;
}

private EthPeer mockPeer(final String protocol, final long chainHeight) {
private EthPeer mockPeer(final long chainHeight) {
EthPeer ethPeer = Mockito.mock(EthPeer.class);
ChainState chainState = Mockito.mock(ChainState.class);

Mockito.when(ethPeer.getProtocolName()).thenReturn(protocol);
Mockito.when(ethPeer.chainState()).thenReturn(chainState);
Mockito.when(chainState.getEstimatedHeight()).thenReturn(chainHeight);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ public void shouldNotImportBlocksThatAreAlreadyBeingImported() {
final EthContext ethContext =
new EthContext(
new EthPeers(
"eth",
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,
Expand Down Expand Up @@ -783,7 +782,6 @@ public Object answer(final InvocationOnMock invocation) throws Throwable {
final EthContext ethContext =
new EthContext(
new EthPeers(
"eth",
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public boolean isMessagePermitted(final EnodeURL destinationEnode, final int cod
};
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void setup() {
final NodeMessagePermissioningProvider nmpp = (destinationEnode, code) -> true;
ethPeers =
new EthPeers(
"ETH",
() -> protocolSpec,
TestClock.fixed(),
new NoOpMetricsSystem(),
Expand Down

0 comments on commit 126debb

Please sign in to comment.