Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Finalize block result sessions #22

Merged
merged 20 commits into from
Mar 28, 2023
Merged

Conversation

noslav
Copy link
Member

@noslav noslav commented Mar 27, 2023

In order to run a single finalizer instance with one moonbeam / moonbase account for both block specimens and results we need to segregate finalization threads as two separate processes, otherwise nonce collisions can occur. We effectively cycle between the two threads that submit the finalizations and call the two BSP reward or BRP rewards functions. For this we need two db managers effectively separately the aggregation of open/closed sessions and tx submissions. We further also need separation of finalization requests that can be made to the db for finalization hashes that have been already indexed.

Further In order to make the finalization process separate for block specimen and results we made upgrades to the smart contracts which modified emitted event SessionStarted for any specimen/result proof submission session started to BSPSessionStarted and BRPSessionStarted respectively - this prevents pollution of one logged event into other logged event’s views because they come from different sources/purposes.

We've re-executed these two SQLs for the same - for moonbase network to have separate views for specimen events and result events -

https://github.com/covalenthq/bsp-finalizer/blob/feature/finalize-block-results/sql/proof_chain_mbase_result.sql
https://github.com/covalenthq/bsp-finalizer/blob/feature/finalize-block-results/sql/proof_chain_mbase_specimen.sql

The same needs to be done for moonbeam main net when this PR is release to prod or main.

https://github.com/covalenthq/bsp-finalizer/blob/feature/finalize-block-results/sql/proof_chain_mbeam_result.sql
https://github.com/covalenthq/bsp-finalizer/blob/feature/finalize-block-results/sql/proof_chain_mbeam_specimen.sql

  • Adds views SQL for proof_chain_result_events which represents indexed result sessions required for finalization (and rewards) using the same finalization hash algorithm as block specimen sessions
  • Updates conventions and topic hashes for upgraded contracts on moonbeam and moonbase SQLs for specimen sessions
  • Update proof chain ABI with updates from phase-2-rewards branch https://github.com/covalenthq/operational-staking/tree/feature/phase-2-rewards
  • Updates pylint for duplicated code in specimen/result bd managers
  • Updates topic hashes for all networks for the new session started events
  • Updates to three threads running in the full finalizer loop

noslav added 15 commits March 27, 2023 16:39
Signed-off-by: Pranay Valson <[email protected]>
Signed-off-by: Pranay Valson <[email protected]>
@noslav noslav requested review from kitti-katy and rogarcia March 28, 2023 21:59
@noslav noslav changed the base branch from main to develop March 28, 2023 22:17
@noslav
Copy link
Member Author

noslav commented Mar 28, 2023

Note this is confirmed running as designed for moonbase at https://moonbase.moonscan.io/address/0x3aeebd0fa9701f4549753c4c8498291c1c8af8d7 and still needs to be tested for moonbeam

Started BSP/BRP Finalizer..
INFO DB (dbmanspecimen.py:74) - Connecting to the database...
INFO DB (dbmanresult.py:74) - Connecting to the database...
INFO DB (dbmanresult.py:76) - Initial scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:76) - Initial scan block_id=1910104892088990000
INFO Finalizer (finalizer.py:48) - Finalizing 0 specimen proof-sessions...
INFO Finalizer (finalizer.py:53) - Finalized 0 specimen proof-sessions
DEBUG Finalizer (finalizer.py:58) - Nothing ready to finalize height=4034000 specimen openSessions=0
INFO Finalizer (finalizer.py:68) - Finalizing 0 result proof-sessions...
INFO Finalizer (finalizer.py:73) - Finalized 0 result proof-sessions
DEBUG Finalizer (finalizer.py:78) - Nothing ready to finalize height=4034000 result openSessions=0
INFO DB (dbmanresult.py:93) - Processing 4 result proof-session records...
INFO DB (dbmanresult.py:56) - Queued 4 result proof-sessions for finalization
INFO DB (dbmanresult.py:99) - Caught up with db block_id=1910104892088990000
INFO DB (dbmanspecimen.py:99) - Caught up with db block_id=1910104892088990000
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO Finalizer (finalizer.py:48) - Finalizing 1 specimen proof-sessions...
INFO Contract (contract.py:297) - Refreshed nonce 33387
INFO Contract (contract.py:120) - TX dynamic gas price for specimen finalization is 125000000
INFO Contract (contract.py:144) - Sending Specimen finalization tx 1/16928610 senderBalance=14.830760676332061541GLMR senderNonce=33387 txHash=0x144a3bbbf27b38564b1556b88f0d6195fb579688447198297fc2ca0d71124b54
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO Contract (contract.py:120) - TX dynamic gas price for specimen finalization is 125028459
INFO Contract (contract.py:144) - Sending Specimen finalization tx 1/16928610 senderBalance=14.830760676332061541GLMR senderNonce=33387 txHash=0x6f8523eaff945e5702f2806746e7f68d81af7fa08f75216eb15dffa5b57ed68b
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO Contract (contract.py:284) - TX mined with txHash=0x0x6f8523eaff945e5702f2806746e7f68d81af7fa08f75216eb15dffa5b57ed68b includedAs=4034028/3 spentGas=90943
INFO Finalizer (finalizer.py:53) - Finalized 1 specimen proof-sessions
INFO Finalizer (finalizer.py:68) - Finalizing 2 result proof-sessions...
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125000000
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16927770 senderBalance=14.830749305868914704GLMR senderNonce=33388 txHash=0x1d4a6d9ff789266baf9ab45baf3fdbeb293a38ff2763a963d9de9d17ff046c98
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:56) - Queued 1 specimen proof-sessions for finalization
INFO Contract (contract.py:284) - TX mined with txHash=0x0x1d4a6d9ff789266baf9ab45baf3fdbeb293a38ff2763a963d9de9d17ff046c98 includedAs=4034030/8 spentGas=126315
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125059459
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16927800 senderBalance=14.830733516493914704GLMR senderNonce=33389 txHash=0xf11f4b9b549fa46e6d9fa0b36981bead697ce914fa4975d54447fcbd1d9b32da
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO Contract (contract.py:284) - TX mined with txHash=0x0xf11f4b9b549fa46e6d9fa0b36981bead697ce914fa4975d54447fcbd1d9b32da includedAs=4034032/1 spentGas=126315
INFO Finalizer (finalizer.py:73) - Finalized 2 result proof-sessions
INFO Finalizer (finalizer.py:48) - Finalizing 1 specimen proof-sessions...
INFO Contract (contract.py:120) - TX dynamic gas price for specimen finalization is 125000000
INFO Contract (contract.py:144) - Sending Specimen finalization tx 1/16928640 senderBalance=14.830717719608351119GLMR senderNonce=33390 txHash=0x64ac536b4687a36c79c2f45694a55121439aad625b29fd99f2432d0bea164877
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO Contract (contract.py:284) - TX mined with txHash=0x0x64ac536b4687a36c79c2f45694a55121439aad625b29fd99f2432d0bea164877 includedAs=4034034/2 spentGas=90943
INFO Finalizer (finalizer.py:53) - Finalized 1 specimen proof-sessions
INFO Finalizer (finalizer.py:68) - Finalizing 2 result proof-sessions...
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125000000
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16928520 senderBalance=14.830706351733351119GLMR senderNonce=33391 txHash=0x339bbc7049090db60a23202da6b41f9603e125e52937a9263ba0a3190b0361ec
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:56) - Queued 1 result proof-sessions for finalization
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125000000
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16928520 senderBalance=14.830706351733351119GLMR senderNonce=33391 txHash=0x339bbc7049090db60a23202da6b41f9603e125e52937a9263ba0a3190b0361ec
INFO Contract (contract.py:259) - Skipping Result finalization tx that's already known...
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125000000
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16928580 senderBalance=14.830706351733351119GLMR senderNonce=33391 txHash=0x476c1bb35cf43a6925aae967e5bd3d8ecb5871e658ab6b0aaa2c52af4dccf076
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered
INFO Contract (contract.py:195) - TX dynamic gas price for result finalization is 125000000
INFO Contract (contract.py:219) - Sending Result finalization tx 1/16928580 senderBalance=14.830706351733351119GLMR senderNonce=33391 txHash=0x476c1bb35cf43a6925aae967e5bd3d8ecb5871e658ab6b0aaa2c52af4dccf076
INFO Contract (contract.py:259) - Skipping Result finalization tx that's already known...
INFO Finalizer (finalizer.py:73) - Finalized 2 result proof-sessions
INFO Finalizer (finalizer.py:48) - Finalizing 2 specimen proof-sessions...
INFO Contract (contract.py:120) - TX dynamic gas price for specimen finalization is 125000000
INFO Contract (contract.py:144) - Sending Specimen finalization tx 1/16928670 senderBalance=14.830706351733351119GLMR senderNonce=33391 txHash=0x33ecedda9c6c2ea18581e4fadf64b37f4d8917b8ea4ed89bc05a95ea6443858f
INFO DB (dbmanspecimen.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanspecimen.py:122) - No new specimen proof-session records discovered
INFO DB (dbmanresult.py:104) - Incremental scan block_id=1910104892088990000
INFO DB (dbmanresult.py:122) - No new result proof-session records discovered

Copy link
Contributor

@rogarcia rogarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for mbase testing

@noslav noslav merged commit 30ef9c5 into develop Mar 28, 2023
@noslav noslav deleted the feature/finalize-block-results branch June 19, 2023 23:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants