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

Remove deprecated SQL tables (batched accrued raw and paid) #1786

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from

Conversation

Doy-lee
Copy link
Collaborator

@Doy-lee Doy-lee commented Jan 22, 2025

For the raw and paid table removal:

The raw table from my understanding is for pop_blocks. Pop blocks was removed
when we redid the SQL DB to support blockchain detach. This was done to unify
the SNL and SQL DB in that the system has a hard requirement that they
need to pop to the same height and update in lock-step because updating
the SNL has side-effects on the SQL. So if one pops and the other
doesn't then it causes the SNL rewards to go out of sync.

Hence the raw table is actually unused. This was discovered when investigating
the origins of delete block payments in the SQL DB which used to be executed
on pop blocks.

It has an accompanying table, the paid table which was a SQL view of the
accrued rewards that, from my understanding, subtracts the amount each
SN was paid from the accrued table. This had unnecessary levels of indirection,
first a view was created, then a trigger was created to hijack when we insert
into the table such that it subtracted the rewards paid out in the
accrued table.

It's possible to skip this busy-work and layers by just subtracting the amount
directly from the accrued table when the payments are "saved".

For removing eth_address from batch_sn_payment:

Batch SN payment code path is only used in <=HF20 which is prior to ETH
addresses start getting written to the DB. Hence it only needs to handle Oxen
addresses so we can remove the eth address.

For eth addresses we use block_payments which is a
variant<eth_address,oxen_address>.

The raw table from my understanding is for pop_blocks. Pop blocks was removed
when we redid the SQL DB to support blockchain detach. This was done to unify
the SNL and SQL DB in that the system has a hard requirement that they
need to pop to the same height and update in lock-step because updating
the SNL has side-effects on the SQL. So if one pops and the other
doesn't then it causes the SNL rewards to go out of sync.

Hence the raw table is actually unused. This was discovered when investigating
the origins of delete block payments in the SQL DB which used to be executed
on pop blocks.

It has an accompanying table, the paid table which was a SQL view of the
accrued rewards that, from my understanding, subtracts the amount each
SN was paid from the accrued table. This had unnecessary levels of indirection,
first a view was created, then a trigger was created to hijack when we insert
into the table such that it subtracted the rewards paid out in the
accrued table.

It's possible to skip this busy-work and layers by just subtracting the amount
directly from the accrued table when the payments are "saved".
Batch SN payment code path is only use in <=HF20 which is prior to ETH
addresses start getting written to the DB. Hence it only needs to handle Oxen
addresses so we can remove the eth address.

For eth addresses we use block_payments which is a
variant<eth_address,oxen_address>.
Prior to HF15 the ONS DB still accepts blocks and updates the height and
hash of the last block it read. This ensures that if you terminate the daemon
before HF15 and get into a situation where it needs to rescan the DB it doesn't
trigger the assert that requires all the subsystems have synchronised to
the same height.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant