remove protocol name (#7922)

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
pull/7945/head
Stefan Pingel 1 week ago committed by GitHub
parent 58fbbe3c37
commit 126debbd92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  2. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/PeerResult.java
  3. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AdminJsonRpcHttpServiceTest.java
  4. 1
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminPeersTest.java
  5. 39
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java
  6. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java
  7. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java
  8. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeerTest.java
  9. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java
  10. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RequestManagerTest.java
  11. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java
  12. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/PeerMessageTaskTest.java
  13. 9
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java
  14. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java
  15. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java
  16. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java

@ -625,7 +625,6 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled());
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
currentProtocolSpecSupplier,
clock,
metricsSystem,

@ -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;
@ -52,7 +53,7 @@ public interface PeerResult {
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();
}

@ -74,7 +74,6 @@ public class AdminJsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
peerList.add(
new EthPeer(
MockPeerConnection.create(info1, addr60301, addr30302),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
@ -84,7 +83,6 @@ public class AdminJsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
peerList.add(
new EthPeer(
MockPeerConnection.create(info2, addr30301, addr60302),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
@ -94,7 +92,6 @@ public class AdminJsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
peerList.add(
new EthPeer(
MockPeerConnection.create(info3, addr30301, addr60303),
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,

@ -120,7 +120,6 @@ public class AdminPeersTest {
final EthPeer ethPeer =
new EthPeer(
p,
"eth",
c -> {},
List.of(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,

@ -85,7 +85,6 @@ public class EthPeer implements Comparable<EthPeer> {
private Optional<BlockHeader> checkpointHeader = Optional.empty();
private final String protocolName;
private final int maxMessageSize;
private final Clock clock;
private final List<NodeMessagePermissioningProvider> permissioningProviders;
@ -124,7 +123,6 @@ public class EthPeer implements Comparable<EthPeer> {
@VisibleForTesting
public EthPeer(
final PeerConnection connection,
final String protocolName,
final Consumer<EthPeer> onStatusesExchanged,
final List<PeerValidator> peerValidators,
final int maxMessageSize,
@ -132,7 +130,6 @@ public class EthPeer implements Comparable<EthPeer> {
final List<NodeMessagePermissioningProvider> permissioningProviders,
final Bytes localNodeId) {
this.connection = connection;
this.protocolName = protocolName;
this.maxMessageSize = maxMessageSize;
this.clock = clock;
this.permissioningProviders = permissioningProviders;
@ -153,21 +150,23 @@ public class EthPeer implements Comparable<EthPeer> {
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() {
@ -237,7 +236,7 @@ public class EthPeer implements Comparable<EthPeer> {
}
public RequestManager.ResponseStream send(final MessageData messageData) throws PeerNotConnected {
return send(messageData, this.protocolName);
return send(messageData, EthProtocol.NAME);
}
public RequestManager.ResponseStream send(
@ -317,7 +316,7 @@ public class EthPeer implements Comparable<EthPeer> {
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);
}
@ -326,32 +325,34 @@ public class EthPeer implements Comparable<EthPeer> {
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(
@ -461,7 +462,7 @@ public class EthPeer implements Comparable<EthPeer> {
* @param ethMessage the Eth message to dispatch
*/
void dispatch(final EthMessage ethMessage) {
dispatch(ethMessage, protocolName);
dispatch(ethMessage, EthProtocol.NAME);
}
/**
@ -587,10 +588,6 @@ public class EthPeer implements Comparable<EthPeer> {
return lastProtocolVersion.get();
}
public String getProtocolName() {
return protocolName;
}
/**
* Return A read-only snapshot of this peer's current {@code chainState}
*

@ -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;
@ -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;
@ -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,
@ -134,7 +133,6 @@ public class EthPeers implements PeerSelector {
final Boolean randomPeerPriority,
final SyncMode syncMode,
final ForkIdManager forkIdManager) {
this.protocolName = protocolName;
this.currentProtocolSpecSupplier = currentProtocolSpecSupplier;
this.clock = clock;
this.permissioningProviders = permissioningProviders;
@ -191,7 +189,6 @@ public class EthPeers implements PeerSelector {
peerInList.orElse(
new EthPeer(
newConnection,
protocolName,
this::ethPeerStatusExchanged,
peerValidators,
maxMessageSize,
@ -294,7 +291,7 @@ public class EthPeers implements PeerSelector {
}
public void dispatchMessage(final EthPeer peer, final EthMessage ethMessage) {
dispatchMessage(peer, ethMessage, protocolName);
dispatchMessage(peer, ethMessage, EthProtocol.NAME);
}
@VisibleForTesting

@ -123,8 +123,7 @@ public class GetReceiptsFromPeerTask
@Override
public Predicate<EthPeer> getPeerRequirementFilter() {
return (ethPeer) ->
ethPeer.getProtocolName().equals(getSubProtocol().getName())
&& (protocolSchedule.anyMatch((ps) -> ps.spec().isPoS())
(protocolSchedule.anyMatch((ps) -> ps.spec().isPoS())
|| ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight);
}

@ -477,7 +477,6 @@ public class EthPeerTest {
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
"foo",
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
@ -513,7 +512,6 @@ public class EthPeerTest {
// that extend the sub-protocol work correctly
return new EthPeer(
peerConnection,
"foo",
onPeerReady,
peerValidators,
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,

@ -84,7 +84,6 @@ public class EthProtocolManagerTestUtil {
final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
@ -211,7 +210,6 @@ public class EthProtocolManagerTestUtil {
final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
@ -262,7 +260,6 @@ public class EthProtocolManagerTestUtil {
final EthPeers peers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
@ -294,7 +291,6 @@ public class EthProtocolManagerTestUtil {
final EthScheduler ethScheduler) {
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),

@ -303,7 +303,6 @@ public class RequestManagerTest {
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
EthProtocol.NAME,
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,

@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager;
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;
@ -114,7 +113,6 @@ public abstract class AbstractMessageTaskTest<T, R> {
ethPeers =
spy(
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,

@ -162,7 +162,6 @@ public abstract class PeerMessageTaskTest<T>
final Consumer<EthPeer> onPeerReady = (peer) -> {};
return new EthPeer(
peerConnection,
EthProtocol.NAME,
onPeerReady,
Collections.emptyList(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,

@ -214,11 +214,9 @@ public class GetReceiptsFromPeerTaskTest {
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));
}
@ -251,11 +249,10 @@ public class GetReceiptsFromPeerTaskTest {
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);

@ -641,7 +641,6 @@ public abstract class AbstractBlockPropagationManagerTest {
final EthContext ethContext =
new EthContext(
new EthPeers(
"eth",
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,
@ -783,7 +782,6 @@ public abstract class AbstractBlockPropagationManagerTest {
final EthContext ethContext =
new EthContext(
new EthPeers(
"eth",
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,

@ -154,7 +154,6 @@ public class TestNode implements Closeable {
};
final EthPeers ethPeers =
new EthPeers(
EthProtocol.NAME,
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
metricsSystem,

@ -112,7 +112,6 @@ public class TransactionPoolFactoryTest {
final NodeMessagePermissioningProvider nmpp = (destinationEnode, code) -> true;
ethPeers =
new EthPeers(
"ETH",
() -> protocolSpec,
TestClock.fixed(),
new NoOpMetricsSystem(),

Loading…
Cancel
Save