ArkProjectNFTs / ark-project

ArkProject is a liquidity layer for digital assets, uniting markets, empowering creators, and bridging the gap to mass adoption. Built on top of Starknet, ArkProject is designed to provide a fully decentralized and trustless orderbook on-chain.
https://arkproject.dev
Apache License 2.0
24 stars 8 forks source link

Starknet pending blocks #340

Closed kwiss closed 1 month ago

kwiss commented 2 months ago

Describe the bug

On Starknet, there is currently a discrepancy between the latest block and the pending block, resulting in a delay:

When we invoke the RPC get_block method, the response we receive is as follows:

{
  "jsonrpc": "2.0",
  "result": 631836,
  "id": 0
}

As evidenced on Starkscan, the latest mined block is indeed 631836, and the subsequent block will be 631837.

Screenshot 2024-04-12 at 11 52 37

Notably, block 631836 has an age of 11 minutes, while the expected time between blocks is 6 minutes. This disparity suggests that the latest block returned by the RPC is not the true latest block, but rather the block preceding it.

631838 -> actual pending block 631837 -> real latest block, yet to be returned by the RPC 631836 -> latest block returned by the RPC

Although transactions achieve finality in pending blocks, this delay creates two user experience issues for Starknet users and the decentralized applications (dapps) utilizing the RPC:

Indexers:

To deliver an optimal and expedient experience, we must index pending transactions in real-time within the pending block and subsequently tag these transactions with a block number after the RPC provides us with the latest block. However, this delay causes our indexer to incorrectly tag some transactions, as there is a lag between when the sequencer furnishes our node with the block.

A potential solution on our end would be to re-parse all transactions and compare our indexed data with the contents of the newly produced block.

Events:

While the previous issue can be resolved independently, it precipitates another user experience problem. Events are genuinely emitted by the node, and if the Starknet sequencer is operating in a sluggish mode, it results in a substantial delay in event production. In our case, since we utilize a custom L3 sequencer with a messaging system that monitors events on the latest block, there is a significant lag before we can mark a swap as complete, for instance. However, this is also an impediment for other applications that rely on events to update the status for their users based on those events.

How to reproduce: You can use the following code to reproduce the issue https://github.com/ArkProjectNFTs/block-issue-sample

Expected behavior

Ugo-X commented 2 months ago

Would love to contribute to this effort, please can i take this?