Skip to content

Commit

Permalink
Keep track of blobs that are part of multiple transactions (#7723)
Browse files Browse the repository at this point in the history
* keep track of blobs that are part of multiple transactions

Signed-off-by: [email protected] <[email protected]>
Signed-off-by: Stefan Pingel <[email protected]>
  • Loading branch information
pinges authored Oct 9, 2024
1 parent 11a62a0 commit 0cd5106
Show file tree
Hide file tree
Showing 5 changed files with 756 additions and 515 deletions.
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

0 comments on commit 0cd5106

Please sign in to comment.