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

Remove EthTaskChainDownloader and supporting code #1373

Merged
merged 9 commits into from
May 1, 2019

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public static Wei fromEth(final long eth) {
return Wei.of(BigInteger.valueOf(eth).multiply(BigInteger.TEN.pow(18)));
}

public static Counter<Wei> newCounter() {
return new WeiCounter();
}

private static class WeiCounter extends Counter<Wei> {
private WeiCounter() {
super(Wei::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ private static boolean accountExists(final Account account) {
return account.getNonce() > 0 || !account.getCode().isEmpty();
}

protected GasCalculator gasCalculator() {
return gasCalculator;
}

@Override
public void start(final MessageFrame frame) {
if (LOG.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
*/
public class MainnetTransactionValidator implements TransactionValidator {

public static MainnetTransactionValidator create() {
return new MainnetTransactionValidator(new FrontierGasCalculator(), false, Optional.empty());
}

private final GasCalculator gasCalculator;

private final boolean disallowSignatureMalleability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import tech.pegasys.pantheon.util.number.PositiveNumber;

import java.util.Objects;

import com.google.common.base.MoreObjects;
import picocli.CommandLine;

public class EthereumWireProtocolConfiguration {
Expand Down Expand Up @@ -68,27 +71,33 @@ public int getMaxGetNodeData() {
}

@Override
public boolean equals(final Object obj) {
if (!(obj instanceof EthereumWireProtocolConfiguration)) {
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EthereumWireProtocolConfiguration other = ((EthereumWireProtocolConfiguration) obj);
return maxGetBlockHeaders == other.maxGetBlockHeaders
&& maxGetBlockBodies == other.maxGetBlockBodies
&& maxGetReceipts == other.maxGetReceipts
&& maxGetNodeData == other.maxGetNodeData;
final EthereumWireProtocolConfiguration that = (EthereumWireProtocolConfiguration) o;
return maxGetBlockHeaders == that.maxGetBlockHeaders
&& maxGetBlockBodies == that.maxGetBlockBodies
&& maxGetReceipts == that.maxGetReceipts
&& maxGetNodeData == that.maxGetNodeData;
}

@Override
public int hashCode() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. Maybe we could test equals and hashCode. Although it is non blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equals is only used by tests and hash code isn't used (but should exist to match equals just for good measure). I really only updated them to match our code style which is the generated code.

return super.hashCode();
return Objects.hash(maxGetBlockHeaders, maxGetBlockBodies, maxGetReceipts, maxGetNodeData);
}

@Override
public String toString() {
return String.format(
"maxGetBlockHeaders=%s\tmaxGetBlockBodies=%s\tmaxGetReceipts=%s\tmaxGetReceipts=%s",
maxGetBlockHeaders, maxGetBlockBodies, maxGetReceipts, maxGetNodeData);
return MoreObjects.toStringHelper(this)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. Unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString is always just for debugging purposes so the only time we should test it is when there's sensitive info that definitely shouldn't appear in a log (ie anything containing a password).

.add("maxGetBlockHeaders", maxGetBlockHeaders)
.add("maxGetBlockBodies", maxGetBlockBodies)
.add("maxGetReceipts", maxGetReceipts)
.add("maxGetNodeData", maxGetNodeData)
.toString();
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@

public class EthContext {

private final String protocolName;
private final EthPeers ethPeers;
private final EthMessages ethMessages;
private final EthScheduler scheduler;

public EthContext(
final String protocolName,
final EthPeers ethPeers,
final EthMessages ethMessages,
final EthScheduler scheduler) {
this.protocolName = protocolName;
final EthPeers ethPeers, final EthMessages ethMessages, final EthScheduler scheduler) {
this.ethPeers = ethPeers;
this.ethMessages = ethMessages;
this.scheduler = scheduler;
}

public String getProtocolName() {
return protocolName;
}

public EthPeers getEthPeers() {
return ethPeers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import tech.pegasys.pantheon.util.Subscribers;

import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

public class EthMessages {
Expand All @@ -31,18 +30,8 @@ void dispatch(final EthMessage message) {
listeners.forEach(callback -> callback.exec(message));
}

public long subscribe(final int messageCode, final MessageCallback callback) {
return listenersByCode
.computeIfAbsent(messageCode, key -> new Subscribers<>())
.subscribe(callback);
}

public void unsubscribe(final long listenerId) {
for (final Entry<Integer, Subscribers<MessageCallback>> entry : listenersByCode.entrySet()) {
if (entry.getValue().unsubscribe(listenerId)) {
break;
}
}
public void subscribe(final int messageCode, final MessageCallback callback) {
listenersByCode.computeIfAbsent(messageCode, key -> new Subscribers<>()).subscribe(callback);
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection;
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection.PeerNotConnected;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

Expand Down Expand Up @@ -63,7 +62,6 @@ public class EthPeer {

private final AtomicReference<Consumer<EthPeer>> onStatusesExchanged = new AtomicReference<>();
private final PeerReputation reputation = new PeerReputation();
private final Subscribers<DisconnectCallback> disconnectCallbacks = new Subscribers<>();

EthPeer(
final PeerConnection connection,
Expand Down Expand Up @@ -110,14 +108,6 @@ public void disconnect(final DisconnectReason reason) {
connection.disconnect(reason);
}

public long subscribeDisconnect(final DisconnectCallback callback) {
return disconnectCallbacks.subscribe(callback);
}

public void unsubscribeDisconnect(final long id) {
disconnectCallbacks.unsubscribe(id);
}

public ResponseStream send(final MessageData messageData) throws PeerNotConnected {
switch (messageData.getCode()) {
case EthPV62.GET_BLOCK_HEADERS:
Expand Down Expand Up @@ -258,7 +248,6 @@ void handleDisconnect() {
bodiesRequestManager.close();
receiptsRequestManager.close();
nodeDataRequestManager.close();
disconnectCallbacks.forEach(callback -> callback.onDisconnect(this));
}

public void registerKnownBlock(final Hash hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ public void unsubscribeConnect(final long id) {
connectCallbacks.unsubscribe(id);
}

public long subscribeDisconnect(final DisconnectCallback callback) {
return disconnectCallbacks.subscribe(callback);
public void subscribeDisconnect(final DisconnectCallback callback) {
disconnectCallbacks.subscribe(callback);
}

public int peerCount() {
return connections.size();
}

public int availablePeerCount() {
return (int) availablePeers().count();
}

public Stream<EthPeer> availablePeers() {
return connections.values().stream().filter(EthPeer::readyForRequests);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public EthProtocolManager(

ethPeers = new EthPeers(getSupportedProtocol());
ethMessages = new EthMessages();
ethContext = new EthContext(getSupportedProtocol(), ethPeers, ethMessages, scheduler);
ethContext = new EthContext(ethPeers, ethMessages, scheduler);

this.blockBroadcaster = new BlockBroadcaster(ethContext);

Expand Down
Loading