diff --git a/executor/Cargo.lock b/executor/Cargo.lock index fe498451..64619a29 100644 --- a/executor/Cargo.lock +++ b/executor/Cargo.lock @@ -46,7 +46,7 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ - "event-listener", + "event-listener 2.5.3", ] [[package]] @@ -190,6 +190,15 @@ dependencies = [ "inout", ] +[[package]] +name = "concurrent-queue" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -278,9 +287,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ "cfg-if", "cpufeatures", @@ -304,19 +313,6 @@ dependencies = [ "syn 2.0.31", ] -[[package]] -name = "curve25519-dalek-ng" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core", - "subtle-ng", - "zeroize", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -367,9 +363,9 @@ dependencies = [ [[package]] name = "ed25519-zebra" -version = "4.0.2" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e83e509bcd060ca4b54b72bde5bb306cb2088cb01e14797ebae90a24f70f5f7" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ "curve25519-dalek", "ed25519", @@ -392,11 +388,21 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "event-listener" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +dependencies = [ + "concurrent-queue", + "pin-project-lite", +] + [[package]] name = "fiat-crypto" -version = "0.1.20" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" [[package]] name = "fnv" @@ -933,17 +939,18 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "schnorrkel" -version = "0.10.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "844b7645371e6ecdf61ff246ba1958c29e802881a749ae3fb1993675d210d28d" +checksum = "da18ffd9f2f5d01bc0b3050b37ce7728665f926b4dd1157fe3221b05737d924f" dependencies = [ "arrayref", "arrayvec 0.7.4", - "curve25519-dalek-ng", + "curve25519-dalek", "merlin", "rand_core", - "sha2 0.9.9", - "subtle-ng", + "serde_bytes", + "sha2 0.10.7", + "subtle", "zeroize", ] @@ -973,6 +980,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "serde_bytes" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.188" @@ -1050,9 +1066,9 @@ checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" [[package]] name = "siphasher" -version = "0.3.11" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "54ac45299ccbd390721be55b412d41931911f654fa99e2cb8bfb57184b2061fe" [[package]] name = "slab" @@ -1071,7 +1087,7 @@ checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "smoldot" -version = "0.11.0" +version = "0.12.0" dependencies = [ "arrayvec 0.7.4", "async-lock", @@ -1085,7 +1101,7 @@ dependencies = [ "derive_more", "ed25519-zebra", "either", - "event-listener", + "event-listener 3.0.0", "fnv", "futures-lite", "futures-util", @@ -1154,12 +1170,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "subtle-ng" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" - [[package]] name = "syn" version = "1.0.109" diff --git a/packages/chopsticks/src/utils/signFake.ts b/packages/chopsticks/src/utils/signFake.ts index 4e2cec35..3c6b5f61 100644 --- a/packages/chopsticks/src/utils/signFake.ts +++ b/packages/chopsticks/src/utils/signFake.ts @@ -11,8 +11,7 @@ export const signFakeWithApi = async ( options: SignFakeOptions = {}, ) => { const nonce = options.nonce ?? (await api.query.system.account(addr)).nonce - - return signFake(tx, addr, { + signFake(tx, addr, { nonce, genesisHash: api.genesisHash, runtimeVersion: api.runtimeVersion, @@ -28,6 +27,4 @@ export const signFake = (tx: GenericExtrinsic, addr: string, options: SignatureO tx.signFake(addr, options) tx.signature.set(mockSignature) - - return tx } diff --git a/packages/core/src/blockchain/storage-layer.ts b/packages/core/src/blockchain/storage-layer.ts index e5fd88d8..fdf7b755 100644 --- a/packages/core/src/blockchain/storage-layer.ts +++ b/packages/core/src/blockchain/storage-layer.ts @@ -4,7 +4,7 @@ import _ from 'lodash' import { Api } from '../api' import { KeyValuePair } from '../db/entities' import { defaultLogger } from '../logger' -import KeyCache from '../utils/key-cache' +import KeyCache, { PREFIX_LENGTH } from '../utils/key-cache' const logger = defaultLogger.child({ name: 'layer' }) @@ -71,7 +71,7 @@ export class RemoteStorageLayer implements StorageLayerProvider { if (pageSize > BATCH_SIZE) throw new Error(`pageSize must be less or equal to ${BATCH_SIZE}`) logger.trace({ at: this.#at, prefix, pageSize, startKey }, 'RemoteStorageLayer getKeysPaged') // can't handle keyCache without prefix - if (prefix.length < 66) { + if (prefix.length < PREFIX_LENGTH || startKey.length < PREFIX_LENGTH) { return this.#api.getKeysPaged(prefix, pageSize, startKey, this.#at) } diff --git a/packages/core/src/executor.ts b/packages/core/src/executor.ts index ae1012bd..02f45de2 100644 --- a/packages/core/src/executor.ts +++ b/packages/core/src/executor.ts @@ -13,6 +13,7 @@ import { run_task, } from '@acala-network/chopsticks-executor' import { defaultLogger, truncate } from './logger' +import { stripChildPrefix } from './utils' import _ from 'lodash' import type { JsCallback } from '@acala-network/chopsticks-executor' @@ -98,7 +99,7 @@ export const taskHandler = (block: Block): JsCallback => { pageSize: 1, startKey: key, }) - return nextKey + return nextKey && stripChildPrefix(nextKey as HexString) }, offchainGetStorage: async function (key: HexString) { if (!block.chain.offchainWorker) throw new Error('offchain worker not found') diff --git a/packages/e2e/src/crowdloan.redeem.test.ts b/packages/e2e/src/crowdloan.redeem.test.ts new file mode 100644 index 00000000..aab07f2e --- /dev/null +++ b/packages/e2e/src/crowdloan.redeem.test.ts @@ -0,0 +1,50 @@ +import { afterAll, beforeAll, describe, expect, it } from 'vitest' +import { testingPairs } from '@acala-network/chopsticks-testing' + +import networks from './networks' + +describe('Polkadot Crowdloan Refund', async () => { + const { alice } = testingPairs() + const { api, dev, teardown } = await networks.polkadot({ blockNumber: 17700000, timeout: 400_000 }) + + beforeAll(async () => { + // make sure crowdloan is ended + await dev.newBlock({ unsafeBlockHeight: 17855999, count: 3 }) + + // give alice some DOTs for transaction fee + await dev.setStorage({ + System: { + Account: [[[alice.address], { providers: 1, data: { free: 1000 * 1e10 } }]], + }, + }) + }, 200_000) + + it( + "should refund Acala's contributers", + async () => { + // trigger refund + await expect(api.tx.crowdloan.refund(3336).signAndSend(alice)).resolves.toBeTruthy() + await dev.newBlock() + + // some address get refund + expect((await api.query.system.events()).toHuman()).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + event: expect.objectContaining({ + method: 'Transfer', + section: 'balances', + data: expect.objectContaining({ + from: '13UVJyLnbVp77Z2t6qZV4fNpRjDHppL6c87bHcZKG48tKJad', + to: '111DbHPUxncZcffEfy1BrtFZNDUzK7hHchLpmJYFEFG4hy1', + amount: '1,000,000,000,000', + }), + }), + }), + ]), + ) + }, + { timeout: 400_000 }, + ) + + afterAll(async () => await teardown()) +}) diff --git a/packages/testing/src/index.ts b/packages/testing/src/index.ts index ebb44ef0..c135d5ff 100644 --- a/packages/testing/src/index.ts +++ b/packages/testing/src/index.ts @@ -49,7 +49,7 @@ export const createConfig = ({ endpoint, port, block: blockNumber || blockHash, - mockSignatureHost: true, + 'mock-signature-host': true, 'build-block-mode': BuildBlockMode.Manual, 'max-memory-block-count': maxMemoryBlockCount ?? 100, db, diff --git a/vendor/smoldot b/vendor/smoldot index 175e2d4c..52e77e74 160000 --- a/vendor/smoldot +++ b/vendor/smoldot @@ -1 +1 @@ -Subproject commit 175e2d4cac9267abc482b49dcb8d4c187df87d84 +Subproject commit 52e77e74a3aed644682d102122e5645abd19f93e diff --git a/vitest.config.ts b/vitest.config.mts similarity index 51% rename from vitest.config.ts rename to vitest.config.mts index 04c6f5c2..d6d4ebde 100644 --- a/vitest.config.ts +++ b/vitest.config.mts @@ -3,10 +3,10 @@ import swc from 'unplugin-swc' import tsconfigPaths from 'vite-tsconfig-paths' export default defineConfig({ - test: { - hookTimeout: 30000, - testTimeout: 120000, - include: ['packages/**/*.test.ts'], - }, - plugins: [swc.vite(), tsconfigPaths()], + test: { + hookTimeout: 30000, + testTimeout: 120000, + include: ['packages/**/*.test.ts'], + }, + plugins: [swc.vite(), tsconfigPaths()], })