signum-node icon indicating copy to clipboard operation
signum-node copied to clipboard

Change rollback behavior on DB level ( node internal)

Open frankTheTank72 opened this issue 3 years ago • 3 comments

Currently when a roll-back happens the node checks via the latest column on many tables if those latest entries due to the block height need to be removed and set the entry prior the roll-back to the latest.

In addition, we also check a lot of balances via the latest columnn.

We should remove this setup.

New behavior If a rollback happens, we should just remove the entries related to the block height. If we check balances, we should use always the newest entry on the DB.

For the bid_order and ask_order table we should change the latest column into active column. We still need the column to indentify if the order is still in progress or filled/cancelled. (see also #672 )

frankTheTank72 avatar Nov 18 '22 12:11 frankTheTank72

To change the current requests by latest we have to change the SQL from (example):

SELECT * FROM account_balance WHERE id = 8952122635653861124 AND latest = 1

to

SELECT * FROM account_balance WHERE id = 8952122635653861124 AND height=(SELECT MAX(height) FROM account_balance WHERE id = 8952122635653861124 );

To get the same speed we need to create a new unique index - here example for account_balance:

grafik

frankTheTank72 avatar Nov 18 '22 12:11 frankTheTank72

The following tables have already a unuqie index on id and height :

  • account
  • account:asset
  • alias
  • alias_offer
  • ask_order
  • at
  • at_map
  • at_state
  • bid_order
  • block
  • escrow
  • escrow_decision
  • goods
  • purchase
  • reward_recip_assign
  • subscription

Tables without unuqie index id/height:

  • asset
  • account_balance - done

Tables should not have this index:

  • asset_transfer
  • indirect_incoming
  • peer
  • purchase_feedback
  • purchase_public_feedback
  • trade
  • transaction
  • unconfirmed:transaction

frankTheTank72 avatar Nov 18 '22 15:11 frankTheTank72

account_balance index is added --> https://github.com/signum-network/signum-node/issues/704

frankTheTank72 avatar Dec 04 '22 22:12 frankTheTank72