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

Manage pending in memory and move it to synchroniser #1844

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

IronGauntlets
Copy link
Contributor

@IronGauntlets IronGauntlets commented Apr 27, 2024

Fixes parts of #1789. A migration to remove the pending from DB is still outstanding.

It would be best to review the commits individually and in order.

@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from 4d851b3 to cf6de15 Compare April 27, 2024 01:37
@IronGauntlets
Copy link
Contributor Author

This also fixes #1450

Copy link

codecov bot commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 69.79866% with 45 lines in your changes missing coverage. Please review.

Project coverage is 74.43%. Comparing base (7687360) to head (45524e2).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
sync/sync.go 66.66% 18 Missing and 4 partials ⚠️
rpc/transaction.go 50.00% 16 Missing and 5 partials ⚠️
blockchain/event_filter.go 87.50% 0 Missing and 1 partial ⚠️
rpc/helpers.go 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1844      +/-   ##
==========================================
- Coverage   74.52%   74.43%   -0.10%     
==========================================
  Files         109      109              
  Lines       11558    11493      -65     
==========================================
- Hits         8614     8555      -59     
- Misses       2272     2275       +3     
+ Partials      672      663       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch 2 times, most recently from 5e2d6e6 to cc6cf21 Compare May 4, 2024 16:45
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from cc6cf21 to 09e6778 Compare May 8, 2024 08:29
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch 2 times, most recently from c9f49cd to 81d8a1c Compare July 23, 2024 22:43
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch 2 times, most recently from 7cd5306 to 9220e49 Compare July 31, 2024 19:15
db/buckets.go Outdated Show resolved Hide resolved
node/node.go Show resolved Hide resolved
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch 3 times, most recently from ca7b92b to 7342444 Compare August 2, 2024 18:22
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from 7342444 to 66f53e1 Compare August 5, 2024 13:49
blockchain/blockchain.go Outdated Show resolved Hide resolved
blockchain/blockchain.go Outdated Show resolved Hide resolved
Copy link
Contributor

This pull request is stale because it has been open 35 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 18, 2024
@github-actions github-actions bot closed this Dec 11, 2024
@IronGauntlets IronGauntlets reopened this Dec 11, 2024
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from 66f53e1 to bb10120 Compare December 11, 2024 17:12
@IronGauntlets IronGauntlets enabled auto-merge (rebase) December 11, 2024 17:13
blockchain/event_filter.go Show resolved Hide resolved
rpc/helpers.go Show resolved Hide resolved
sync/sync.go Outdated Show resolved Hide resolved
sync/sync.go Show resolved Hide resolved
node/node.go Show resolved Hide resolved
Pending Block is now only managed in memory this is to make sure that
pending block in the DB and in memory do not become out of sync. Before
the pending block was managed in memory as a cache, however, since there
is only one pending block at a given time it doesn't make sense to keep
track of pending block in both memory and DB.

To reduce the number of block not found errors while simulating
transactions it was decided to store empty pending block, using the
latest header to fill in fields such as block number, parent block hash,
etc. This meant that any time we didn't have a pending block this
empty pending block would be served along with empty state diff and
classes. Every time a new block was added to the blockchain a new empty
pending block was also added to the DB.

The unforeseen side effect of this change was when the
--poll-pending-interval flag was disabled the rpc would still serve a
pending block. This is incorrect behaviour.

As the blocks changed per new versions of starknet the empty block also
needed to be changed and a storage diff with a special contract "0x1"
needed to be updated in the state diff. This overhead is unnecessary and
incorrectly informs the user that there is a pending block when
there isn't one.
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from bb10120 to a562e91 Compare December 12, 2024 14:57
In order to moved handling of pending to synchroniser the following
changes needed to be made:
- Add database to synchroniser, so that pending state can be served
- Blockchain and Events Filter have a pendingBlockFn() which returns the
  pending block. Due to import cycle pending struct could not be
  referenced, therefore, the anonymous function is passed.
- Add PendingBlock() to return just the pending block, this was mainly
  added to support the pendingBlockFn().
- In rpc package the pending block and state is retrieved through
  synchroniser. Therefore, receipt and transaction handler now check the
  pending block for the requested transaction/receipt.
@IronGauntlets IronGauntlets force-pushed the IronGauntlets/fix-pending-block-issues branch from a562e91 to 45524e2 Compare December 12, 2024 15:10
@kirugan kirugan disabled auto-merge December 12, 2024 16:27
@IronGauntlets IronGauntlets merged commit 4ff174d into main Dec 12, 2024
13 checks passed
@IronGauntlets IronGauntlets deleted the IronGauntlets/fix-pending-block-issues branch December 12, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants