Skip to content

Commit

Permalink
Merge pull request #353 from tonlabs/0.62.0-rc
Browse files Browse the repository at this point in the history
Version 0.62.0
  • Loading branch information
d3p authored Jul 21, 2023
2 parents 7536cea + 1ea63db commit 03c2314
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 28 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file.

## [0.62.0] - 2023-07-20

### New

- `trace` field in transaction is a list of VM step info objects

### Fixed

- implemented support for `archive` parameter in all blockchain queries.
- `archive` parameter was not propagated to the nested join queries.

### Improved

- All user parameters that are enums are now checked for typos on startup

## [0.61.0] - 2023-07-04

### New
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-q-server",
"version": "0.61.0",
"version": "0.62.0",
"description": "TON Q Server – realtime queries over TON blockchain.",
"main": "index.js",
"repository": "[email protected]:tonlabs/ton-q-server.git",
Expand Down
13 changes: 13 additions & 0 deletions res/type-defs-blockchain/codegen-stubs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ enum BounceTypeEnum {
Ok
}

type TransactionTrace {
info_type: String,
step: Int,
cmd_str: String,
stack: [String],
gas_used: String,
gas_cmd: String,
cmd_code_rem_bits: Int,
cmd_code_hex: String,
cmd_code_cell_hash: String,
cmd_code_offset: Int,
}

"""
Due to GraphQL limitations big numbers are returned as a string.
You can specify format used to string representation for big integers.
Expand Down
2 changes: 1 addition & 1 deletion res/type-defs-blockchain/transaction.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type BlockchainTransaction implements Node {
tr_type: Int
tr_type_name: TransactionTypeEnum
"VM debug trace"
trace: String
trace: [TransactionTrace]
tt: String
"Workchain id of the account address (account_addr field)"
workchain_id: Int
Expand Down
38 changes: 34 additions & 4 deletions res/type-defs-generated.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,19 @@ type TransactionSplitInfo {
this_addr: String
}

type TransactionTrace {
cmd_code_cell_hash: String
cmd_code_hex: String
cmd_code_offset: Float
cmd_code_rem_bits: Float
cmd_str: String
gas_cmd: String
gas_used: String
info_type: String
stack: [String]
step: Float
}

type BlockValueFlow {
created(format: BigIntFormat): String
created_other: [OtherCurrency]
Expand Down Expand Up @@ -1233,8 +1246,7 @@ type Transaction {
"""
tr_type: Int
tr_type_name: TransactionTypeEnum
"VM debug trace"
trace: String
trace: [TransactionTrace]
tt: String
"Workchain id of the account address (account_addr field)"
workchain_id: Int
Expand Down Expand Up @@ -2103,6 +2115,20 @@ input TransactionSplitInfoFilter {
OR: TransactionSplitInfoFilter
}

input TransactionTraceFilter {
cmd_code_cell_hash: StringFilter
cmd_code_hex: StringFilter
cmd_code_offset: FloatFilter
cmd_code_rem_bits: FloatFilter
cmd_str: StringFilter
gas_cmd: StringFilter
gas_used: StringFilter
info_type: StringFilter
stack: StringArrayFilter
step: FloatFilter
OR: TransactionTraceFilter
}

input BlockValueFlowFilter {
created: StringFilter
created_other: OtherCurrencyArrayFilter
Expand Down Expand Up @@ -2605,6 +2631,11 @@ input MessageArrayFilter {
all: MessageFilter
}

input TransactionTraceArrayFilter {
any: TransactionTraceFilter
all: TransactionTraceFilter
}

input TransactionProcessingStatusEnumFilter {
eq: TransactionProcessingStatusEnum
ne: TransactionProcessingStatusEnum
Expand Down Expand Up @@ -2737,8 +2768,7 @@ input TransactionFilter {
"""
tr_type: IntFilter
tr_type_name: TransactionTypeEnumFilter
"VM debug trace"
trace: StringFilter
trace: TransactionTraceArrayFilter
tt: StringFilter
"Workchain id of the account address (account_addr field)"
workchain_id: IntFilter
Expand Down
40 changes: 40 additions & 0 deletions src/__tests__/config-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ test("Config Priority", () => {
expect(only_env_options.server.port).toEqual(8081)
})

test("Test SubscriptionsMode enum", () => {
const config = resolveConfig({}, {}, { Q_SUBSCRIPTIONS_MODE: "disabled" })
expect(config.subscriptionsMode).toEqual("disabled")

expect(() => {
resolveConfig({}, {}, { Q_SUBSCRIPTIONS_MODE: "disable" })
}).toThrowError(/Unknown subscriptions-mode/)
})

test("Test SlowQueriesMode enum", () => {
const config = resolveConfig({}, {}, { Q_SLOW_QUERIES: "redirect" })
expect(config.queries.slowQueries).toEqual("redirect")

expect(() => {
resolveConfig({}, {}, { Q_SLOW_QUERIES: "something" })
}).toThrowError(/Unknown slow-queries/)
})

test("Test RequestsMode enum", () => {
const config = resolveConfig({}, {}, { Q_REQUESTS_MODE: "kafka" })
expect(config.requests.mode).toEqual("kafka")

expect(() => {
resolveConfig({}, {}, { Q_REQUESTS_MODE: "something" })
}).toThrowError(/Unknown requests-mode/)
})

test("Test FilterOrConversion enum", () => {
const config = resolveConfig(
{},
{},
{ Q_FILTER_OR_CONVERSION: "sub-queries" },
)
expect(config.queries.filter.orConversion).toEqual("sub-queries")

expect(() => {
resolveConfig({}, {}, { Q_FILTER_OR_CONVERSION: "something" })
}).toThrowError(/Unknown filter-or-conversion/)
})

test("Arango Config", () => {
expect(parseArangoConfig("arango")).toMatchObject({
server: "https://arango",
Expand Down
32 changes: 23 additions & 9 deletions src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,6 @@ function checkSubscriptionsConfig(
? SubscriptionsMode.Arango
: SubscriptionsMode.Disabled
}
if (!Object.values(SubscriptionsMode).includes(config.subscriptionsMode)) {
throw QError.invalidConfig(
`Unknown subscriptions-mode: got ${
config.subscriptionsMode
}, but expected one of [${Object.values(SubscriptionsMode).join(
", ",
)}]`,
)
}
}

function applyDatabaseDefaults(config: string[], def: string[]) {
Expand Down Expand Up @@ -548,6 +539,15 @@ export function resolveConfig(
applyDataProviderDefaults(config.blockchain.blocks, config)
applyDataProviderDefaults(config.blockchain.transactions, config)
checkSubscriptionsConfig(config, specified)
// Check all parameters that are enums
checkEnum("subscriptions-mode", config.subscriptionsMode, SubscriptionsMode)
checkEnum("slow-queries", config.queries.slowQueries, SlowQueriesMode)
checkEnum("requests-mode", config.requests.mode, RequestsMode)
checkEnum(
"filter-or-conversion",
config.queries.filter.orConversion,
FilterOrConversion,
)

const slow = config.slowQueriesBlockchain
if (slow !== undefined) {
Expand All @@ -573,3 +573,17 @@ export function resolveConfig(
}
return config
}

function checkEnum(
paramName: string,
paramValue: string,
matchedEnum: Record<string, unknown>,
) {
if (!Object.values(matchedEnum).includes(`${paramValue}`)) {
throw QError.invalidConfig(
`Unknown ${paramName}: got ${paramValue}, but expected one of [${Object.values(
matchedEnum,
).join(", ")}]`,
)
}
}
2 changes: 1 addition & 1 deletion src/server/data/data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export type QDataProviderQueryParams = {
request: QRequestContext
traceSpan: QTraceSpan
maxRuntimeInS?: number
archive?: boolean
archive?: boolean | null
}

export interface QDataProvider {
Expand Down
3 changes: 3 additions & 0 deletions src/server/graphql/blockchain/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const resolvers: Resolvers<QRequestContext> = {
context,
info,
traceSpan,
args.archive,
)
})
},
Expand Down Expand Up @@ -235,6 +236,7 @@ export const resolvers: Resolvers<QRequestContext> = {
context,
info,
traceSpan,
args.archive,
)
})
},
Expand All @@ -258,6 +260,7 @@ export const resolvers: Resolvers<QRequestContext> = {
context,
info,
traceSpan,
args.archive,
)
})
},
Expand Down
4 changes: 4 additions & 0 deletions src/server/graphql/blockchain/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export type CompiledCollectionConfig<TItem> = {
context: QRequestContext,
traceSpan: QTraceSpan,
maxJoinDepth: number,
archive: boolean | undefined | null,
) => Promise<void>
qDataCollectionSelector: (context: QRequestContext) => QDataCollection
}
Expand Down Expand Up @@ -357,6 +358,7 @@ export function compileCollectionConfig<TItem>(
context: QRequestContext,
traceSpan: QTraceSpan,
maxJoinDepth: number,
archive: boolean | undefined | null,
) => {
for (const join of collection.joins || []) {
const joinSelectionSet = getFieldSelectionSet(
Expand Down Expand Up @@ -412,6 +414,7 @@ export function compileCollectionConfig<TItem>(
orderBy: [],
request: context,
traceSpan,
archive,
},
)) as any[][]
for (const joinItem of queryResult.flat()) {
Expand Down Expand Up @@ -461,6 +464,7 @@ export function compileCollectionConfig<TItem>(
context,
traceSpan,
maxJoinDepth - 1,
archive,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/server/graphql/blockchain/fetchers/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function resolve_account(
context,
traceSpan,
maxJoinDepth,
false,
)

return queryResult[0]
Expand Down
14 changes: 11 additions & 3 deletions src/server/graphql/blockchain/fetchers/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function fetch_blocks(
context: QRequestContext,
info: GraphQLResolveInfo,
traceSpan: QTraceSpan,
archive: boolean | undefined | null,
additionalFields: KeyOf<BlockchainBlock>[] = [],
maxJoinDepth = 1,
) {
Expand Down Expand Up @@ -59,6 +60,7 @@ async function fetch_blocks(
orderBy: [],
request: context,
traceSpan,
archive,
},
)) as BlockchainBlock[]

Expand All @@ -68,6 +70,7 @@ async function fetch_blocks(
context,
traceSpan,
maxJoinDepth,
archive,
)

return queryResult
Expand All @@ -78,14 +81,15 @@ export async function resolve_block(
context: QRequestContext,
info: GraphQLResolveInfo,
traceSpan: QTraceSpan,
archive: boolean | undefined | null,
) {
return (
await fetch_blocks(
params => `doc._key == @${params.add(hash)}`,
context,
info,
traceSpan,
// TODO: shard
archive,
)
)[0]
}
Expand All @@ -109,6 +113,7 @@ export async function resolve_block_by_seq_no(
context,
info,
traceSpan,
args.archive,
)
)[0]
}
Expand Down Expand Up @@ -146,6 +151,7 @@ export async function resolve_prev_shard_blocks(
orderBy: [],
request: context,
traceSpan,
archive: args.archive,
},
)) as BlockchainBlock[]

Expand All @@ -155,6 +161,7 @@ export async function resolve_prev_shard_blocks(
context,
traceSpan,
0,
args.archive,
)

return queryResult
Expand All @@ -174,6 +181,7 @@ export async function resolve_next_shard_blocks(
context,
info,
traceSpan,
args.archive,
["after_split"],
0,
)
Expand Down Expand Up @@ -236,7 +244,7 @@ export async function resolve_key_blocks(
],
request: context,
traceSpan,
archive: args.archive ?? undefined,
archive: args.archive,
},
)) as BlockchainBlock[]

Expand Down Expand Up @@ -312,7 +320,7 @@ export async function resolve_blockchain_blocks(
],
request: context,
traceSpan,
archive: args.archive ?? undefined,
archive: args.archive,
},
)) as BlockchainBlock[]

Expand Down
Loading

0 comments on commit 03c2314

Please sign in to comment.