Search in sources :

Example 1 with BftExtraData

use of org.hyperledger.besu.consensus.common.bft.BftExtraData in project besu by hyperledger.

the class QbftExtraDataCodecTest method decodingOfKnownRawHexStringMatchesKnowExtraDataObject.

@Test
public void decodingOfKnownRawHexStringMatchesKnowExtraDataObject() {
    final BftExtraData expectedExtraData = DECODED_EXTRA_DATA_FOR_RAW_HEX_ENCODING_STRING;
    Bytes rawDecoding = Bytes.fromHexString(RAW_HEX_ENCODING_STRING);
    BftExtraData actualExtraData = bftExtraDataCodec.decodeRaw(rawDecoding);
    assertThat(actualExtraData).isEqualToComparingFieldByField(expectedExtraData);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Example 2 with BftExtraData

use of org.hyperledger.besu.consensus.common.bft.BftExtraData in project besu by hyperledger.

the class QbftExtraDataCodecTest method extraDataCanBeEncodedWithoutCommitSeals.

@Test
public void extraDataCanBeEncodedWithoutCommitSeals() {
    final List<Address> validators = Arrays.asList(Address.fromHexString("1"), Address.fromHexString("2"));
    final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
    final int round = 0x00FEDCBA;
    final List<SECPSignature> committerSeals = Arrays.asList(SIGNATURE_ALGORITHM.get().createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 0), SIGNATURE_ALGORITHM.get().createSignature(BigInteger.TEN, BigInteger.ONE, (byte) 0));
    // Create a byte buffer with no data.
    final byte[] vanity_bytes = createNonEmptyVanityData();
    final Bytes vanity_data = Bytes.wrap(vanity_bytes);
    final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
    encoder.startList();
    encoder.writeBytes(vanity_data);
    encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
    // encoded vote
    encoder.startList();
    encoder.writeBytes(Address.fromHexString("1"));
    encoder.writeByte(Vote.ADD_BYTE_VALUE);
    encoder.endList();
    encoder.writeIntScalar(round);
    encoder.writeEmptyList();
    encoder.endList();
    Bytes expectedEncoding = encoder.encoded();
    Bytes actualEncoding = bftExtraDataCodec.encodeWithoutCommitSeals(new BftExtraData(vanity_data, committerSeals, vote, round, validators));
    System.out.println("actualEncoding = " + actualEncoding);
    assertThat(actualEncoding).isEqualTo(expectedEncoding);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Vote(org.hyperledger.besu.consensus.common.bft.Vote) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Address(org.hyperledger.besu.datatypes.Address) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Example 3 with BftExtraData

use of org.hyperledger.besu.consensus.common.bft.BftExtraData in project besu by hyperledger.

the class QbftExtraDataCodecTest method emptyListConstituteValidContent.

@Test
public void emptyListConstituteValidContent() {
    final List<Address> validators = Lists.newArrayList();
    final Optional<Vote> vote = Optional.of(Vote.dropVote(Address.fromHexString("1")));
    final int round = 0x00FEDCBA;
    final List<SECPSignature> committerSeals = Lists.newArrayList();
    // Create a byte buffer with no data.
    final byte[] vanity_bytes = new byte[32];
    final Bytes vanity_data = Bytes.wrap(vanity_bytes);
    final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
    encoder.startList();
    encoder.writeBytes(vanity_data);
    encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
    // encoded vote
    encoder.startList();
    encoder.writeBytes(vote.get().getRecipient());
    encoder.writeNull();
    encoder.endList();
    encoder.writeIntScalar(round);
    encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
    encoder.endList();
    final Bytes bufferToInject = encoder.encoded();
    final BftExtraData extraData = bftExtraDataCodec.decodeRaw(bufferToInject);
    assertThat(extraData.getVanityData()).isEqualTo(vanity_data);
    assertThat(extraData.getRound()).isEqualTo(round);
    assertThat(extraData.getSeals()).isEqualTo(committerSeals);
    assertThat(extraData.getValidators()).isEqualTo(validators);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Vote(org.hyperledger.besu.consensus.common.bft.Vote) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Address(org.hyperledger.besu.datatypes.Address) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Example 4 with BftExtraData

use of org.hyperledger.besu.consensus.common.bft.BftExtraData in project besu by hyperledger.

the class QbftExtraDataCodecTest method correctlyCodedRoundConstitutesValidContent.

@Test
public void correctlyCodedRoundConstitutesValidContent() {
    final List<Address> validators = Lists.newArrayList();
    final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
    final int round = 0xDCBA;
    final byte[] roundAsByteArray = new byte[] { (byte) 0xDC, (byte) 0xBA };
    final List<SECPSignature> committerSeals = Lists.newArrayList();
    // Create a byte buffer with no data.
    final byte[] vanity_bytes = new byte[32];
    final Bytes vanity_data = Bytes.wrap(vanity_bytes);
    final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
    encoder.startList();
    encoder.writeBytes(vanity_data);
    encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
    encoder.startList();
    encoder.writeBytes(vote.get().getRecipient());
    encoder.writeByte(Vote.ADD_BYTE_VALUE);
    encoder.endList();
    // This is to verify that the decoding works correctly when the round is encoded as non-fixed
    // length bytes
    encoder.writeBytes(Bytes.wrap(roundAsByteArray));
    encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
    encoder.endList();
    final Bytes bufferToInject = encoder.encoded();
    final BftExtraData extraData = bftExtraDataCodec.decodeRaw(bufferToInject);
    assertThat(extraData.getVanityData()).isEqualTo(vanity_data);
    assertThat(extraData.getRound()).isEqualTo(round);
    assertThat(extraData.getSeals()).isEqualTo(committerSeals);
    assertThat(extraData.getValidators()).isEqualTo(validators);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Vote(org.hyperledger.besu.consensus.common.bft.Vote) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Address(org.hyperledger.besu.datatypes.Address) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Example 5 with BftExtraData

use of org.hyperledger.besu.consensus.common.bft.BftExtraData in project besu by hyperledger.

the class QbftExtraDataCodecTest method emptyListsAreEncodedAndDecodedCorrectly.

@Test
public void emptyListsAreEncodedAndDecodedCorrectly() {
    final List<Address> validators = Lists.newArrayList();
    final Optional<Vote> vote = Optional.of(Vote.authVote(Address.fromHexString("1")));
    final int round = 0x00FEDCBA;
    final List<SECPSignature> committerSeals = Lists.newArrayList();
    // Create a byte buffer with no data.
    final byte[] vanity_bytes = new byte[32];
    final Bytes vanity_data = Bytes.wrap(vanity_bytes);
    BftExtraData expectedExtraData = new BftExtraData(vanity_data, committerSeals, vote, round, validators);
    BftExtraData actualExtraData = bftExtraDataCodec.decodeRaw(bftExtraDataCodec.encode(expectedExtraData));
    assertThat(actualExtraData).isEqualToComparingFieldByField(expectedExtraData);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Vote(org.hyperledger.besu.consensus.common.bft.Vote) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Address(org.hyperledger.besu.datatypes.Address) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Aggregations

BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)64 Bytes (org.apache.tuweni.bytes.Bytes)30 Address (org.hyperledger.besu.datatypes.Address)29 Test (org.junit.Test)29 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)26 Vote (org.hyperledger.besu.consensus.common.bft.Vote)20 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)19 Block (org.hyperledger.besu.ethereum.core.Block)16 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)15 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)12 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)9 BftBlockHashing (org.hyperledger.besu.consensus.common.bft.BftBlockHashing)7 IbftExtraDataCodec (org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec)6 Hash (org.hyperledger.besu.datatypes.Hash)6 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)6 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)4 BlockHeaderBuilder (org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)4 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)3 QbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)3 Arrays (java.util.Arrays)2