Skip to content

Commit

Permalink
update smoldot and fix empty next key (#438)
Browse files Browse the repository at this point in the history
* update smoldot and fix empty next key

* fix trie empty next key

* lint

* update test
  • Loading branch information
ermalkaleci authored Oct 13, 2023
1 parent 4a5e41e commit 118aa89
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 50 deletions.
80 changes: 45 additions & 35 deletions executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/chopsticks/src/utils/signFake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,6 +27,4 @@ export const signFake = (tx: GenericExtrinsic, addr: string, options: SignatureO
tx.signFake(addr, options)

tx.signature.set(mockSignature)

return tx
}
4 changes: 2 additions & 2 deletions packages/core/src/blockchain/storage-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })

Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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')
Expand Down
50 changes: 50 additions & 0 deletions packages/e2e/src/crowdloan.redeem.test.ts
Original file line number Diff line number Diff line change
@@ -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())
})
2 changes: 1 addition & 1 deletion packages/testing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vendor/smoldot
Submodule smoldot updated 105 files
12 changes: 6 additions & 6 deletions vitest.config.ts → vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
})

0 comments on commit 118aa89

Please sign in to comment.