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

optimizations #1607

Merged
merged 17 commits into from
Feb 2, 2024
Merged

optimizations #1607

merged 17 commits into from
Feb 2, 2024

Conversation

kderme
Copy link
Contributor

@kderme kderme commented Jan 18, 2024

Description

Fixes #1589, #1582, #1584, #1606

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

The reward migration works on upgrade
The tx_out migation is WIP

BEGIN
SELECT stage_two + 1 INTO next_version FROM schema_version ;
IF next_version = 35 THEN
EXECUTE 'alter domain addr29type drop constraint addr29type_check' ;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we create these domains

CREATE DOMAIN addr29type AS bytea CHECK (octet_length (VALUE) = 29);

we don't give any name to the constraint. addr29type_check is the name that postgres gives by default.

EXECUTE 'ALTER TABLE "instant_reward" ALTER COLUMN "amount" SET NOT NULL' ;
EXECUTE 'ALTER TABLE "instant_reward" ALTER COLUMN "spendable_epoch" SET NOT NULL' ;
EXECUTE 'ALTER TABLE "instant_reward" DROP COLUMN "earned_epoch"' ;
EXECUTE 'ALTER TABLE "instant_reward" ADD COLUMN "earned_epoch" bigint NOT NULL GENERATED ALWAYS AS ((CASE WHEN spendable_epoch >= 1 then spendable_epoch-1 else 0 end)) STORED' ;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no way to ALTER an existing column to add a GENERATED ALWAYS AS clause. This clause can only be added to a new column. So we drop the old one and add it here. I've checked on a new snapshot that the GENERATED ALWAYS AS rule is always followed even if it didn't exist before. Similarly for reward table.

@kderme kderme marked this pull request as ready for review January 22, 2024 15:24
Copy link
Contributor

@Cmdv Cmdv left a comment

Choose a reason for hiding this comment

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

LGTM minor question and suggestions

cardano-chain-gen/test/Test/Cardano/Db/Mock/Validate.hs Outdated Show resolved Hide resolved
cardano-db/src/Cardano/Db/Schema.hs Show resolved Hide resolved
schema/migration-2-0037-20240117.sql Outdated Show resolved Hide resolved
sgillespie
sgillespie previously approved these changes Jan 24, 2024
@sgillespie
Copy link
Contributor

The hlint check seems to be failing

@kderme kderme force-pushed the kderme/optimizations branch 2 times, most recently from 950110c to f85980b Compare January 31, 2024 20:01
Move MIR to a separate table
Use "generated always as" for earned_epoch
Remove primary keys
Since instant rewards no longer cause a uniqueness issue
@kderme kderme force-pushed the kderme/optimizations branch 2 times, most recently from 66bc886 to 9bb7ed3 Compare February 2, 2024 12:19
Copy link
Contributor

@Cmdv Cmdv left a comment

Choose a reason for hiding this comment

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

LGTM minor recommendation

@@ -197,11 +197,11 @@ insertShelleyBlock syncEnv shouldLog withinTwoMins withinHalfHour blk details is

insertStakeSlice syncEnv $ apStakeSlice applyResult

when (ioGov iopts)
when (ioGov iopts && (withinHalfHour || unBlockNo (Generic.blkBlockNo blk) `mod` 10000 == 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

(withinHalfHour || unBlockNo (Generic.blkBlockNo blk) mod 10000 == 0) could probably sit in the where clause

@kderme kderme merged commit c5d6b8a into master Feb 2, 2024
13 of 17 checks passed
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.

Remove redundant fields
3 participants