Use maxBlock value for weight limits (#4287)

This commit is contained in:
Jaco Greeff 2020-12-29 12:17:08 +01:00 committed by GitHub
parent 8a25a69b17
commit 947d3305e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View File

@ -17,7 +17,7 @@ export default function useWeight (): UseWeight {
const [blockTime] = useBlockTime();
const [megaGas, _setMegaGas] = useState<BN>(
(api.consts.system.blockWeights
? api.consts.system.blockWeights.perClass.normal.maxExtrinsic
? api.consts.system.blockWeights.maxBlock
: api.consts.system.maximumBlockWeight as Weight
).div(BN_MILLION).div(BN_TEN)
);
@ -26,7 +26,7 @@ export default function useWeight (): UseWeight {
const setMegaGas = useCallback(
(value?: BN | undefined) => _setMegaGas(value || (
(api.consts.system.blockWeights
? api.consts.system.blockWeights.perClass.normal.maxExtrinsic
? api.consts.system.blockWeights.maxBlock
: api.consts.system.maximumBlockWeight as Weight
).div(BN_MILLION).div(BN_TEN)
)),
@ -43,7 +43,7 @@ export default function useWeight (): UseWeight {
weight = megaGas.mul(BN_MILLION);
executionTime = weight.muln(blockTime).div(
api.consts.system.blockWeights
? api.consts.system.blockWeights.perClass.normal.maxExtrinsic
? api.consts.system.blockWeights.maxBlock
: api.consts.system.maximumBlockWeight as Weight
).toNumber();
percentage = (executionTime / blockTime) * 100;

View File

@ -89,15 +89,14 @@ function PayButton ({ className, isAll, isDisabled, payout }: Props): React.Reac
.payoutStakers(validatorId, eras[0].era)
.paymentInfo(allAccounts[0])
.then((info) => setMaxPayouts(Math.floor(
api.consts.system.blockWeights
? api.consts.system.blockWeights.perClass.normal.maxExtrinsic
.sub(api.consts.system.blockWeights.perClass.normal.baseExtrinsic)
.div(info.weight)
.toNumber()
: (api.consts.system.maximumBlockWeight as Weight)
.muln(64) // 65% of the block weight on a single extrinsic (64 for safety)
.div(info.weight)
.toNumber() / 100
(
api.consts.system.blockWeights
? api.consts.system.blockWeights.maxBlock
: api.consts.system.maximumBlockWeight as Weight
)
.muln(64) // 65% of the block weight on a single extrinsic (64 for safety)
.div(info.weight)
.toNumber() / 100
)))
.catch(console.error);
} else {