Skip to content

Commit

Permalink
Return a user error when failing to decode or find the latest genesis…
Browse files Browse the repository at this point in the history
… configuration

  ```json
  {
    "code": 2004,
    "data": "Could not decode the genesis configuration probably because of a mismatch between the configuration and the current version of the underlying ledger library in-use in Ogmios: field 'minFeeRefScriptCostPerByte' not found"
  }
  ```

  Fixes #388.
  • Loading branch information
KtorZ committed Jun 6, 2024
1 parent 395776e commit 2a7db8d
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 67 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ layout: changelog
pre: "<b>5. </b>"
---

### [6.4.0] - 2024-05-07
### [6.4.0] - 2024-06-06

#### Added

- Integrated with `cardano-node==8.11.1-pre`.

- A new transaction submission / evaluation error:
- [`UnauthorizedGovernanceAction`](https://ogmios.dev/mini-protocols/local-tx-submission#schema-3165/UnauthorizedGovernanceAction) (`code=3165`).
- [`UnauthorizedGovernanceAction`](https://ogmios.dev/mini-protocols/local-tx-submission#schema-3165/UnauthorizedGovernanceAction) (`code=3165`) raised when trying to submit a governance action other than protocol parameters change, hard fork initiation or info **during the bootstrapping** phase of the Conway era.

- A new queryNetwork error:
- [`InvalidGenesis`](https://ogmios.dev/mini-protocols/local-state-query#schema-2004/InvalidGenesis) (`code=2004`) raised when trying to query a genesis configuration which is invalid or missing (for instance, when there's a mismatch between the Conway configuration and the underlying ledger library parsing it).

#### Changed

- The `data.providedCollateral` and `data.computedTotalCollateral` from submission errors with code `3128` and `3135` can now be _negative_ Ada values.

- ![TypeScript][] Fixed missing `conway` option in the state query client for the `genesisConfiguration` query.

#### Removed

- N/A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
EraWithGenesis,
GenesisAlonzo,
GenesisByron,
GenesisConway,
GenesisShelley,
Origin,
Point,
Expand All @@ -51,6 +52,7 @@ export interface LedgerStateQueryClient {
genesisConfiguration(era: 'byron'): Promise<GenesisByron>
genesisConfiguration(era: 'shelley'): Promise<GenesisShelley>
genesisConfiguration(era: 'alonzo'): Promise<GenesisAlonzo>
genesisConfiguration(era: 'conway'): Promise<GenesisConway>
ledgerTip(): ReturnType<typeof ledgerTip>
liveStakeDistribution(): ReturnType<typeof liveStakeDistribution>
networkBlockHeight(): ReturnType<typeof networkBlockHeight>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ export function genesisConfiguration (
* @internal
*/
export function isQueryNetworkGenesisConfigurationByron (response: any): response is GenesisByron {
return (response as Response)?.result?.era === 'byron'
return ((response as Response)?.result as GenesisByron)?.era === 'byron'
}

/**
* @internal
*/
export function isQueryNetworkGenesisConfigurationShelley (response: any): response is GenesisShelley {
return (response as Response)?.result?.era === 'shelley'
return ((response as Response)?.result as GenesisShelley)?.era === 'shelley'
}

/**
* @internal
*/
export function isQueryNetworkGenesisConfigurationAlonzo (response: any): response is GenesisAlonzo {
return (response as Response)?.result?.era === 'alonzo'
return ((response as Response)?.result as GenesisAlonzo)?.era === 'alonzo'
}

/**
* @internal
*/
export function isQueryNetworkGenesisConfigurationConway (response: any): response is GenesisConway {
return (response as Response)?.result?.era === 'conway'
return ((response as Response)?.result as GenesisConway)?.era === 'conway'
}
13 changes: 11 additions & 2 deletions clients/TypeScript/packages/client/test/LedgerStateQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import delay from 'delay'
import { dummyInteractionContext } from './helpers'
import { InteractionContext, JSONRPCError, LedgerStateQuery } from '../src'
import {
RewardAccountSummary,
DigestBlake2B256,
DigestBlake2B224,
DigestBlake2B256,
GenesisAlonzo,
GenesisByron,
GenesisShelley,
Point,
QueryNetworkInvalidGenesis,
RewardAccountSummary,
Slot
} from '@cardano-ogmios/schema'

Expand Down Expand Up @@ -83,6 +84,14 @@ describe('Local state queries', () => {
expect(context.socket.readyState).toBe(context.socket.OPEN)
})

it('rejects if the query is for another era', async () => {
try {
await client.genesisConfiguration('conway')
} catch (e) {
expect((e as QueryNetworkInvalidGenesis['error']).code).toBe(2004)
}
})

it('exposes the queries, uses a single context, and should be shutdowned when done', async () => {
const epoch = await client.epoch()
expect(epoch).toBeDefined()
Expand Down
33 changes: 29 additions & 4 deletions clients/TypeScript/packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export type SubmitTransactionFailure =
| SubmitTransactionFailureInvalidHardForkVersionBump
| SubmitTransactionFailureConstitutionGuardrailsHashMismatch
| SubmitTransactionFailureConflictingInputsAndReferences
| SubmitTransactionFailureUnauthorizedGovernanceAction
| SubmitTransactionFailureUnrecognizedCertificateType;
export type Era = "byron" | "shelley" | "allegra" | "mary" | "alonzo" | "babbage" | "conway";
export type ScriptPurpose =
Expand Down Expand Up @@ -303,7 +304,7 @@ export interface Ogmios {
ReleaseLedgerStateResponse: ReleaseLedgerStateResponse;
QueryLedgerStateEraMismatch?: QueryLedgerStateEraMismatch;
QueryLedgerStateUnavailableInCurrentEra?: QueryLedgerStateUnavailableInCurrentEra;
QueryLedgerStateAcquiredExpire?: QueryLedgerStateAcquiredExpired;
QueryLedgerStateAcquiredExpired?: QueryLedgerStateAcquiredExpired;
QueryLedgerStateConstitution: QueryLedgerStateConstitution;
QueryLedgerStateConstitutionResponse:
| QueryLedgerStateConstitutionResponse
Expand Down Expand Up @@ -392,6 +393,7 @@ export interface Ogmios {
QueryNetworkBlockHeightResponse: QueryNetworkBlockHeightResponse;
QueryNetworkGenesisConfiguration: QueryNetworkGenesisConfiguration;
QueryNetworkGenesisConfigurationResponse: QueryNetworkGenesisConfigurationResponse;
QueryNetworkInvalidGenesis?: QueryNetworkInvalidGenesis;
QueryNetworkStartTime: QueryNetworkStartTime;
QueryNetworkStartTimeResponse: QueryNetworkStartTimeResponse;
QueryNetworkTip: QueryNetworkTip;
Expand Down Expand Up @@ -1527,7 +1529,7 @@ export interface SubmitTransactionFailureInsufficientCollateral {
code: 3128;
message: string;
data: {
providedCollateral: ValueAdaOnly;
providedCollateral: ValueDelta;
minimumRequiredCollateral: ValueAdaOnly;
};
}
Expand Down Expand Up @@ -1598,7 +1600,7 @@ export interface SubmitTransactionFailureTotalCollateralMismatch {
message: string;
data: {
declaredTotalCollateral: ValueAdaOnly;
computedTotalCollateral: ValueAdaOnly;
computedTotalCollateral: ValueDelta;
};
}
/**
Expand Down Expand Up @@ -1912,6 +1914,13 @@ export interface SubmitTransactionFailureConflictingInputsAndReferences {
conflictingReferences: TransactionOutputReference[];
};
}
/**
* The ledger is still in a bootstrapping phase. During that phase, only protocol parameters changes, hard fork initiations and info actions are authorized. The transaction contains other types of governance action and was therefore rejected
*/
export interface SubmitTransactionFailureUnauthorizedGovernanceAction {
code: 3164;
message: string;
}
/**
* Unrecognized certificate type. This error is a placeholder due to how internal data-types are modeled. If you ever run into this, please report the issue as you've likely discoverd a critical bug...
*/
Expand Down Expand Up @@ -2645,7 +2654,23 @@ export interface QueryNetworkGenesisConfiguration {
export interface QueryNetworkGenesisConfigurationResponse {
jsonrpc: "2.0";
method: "queryNetwork/genesisConfiguration";
result: GenesisByron | GenesisShelley | GenesisAlonzo | GenesisConway;
result: QueryNetworkInvalidGenesis | (GenesisByron | GenesisShelley | GenesisAlonzo | GenesisConway);
id?: unknown;
}
export interface QueryNetworkInvalidGenesis {
jsonrpc: "2.0";
method: "queryNetwork/genesisConfiguration";
/**
* Something went wrong (e.g. misconfiguration) in reading genesis file for the latest era.
*/
error?: {
code: 2004;
message: string;
/**
* A reason for the failure.
*/
data: string;
};
id?: unknown;
}
/**
Expand Down
4 changes: 3 additions & 1 deletion docs/content/mini-protocols/local-state-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ components:
2002/UnavailableInCurrentEra:
$ref: "/ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra/properties/error"
2003/AcquireExpired:
$ref: "/ogmios.json#/properties/QueryLedgerStateAcquiredExpire/properties/error"
$ref: "/ogmios.json#/properties/QueryLedgerStateAcquiredExpired/properties/error"
2004/InvalidGenesis:
$ref: "/ogmios.json#/properties/QueryNetworkInvalidGenesis/properties/error"
{{% /embed-async-api %}}

## API Reference
Expand Down
73 changes: 54 additions & 19 deletions docs/static/ogmios.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
}
}

, "QueryLedgerStateAcquiredExpire" :
, "QueryLedgerStateAcquiredExpired" :
{ "title": "QueryLedgerStateAcquiredExpired"
, "type": "object"
, "required": [ "jsonrpc", "method", "error" ]
Expand Down Expand Up @@ -837,7 +837,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -905,7 +905,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -956,7 +956,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1006,7 +1006,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1057,7 +1057,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1107,7 +1107,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1175,7 +1175,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1228,7 +1228,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1278,7 +1278,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1345,7 +1345,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1395,7 +1395,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1465,7 +1465,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1515,7 +1515,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1595,7 +1595,7 @@
}
, { "$ref": "ogmios.json#/properties/QueryLedgerStateEraMismatch" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateUnavailableInCurrentEra" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpire" }
, { "$ref": "ogmios.json#/properties/QueryLedgerStateAcquiredExpired" }
]
}

Expand Down Expand Up @@ -1693,10 +1693,14 @@
}
, "result":
{ "oneOf":
[ { "$ref": "cardano.json#/definitions/Genesis<Byron>" }
, { "$ref": "cardano.json#/definitions/Genesis<Shelley>" }
, { "$ref": "cardano.json#/definitions/Genesis<Alonzo>"}
, { "$ref": "cardano.json#/definitions/Genesis<Conway>"}
[ { "$ref": "ogmios.json#/properties/QueryNetworkInvalidGenesis" }
, { "oneOf":
[ { "$ref": "cardano.json#/definitions/Genesis<Byron>" }
, { "$ref": "cardano.json#/definitions/Genesis<Shelley>" }
, { "$ref": "cardano.json#/definitions/Genesis<Alonzo>"}
, { "$ref": "cardano.json#/definitions/Genesis<Conway>"}
]
}
]
}
, "id":
Expand All @@ -1705,6 +1709,37 @@
}
}

, "QueryNetworkInvalidGenesis":
{ "title": "QueryNetworkInvalidGenesis"
, "type": "object"
, "required": [ "jsonrpc", "method", "result" ]
, "additionalProperties": false
, "properties":
{ "jsonrpc":
{ "type": "string"
, "enum": [ "2.0" ]
}
, "method":
{ "type": "string"
, "enum": [ "queryNetwork/genesisConfiguration" ]
}
, "error":
{ "description": "Something went wrong (e.g. misconfiguration) in reading genesis file for the latest era."
, "type": "object"
, "required": [ "code", "message", "data" ]
, "additionalProperties": false
, "properties":
{ "code": { "type": "integer", "enum": [ 2004 ] }
, "message": { "type": "string" }
, "data": { "type": "string", "description": "A reason for the failure." }
}
}
, "id":
{ "description": "Any value that was set by a client request in the 'id' field."
}
}
}

, "QueryNetworkStartTime":
{ "title": "QueryNetworkStartTime"
, "description": "Query the network start time."
Expand Down
Loading

0 comments on commit 2a7db8d

Please sign in to comment.