citahub / cita

A high performance blockchain kernel for enterprise users.
https://www.citahub.com/
Apache License 2.0
1.31k stars 208 forks source link

cost same quota when send a transaction with data or not, even the data is very big #677

Closed luqz closed 5 years ago

luqz commented 5 years ago

Description

cost same quota when send a transaction with data or not, even the data is very big

Steps to Reproduce

sdk.base.getBlockNumber()
    .then(async current => {
      let testString = "测试"
      for (let index = 0; index < 20; index++) {
        testString += testString
      }

      let blcokNumber = await sdk.base.getBlockNumber()
      let metaData = await sdk.base.getMetaData()

      let tx = {
        to: "0x1072fd65138cf36cd5d3e77661c1138e475ebf4d",
        value: "0x1",
        data: sdk.utils.stringToHex(testString),
        quota: 21000,
        chainId: metaData.chainIdV1,
        version: metaData.version,
        validUntilBlock: blcokNumber + 99,
        privateKey: "0xe37861d07588985bf01d5e4b314477d9d11f0189e446d009930e5b20be3d19f1"
      }

      let res = await sdk.base.sendTransaction(tx)
      console.log(res.hash)
      let receipt = await sdk.listeners.listenToTransactionReceiptEx(res.hash)
      console.log(receipt)

    })

Expected behavior: quotaUsed is different by tx.data.length

Actual behavior: quotaUsed always 21000

Reproduce how often: every time

Versions

v0.25.0

Additional Information

I think this behavior need be change soon.

kaikai1024 commented 5 years ago

21000 is the base gas of a tx. Is the 0x1072fd65138cf36cd5d3e77661c1138e475ebf4d a contract address? and the what's the data?

luqz commented 5 years ago

21000 is the base gas of a tx. Is the 0x1072fd65138cf36cd5d3e77661c1138e475ebf4d a contract address? and the what's the data?

It's not a contract address. The data is just for test, it‘s meaningless, maybe something to record。

kaikai1024 commented 5 years ago

It's not a contract address.

Then it's normal for CITA for now. It's a tx with the data that will not be executed. so it will cost the base gas no matter how long the data is.

But i thinkg it's not a normal situation, either.

I remember there's an EIP about this. wait a minute

kaikai1024 commented 5 years ago

I will add some descriptions about this later.

CITA executes txs after consensus, while ethereum executes txs before consensus. This tx can not be executed successful on ethereum, so it will not be included in block. while, for cita, it will be included in block even though it's failed. It's the difference, the base quota/gas is ok for ethreum, but it's a problem for cita.

Maybe we need a way to calculate the tx data size. @jerry-yu @leeyr338 @ouwenkg

boundless-forest commented 5 years ago

~I will add some descriptions about this later.~

CITA executes txs after consensus, while ethereum executes txs before consensus. This tx can not be executed successful on ethereum, so it will not be included in block. while, for cita, it will be included in block even though it's failed. It's the difference, the base quota/gas is ok for ethreum, but it's a problem for cita.

Maybe we need a way to calculate the tx data size. @jerry-yu @leeyr338 @ouwenkg

It's a uncompatible change, maybe later in a new version upgrade.

kaikai1024 commented 5 years ago

It's a uncompatible change, maybe later in a new version upgrade.

Actually, we can only calculate the data of failed tx. then it's not a uncompatible change.

kaikai1024 commented 5 years ago
// gas_prepare = 21000 + (68 or 4 per byte) + (32000 if tx.to == 0)
kaikai1024 commented 5 years ago

Be triggerd by protocol version 3