walnuthq / op-scan

Lightweight transaction explorer for the OP Stack.
https://opscan.co
12 stars 22 forks source link

Feat fetch latest l1->l2 transactions #27

Closed danielcdz closed 3 months ago

danielcdz commented 3 months ago

Background

saimeunt commented 3 months ago

@danielcdz This is going in the right direction, note that you could use a slightly more friendly syntax to fetch logs from the contracts:

l1CrossDomainMessenger.getEvents.SentMessage(undefined, {
  fromBlock: l1FromBlock,
})
danielcdz commented 3 months ago

@saimeunt I added more commits, one is a refactor to the way of retrieving logs following your suggestions and separating them into one function for each event log, and the other is a WIP related to the re-computing of the msgHash and an attempt of search in the L2 logs, I want to know if I'm doing the recomputing right since I'm not getting any matching hash on the L2 logs, I'm following this as reference

saimeunt commented 3 months ago

@danielcdz here is my understanding on why you're not getting any matches:

Hope this helps!

danielcdz commented 3 months ago

@danielcdz here is my understanding on why you're not getting any matches:

  • Your compute hexToBytes function is unnecessary, you can pass the result of encodeFunctionData directly to keccak256.
  • Your reconciliation of SentMessage and SentMessageExtension1 is wrong, you should compare against both transactionHashes, not involving the sender.

Hope this helps!

Thank you @saimeunt! 🫡 Related to the 2nd point, what do I need to do is this separately for SentMessage and SentMessageExtension1 and then compare the results with the transaction hash in the L2Events?

saimeunt commented 3 months ago

@danielcdz For each SentMessage event, you can easily track the accompanying SentMessageExtension1 event by searching for a log with the same transactionHash. With these 2 events you will have all the data necessary to recompute the msgHash and find a matching RelayedMessage event on L2, which will give you the L2 transactionHash.

danielcdz commented 3 months ago

@danielcdz For each SentMessage event, you can easily track the accompanying SentMessageExtension1 event by searching for a log with the same transactionHash. With these 2 events you will have all the data necessary to recompute the msgHash and find a matching RelayedMessage event on L2, which will give you the L2 transactionHash.

Gotcha! ty @saimeunt !

saimeunt commented 3 months ago

@danielcdz You're almost there, a couple problems with your PR right now:

danielcdz commented 3 months ago

@danielcdz You're almost there, a couple problems with your PR right now:

  • Your output is different than Etherscan homepage, you need to get the very latest L1L2 transactions and at the moment you're missing the most recent ones.
  • Remove the fetch* functions from @/lib/utils.ts because they're duplicated in your PR, probably because of a merge that happened at some point.
  • Fix the conflict in @/components/pages/home/latest-l1-l2-transactions.tsx : don't touch this file it was already fine, you don't need to plug the L2 chain block explorer as it will always be the origin of this webapp.

Ohh got it! I'm working on that!

danielcdz commented 3 months ago

@saimeunt I addressed your requests! Right now is matching perfectly the information with Etherscan