Skip to content

Commit

Permalink
javadoc and more cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
jflo committed Nov 9, 2023
1 parent 3b67fa5 commit 47aef7a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
15 changes: 15 additions & 0 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

import java.util.Objects;

import org.apache.tuweni.bytes.Bytes;

/** Arbitrary data for use in the KZG scheme. */
Expand Down Expand Up @@ -61,4 +63,17 @@ public void writeTo(final RLPOutput out) {
public Bytes getData() {
return data;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Blob blob = (Blob) o;
return Objects.equals(getData(), blob.getData());
}

@Override
public int hashCode() {
return Objects.hash(getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,34 @@
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/** A class to hold the blobs, commitments, proofs and versioned hashes for a set of blobs. */
public class BlobsWithCommitments {

/**
* A record to hold the blob, commitment, proof and versioned hash for a blob.
*/
public record BlobQuad(
Blob blob, KZGCommitment kzgCommitment, KZGProof kzgProof, VersionedHash versionedHash) {}
Blob blob, KZGCommitment kzgCommitment, KZGProof kzgProof, VersionedHash versionedHash) {

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlobQuad blobQuad = (BlobQuad) o;
return Objects.equals(blob, blobQuad.blob)
&& Objects.equals(kzgCommitment, blobQuad.kzgCommitment)
&& Objects.equals(kzgProof, blobQuad.kzgProof)
&& Objects.equals(versionedHash, blobQuad.versionedHash);
}

@Override
public int hashCode() {
return Objects.hash(blob, kzgCommitment, kzgProof, versionedHash);
}
}
;

private final List<BlobQuad> blobQuads;
Expand Down Expand Up @@ -60,6 +81,10 @@ public BlobsWithCommitments(
this.blobQuads = toBuild;
}

/**
* Construct the class from a list of BlobQuads.
* @param quads the list of blob quads to be attached to the transaction
*/
public BlobsWithCommitments(final List<BlobQuad> quads) {
this.blobQuads = quads;
}
Expand Down Expand Up @@ -100,7 +125,25 @@ public List<VersionedHash> getVersionedHashes() {
return blobQuads.stream().map(BlobQuad::versionedHash).collect(Collectors.toList());
}

/**
* Get the list of BlobQuads.
*
* @return blob quads
*/
public List<BlobQuad> getBlobQuads() {
return blobQuads;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlobsWithCommitments that = (BlobsWithCommitments) o;
return Objects.equals(getBlobQuads(), that.getBlobQuads());
}

@Override
public int hashCode() {
return Objects.hash(getBlobQuads());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

import java.util.Objects;

import org.apache.tuweni.bytes.Bytes48;

/** This class contains the data for a KZG commitment. */
Expand Down Expand Up @@ -60,4 +62,17 @@ public void writeTo(final RLPOutput out) {
public Bytes48 getData() {
return data;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
KZGCommitment that = (KZGCommitment) o;
return Objects.equals(getData(), that.getData());
}

@Override
public int hashCode() {
return Objects.hash(getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

import java.util.Objects;

import org.apache.tuweni.bytes.Bytes48;

/** This class contains the data for a KZG proof for a KZG commitment. */
Expand Down Expand Up @@ -60,4 +62,17 @@ public void writeTo(final RLPOutput out) {
public Bytes48 getData() {
return data;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
KZGProof kzgProof = (KZGProof) o;
return Objects.equals(getData(), kzgProof.getData());
}

@Override
public int hashCode() {
return Objects.hash(getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ public void shouldReAddBlobTxsWhenReorgHappens() {
assertThat(maybeBlob).isPresent();
Transaction restoredBlob = maybeBlob.get();
assertThat(restoredBlob).isEqualTo(transactionBlob);
assertThat(restoredBlob.getBlobsWithCommitments().get().getBlobQuads())
.isEqualTo(transactionBlob.getBlobsWithCommitments().get().getBlobQuads());
}

@ParameterizedTest
Expand Down Expand Up @@ -1465,7 +1467,7 @@ protected Transaction createBlobTransaction(final int nonce) {
.maxFeePerGas(Optional.of(Wei.of(5000L)))
.maxPriorityFeePerGas(Optional.of(Wei.of(1000L)))
.type(TransactionType.BLOB)
.blobsWithCommitments(Optional.of(new BlobTestFixture().createBlobsWithCommitments(1)))
.blobsWithCommitments(Optional.of(new BlobTestFixture().createBlobsWithCommitments(6)))
.createTransaction(KEY_PAIR1);
}

Expand Down

0 comments on commit 47aef7a

Please sign in to comment.