Skip to content

Commit

Permalink
Fix wasm.length to use parasConfig.maxCodeSize (#10671)
Browse files Browse the repository at this point in the history
* Fix wasm.length to use parasConfig.maxCodeSize

* Safety check
  • Loading branch information
TarikGul authored Jun 14, 2024
1 parent c4b1f9d commit 849cae3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/page-parachains/src/Parathreads/RegisterThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import type { BalanceOf } from '@polkadot/types/interfaces';
import type { PolkadotRuntimeParachainsConfigurationHostConfiguration } from '@polkadot/types/lookup';
import type { OwnedId, OwnerInfo } from '../types.js';

import React, { useCallback, useMemo, useState } from 'react';

import { InputAddress, InputBalance, InputFile, InputNumber, Modal, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { BN, compactAddLength } from '@polkadot/util';

import InputOwner from '../InputOwner.js';
Expand All @@ -28,6 +29,7 @@ function RegisterThread ({ className, nextParaId, onClose, ownedIds }: Props): R
const [paraId, setParaId] = useState<BN | undefined>();
const [wasm, setWasm] = useState<Uint8Array | null>(null);
const [genesisState, setGenesisState] = useState<Uint8Array | null>(null);
const paraConfig = useCall<PolkadotRuntimeParachainsConfigurationHostConfiguration>(api.query.configuration?.activeConfig);

const _setGenesisState = useCallback(
(data: Uint8Array) => setGenesisState(compactAddLength(data)),
Expand All @@ -49,9 +51,15 @@ function RegisterThread ({ className, nextParaId, onClose, ownedIds }: Props): R

const reservedDeposit = useMemo(
() => (api.consts.registrar.paraDeposit as BalanceOf)
.add((api.consts.registrar.dataDepositPerByte as BalanceOf).muln(wasm ? wasm.length : 0))
.add((api.consts.registrar.dataDepositPerByte as BalanceOf).muln(
paraConfig?.maxCodeSize
? paraConfig.maxCodeSize.toNumber()
: wasm
? wasm.length
: 0
))
.iadd((api.consts.registrar.dataDepositPerByte as BalanceOf).muln(genesisState ? genesisState.length : 0)),
[api, wasm, genesisState]
[api, wasm, genesisState, paraConfig]
);

const isIdError = !paraId || !paraId.gt(LOWEST_INVALID_ID);
Expand Down

0 comments on commit 849cae3

Please sign in to comment.