Skip to content

Commit 329ef42

Browse files
authored
Default to soft finality (#2252)
1 parent 059e48e commit 329ef42

File tree

8 files changed

+25
-101
lines changed

8 files changed

+25
-101
lines changed

.changeset/thin-pants-walk.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@onflow/fcl-react-native": minor
3+
"@onflow/fcl-core": minor
4+
"@onflow/fcl": minor
5+
"@onflow/sdk": minor
6+
---
7+
8+
Default to soft-finality for all queries (get account, get block, get block header, execute script). Developers can manually override this setting on a per-query basis if required.
9+
10+
Because developers can now query against un-sealed blocks, it is now recommended to switch to waiting for soft-finality ("executed" status) when awaiting for transaction results whenever possible for significant latency improvements (~2.5x faster).
11+
12+
This can be done by switching from `fcl.tx(...).onceSealed()` to `fcl.tx(...).onceExecuted()` or updating listeners passed to `fcl.tx(...).subscribe()`.

packages/fcl-core/src/exec/query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function query(opts = {}) {
4141
.send([
4242
sdk.script(opts.cadence),
4343
sdk.args(normalizeArgs(opts.args || [])),
44-
opts.isSealed != null && sdk.atLatestBlock(opts.isSealed),
44+
sdk.atLatestBlock(opts.isSealed ?? false),
4545
opts.limit && typeof opts.limit === "number" && sdk.limit(opts.limit),
4646
])
4747
.then(sdk.decode)

packages/sdk/src/account/account.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function account(
4343

4444
// Get account by latest block
4545
return await send(
46-
[getAccount(address), isSealed != null && atLatestBlock(isSealed)],
46+
[getAccount(address), atLatestBlock(isSealed ?? false)],
4747
opts
4848
).then(decode)
4949
}

packages/sdk/src/resolve/resolve-is-sealed.js

-12
This file was deleted.

packages/sdk/src/resolve/resolve-is-sealed.test.js

-74
This file was deleted.

packages/sdk/src/resolve/resolve.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {resolveValidators} from "./resolve-validators.js"
1818
import {resolveFinalNormalization} from "./resolve-final-normalization.js"
1919
import {resolveVoucherIntercept} from "./resolve-voucher-intercept.js"
2020
import {resolveComputeLimit} from "./resolve-compute-limit.js"
21-
import {resolveIsSealed} from "./resolve-is-sealed"
2221

2322
const noop = v => v
2423
const debug =
@@ -50,7 +49,6 @@ const debug =
5049
}
5150

5251
export const resolve = pipe([
53-
resolveIsSealed,
5452
resolveCadence,
5553
debug("cadence", (ix, log) => log(ix.message.cadence)),
5654
resolveComputeLimit,

packages/transport-http/src/send-execute-script.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ describe("Send Execute Script", () => {
2727

2828
let response = await sendExecuteScript(
2929
await resolve(
30-
await build([script(cadence), args([arg(123, types.Int)])])
30+
await build([
31+
script(cadence),
32+
args([arg(123, types.Int)]),
33+
atLatestBlock(true),
34+
])
3135
),
3236
{
3337
response: responseADT,
@@ -75,11 +79,7 @@ describe("Send Execute Script", () => {
7579

7680
let response = await sendExecuteScript(
7781
await resolve(
78-
await build([
79-
script(cadence),
80-
args([arg(123, types.Int)]),
81-
atLatestBlock(false),
82-
])
82+
await build([script(cadence), args([arg(123, types.Int)])])
8383
),
8484
{
8585
response: responseADT,

packages/transport-http/src/send-get-account.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("Send Get Account", () => {
6060
})
6161
})
6262

63-
test("GetAccountAtLatestBlockRequest - sealed", async () => {
63+
test("GetAccountAtLatestBlockRequest - final", async () => {
6464
const httpRequestMock = jest.fn()
6565

6666
const returnedAccount = {
@@ -95,7 +95,7 @@ describe("Send Get Account", () => {
9595

9696
expect(valueSent).toEqual({
9797
hostname: "localhost",
98-
path: "/v1/accounts/1654653399040a61?block_height=sealed&expand=contracts,keys",
98+
path: "/v1/accounts/1654653399040a61?block_height=final&expand=contracts,keys",
9999
method: "GET",
100100
body: null,
101101
})
@@ -108,7 +108,7 @@ describe("Send Get Account", () => {
108108
})
109109
})
110110

111-
test("GetAccountAtLatestBlockRequest - final", async () => {
111+
test("GetAccountAtLatestBlockRequest - sealed", async () => {
112112
const httpRequestMock = jest.fn()
113113

114114
const returnedAccount = {
@@ -123,7 +123,7 @@ describe("Send Get Account", () => {
123123

124124
const response = await sendGetAccount(
125125
await resolve(
126-
await build([getAccount("0x1654653399040a61"), atLatestBlock(false)])
126+
await build([getAccount("0x1654653399040a61"), atLatestBlock(true)])
127127
),
128128
{
129129
response: responseADT,
@@ -145,7 +145,7 @@ describe("Send Get Account", () => {
145145

146146
expect(valueSent).toEqual({
147147
hostname: "localhost",
148-
path: "/v1/accounts/1654653399040a61?block_height=final&expand=contracts,keys",
148+
path: "/v1/accounts/1654653399040a61?block_height=sealed&expand=contracts,keys",
149149
method: "GET",
150150
body: null,
151151
})

0 commit comments

Comments
 (0)