Skip to content

Commit 6705ead

Browse files
authored
Merge pull request #1480 from input-output-hk/fix/LW-9675-conway-era-fixes
LW-9675 conway era fixes
2 parents 96658a2 + 8f1ca36 commit 6705ead

File tree

6 files changed

+23
-41
lines changed

6 files changed

+23
-41
lines changed

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/ChainHistoryBuilder.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// cSpell:ignore descr
1+
// cSpell:ignore descr timelock
22

33
import * as Queries from './queries';
44
import {
@@ -60,6 +60,7 @@ import orderBy from 'lodash/orderBy.js';
6060

6161
const {
6262
CredentialType,
63+
FractionUtils,
6364
GovernanceActionType,
6465
NetworkId: { Mainnet, Testnet },
6566
RewardAccount,
@@ -77,26 +78,15 @@ const mapWithdrawals: (source: [{ credential: DbSyncCredential; network: string
7778
rewardAccount: Cardano.RewardAccount;
7879
coin: Cardano.Lovelace;
7980
} = ([{ credential, network }, coin]) => ({
80-
// Due to https://github.com/IntersectMBO/cardano-db-sync/issues/1614
81-
// this will be source of NOT CORRECT AMOUNT for amounts greater than
82-
// Number.MAX_SAFE_INTEGER (most likely, never).
83-
// In case such amount will be present in some networks before db-sync solve the
84-
// issue, we need to query the amount from treasury_withdrawal table.
85-
// In case the issue is solved before we need to touch this again, the next line
86-
// will work as well and we just need to remove this comment.
8781
coin: BigInt(coin),
8882
rewardAccount: RewardAccount.fromCredential(
8983
credentialFromDbSync(credential),
9084
network === 'Mainnet' ? Mainnet : Testnet
9185
)
9286
});
9387

94-
// eslint-disable-next-line sonarjs/cognitive-complexity, complexity
95-
const getGovernanceAction = ({
96-
denominator,
97-
description,
98-
numerator
99-
}: ProposalProcedureModel): Cardano.GovernanceAction => {
88+
// eslint-disable-next-line complexity, @typescript-eslint/no-explicit-any
89+
const getGovernanceAction = (description: any): Cardano.GovernanceAction => {
10090
const { contents, tag } = description;
10191
const governanceActionId =
10292
contents && contents[0] ? { actionIndex: contents[0].govActionIx, id: contents[0].txId } : null;
@@ -115,10 +105,7 @@ const getGovernanceAction = ({
115105
case 'InfoAction':
116106
return { __typename: GovernanceActionType.info_action };
117107

118-
case 'NewCommittee':
119-
// LW-9675
120-
if (typeof contents[3] !== 'number') throw new Error('New db-sync version detected: ref LW-9675');
121-
108+
case 'UpdateCommittee':
122109
return {
123110
__typename: GovernanceActionType.update_committee,
124111
governanceActionId,
@@ -128,11 +115,8 @@ const getGovernanceAction = ({
128115
epoch: value as Cardano.EpochNo
129116
}))
130117
),
131-
membersToBeRemoved: new Set((contents[1] as DbSyncCredential[]).map(credentialFromDbSync)),
132-
newQuorumThreshold: {
133-
denominator: Number.parseInt(denominator!, 10),
134-
numerator: Number.parseInt(numerator!, 10)
135-
}
118+
membersToBeRemoved: new Set(contents[1].map(credentialFromDbSync)),
119+
newQuorumThreshold: typeof contents[3] === 'number' ? FractionUtils.toFraction(contents[3]) : contents[3]
136120
};
137121

138122
case 'NewConstitution':
@@ -385,7 +369,7 @@ export class ChainHistoryBuilder {
385369
const result = new Map<Cardano.TransactionId, Cardano.ProposalProcedure[]>();
386370

387371
for (const row of rows) {
388-
const { data_hash, deposit, tx_id, url, view } = row;
372+
const { data_hash, deposit, description, tx_id, url, view } = row;
389373
const txId = tx_id.toString('hex') as Cardano.TransactionId;
390374

391375
const actions = (() => {
@@ -399,7 +383,7 @@ export class ChainHistoryBuilder {
399383
actions.push({
400384
anchor: mapAnchor(url, data_hash.toString('hex'))!,
401385
deposit: BigInt(deposit),
402-
governanceAction: getGovernanceAction(row),
386+
governanceAction: getGovernanceAction(description),
403387
rewardAccount: Cardano.RewardAccount(view)
404388
});
405389
}

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ const stubRedeemerData = Buffer.from('not implemented');
142142
const redeemerPurposeMap: Record<RedeemerModel['purpose'], Cardano.RedeemerPurpose> = {
143143
cert: Cardano.RedeemerPurpose.certificate,
144144
mint: Cardano.RedeemerPurpose.mint,
145-
proposing: Cardano.RedeemerPurpose.propose,
145+
propose: Cardano.RedeemerPurpose.propose,
146146
reward: Cardano.RedeemerPurpose.withdrawal,
147147
spend: Cardano.RedeemerPurpose.spend,
148-
voting: Cardano.RedeemerPurpose.vote
148+
vote: Cardano.RedeemerPurpose.vote
149149
};
150150

151151
const mapRedeemerPurpose = (purpose: RedeemerModel['purpose']): Cardano.RedeemerPurpose =>
@@ -351,7 +351,7 @@ export const mapCertificate = (
351351
if (isResignCommitteeColdCertModel(certModel))
352352
return {
353353
__typename: Cardano.CertificateType.ResignCommitteeCold,
354-
anchor: mapAnchor(certModel.url, certModel.data_hash),
354+
anchor: mapAnchor(certModel.url, certModel.data_hash.toString('hex')),
355355
cert_index: certModel.cert_index,
356356
coldCredential: {
357357
hash: certModel.cold_key.toString('hex') as unknown as Crypto.Hash28ByteBase16,

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/queries.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// cSpell:ignore serialised
2+
13
export const DB_MAX_SAFE_INTEGER = 2_147_483_647;
24

35
const selectTxInput = (collateral?: boolean) => `
@@ -224,14 +226,11 @@ export const findProposalProceduresByTxIds = `
224226
ga.description,
225227
va.url,
226228
va.data_hash,
227-
sa.view,
228-
quorum_numerator AS numerator,
229-
quorum_denominator AS denominator
229+
sa.view
230230
FROM tx
231231
JOIN gov_action_proposal AS ga ON tx.id = ga.tx_id
232232
JOIN voting_anchor AS va ON voting_anchor_id = va.id
233233
JOIN stake_address AS sa ON ga.return_address = sa.id
234-
LEFT JOIN new_committee AS nc ON gov_action_proposal_id = ga.id
235234
WHERE tx.id = ANY($1)
236235
ORDER BY ga.index`;
237236

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// cSpell:ignore serialised timelock
2+
13
import { Cardano } from '@cardano-sdk/core';
24
import { CostModelsParamModel } from '../../NetworkInfo/DbSyncNetworkInfoProvider/types';
35

@@ -105,7 +107,7 @@ export interface WithdrawalModel {
105107

106108
export interface RedeemerModel {
107109
index: number;
108-
purpose: 'cert' | 'mint' | 'spend' | 'reward' | 'voting' | 'proposing';
110+
purpose: 'cert' | 'mint' | 'spend' | 'reward' | 'vote' | 'propose';
109111
script_hash: Buffer;
110112
unit_mem: string;
111113
unit_steps: string;
@@ -139,9 +141,6 @@ export interface ProposalProcedureModel {
139141
tx_id: Buffer;
140142
url: string;
141143
view: string;
142-
// LW-9675
143-
numerator?: string;
144-
denominator?: string;
145144
}
146145

147146
export interface CertificateModel {
@@ -235,7 +234,7 @@ export interface ResignCommitteeColdCertModel extends CertificateModel {
235234
cold_key: Buffer;
236235
cold_key_has_script: boolean;
237236
url: string;
238-
data_hash: string;
237+
data_hash: Buffer;
239238
}
240239

241240
export interface TxIdModel {

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export const applyPagination = (ids: Cardano.TransactionId[], { startAt, limit }
8686
* certificates_.
8787
*
8888
* Example: given an array of `reg_cert` and an array of `vote_deleg_cert`, the result is an array of:
89-
* - all input `reg_cert` which can't be neither `vote_reg_deleg_cert` nor `stake_vote_reg_deleg_cert,
90-
* - all input `vote_deleg_cert` which can't be neither `vote_reg_deleg_cert` nor `stake_vote_reg_deleg_cert,
89+
* - all input `reg_cert` which can be neither `vote_reg_deleg_cert` nor `stake_vote_reg_deleg_cert`,
90+
* - all input `vote_deleg_cert` which can be neither `vote_reg_deleg_cert` nor `stake_vote_reg_deleg_cert`,
9191
* - the array of `vote_reg_deleg_cert` (it includes also the partials `stake_vote_reg_deleg_cert`)
9292
*
9393
* @param certs1 the first certificates array

packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ describe('chain history mappers', () => {
467467
['mint' as const, Cardano.RedeemerPurpose.mint],
468468
['cert' as const, Cardano.RedeemerPurpose.certificate],
469469
['reward' as const, Cardano.RedeemerPurpose.withdrawal],
470-
['voting' as const, Cardano.RedeemerPurpose.vote],
471-
['proposing' as const, Cardano.RedeemerPurpose.propose]
470+
['vote' as const, Cardano.RedeemerPurpose.vote],
471+
['propose' as const, Cardano.RedeemerPurpose.propose]
472472
])("maps '%p' redeemer", (dbSyncRedeemerPurpose, sdkRedeemerPurpose) => {
473473
const result = mappers.mapRedeemer({ ...redeemerModel, purpose: dbSyncRedeemerPurpose });
474474
expect(result).toEqual<Cardano.Redeemer>({

0 commit comments

Comments
 (0)