Minor changes from the ibft hackathon code (#394)

Chris Mckay 6 years ago committed by GitHub
parent 853799d3d3
commit b5df96c2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueBlockInterface.java
  2. 3
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueBlockInterfaceTest.java
  3. 4
      consensus/common/src/main/java/tech/pegasys/pantheon/consensus/common/BlockInterface.java
  4. 3
      consensus/common/src/main/java/tech/pegasys/pantheon/consensus/common/VoteTally.java
  5. 4
      consensus/common/src/main/java/tech/pegasys/pantheon/consensus/common/VoteTallyUpdater.java
  6. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ConsensusRoundIdentifier.java
  7. 19
      consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftExtraData.java
  8. 4
      consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftLegacyBlockInterface.java
  9. 3
      consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftLegacyBlockInterfaceTest.java
  10. 4
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/BlockImporter.java
  11. 3
      pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java
  12. 0
      pantheon/src/test/resources/ibftlegacy_genesis.json

@ -20,7 +20,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder; import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.List; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
@ -71,7 +71,7 @@ public class CliqueBlockInterface implements BlockInterface {
} }
@Override @Override
public List<Address> validatorsInBlock(final BlockHeader header) { public Collection<Address> validatorsInBlock(final BlockHeader header) {
return CliqueExtraData.decode(header.getExtraData()).getValidators(); return CliqueExtraData.decode(header.getExtraData()).getValidators();
} }

@ -27,6 +27,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -123,7 +124,7 @@ public class CliqueBlockInterfaceTest {
public void extractsValidatorsFromHeader() { public void extractsValidatorsFromHeader() {
final BlockHeader header = final BlockHeader header =
TestHelpers.createCliqueSignedBlockHeader(headerBuilder, proposerKeys, validatorList); TestHelpers.createCliqueSignedBlockHeader(headerBuilder, proposerKeys, validatorList);
final List<Address> extractedValidators = blockInterface.validatorsInBlock(header); final Collection<Address> extractedValidators = blockInterface.validatorsInBlock(header);
assertThat(extractedValidators).isEqualTo(validatorList); assertThat(extractedValidators).isEqualTo(validatorList);
} }

@ -15,7 +15,7 @@ package tech.pegasys.pantheon.consensus.common;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import java.util.List; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
public interface BlockInterface { public interface BlockInterface {
@ -24,5 +24,5 @@ public interface BlockInterface {
Optional<ValidatorVote> extractVoteFromHeader(final BlockHeader header); Optional<ValidatorVote> extractVoteFromHeader(final BlockHeader header);
List<Address> validatorsInBlock(final BlockHeader header); Collection<Address> validatorsInBlock(final BlockHeader header);
} }

@ -18,7 +18,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -35,7 +34,7 @@ public class VoteTally implements ValidatorProvider {
private final Map<Address, Set<Address>> addVotesBySubject; private final Map<Address, Set<Address>> addVotesBySubject;
private final Map<Address, Set<Address>> removeVotesBySubject; private final Map<Address, Set<Address>> removeVotesBySubject;
public VoteTally(final List<Address> initialValidators) { public VoteTally(final Collection<Address> initialValidators) {
this(new TreeSet<>(initialValidators), new HashMap<>(), new HashMap<>()); this(new TreeSet<>(initialValidators), new HashMap<>(), new HashMap<>());
} }

@ -16,7 +16,7 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import java.util.List; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -49,7 +49,7 @@ public class VoteTallyUpdater {
final long epochBlockNumber = epochManager.getLastEpochBlock(chainHeadBlockNumber); final long epochBlockNumber = epochManager.getLastEpochBlock(chainHeadBlockNumber);
LOG.info("Loading validator voting state starting from block {}", epochBlockNumber); LOG.info("Loading validator voting state starting from block {}", epochBlockNumber);
final BlockHeader epochBlock = blockchain.getBlockHeader(epochBlockNumber).get(); final BlockHeader epochBlock = blockchain.getBlockHeader(epochBlockNumber).get();
final List<Address> initialValidators = blockInterface.validatorsInBlock(epochBlock); final Collection<Address> initialValidators = blockInterface.validatorsInBlock(epochBlock);
final VoteTally voteTally = new VoteTally(initialValidators); final VoteTally voteTally = new VoteTally(initialValidators);
for (long blockNumber = epochBlockNumber + 1; for (long blockNumber = epochBlockNumber + 1;
blockNumber <= chainHeadBlockNumber; blockNumber <= chainHeadBlockNumber;

@ -100,7 +100,7 @@ public class ConsensusRoundIdentifier implements Comparable<ConsensusRoundIdenti
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
ConsensusRoundIdentifier that = (ConsensusRoundIdentifier) o; final ConsensusRoundIdentifier that = (ConsensusRoundIdentifier) o;
return sequence == that.sequence && round == that.round; return sequence == that.sequence && round == that.round;
} }

@ -22,7 +22,7 @@ import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.List; import java.util.Collection;
/** /**
* Represents the data structure stored in the extraData field of the BlockHeader used when * Represents the data structure stored in the extraData field of the BlockHeader used when
@ -33,15 +33,15 @@ public class IbftExtraData {
public static final int EXTRA_VANITY_LENGTH = 32; public static final int EXTRA_VANITY_LENGTH = 32;
private final BytesValue vanityData; private final BytesValue vanityData;
private final List<Signature> seals; private final Collection<Signature> seals;
private final Signature proposerSeal; private final Signature proposerSeal;
private final List<Address> validators; private final Collection<Address> validators;
public IbftExtraData( public IbftExtraData(
final BytesValue vanityData, final BytesValue vanityData,
final List<Signature> seals, final Collection<Signature> seals,
final Signature proposerSeal, final Signature proposerSeal,
final List<Address> validators) { final Collection<Address> validators) {
checkNotNull(vanityData); checkNotNull(vanityData);
checkNotNull(seals); checkNotNull(seals);
@ -64,9 +64,10 @@ public class IbftExtraData {
final RLPInput rlpInput = new BytesValueRLPInput(rlpData, false); final RLPInput rlpInput = new BytesValueRLPInput(rlpData, false);
rlpInput.enterList(); // This accounts for the "root node" which contains IBFT data items. rlpInput.enterList(); // This accounts for the "root node" which contains IBFT data items.
final List<Address> validators = rlpInput.readList(Address::readFrom); final Collection<Address> validators = rlpInput.readList(Address::readFrom);
final Signature proposerSeal = parseProposerSeal(rlpInput); final Signature proposerSeal = parseProposerSeal(rlpInput);
final List<Signature> seals = rlpInput.readList(rlp -> Signature.decode(rlp.readBytesValue())); final Collection<Signature> seals =
rlpInput.readList(rlp -> Signature.decode(rlp.readBytesValue()));
rlpInput.leaveList(); rlpInput.leaveList();
return new IbftExtraData(vanityData, seals, proposerSeal, validators); return new IbftExtraData(vanityData, seals, proposerSeal, validators);
@ -97,7 +98,7 @@ public class IbftExtraData {
return vanityData; return vanityData;
} }
public List<Signature> getSeals() { public Collection<Signature> getSeals() {
return seals; return seals;
} }
@ -105,7 +106,7 @@ public class IbftExtraData {
return proposerSeal; return proposerSeal;
} }
public List<Address> getValidators() { public Collection<Address> getValidators() {
return validators; return validators;
} }
} }

@ -20,7 +20,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder; import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.List; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
@ -71,7 +71,7 @@ public class IbftLegacyBlockInterface implements BlockInterface {
} }
@Override @Override
public List<Address> validatorsInBlock(final BlockHeader header) { public Collection<Address> validatorsInBlock(final BlockHeader header) {
return IbftExtraData.decode(header.getExtraData()).getValidators(); return IbftExtraData.decode(header.getExtraData()).getValidators();
} }

@ -27,6 +27,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -122,7 +123,7 @@ public class IbftLegacyBlockInterfaceTest {
final BlockHeader header = final BlockHeader header =
TestHelpers.createIbftSignedBlockHeader(headerBuilder, proposerKeys, validatorList); TestHelpers.createIbftSignedBlockHeader(headerBuilder, proposerKeys, validatorList);
final List<Address> extractedValidators = blockInterface.validatorsInBlock(header); final Collection<Address> extractedValidators = blockInterface.validatorsInBlock(header);
assertThat(extractedValidators).isEqualTo(validatorList); assertThat(extractedValidators).isEqualTo(validatorList);
} }

@ -27,7 +27,7 @@ import java.util.List;
public interface BlockImporter<C> { public interface BlockImporter<C> {
/** /**
* Attempts to import the given block to the specificed blockchain and world state. * Attempts to import the given block to the specified blockchain and world state.
* *
* @param context The context to attempt to update * @param context The context to attempt to update
* @param block The block * @param block The block
@ -43,7 +43,7 @@ public interface BlockImporter<C> {
} }
/** /**
* Attempts to import the given block to the specificed blockchain and world state. * Attempts to import the given block to the specified blockchain and world state.
* *
* @param context The context to attempt to update * @param context The context to attempt to update
* @param block The block * @param block The block

@ -65,7 +65,8 @@ public final class BlockImporterTest {
@Test @Test
public void ibftImport() throws IOException { public void ibftImport() throws IOException {
final Path source = folder.newFile().toPath(); final Path source = folder.newFile().toPath();
final String config = Resources.toString(Resources.getResource("ibft_genesis.json"), UTF_8); final String config =
Resources.toString(Resources.getResource("ibftlegacy_genesis.json"), UTF_8);
try { try {
Files.write( Files.write(

Loading…
Cancel
Save