Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep track of blobs that are part of multiple transactions #7723

Merged
merged 10 commits into from
Oct 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,6 +34,8 @@

public class BlobTestFixture {

private byte byteValue = 0x00;

public BlobTestFixture() {
try {
// optimistically tear down a potential previous loaded trusted setup
Expand All @@ -58,14 +58,8 @@ record BlobTriplet(
;

public BlobTriplet createBlobTriplet() {
byte[] rawMaterial = {};
try (InputStream readme =
BlobTestFixture.class.getResourceAsStream(
"/org/hyperledger/besu/ethereum/core/encoding/BlobDataFixture.bin")) {
rawMaterial = readme.readAllBytes();
} catch (IOException e) {
fail("Failed to read blob file", e);
}
byte[] rawMaterial = new byte[131072];
rawMaterial[0] = byteValue++;

Bytes48 commitment = Bytes48.wrap(CKZG4844JNI.blobToKzgCommitment(rawMaterial));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
Expand All @@ -77,6 +78,8 @@
import java.util.stream.Stream;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -107,8 +110,10 @@ public class TransactionPool implements BlockAddedObserver {
private final SaveRestoreManager saveRestoreManager = new SaveRestoreManager();
private final Set<Address> localSenders = ConcurrentHashMap.newKeySet();
private final EthScheduler.OrderedProcessor<BlockAddedEvent> blockAddedEventOrderedProcessor;
private final Map<VersionedHash, BlobsWithCommitments.BlobQuad> mapOfBlobsInTransactionPool =
new HashMap<>();
private final ListMultimap<VersionedHash, BlobsWithCommitments.BlobQuad>
mapOfBlobsInTransactionPool =
Multimaps.synchronizedListMultimap(
Multimaps.newListMultimap(new HashMap<>(), () -> new ArrayList<>(1)));

public TransactionPool(
final Supplier<PendingTransactions> pendingTransactionsSupplier,
Expand Down Expand Up @@ -660,6 +665,7 @@ private void mapBlobsOnTransactionAdded(
}
final List<BlobsWithCommitments.BlobQuad> blobQuads =
maybeBlobsWithCommitments.get().getBlobQuads();

blobQuads.forEach(bq -> mapOfBlobsInTransactionPool.put(bq.versionedHash(), bq));
}

Expand All @@ -672,15 +678,18 @@ private void unmapBlobsOnTransactionDropped(
}
final List<BlobsWithCommitments.BlobQuad> blobQuads =
maybeBlobsWithCommitments.get().getBlobQuads();
blobQuads.forEach(bq -> mapOfBlobsInTransactionPool.remove(bq.versionedHash()));

blobQuads.forEach(bq -> mapOfBlobsInTransactionPool.remove(bq.versionedHash(), bq));
}

public BlobsWithCommitments.BlobQuad getBlobQuad(final VersionedHash vh) {
BlobsWithCommitments.BlobQuad blobQuad = mapOfBlobsInTransactionPool.get(vh);
if (blobQuad == null) {
blobQuad = cacheForBlobsOfTransactionsAddedToABlock.get(vh);
try {
// returns an empty list if the key is not present, so getFirst() will throw
return mapOfBlobsInTransactionPool.get(vh).getFirst();
} catch (NoSuchElementException e) {
// do nothing
}
return blobQuad;
return cacheForBlobsOfTransactionsAddedToABlock.get(vh);
}

public boolean isEnabled() {
Expand Down
Loading
Loading