在 Hedera 上几乎相同的交易中,`gasUsed` 值存在巨大差异 - 为什么?

问题描述 投票:0回答:0

我注意到使用的气体量之间存在差异 通过交易几乎相同:

我正在调用一个智能合约, 连续两次使用相同的参数, 和 2 之间的唯一区别 是我将

gasLimit
设置为精确值 由
eth_estimateGas
在第一个中返回, 我在第二个中将
gasLimit
设置为
eth_estimateGas * 1.1
.

    // with exact estimated amount of gas
    const estimatedGas2 = (await expendGasSc.estimateGas.updateState(1_000_000_123n)).toBigInt();
    console.log('estimatedGas2', estimatedGas2);
    const gasLimit2 = estimatedGas2 * 1n;
    console.log('gasLimit2', gasLimit2);
    const txResponse2 = await (await expendGasSc
        .updateState(
            1_000_000_123n,
            { gasLimit: gasLimit2 },
        ))
        .wait();
    const gasUsed2 = txResponse2.gasUsed.toBigInt();
    console.log('gasUsed2', gasUsed2);

    // with 110%  of estimated amount of gas
    const estimatedGas3 = (await expendGasSc.estimateGas.updateState(1_000_000_123n)).toBigInt();
    console.log('estimatedGas3', estimatedGas3);
    const gasLimit3 = estimatedGas3 * 11n / 10n;
    console.log('gasLimit3', gasLimit3);
    const txResponse3 = await (await expendGasSc
        .updateState(
            1_000_000_123n,
            { gasLimit: gasLimit3 },
        ))
        .wait();
    const gasUsed3 = txResponse3.gasUsed.toBigInt();
    console.log('gasUsed3', gasUsed3);

这是输出,显示:

  • gasLimit
    设置为400,000时,
    gasUsed
    为320,000
  • gasLimit
    设置为440,000时,已使用为352,000
estimatedGas2 400000n
gasLimit2 400000n
gasUsed2 320000n
estimatedGas3 400000n
gasLimit3 440000n
gasUsed3 352000n

为什么第二次调用会额外消耗 32,000 gas? (我预计

gasUsed
值在两种情况下都相同。)

solidity rpc hedera-hashgraph hedera
© www.soinside.com 2019 - 2024. All rights reserved.