-
Couldn't load subscription status.
- Fork 46
feat: trace all previous blockhashes #2353
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
Changes from all commits
cdb6bd7
3291986
a1e59dc
1fe4014
a65dbec
f7c987f
374fe0d
12e274c
d3283b9
55556e2
1fde88d
53257e6
c964177
284f8b7
afc5d85
01e6802
b07cbc9
860d03d
b8bbcf5
975d9fb
17a0055
e649367
6d52a97
12499a6
5e37279
69f8899
db32703
fa0abf5
f7aa5cf
7accb81
aebd4ab
e6ce843
ffbc23e
3bf9585
5a592bb
0046e4c
c1068c8
27b52fe
b973e31
c34f97d
91cf927
3bc11d6
4746eca
27addb1
fa1b3bd
42a2230
5c64388
febd637
c6df212
f06c44b
077effe
b0dc1c5
599cee0
62e8170
077d742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,16 @@ | |
|
|
||
| package net.consensys.linea.blockcapture.reapers; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static net.consensys.linea.zktracer.Trace.HISTORY_BUFFER_LENGTH; | ||
| import static net.consensys.linea.zktracer.Trace.HISTORY_SERVE_WINDOW; | ||
| import static net.consensys.linea.zktracer.module.hub.section.systemTransaction.EIP2935HistoricalHash.EIP2935_HISTORY_STORAGE_ADDRESS; | ||
| import static net.consensys.linea.zktracer.module.hub.section.systemTransaction.EIP4788BeaconBlockRootSection.EIP4788_BEACONROOT_ADDRESS; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import net.consensys.linea.blockcapture.snapshots.AccountSnapshot; | ||
| import net.consensys.linea.blockcapture.snapshots.BlockHashSnapshot; | ||
| import net.consensys.linea.blockcapture.snapshots.BlockSnapshot; | ||
| import net.consensys.linea.blockcapture.snapshots.ConflationSnapshot; | ||
| import net.consensys.linea.blockcapture.snapshots.StorageSnapshot; | ||
|
|
@@ -44,6 +48,7 @@ | |
| * <p>This data can than be collapsed into a “replay” ({@link ConflationSnapshot}), i.e. the minimal | ||
| * required information to replay a conflation as if it were executed on the blockchain. | ||
| */ | ||
| @Slf4j | ||
| public class Reaper { | ||
| /** Collect storage locations read / written by the entire conflation */ | ||
| private final StorageReaper conflationStorage = new StorageReaper(); | ||
|
|
@@ -52,7 +57,7 @@ public class Reaper { | |
| private final AddressReaper conflationAddresses = new AddressReaper(); | ||
|
|
||
| /** Collection all block hashes read during the conflation * */ | ||
| private final BlockHashReaper conflationHashes = new BlockHashReaper(); | ||
| private final Map<Long, Hash> conflationHashes = new HashMap<>(); | ||
|
|
||
| /** Collect the blocks within a conflation */ | ||
| private final List<BlockSnapshot> blocks = new ArrayList<>(); | ||
|
|
@@ -75,6 +80,38 @@ public void enterBlock( | |
| BlockSnapshot.of((org.hyperledger.besu.ethereum.core.BlockHeader) header, body)); | ||
| this.conflationAddresses.touch(miningBeneficiary); | ||
| txIndex = 0; // reset | ||
| touchedBySystemTransactions(header); | ||
| } | ||
|
|
||
| private void touchedBySystemTransactions(BlockHeader header) { | ||
| // EIP 4788 (CANCUN): | ||
| try { | ||
| conflationAddresses.touch(EIP4788_BEACONROOT_ADDRESS); | ||
| final UInt256 timestamp = UInt256.valueOf(header.getTimestamp()); | ||
| final UInt256 keyTimestamp = timestamp.mod(HISTORY_BUFFER_LENGTH); | ||
| conflationStorage.touch(EIP4788_BEACONROOT_ADDRESS, timestamp); | ||
| conflationStorage.touch(EIP4788_BEACONROOT_ADDRESS, keyTimestamp); | ||
| } catch (Exception e) { | ||
| log.warn( | ||
| "Failed to retrieve EIP4788 infos for block {}, exception caught is: {}", | ||
| header.getNumber(), | ||
| e.getMessage()); | ||
| } | ||
|
|
||
| // EIP 2935 (PRAGUE) | ||
| try { | ||
| conflationAddresses.touch(EIP2935_HISTORY_STORAGE_ADDRESS); | ||
| final long blockNumber = header.getNumber(); | ||
| final long previousBlockNumber = blockNumber == 0 ? 0 : blockNumber - 1; | ||
| final UInt256 previousBlockNumberMod8191 = | ||
| UInt256.valueOf(previousBlockNumber % HISTORY_SERVE_WINDOW); | ||
| conflationStorage.touch(EIP2935_HISTORY_STORAGE_ADDRESS, previousBlockNumberMod8191); | ||
| } catch (Exception e) { | ||
| log.warn( | ||
| "Failed to retrieve EIP2935 infos for block {}, exception caught is: {}", | ||
| header.getNumber(), | ||
| e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public void prepareTransaction(Transaction tx) { | ||
|
|
@@ -96,7 +133,7 @@ public void exitTransaction( | |
| TransactionSnapshot txSnapshot = blocks.getLast().txs().get(txIndex); | ||
| // Convert logs into hex strings | ||
| List<String> logStrings = logs.stream().map(l -> l.getData().toHexString()).toList(); | ||
| // Convert destructed account addresses into into hex strings | ||
| // Convert destructed account addresses into hex strings | ||
| List<String> destructStrings = selfDestructs.stream().map(Address::toHexString).toList(); | ||
| // Collapse accounts | ||
| final List<AccountSnapshot> accounts = this.txAddresses.collapse(world); | ||
|
|
@@ -125,8 +162,16 @@ public void touchStorage(final Address address, final UInt256 key) { | |
| } | ||
|
|
||
| public void touchBlockHash(final long blockNumber, Hash blockHash) { | ||
| this.conflationHashes.touch(blockNumber, blockHash); | ||
| // No need to tx local hashes, since they are a global concept. | ||
| if (!conflationHashes.containsKey(blockNumber) || conflationHashes.get(blockNumber).isEmpty()) { | ||
| conflationHashes.put(blockNumber, blockHash); | ||
| } else { | ||
| checkArgument( | ||
| conflationHashes.get(blockNumber).equals(blockHash), | ||
| "Block hash mismatch for block number %s: existing %s, new %s", | ||
| blockNumber, | ||
| conflationHashes.get(blockNumber), | ||
| blockHash); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Null Handling Error in Hash RetrievalThe |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -139,12 +184,10 @@ public void touchBlockHash(final long blockNumber, Hash blockHash) { | |
| */ | ||
| public ConflationSnapshot collapse(final WorldUpdater world) { | ||
| // Collapse accounts | ||
| final List<AccountSnapshot> accounts = this.conflationAddresses.collapse(world); | ||
| final List<AccountSnapshot> accounts = conflationAddresses.collapse(world); | ||
| // Collapse storage | ||
| final List<StorageSnapshot> storage = conflationStorage.collapse(world); | ||
| // Collapse block hashes | ||
| final List<BlockHashSnapshot> hashes = conflationHashes.collapse(); | ||
| // Done | ||
| return new ConflationSnapshot(this.blocks, accounts, storage, hashes); | ||
| return ConflationSnapshot.from(blocks, accounts, storage, conflationHashes); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys that are touched by 4788 system transactions are
Am I misunderstanding here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, you're right