Skip to content

Handle rollback events properly - #164

Closed
adithyaov wants to merge 11 commits into
mainfrom
rollback-rep
Closed

adithyaov wants to merge 11 commits into
mainfrom
rollback-rep

Conversation

@adithyaov

@adithyaov adithyaov commented Mar 13, 2026

Copy link
Copy Markdown
Member
  • Change the event intereface
  • Update the db structure

TODO:

  • Test
  • Address the TODOs in the PR
  • Create an index on slot_no in block - Open an issue to further think about this
  • Rename cancellation_event table to rollback_event
  • Ensure an empty database and an empty event log when running the tests
  • GetEvents fails in deserialising blcokheader as block no. can now be null
  • Address the use of sudo
  • pfctl should have localised effect
  • Add support for linux

@axman6 axman6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good, I think there's a few things to change or at least have a chat about before merging.

The big thing that is missing here is that I think we also need to update the leash to the rollback point.

Comment thread lib/PSR/Storage/SQLite/GetEvents.hs Outdated
Comment thread lib/PSR/Storage/SQLite/Instances.hs Outdated
Comment thread lib/PSR/Storage/SQLite.hs Outdated
-- TODO: Update the metric
cancelBlocksAfterSlot :: Connection -> SlotNo -> IO ()
cancelBlocksAfterSlot conn slotNo = do
let q = "UPDATE block SET status = :set_status WHERE slot_no > :slot_no;"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is probably correct, but I think I'd need to see an argument that this is the right predicate - I think technically when we see a rollback, every block from the rollback point to the current top needs to be marked, but I'm not sure if we need a more complex query (and more metadata) to track the previous block for each block to say "all the blocks from the current tip back to the rollback point via their parent hashes needs to be cancelled".

I'm not sure if that is equivalent to "all blocks after slow N need to be cancelled", whether there's some kind of race condition were we could have inserted info about a new block after the rollback point which then gets cancelled erroneously or not. I can't actually think of how this could happen, but it feels like it may be possible, and difficult to test for.

We should have a chat about this to make sure the logic is definitely right.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, agreed. We need to discuss.

Comment thread lib/PSR/Storage/SQLite.hs Outdated
Comment thread lib/PSR/Events.hs
Comment thread lib/PSR/Storage/SQLite.hs Outdated
Comment thread schema.sql Outdated
Comment thread schema.sql Outdated
slot_no UNSIGNED INTEGER NOT NULL
block_no UNSIGNED INTEGER,
slot_no UNSIGNED INTEGER NOT NULL,
status TEXT CHECK(status IN ('unknown', 'canceled', 'committed'))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need status? We already know if the block was cancelled by cancellation_event which references block.

And I don't see how we can use committed status in our app. There is no any functionality that depends on that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. This will make more sense once I show the UI.
  2. We will query all executions related to cancelled blocks and they will be used in the rollback payload.
  3. We need to track the status of the block somehow. The block table seems to be the most optimal place to track this.

Comment thread schema.sql
hash BLOB PRIMARY KEY,
block_no UNSIGNED INTEGER NOT NULL,
slot_no UNSIGNED INTEGER NOT NULL
block_no UNSIGNED INTEGER,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I would rather drop the reference constraint from cancellation_event.block_hash than NOT NULL here... This partiality of the block feels strange. While the cancellation_event can reference some block_hash we don't have.

@adithyaov adithyaov Mar 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reference constraint is good. I think we should have that.

This partiality of the block feels strange

I don't see this as a partial block. The identity of a block is block_hash right?
But I see where you're coming from. Let me think if there is a better way to represent this in the DB.

@adithyaov
adithyaov force-pushed the rollback-rep branch 2 times, most recently from 99625fa to a54c86c Compare March 17, 2026 11:03
Comment thread schema.sql
target_script_hash BLOB NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
blocks_cancelled BLOB NOT NULL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CREATE TABLE IF NOT EXISTS rollback_event_blocks (
  event_id INTEGER NOT NULL REFERENCES rollback_event(event_id),
  block_hash BLOB NOT NULL REFERENCES block(block_hash)
)

@tweag-ev-ak tweag-ev-ak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@axman6 axman6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As discussed earlier, happy to merge once there's a better solution for inducing rollbacks (maybe that should be split into its own PR at this stage, since I think it might take some time to get the networking side happening)

@adithyaov

Copy link
Copy Markdown
Member Author

As discussed earlier, happy to merge once there's a better solution for inducing rollbacks (maybe that should be split into its own PR at this stage, since I think it might take some time to get the networking side happening)

Yeah, that's a good idea.

@adithyaov

Copy link
Copy Markdown
Member Author

Succeeded by:
#168
#169

@adithyaov adithyaov closed this Mar 25, 2026
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.

3 participants