Skip to content

Conversation

sgillespie
Copy link
Contributor

Description

This separates the Ledger State from Ledger Tables, and we carry them separately. This allows us to keep the smallest possible UTxO set when applying blocks to the ledger state.

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu on version 0.10.1.0 (which can be run with scripts/fourmolize.sh)
  • Self-reviewed the diff

Migrations

  • The pr causes a breaking change of type a,b or c
  • If there is a breaking change, the pr includes a database migration and/or a fix process for old values, so that upgrade is possible
  • Resyncing and running the migrations provided will result in the same database semantically

If there is a breaking change, especially a big one, please add a justification here. Please elaborate
more what the migration achieves, what it cannot achieve or why a migration is not possible.

This allows us to carry around ledger tables with a minimal UTxO
set, which reduces the amount of processing we have to do when
applying blocks to the ledger state
(encodeDisk codecConfig)
(encodeDisk codecConfig)
(encodeDisk codecConfig)
. forgetLedgerTables
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to pass the Tables to the encoder. Otherwise the whole UTxO set is lost on restarts.

mconcat
[ encodeExt (clsState cls)
, toCBOR (clsEpochBlockNo cls)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Also encode the ledger tables, preferebly after the clsEpochBlockNo

ldgrState <- decodeExt
CardanoLedgerState ldgrState <$> fromCBOR
let ldgrTables = Consensus.projectLedgerTables (Consensus.unstowLedgerTables ldgrState)
CardanoLedgerState ldgrState ldgrTables <$> fromCBOR
Copy link
Contributor

@kderme kderme Aug 27, 2025

Choose a reason for hiding this comment

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

These ledger tables must be empty here, since forgetLedgerTables is used before the encoder. The maintained edger tables should be passed here

Another possible extention is trying to achive backwards compatibility on ledger snapshots. This would be a an decoder that can decoder either old snapshots with ledger state containing values or an empty ledger state with a edger table attached separately. This can be done on a separate pr though, so feel free to ignore for now.

(MonadBaseControl IO m, MonadIO m) =>
SyncEnv ->
ExtLedgerState CardanoBlock ->
ExtLedgerState CardanoBlock mk ->
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to pass the Ledger Tables here as well, since the Ledger state is expected to be empty. getUTxO woud then extract UTxO using the tables instead of the state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also if we ever use this function once, we could avoid parametrizing it over mk

}

epochUpdate :: ExtLedgerState CardanoBlock -> EpochUpdate
epochUpdate :: ExtLedgerState CardanoBlock mk -> EpochUpdate
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid parametrizing these functions if we ever use them once.

blk
tipState
-- Apply the diffs
!newTipState = applyDiffs tipState diffState
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's monitor tests in case this makes them too slow.Especially tests that mass produce transactions.

@sgillespie sgillespie mentioned this pull request Sep 2, 2025
9 tasks
@sgillespie
Copy link
Contributor Author

Superceded by #1998

@sgillespie sgillespie closed this Sep 2, 2025
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.

2 participants