quorum icon indicating copy to clipboard operation
quorum copied to clipboard

Events emitted in Private Transactions are not present in the transaction receipt logs

Open macro88 opened this issue 8 years ago • 4 comments

System information

Geth version: 1.7.2-stable-0905eda4 (Geth/v1.7.2-stable-0905eda4/linux-amd64/go1.9.2)

OS & Version: Linux Ubuntu 16.04.3 LTS

Branch, Commit Hash or Release: HEAD detached at v2.0.0 nothing to commit, working directory clean

Expected behaviour

Events logged/emitted from a Private transaction are retrieved when recalling the transaction receipt. E.g. eth.getTransactionReceipt(tHash) In relation to the test contract below the expected behaviour is

  • Event is present in the logs when recalling the transaction receipt
  • Callback function called when watching the event
  • invocation is incremented.

Actual behaviour

The logs are empty when recalling the transaction receipt for a Private Contract and Private transaction. The transaction succeeds and state is updated in the contract. In relation to the test contract below the expected behaviour is:

  • [Fail] Event is present in the logs when recalling the transaction receipt
  • [Pass] Callback function called when watching the event
  • [Pass] invocation is incremented.

Summary of testing performed

A test contract EventEmitter.sol was created. This contract is a simple contract that emits and event and increments a counter.

contract EventEmitter {
    event ContractEvent(string payload); 
    uint public invocations; 

    function EventEmitter() { 
    }

    function RaiseEvent(string payload) {
        ContractEvent(payload);
        invocations++;
    } 
}

Tested under Raft and Istanbul consensus and for each solc version 0.3.6, 0.4.8, 0.4.18 (the behaviour below was consistent)

  1. Deploy the contract without privateFor and send transaction without privateFor - this works as expected.
  • [Pass] Event is present in the logs when recalling the transaction receipt
  • [Pass] Callback was called when watching the event in geth
  • [Pass] invocation was incremented.
  1. Deploy the contract with privateFor and send transaction without privateFor - Failed. Occasionally this killed the geth/constellation process of the sender and recipient – this was random and I can’t reliably repro it.
  • [Fail] Event is present in the logs when recalling the transaction receipt
  • [Fail] Callback was not called when watching the event in geth
  • [Fail] invocation was not incremented.
  1. Deploy the contract with privateFor and send transaction with privateFor - Partial success.
  • [Fail] Event is present in the logs when recalling the transaction receipt
  • [Pass] Callback was called when watching the event in geth
  • [Pass] invocation was not incremented.

Steps to reproduce the behaviour

  1. Deploy EventEmitter contract with privateFor
  2. sendTransaction with privateFor for RaiseEvent
  3. eth.getTransactionReceipt(tHash)
  4. The logs are not populated.

Using 7nodes example network run the script node .\7nodeEventTest.js

var Web3 = require('Web3');

const contract_0_3_6 = {
    bytecode: "0x6060604052610126806100126000396000f3606060405260e060020a6000350463884db6978114610026578063bdaaf5fa1461010b575b005b6100246004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050507f28c897b95b6a7b24d70049fbeb434347507a234a61f419e2236f733e85b638008160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156100f25780820380516001836020036101000a031916815260200191505b509250505060405180910390a160008054600101905550565b61011460005481565b60408051918252519081900360200190f3",
    abi: [{ "constant": false, "inputs": [{ "name": "payload", "type": "string" }], "name": "RaiseEvent", "outputs": [], "type": "function" }, { "constant": true, "inputs": [], "name": "invocations", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }, { "inputs": [], "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": false, "name": "payload", "type": "string" }], "name": "ContractEvent", "type": "event" }]
}

const contract_0_4_8 = {
    bytecode: "0x606060405234610000575b5b5b6101888061001b6000396000f300606060405263ffffffff60e060020a600035041663884db697811461002f578063bdaaf5fa14610084575b610000565b3461000057610082600480803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496506100a395505050505050565b005b3461000057610091610156565b60408051918252519081900360200190f35b7f28c897b95b6a7b24d70049fbeb434347507a234a61f419e2236f733e85b63800816040518080602001828103825283818151815260200191508051906020019080838360008314610110575b80518252602083111561011057601f1990920191602091820191016100f0565b505050905090810190601f16801561013c5780820380516001836020036101000a031916815260200191505b509250505060405180910390a16000805460010190555b50565b600054815600a165627a7a7230582066d610e213af2fead6c87a9f245b0e3001874af08f67bfc71aae9bb614a5942f0029",
    abi: [{ "constant": false, "inputs": [{ "name": "payload", "type": "string" }], "name": "RaiseEvent", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "invocations", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "type": "function" }, { "inputs": [], "payable": false, "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": false, "name": "payload", "type": "string" }], "name": "ContractEvent", "type": "event" }]
}

const contract_0_4_18 = {
    bytecode: "0x6060604052341561000f57600080fd5b61019e8061001e6000396000f30060606040526004361061004b5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663884db6978114610050578063bdaaf5fa146100a3575b600080fd5b341561005b57600080fd5b6100a160046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506100c895505050505050565b005b34156100ae57600080fd5b6100b661016c565b60405190815260200160405180910390f35b7f28c897b95b6a7b24d70049fbeb434347507a234a61f419e2236f733e85b638008160405160208082528190810183818151815260200191508051906020019080838360005b8381101561012657808201518382015260200161010e565b50505050905090810190601f1680156101535780820380516001836020036101000a031916815260200191505b509250505060405180910390a150600080546001019055565b600054815600a165627a7a72305820454857ffdad699126e737b3f187848ccc94807cc30cd35dacdb36f8661aeba340029",
    abi: [{ "constant": false, "inputs": [{ "name": "payload", "type": "string" }], "name": "RaiseEvent", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "invocations", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": false, "name": "payload", "type": "string" }], "name": "ContractEvent", "type": "event" }]
}

const versionUnderTest = contract_0_3_6;

const defaultGas = 4700000;
const sender = {
    node: 'http://localhost:22000',
    address: '0xed9d02e382b34818e88b88a309c7fe71e65f419d',
    publicKey: 'BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo='
}
const recipient = {
    node: 'http://localhost:22001',
    address: '0xca843569e3427144cead5e4d5999a3d0ccf92b8e',
    publicKey: 'QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc='
}

let privateFor;
privateFor = [recipient.publicKey]; //comment this line out for public transactions.

var senderWeb3 = new Web3(new Web3.providers.HttpProvider(sender.node));

let contract;
console.log('Test: Deploying contract...');
let deployTx = { data: versionUnderTest.bytecode, from: sender.address, gas: defaultGas };
let eventTx = { from: sender.address, gas: defaultGas };

if (privateFor) {
    deployTx['privateFor'] = privateFor;    
    eventTx['privateFor'] = privateFor;
}

senderWeb3.eth.contract(versionUnderTest.abi).new(deployTx, (err, c) => {
    if (err) {
        console.error("Error deploying contract.");
        console.error(err);
        return;
    } else if (c.address) {
        console.log(`Contract mined. Address ${c.address} transaction hash is ${c.transactionHash}`);
        contract = c;

        
        var senderEvents = contract.allEvents({ fromBlock: 0, toBlock: 'latest' });
        senderEvents.watch((error, event) => {
            if (error) {
                console.error('Error with event: ' + error);
            } else {
                console.log(event);
                console.log('Verifing event...');
                if (event.event === 'ContractEvent') {
                    console.log('[PASS] Callback was called when watching the event');
                } else { 
                    console.log('[FAIL] Callback was called but not with the correct event');
                }

                senderWeb3.eth.getTransactionReceipt(event.transactionHash, (e, r) => {
                    if (e) {
                        console.error('Error getting receipt: ' + e);
                    }
                    else if (!r.logs || !r.logs.length) {
                        console.error('[FAIL] Event is NOT present in the logs when recalling the transaction receipt');
                    }
                    else {
                        console.log('[PASS]: Event is present in the logs when recalling the transaction receipt');
                    }
                
                    var invoked = contract.invocations();
                    if (invoked != 1) {
                        console.log('[FAIL]: invocations should equal 1 but was ' + invoked);
                    }
                    else {
                        console.log('[PASS]: invocations should equal 1 and was ' + invoked);
                    }

                    senderEvents.stopWatching();
                });
            }    
        });

        contract.RaiseEvent.sendTransaction('Event Contract Tran Test ' + new Date(), eventTx );
    }
});

Backtrace

Private Transactions

Test: Deploying contract...
Contract mined. Address 0x3950943d8d86267c04a4bba804f9f0b8a01c2fb8 transaction hash is 0xcaa0a644a72660b97e82db86fc6c7ca1bc6973a228d766787e97daa349d4edc3
{ address: '0x3950943d8d86267c04a4bba804f9f0b8a01c2fb8',
  blockNumber: 11,
  transactionHash: '0x3f541b743edeec6c61efa37ad11267522764d56f979737eb6d921e4f11e58255',
  transactionIndex: 0,
  blockHash: '0x1d6184bac09dda6e0c1ca3be23c9a48b6d19ce5694d92f9f189342ed99d354d7',
  logIndex: 0,
  removed: false,
  event: 'ContractEvent',
  args: { payload: 'Event Contract Tran Test Thu Jan 11 2018 10:20:46 GMT+1100 (AUS Eastern Daylight Time)' } }
Verifing event...
[PASS] Callback was called when watching the event
[FAIL] Event is NOT present in the logs when recalling the transaction receipt
[PASS]: invocations should equal 1 and was 1

Public Transactions

Test: Deploying contract...
Contract mined. Address 0xe62a84ad37f45ad4cb238192bb996ddc1afcb69a transaction hash is 0xe5e0d1aa5cce71d2b0050b491a200d8d36efd48654752119c41e8d43910ca820
{ address: '0xe62a84ad37f45ad4cb238192bb996ddc1afcb69a',
  blockNumber: 16,
  transactionHash: '0x48d39a9f64804a4cc1c0a8ad0d4f3eee57e8032fe27ddf5e565da1979c4e4554',
  transactionIndex: 0,
  blockHash: '0x9c60adbaeaaf99d0a1907f2415684f1590701d84e8fb432fe9874b778e6edfcc',
  logIndex: 0,
  removed: false,
  event: 'ContractEvent',
  args: { payload: 'Event Contract Tran Test Thu Jan 11 2018 10:24:47 GMT+1100 (AUS Eastern Daylight Time)' } }
Verifing event...
[PASS] Callback was called when watching the event
[PASS]: Event is present in the logs when recalling the transaction receipt
[PASS]: invocations should equal 1 and was 1

macro88 avatar Jan 10 '18 23:01 macro88

This may be a regression.

patrickmn avatar Jan 25 '18 16:01 patrickmn

This should now be fixed

patrickmn avatar Feb 15 '18 22:02 patrickmn

Hi,

Is this issue resolved? While testing logs and Events for private transactions, I deployed a simplestorage contract on latest Quorum 2.0.2. While the contract is deployed successfully when I do not use privatefor; with privateFor, I get the following error:

Error: Non-200 status code: &{Status:400 Bad Request StatusCode:400 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Date:[Thu, 19 Apr 2018 12:57:10 GMT] Server:[Warp/3.2.13]] Body:0xc42216c600 ContentLength:-1 TransferEncoding:[chunked] Close:false Uncompressed:false Trailer:map[] Request:0xc434db4100 TLS:} undefined

instance: Geth/v1.7.2-stable-df4267a2/linux-amd64/go1.9.4 coinbase: 0xed9d02e382b34818e88b88a309c7fe71e65f419d at block: 1 (Sun, 24 Nov 48289492216 16:02:55 EST) datadir: /root/temp1/quorum-examples/examples/5nodesRTGS/qdata/dd1 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 raft:1.0 rpc:1.0 txpool:1.0 web3:1.0

var initVal = 1234 ; undefined var simplestorageContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]); undefined var simplestorage = simplestorageContract.new( ... initVal, ... { ...... from: web3.eth.accounts[0], ...... data: '0x6060604052341561000f57600080fd5b60405160208061014b833981016040528080519060200190919050508060008190555050610109806100426000396000f3006060604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605857806360fe47b114607e5780636d4ce63c14609e575b600080fd5b3415606257600080fd5b606860c4565b6040518082815260200191505060405180910390f35b3415608857600080fd5b609c600480803590602001909190505060ca565b005b341560a857600080fd5b60ae60d4565b6040518082815260200191505060405180910390f35b60005481565b8060008190555050565b600080549050905600a165627a7a7230582041f2dfdd0c581877d6c0485d2c4aa07f5db826f1d2c997bfe096f963e4f0e11c0029', ...... gas: '4700000' ...... }, function (e, contract){ ...... console.log(e, contract); ...... if (typeof contract.address !== 'undefined') { ......... console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); ......... } ...... }) null [object Object] undefined null [object Object] Contract mined! address: 0x1349f3e1b8d71effb47b840594ff27da7e603d17 transactionHash: 0xfa88deec4d97b275b26735772268418a95fa66746baa9d4226b3750afb189f90

var initVal = 1234 ; undefined var simplestorageContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]); undefined

var simplestorage = simplestorageContract.new( ... initVal, ... { ...... from: web3.eth.accounts[0], ...... data: '0x6060604052341561000f57600080fd5b60405160208061014b833981016040528080519060200190919050508060008190555050610109806100426000396000f3006060604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605857806360fe47b114607e5780636d4ce63c14609e575b600080fd5b3415606257600080fd5b606860c4565b6040518082815260200191505060405180910390f35b3415608857600080fd5b609c600480803590602001909190505060ca565b005b341560a857600080fd5b60ae60d4565b6040518082815260200191505060405180910390f35b60005481565b8060008190555050565b600080549050905600a165627a7a7230582041f2dfdd0c581877d6c0485d2c4aa07f5db826f1d2c997bfe096f963e4f0e11c0029', ...... gas: '4700000',privateFor:["oNspPPgszVUFw0qmGFfWwh1uxVUXgvBxleXORHj07g8="] ...... }, function (e, contract){ ...... console.log(e, contract); ...... if (typeof contract.address !== 'undefined') { ......... console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); ......... } ...... }) Error: Non-200 status code: &{Status:400 Bad Request StatusCode:400 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Date:[Thu, 19 Apr 2018 12:57:10 GMT] Server:[Warp/3.2.13]] Body:0xc42216c600 ContentLength:-1 TransferEncoding:[chunked] Close:false Uncompressed:false Trailer:map[] Request:0xc434db4100 TLS:} undefined

TFPoC avatar Apr 19 '18 13:04 TFPoC

does anybody know a work around ?

Sh0g0-1758 avatar Jul 04 '23 16:07 Sh0g0-1758