Skip to content
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

Bad conversion from hex to decimal with eth_getBlockByNumber after tx #2600

Closed
tclairet opened this issue Mar 28, 2019 · 4 comments
Closed

Comments

@tclairet
Copy link

tclairet commented Mar 28, 2019

Description

This issue may be related to this issue but I think I found a bug not fixed by the fix.

There is a bad conversion from hex to decimal with eth_getBlockByNumber done by web3 after tx. I found that because I have a middleware in php before my node.

I have a simple script which do a tx on my private network.

const web3 = new Web3("http://my-middleware.com");
const rawTx = {...}
const tx = new Tx(rawTx);
tx.sign(privateKey);
const serializedTx = tx.serialize();

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.then(function(receipt){
  console.log(receipt);
});

Actual behavior

Got an error

{
  "blockHash": "0x61eb0fa85b9d1515c6f2eadc96d05ebe7291f4a5a7c7076a44f9f13b315d75fc",
  "blockNumber": 2829,
 ...
}
    at SafeSubscriber._next (/Users/tcl/code/truffle/classic/node_modules/web3-core-method/dist/web3-core-method.cjs.js:1017:32)
    at SafeSubscriber.__tryOrUnsub (/Users/tcl/code/truffle/classic/node_modules/rxjs/internal/Subscriber.js:207:16)
    at SafeSubscriber.next (/Users/tcl/code/truffle/classic/node_modules/rxjs/internal/Subscriber.js:145:22)
    at Subscriber._next (/Users/tcl/code/truffle/classic/node_modules/rxjs/internal/Subscriber.js:89:26)
    at Subscriber.next (/Users/tcl/code/truffle/classic/node_modules/rxjs/internal/Subscriber.js:66:18)
    at TransactionObserver.emitNext (/Users/tcl/code/truffle/classic/node_modules/web3-core-method/dist/web3-core-method.cjs.js:438:16)
    at _callee2$ (/Users/tcl/code/truffle/classic/node_modules/web3-core-method/dist/web3-core-method.cjs.js:408:24)
    at tryCatch (/Users/tcl/code/truffle/classic/node_modules/regenerator-runtime/runtime.js:45:40)
    at Generator.invoke [as _invoke] (/Users/tcl/code/truffle/classic/node_modules/regenerator-runtime/runtime.js:271:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/tcl/code/truffle/classic/node_modules/regenerator-runtime/runtime.js:97:21)
    at asyncGeneratorStep (/Users/tcl/code/truffle/classic/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/Users/tcl/code/truffle/classic/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

And the last log, before the error, caught by the middleware are :

INPUT: array (
  'jsonrpc' => '2.0',
  'id' => 10,
  'method' => 'eth_getTransactionReceipt',
  'params' => 
  array (
    0 => '0x8aa2b3824c9434b91ec9dd2caeab828659c3ffa2d244521ec2077d3b5ea538b0',
  ),
)  
RESPONSE: array (
  'jsonrpc' => '2.0',
  'result' => 
  array (
    'blockHash' => '0x61eb0fa85b9d1515c6f2eadc96d05ebe7291f4a5a7c7076a44f9f13b315d75fc',
    'blockNumber' => '0xb0d',
    'from' => '0x6720359a3c9bae94e5e5d3d80edf0aca45b1f425',
    'status' => '0x1',
    'to' => '0x07aa1cbff46c82119e341524044052efdada65bb',
    'transactionHash' => '0x8aa2b3824c9434b91ec9dd2caeab828659c3ffa2d244521ec2077d3b5ea538b0',
    'transactionIndex' => '0x0',
    ...
  ),
  'id' => 10,
)  
INPUT: array (
  'jsonrpc' => '2.0',
  'id' => 11,
  'method' => 'eth_getBlockByNumber',
  'params' => 
  array (
    0 => '0x282a',
    1 => false,
  ),
)  
RESPONSE: array (
  'jsonrpc' => '2.0',
  'result' => NULL,
  'id' => 11,
)  

The interesting information is that the last call eth_getBlockByNumber request block 0x282a but the actual last block is 0xb0d. Moreover 0xb0d in decimal is 2829 and if we consider it as a hex 0x2829 + 0x1 = 0x282a.

Versions

  • web3.js: 1.0.0-beta.50
@nivida
Copy link
Contributor

nivida commented Mar 28, 2019

eth_getBlockByNumber gets called for the transaction confirmation workflow to proof that there is really a new block. The ouputTransactionReceipt formatter is using the Utils.hexToNumber() method as it was using it before too.

Did you test it also directly with a real node?

Btw: I wouldn't send my transactions over a centralized point.

@princesinha19
Copy link
Contributor

@nivida yes, you are right. The outputTransactionReceipt fotmatter is using Utils.hexToNumber() method but the method produces incorrect results that was listed in issue #1677.
After that I tested the function utils.hexToNumber(), that was incorrect and then, I modified the code and created a pull request #2586. Please check the pull request.
@tclairet you are right. We need to check it.

@tclairet
Copy link
Author

tclairet commented Mar 29, 2019

I tested with web3.js: 1.0.0-beta.51, I no longer have the error but the I never receive the receipt, it's just hanging for ever.

@nivida
Copy link
Contributor

nivida commented Apr 1, 2019

@tclairet This got already fixed and will be released this week. Thanks for testing it again!

@nivida nivida closed this as completed Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants