Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

infinite event loop #56

Closed
JMLX42 opened this issue Apr 3, 2016 · 8 comments
Closed

infinite event loop #56

JMLX42 opened this issue Apr 3, 2016 · 8 comments

Comments

@JMLX42
Copy link

JMLX42 commented Apr 3, 2016

I get this error with testrpc:

"Error: Error: sender doesn't have enough funds to send tx. The upfront cost is: 19999980000000000 and the senders account only has: 19218460000000000
    at runCall (/usr/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/lib/runTx.js:93:10)
    at /usr/lib/node_modules/ethereumjs-testrpc/node_modules/async/lib/async.js:718:13
    at Immediate.iterate [as _onImmediate] (/usr/lib/node_modules/ethereumjs-testrpc/node_modules/async/lib/async.js:262:13)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

First of all, I don't get this error with geth.
But also after this error, an event which is supposed to be emitted at the very end of the smart contract function is emitted in a infinite loop:

{"name":"ballot-queue-worker","hostname":"local.cocorico.cc-local","pid":6571,"level":30,"balance":"19218460000000000","event":{"logIndex":0,"transactionIndex":0,"transactionHash":"0x966daa499879fe93a1c8c43cdb69dec5843166c47f3088d5af76fbb0c4f845c7","blockHash":"0xd6701b9c7eacb014cb2374012b22297e417ea83ae50844fdc0b75982db06d41c","blockNumber":7,"address":"0x01cf04804565c1f45aec92cf94a2a78e239aa231","type":"mined","event":"Ballot","args":{"voter":"0xb4d0b2358bd40fabd1d260eee60871e4c0c0e176","proposal":"0"}},"msg":"ballot event","time":"2016-04-03T20:33:07.479Z","v":0}
{"name":"ballot-queue-worker","hostname":"local.cocorico.cc-local","pid":6571,"level":30,"balance":"19218460000000000","event":{"logIndex":0,"transactionIndex":0,"transactionHash":"0x966daa499879fe93a1c8c43cdb69dec5843166c47f3088d5af76fbb0c4f845c7","blockHash":"0xd6701b9c7eacb014cb2374012b22297e417ea83ae50844fdc0b75982db06d41c","blockNumber":7,"address":"0x01cf04804565c1f45aec92cf94a2a78e239aa231","type":"mined","event":"Ballot","args":{"voter":"0xb4d0b2358bd40fabd1d260eee60871e4c0c0e176","proposal":"0"}},"msg":"ballot event","time":"2016-04-03T20:33:07.653Z","v":0}
{"name":"ballot-queue-worker","hostname":"local.cocorico.cc-local","pid":6571,"level":30,"balance":"19218460000000000","event":{"logIndex":0,"transactionIndex":0,"transactionHash":"0x966daa499879fe93a1c8c43cdb69dec5843166c47f3088d5af76fbb0c4f845c7","blockHash":"0xd6701b9c7eacb014cb2374012b22297e417ea83ae50844fdc0b75982db06d41c","blockNumber":7,"address":"0x01cf04804565c1f45aec92cf94a2a78e239aa231","type":"mined","event":"Ballot","args":{"voter":"0xb4d0b2358bd40fabd1d260eee60871e4c0c0e176","proposal":"0"}},"msg":"ballot event","time":"2016-04-03T20:33:07.837Z","v":0}
{"name":"ballot-queue-worker","hostname":"local.cocorico.cc-local","pid":6571,"level":30,"balance":"19218460000000000","event":{"logIndex":0,"transactionIndex":0,"transactionHash":"0x966daa499879fe93a1c8c43cdb69dec5843166c47f3088d5af76fbb0c4f845c7","blockHash":"0xd6701b9c7eacb014cb2374012b22297e417ea83ae50844fdc0b75982db06d41c","blockNumber":7,"address":"0x01cf04804565c1f45aec92cf94a2a78e239aa231","type":"mined","event":"Ballot","args":{"voter":"0xb4d0b2358bd40fabd1d260eee60871e4c0c0e176","proposal":"0"}},"msg":"ballot event","time":"2016-04-03T20:33:08.118Z","v":0}
...

Since the transaction cannot occur, it would be surprisingly to have this event emitted even once.
But here it's emitted in a loop.

Any idea what's wrong?

Thank you !

@JMLX42
Copy link
Author

JMLX42 commented Apr 3, 2016

Calling event.stopWatching() when I get the event I want solves the issue.
Still, that's a weird behavior and it doesn't happen with geth so I think it's worth investigating.

@tcoulter
Copy link
Contributor

tcoulter commented Apr 3, 2016

First, it's hard to debug when I can't see the code that makes the
transactions, nor the contract code itself.

Second, that error means there's not enough Ether in the address you're
sending from.

I don't have enough information to start debugging, or to assume it isn't
an error on your end. You'll have to provide that before I can do anything
further.
On Apr 3, 2016 1:44 PM, "Jean-Marc Le Roux" notifications@github.com
wrote:

Calling event.stopWatching() when I get the event I want solves the issue.
Still, that's a weird behavior and it doesn't happen with geth so I think
it's worth investigating.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#56 (comment)

@JMLX42
Copy link
Author

JMLX42 commented Apr 3, 2016

Second, that error means there's not enough Ether in the address you're
sending from.

I know that. But why does it happen with testrpc and not geth?

Here is the contract:

contract Vote {

    event Ballot (
        address indexed voter,
        uint8 proposal
    );

    event VoterRegistered (
        address indexed voter
    );

    event VoteError (
        address indexed user,
        string message
    );

    struct Voter {
        bool registered;
        bool voted;
        uint8 vote;
    }
    struct Proposal {
        uint voteCount;
    }

    address chairperson;
    mapping(address => Voter) voters;
    Proposal[] proposals;

    // Create a new ballot with $(_numProposals) different proposals.
    function Vote(uint8 _numProposals) {
        chairperson = msg.sender;
        proposals.length = _numProposals;
    }

    modifier onlyChairPerson() {
        if (msg.sender != chairperson)
            throw;
        _
    }

    modifier onlyRegisteredVoter() {
        Voter voter = voters[msg.sender];

        if (voter.voted || !voter.registered)
            throw;
        _
    }

    function registerVoter(address voterAddress) onlyChairPerson {
        Voter voter = voters[voterAddress];

        if (voter.voted || voter.registered)
            throw;

        voter.registered = true;

        VoterRegistered(voterAddress);
    }

    // Give a single vote to proposal $(proposal).
    function vote(uint8 proposal) onlyRegisteredVoter {
        Voter voter = voters[msg.sender];

        if (proposal >= proposals.length)
            return; // FIXME: emit a BallotError event

        voter.voted = true;
        voter.vote = proposal;
        proposals[proposal].voteCount += 1;

        Ballot(msg.sender, proposal);
    }

    function winningProposal() constant returns (uint8 winningProposal) {
        uint256 winningVoteCount = 0;
        for (uint8 proposal = 0; proposal < proposals.length; proposal++)
            if (proposals[proposal].voteCount > winningVoteCount) {
                winningVoteCount = proposals[proposal].voteCount;
                winningProposal = proposal;
            }
    }

    /* This unnamed function is called whenever someone tries to send ether to it */
    function () {
        throw; // Prevents accidental sending of ether
    }
}

@v1v2r0b8
Copy link

v1v2r0b8 commented Apr 4, 2016

Here is infinite event emitting loop issue in the very simple situation: http://ethereum.stackexchange.com/questions/2614/event-watch-gets-fired-infinitely-many-times

UPD I tried the very same script with geth and it worked properly, so it is probably a testrpc issue.

@lastperson
Copy link

Hi, just stumble upon the same problem, but bug is not that the event got emitted infinitely, bug is that after calling eth_getFilterChanges testrpc reports the events, and forgets that it reported it for current block, so when the next eth_getFilterChanges happens, testrpc reports the same events again, and again, infinitely, until the new transaction(block) happens, then it starts reporting the event from new latest block endlessly.
@tcoulter hope this helps.

@tcoulter
Copy link
Contributor

@kumavis @FlySwatter Have you seen this?

@kumavis
Copy link
Contributor

kumavis commented Apr 12, 2016

i have seen this before MetaMask/web3-provider-engine#55
I can investigate

@tcoulter
Copy link
Contributor

Fixed and published in v2.0.3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants