Removing dead code from the consensus package (#554)

* Removing code identified by the 'unused declaration' analysis in IntelliJ

* Undoing removal of injectNewRound as that's actually used

* Removing wrapper class from Clique UT

* Spotless

* Adding back code

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
CJ Hare 6 years ago committed by GitHub
parent fea9168ef4
commit 9cfa01b516
  1. 4
      consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueRpcApis.java
  2. 37
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueBlockHashingTest.java
  3. 18
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/headervalidationrules/SignerRateLimitValidationRuleTest.java
  4. 1
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/methods/DiscardTest.java
  5. 5
      consensus/common/src/main/java/tech/pegasys/pantheon/consensus/common/VoteProposer.java
  6. 5
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContext.java
  7. 51
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftMessages.java
  8. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/Vote.java
  9. 37
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockMiner.java
  10. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftRpcApis.java
  11. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/AbstractIbftMessageData.java
  12. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/CommitMessageData.java
  13. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/NewRoundMessageData.java
  14. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/PrepareMessageData.java
  15. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/ProposalMessageData.java
  16. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagedata/RoundChangeMessageData.java
  17. 6
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/NewRoundPayload.java
  18. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java
  19. 6
      consensus/ibft/src/test-support/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolContextFixture.java
  20. 4
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/MockPeerFactory.java
  21. 5
      consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreator.java
  22. 42
      consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftExtraDataCalculator.java

@ -26,8 +26,4 @@ public class CliqueRpcApis {
return Optional.empty();
}
}
public static final String getName(final RpcApi rpcapi) {
return rpcapi.getCliValue();
}
}

@ -31,25 +31,7 @@ import org.junit.Test;
public class CliqueBlockHashingTest {
public static class LoadedBlockHeader {
private final BlockHeader header;
private final Hash parsedBlockHash;
public LoadedBlockHeader(final BlockHeader header, final Hash parsedBlockHash) {
this.header = header;
this.parsedBlockHash = parsedBlockHash;
}
public BlockHeader getHeader() {
return header;
}
public Hash getParsedBlockHash() {
return parsedBlockHash;
}
}
private LoadedBlockHeader expectedHeader = null;
private BlockHeader expectedHeader = null;
// clique.getSignersAtHash("0x8b27a29300811af926039b90288d3d384dcb55931049c17c4f762e45c116776e")
private static final List<Address> VALIDATORS_IN_HEADER =
@ -67,27 +49,25 @@ public class CliqueBlockHashingTest {
@Test
public void recoverProposerAddressFromSeal() {
final CliqueExtraData cliqueExtraData =
CliqueExtraData.decode(expectedHeader.getHeader().getExtraData());
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(expectedHeader.getExtraData());
final Address proposerAddress =
CliqueBlockHashing.recoverProposerAddress(expectedHeader.getHeader(), cliqueExtraData);
CliqueBlockHashing.recoverProposerAddress(expectedHeader, cliqueExtraData);
assertThat(VALIDATORS_IN_HEADER.contains(proposerAddress)).isTrue();
}
@Test
public void readValidatorListFromExtraData() {
final CliqueExtraData cliqueExtraData =
CliqueExtraData.decode(expectedHeader.getHeader().getExtraData());
final CliqueExtraData cliqueExtraData = CliqueExtraData.decode(expectedHeader.getExtraData());
assertThat(cliqueExtraData.getValidators()).isEqualTo(VALIDATORS_IN_HEADER);
}
@Test
public void calculateBlockHash() {
assertThat(expectedHeader.getHeader().getHash()).isEqualTo(KNOWN_BLOCK_HASH);
assertThat(expectedHeader.getHash()).isEqualTo(KNOWN_BLOCK_HASH);
}
private LoadedBlockHeader createKnownHeaderFromCapturedData() {
private BlockHeader createKnownHeaderFromCapturedData() {
// The following text was a dump from the geth console of the 30_000 block on Rinkeby.
// eth.getBlock(30000)
final BlockHeaderBuilder builder = new BlockHeaderBuilder();
@ -118,11 +98,8 @@ public class CliqueBlockHashingTest {
builder.transactionsRoot(
Hash.fromHexString("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"));
final Hash parsedHash =
Hash.fromHexString("0x8b27a29300811af926039b90288d3d384dcb55931049c17c4f762e45c116776e");
builder.blockHashFunction(MainnetBlockHashFunction::createHash);
return new LoadedBlockHeader(builder.buildBlockHeader(), parsedHash);
return builder.buildBlockHeader();
}
}

@ -1,18 +0,0 @@
/*
* Copyright 2018 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.clique.headervalidationrules;
public class SignerRateLimitValidationRuleTest {
// Implicitly conducted by NodeCanProduceNextBlockTest.
}

@ -102,7 +102,6 @@ public class DiscardTest {
public void discardWithoutAddress() {
final VoteProposer proposer = new VoteProposer();
final Discard discard = new Discard(proposer, new JsonRpcParameter());
final Address a0 = Address.fromHexString("0");
assertThatThrownBy(() -> discard.response(requestWithParams()))
.hasMessage("Missing required json rpc parameter at index 0")

@ -55,11 +55,6 @@ public class VoteProposer {
proposals.remove(address);
}
/** Discards all pending votes */
public void clear() {
proposals.clear();
}
public Map<Address, VoteType> getProposals() {
return proposals;
}

@ -21,7 +21,6 @@ import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Block;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -51,10 +50,6 @@ public class TestContext {
this.finalState = finalState;
}
public Collection<ValidatorPeer> getRemotePeers() {
return remotePeers.values();
}
public MutableBlockchain getBlockchain() {
return blockchain;
}

@ -1,51 +0,0 @@
/*
* Copyright 2018 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.messagedata.CommitMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2;
import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.Message;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
public class IbftMessages {
public static SignedData<?> fromMessage(final Message message) {
final MessageData messageData = message.getData();
switch (messageData.getCode()) {
case IbftV2.PROPOSAL:
return ProposalMessageData.fromMessageData(messageData).decode();
case IbftV2.PREPARE:
return PrepareMessageData.fromMessageData(messageData).decode();
case IbftV2.COMMIT:
return CommitMessageData.fromMessageData(messageData).decode();
case IbftV2.ROUND_CHANGE:
return RoundChangeMessageData.fromMessageData(messageData).decode();
case IbftV2.NEW_ROUND:
return NewRoundMessageData.fromMessageData(messageData).decode();
default:
throw new IllegalArgumentException(
"Received message does not conform to any recognised IBFT message structure.");
}
}
}

@ -79,10 +79,6 @@ public class Vote {
return Objects.hashCode(recipient, voteType);
}
public VoteType getVoteType() {
return voteType;
}
public void writeTo(final RLPOutput rlpOutput) {
rlpOutput.startList();
rlpOutput.writeBytesValue(recipient);

@ -1,37 +0,0 @@
/*
* Copyright 2018 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.blockcreation;
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockScheduler;
import tech.pegasys.pantheon.ethereum.blockcreation.BlockMiner;
import tech.pegasys.pantheon.ethereum.chain.MinedBlockObserver;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.util.Subscribers;
public class IbftBlockMiner extends BlockMiner<IbftContext, IbftBlockCreator> {
// TODO(tmm): Currently a place holder to allow infrastructure code to continue to operate
// with the advent of multiple consensus methods.
public IbftBlockMiner(
final IbftBlockCreator blockCreator,
final ProtocolSchedule<IbftContext> protocolSchedule,
final ProtocolContext<IbftContext> protocolContext,
final Subscribers<MinedBlockObserver> observers,
final AbstractBlockScheduler scheduler,
final BlockHeader parentHeader) {
super(blockCreator, protocolSchedule, protocolContext, observers, scheduler, parentHeader);
}
}

@ -26,8 +26,4 @@ public class IbftRpcApis {
return Optional.empty();
}
}
public static final String getName(final RpcApi rpcapi) {
return rpcapi.getCliValue();
}
}

@ -12,8 +12,6 @@
*/
package tech.pegasys.pantheon.consensus.ibft.messagedata;
import tech.pegasys.pantheon.consensus.ibft.payload.Payload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.p2p.wire.AbstractMessageData;
import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -25,8 +23,6 @@ public abstract class AbstractIbftMessageData extends AbstractMessageData {
super(data);
}
public abstract SignedData<? extends Payload> decode();
protected static <T extends AbstractIbftMessageData> T fromMessageData(
final MessageData messageData,
final int messageCode,

@ -31,7 +31,6 @@ public class CommitMessageData extends AbstractIbftMessageData {
messageData, MESSAGE_CODE, CommitMessageData.class, CommitMessageData::new);
}
@Override
public SignedData<CommitPayload> decode() {
return SignedData.readSignedCommitPayloadFrom(RLP.input(data));
}

@ -31,7 +31,6 @@ public class NewRoundMessageData extends AbstractIbftMessageData {
messageData, MESSAGE_CODE, NewRoundMessageData.class, NewRoundMessageData::new);
}
@Override
public SignedData<NewRoundPayload> decode() {
return SignedData.readSignedNewRoundPayloadFrom(RLP.input(data));
}

@ -31,7 +31,6 @@ public class PrepareMessageData extends AbstractIbftMessageData {
messageData, MESSAGE_CODE, PrepareMessageData.class, PrepareMessageData::new);
}
@Override
public SignedData<PreparePayload> decode() {
return SignedData.readSignedPreparePayloadFrom(RLP.input(data));
}

@ -31,7 +31,6 @@ public class ProposalMessageData extends AbstractIbftMessageData {
messageData, MESSAGE_CODE, ProposalMessageData.class, ProposalMessageData::new);
}
@Override
public SignedData<ProposalPayload> decode() {
return SignedData.readSignedProposalPayloadFrom(RLP.input(data));
}

@ -31,7 +31,6 @@ public class RoundChangeMessageData extends AbstractIbftMessageData {
messageData, MESSAGE_CODE, RoundChangeMessageData.class, RoundChangeMessageData::new);
}
@Override
public SignedData<RoundChangePayload> decode() {
return SignedData.readSignedRoundChangePayloadFrom(RLP.input(data));
}

@ -113,8 +113,6 @@ public class NewRoundPayload implements Payload {
private SignedData<ProposalPayload> proposalPayload = null;
public Builder() {}
public Builder(
final ConsensusRoundIdentifier roundChangeIdentifier,
final RoundChangeCertificate roundChangeCertificate,
@ -137,10 +135,6 @@ public class NewRoundPayload implements Payload {
this.roundChangeCertificate = roundChangeCertificate;
}
public void setProposalPayload(final SignedData<ProposalPayload> proposalPayload) {
this.proposalPayload = proposalPayload;
}
public NewRoundPayload build() {
return new NewRoundPayload(roundChangeIdentifier, roundChangeCertificate, proposalPayload);
}

@ -88,10 +88,6 @@ public class IbftFinalState {
return localAddress;
}
public ProposerSelector getProposerSelector() {
return proposerSelector;
}
public boolean isLocalNodeProposerForRound(final ConsensusRoundIdentifier roundIdentifier) {
return getProposerForRound(roundIdentifier).equals(localAddress);
}

@ -12,8 +12,6 @@
*/
package tech.pegasys.pantheon.consensus.ibft;
import static java.util.Arrays.asList;
import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.consensus.common.VoteTally;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
@ -23,10 +21,6 @@ import java.util.List;
public class IbftProtocolContextFixture {
public static ProtocolContext<IbftContext> protocolContext(final Address... validators) {
return protocolContext(asList(validators));
}
public static ProtocolContext<IbftContext> protocolContext(final List<Address> validators) {
return new ProtocolContext<>(
null, null, new IbftContext(new VoteTally(validators), new VoteProposer()));

@ -16,14 +16,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.AddressHelpers;
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection;
import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo;
public class MockPeerFactory {
public static PeerConnection create() {
return create(AddressHelpers.ofValue(9));
}
public static PeerConnection create(final Address address) {
final PeerConnection peerConnection = mock(PeerConnection.class);

@ -34,9 +34,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import java.util.function.Function;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Responsible for producing a Block which conforms to IBFT validation rules (other than missing
* commit seals). Transactions and associated Hashes (stateroot, receipts etc.) are loaded into the
@ -44,8 +41,6 @@ import org.apache.logging.log4j.Logger;
*/
public class IbftBlockCreator extends AbstractBlockCreator<IbftContext> {
private static final Logger LOG = LogManager.getLogger();
private final KeyPair nodeKeys;
public IbftBlockCreator(

@ -1,42 +0,0 @@
/*
* Copyright 2018 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.ibftlegacy.blockcreation;
import tech.pegasys.pantheon.consensus.common.ValidatorProvider;
import tech.pegasys.pantheon.consensus.ibftlegacy.IbftExtraData;
import tech.pegasys.pantheon.ethereum.blockcreation.AbstractBlockCreator.ExtraDataCalculator;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import com.google.common.collect.Lists;
public class IbftExtraDataCalculator implements ExtraDataCalculator {
private final ValidatorProvider validatorProvider;
public IbftExtraDataCalculator(final ValidatorProvider validatorProvider) {
this.validatorProvider = validatorProvider;
}
@Override
public BytesValue get(final BlockHeader parent) {
final BytesValue vanityData = BytesValue.wrap(new byte[32]);
final IbftExtraData baseExtraData =
new IbftExtraData(
vanityData,
Lists.newArrayList(),
null,
Lists.newArrayList(validatorProvider.getValidators()));
return baseExtraData.encode();
}
}
Loading…
Cancel
Save