New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field tx.gasUsed when there are multiple tx per bloc is the cumulative gas used and not the gasUsed of the transaction #530

Closed
guenoledc opened this Issue Apr 14, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@guenoledc

guenoledc commented Apr 14, 2018

When there are multiple transactions in a bloc, the field gasUsed returned to eth.getTransactionReceipt is the cumulative gas and not the gas used of that particular transaction

Ganache is in mining every 5 seconds, running on port 7545.
I have submitted 3 transactions in sequence, that consume each less that 140000 gas.
They are correctly processed and integrated in the same block (70)

Expected Behavior

eth.getTransactionReceipt(hash1).gasUsed = 136578
eth.getTransactionReceipt(hash2).gasUsed = 117154
eth.getTransactionReceipt(hash3).gasUsed = 117090
eth.getTransactionReceipt(hash3).cumulativeGasUsed = 370822

Current Behavior

eth.getTransactionReceipt(hash1).gasUsed = 136578
eth.getTransactionReceipt(hash2).gasUsed = 253732
eth.getTransactionReceipt(hash3).gasUsed = 370822
eth.getTransactionReceipt(hash3).cumulativeGasUsed = 370822

Proof and log

screen shot 2018-04-14 at 20 58 40

And from a "geth attach http://localhost:7545"

> eth.getBlock("0xf70085e73644a9b8d506b3a4d4c5f7692631b173d6daf10bf9540076fc087a10")
{
  difficulty: 0,
  extraData: "0x00",
  gasLimit: 6721975,
  gasUsed: 370822,
  hash: "0xf70085e73644a9b8d506b3a4d4c5f7692631b173d6daf10bf9540076fc087a10",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0x0000000000000000000000000000000000000000",
  mixHash: "0x1010101010101010101010101010101010101010101010101010101010101010",
  nonce: "0x0000000000000000",
  number: 70,
  parentHash: "0x892e47d43034a1987752bf4fc96c5f189ef7550448db4d32b382474d91f90319",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 1000,
  stateRoot: "0x35faa7800f7e26716f5bc55f099a7aea367aeb729b3de91ddf249a87c1de1abe",
  timestamp: 1523729788,
  totalDifficulty: 0,
  transactions: ["0x7b02452922e26dafa7b237514830b73e2d3421c943e5c5ebac0bf292ae7cbb02", "0x78073019177c2aa1610faecc32257b65580deca151c4c5c296b8b706ad7d9ca0", "0xb63e8ba9bcd5b430b9daafa738896eb588e85c9ea8c1f4bca984609a58a3eab3"],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}
> eth.getTransactionReceipt("0x7b02452922e26dafa7b237514830b73e2d3421c943e5c5ebac0bf292ae7cbb02")
{
  blockHash: "0xf70085e73644a9b8d506b3a4d4c5f7692631b173d6daf10bf9540076fc087a10",
  blockNumber: 70,
  contractAddress: null,
  cumulativeGasUsed: 370822,
  gasUsed: 136578,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  status: "0x01",
  transactionHash: "0x7b02452922e26dafa7b237514830b73e2d3421c943e5c5ebac0bf292ae7cbb02",
  transactionIndex: 0
}
> eth.getTransactionReceipt("0x78073019177c2aa1610faecc32257b65580deca151c4c5c296b8b706ad7d9ca0")
{
  blockHash: "0xf70085e73644a9b8d506b3a4d4c5f7692631b173d6daf10bf9540076fc087a10",
  blockNumber: 70,
  contractAddress: null,
  cumulativeGasUsed: 370822,
  gasUsed: 253732,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  status: "0x01",
  transactionHash: "0x78073019177c2aa1610faecc32257b65580deca151c4c5c296b8b706ad7d9ca0",
  transactionIndex: 1
}
> eth.getTransactionReceipt("0xb63e8ba9bcd5b430b9daafa738896eb588e85c9ea8c1f4bca984609a58a3eab3")
{
  blockHash: "0xf70085e73644a9b8d506b3a4d4c5f7692631b173d6daf10bf9540076fc087a10",
  blockNumber: 70,
  contractAddress: null,
  cumulativeGasUsed: 370822,
  gasUsed: 370822,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  status: "0x01",
  transactionHash: "0xb63e8ba9bcd5b430b9daafa738896eb588e85c9ea8c1f4bca984609a58a3eab3",
  transactionIndex: 2
}

Possible Solution

Probably a missing reset of the gas used when creating the block

Steps to Reproduce (for bugs)

From a "geth attach" console, send 3 payment transactions

personal.unlockAccount(eth.accounts[0], "passphrase",0)
eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:1, gas:21000});eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:1, gas:21000});eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:1, gas:21000})

Context

Cannot really use my logical function that test if too much gas has been used

Your Environment

PLATFORM: darwin
GANACHE VERSION: 1.1.0

@seesemichaelj

This comment has been minimized.

Member

seesemichaelj commented Aug 27, 2018

Thanks for reporting this! We're closing this issue in favor of trufflesuite/ganache-cli#445 where we'll track this issue further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment