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

web3.eth.currentProvider.send() Hangs, Missing Data when Iterating through 'Transaction Traces' in a Local Parity Archive Node #3193

Closed
ymonye opened this issue Nov 10, 2019 · 3 comments
Labels
1.x 1.0 related issues Needs Clarification Requires additional input

Comments

@ymonye
Copy link
Contributor

ymonye commented Nov 10, 2019

web3.eth.currentProvider.send() Hangs, Missing Data when Iterating through 'Transaction Traces' in a Local Parity Archive Node

Versions

  • OS: Ubuntu 18.04.2 LTS
  • web3.js: v1.2.2
  • Node.js: v10.17.0
  • Ethereum Node: Parity v2.6.4-beta

Expected behavior

Hi, I'm using web3js to iterate through 'Transaction Traces' in a local Parity archive node, specifically the web3.eth.currentProvider.send() function, while passing the correct "trace_transaction" parameters via JSONRPC to Parity. The end goal is to record & index contract calls to a DB. Somewhere in my code, the web3.eth.currentProvider.send() functions are not passing through, and as a result I'm seeing a fraction of Contract Calls in each block instead of 100% of the data.

At first I'd though there was a communication issue between web3js & the local Parity node, so I then simplified the code to only call the web3.eth.currentProvider.send() function twice.

Below is what I expected to see in console:

Transaction Trace #1

transactionHash 0x4142d213b4de56d872b26f9f1955f75bc8d9bd32bdfdb85bbf13455b8dcbd6db
blockNumber: 4754946
addrFrom: 0x8d12a197cb00d4747a1fe03395095ce2a5cc6819
addrTo: 0x9b7e2697d1a213fc00162f7b453b64347186d367
value: 5.9

Transaction Trace #2

transactionHash 0x83c14a4199095e293b81f0ee58f1212dde6f74f577ba52344ad6c3b0d6dff29a
blockNumber: 4754946
addrFrom: 0x8d12a197cb00d4747a1fe03395095ce2a5cc6819
addrTo: 0xea860b5328218a238834bcecd613bb81ec29dccd
value: 3

Actual behavior

Only one of the Transaction Traces is showing up in console. However if I were to comment out the 2nd web3.eth.currentProvider.send() function, I'm able to see the results from the 1st function, and the same applies when commenting out the 1st function: I'll be able to see the 2nd.

Is there a proper method of calling web3.eth.currentProvider.send() to display both functions? This becomes a bigger problem if, let's say, I ran everything in a loop from for ex: Blocks '7 million' through '8 million', as not all contract calls will properly show. Or perhaps am I better off passing the JSON parameters outside of web3.eth.currentProvider.send() via a 3rd party CURL command or another method within Node.js, then storing the data from there?

Steps to reproduce the behavior

Below is the code to reproduce everything, assuming you're running a local Parity archive node. Just change '/parity/mainnet/jsonrpc.ipc' to your proper IPC path.

Here are the commands I'm using for my local Parity node with Tracing enabled, which'll allow me to access Parity's debug functions of iterating through contract calls:

parity --pruning=archive --tracing=on --fat-db=on --db-path=/parity/mainnet --ipc-path=/parity/mainnet/jsonrpc.ipc

Node.js Code:

const net = require('net');
const Web3 = require('web3');
const web3 = new Web3('/parity/mainnet/jsonrpc.ipc', net);

console.log('Transaction Trace #1\n');

web3.eth.currentProvider.send({
    method: "trace_transaction",
    params: ['0x4142d213b4de56d872b26f9f1955f75bc8d9bd32bdfdb85bbf13455b8dcbd6db'],
    id: "2",
    jsonrpc: "2.0"
}, function (err, result) {
    if (err) throw err;
    if (result.result.length > 1) {
        if (result.result[0].type == 'call') {
            for (let i = 1; i < result.result.length; i++) {
               
                if (result.result[i].type == 'call') {
                    var addrFrom = result.result[i].action.from
                    var addrTo = result.result[i].action.to
                    var value = web3.utils.fromWei(result.result[i].action.value,'ether');

		    console.log('transactionHash', result.result[i].transactionHash);
		    console.log('blockNumber:', result.result[i].blockNumber);
		    console.log('addrFrom:', addrFrom);
		    console.log('addrTo:', addrTo);
		    console.log('value:', value);
		    console.log('\n');
                }     
            }
        }
    };
});

console.log('Transaction Trace #2\n');

web3.eth.currentProvider.send({
    method: "trace_transaction",
    params: ['0x83c14a4199095e293b81f0ee58f1212dde6f74f577ba52344ad6c3b0d6dff29a'],
    id: "2",
    jsonrpc: "2.0"
}, function (err, result) {
    if (err) throw err;
    if (result.result.length > 1) {
        if (result.result[0].type == 'call') {
            for (let i = 1; i < result.result.length; i++) {
               
                if (result.result[i].type == 'call') {
                    var addrFrom = result.result[i].action.from
                    var addrTo = result.result[i].action.to
                    var value = web3.utils.fromWei(result.result[i].action.value,'ether');

		    console.log('transactionHash', result.result[i].transactionHash);
		    console.log('blockNumber:', result.result[i].blockNumber);
		    console.log('addrFrom:', addrFrom);
		    console.log('addrTo:', addrTo);
		    console.log('value:', value);
		    console.log('\n');
                }     
            }
        }
    };
});
@nivida
Copy link
Contributor

nivida commented Nov 11, 2019

Thanks for opening this issue! We will check this closer as soon as possible.

@nivida nivida added 1.x 1.0 related issues Needs Clarification Requires additional input labels Nov 11, 2019
@ymonye
Copy link
Contributor Author

ymonye commented Nov 11, 2019

Hey @nivida, I think I figured out my issue. It has more to do with my lack of understanding how POST requests work, as the "id" tag has to be unique with each interaction. Thankfully I can just fill this out with the 'transactionHash' variable & pass that value into a new function for each transaction call.

const net = require('net');
const Web3 = require('web3');
const web3 = new Web3('/parity/mainnet/jsonrpc.ipc', net);

console.log('Transaction Trace #1\n');
getTransactionTrace(0x4142d213b4de56d872b26f9f1955f75bc8d9bd32bdfdb85bbf13455b8dcbd6db);

console.log('Transaction Trace #2\n');
getTransactionTrace(0x83c14a4199095e293b81f0ee58f1212dde6f74f577ba52344ad6c3b0d6dff29a);

function getTransactionTrace(transactionHash) {
    web3.eth.currentProvider.send({
        method: "trace_transaction",
        params: [transactionHash],
        id: transactionHash,
        jsonrpc: "2.0"
    }, function (err, result) {
        if (err) throw err;
        if (result.result.length > 1) {
            if (result.result[0].type == 'call') {
                for (let i = 1; i < result.result.length; i++) {
                
                    if (result.result[i].type == 'call') {
                        var addrFrom = result.result[i].action.from
                        var addrTo = result.result[i].action.to
                        var value = web3.utils.fromWei(result.result[i].action.value,'ether');

                console.log('transactionHash', result.result[i].transactionHash);
                console.log('blockNumber:', result.result[i].blockNumber);
                console.log('addrFrom:', addrFrom);
                console.log('addrTo:', addrTo);
                console.log('value:', value);
                console.log('\n');
                    }     
                }
            }
        };
    });
};

@ymonye
Copy link
Contributor Author

ymonye commented Nov 15, 2019

Yep, confirmed working now

@ymonye ymonye closed this as completed Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Needs Clarification Requires additional input
Projects
None yet
Development

No branches or pull requests

3 participants
@nivida @ymonye and others