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

Sometimes lose array items #423

Closed
romanov-alex opened this issue Nov 11, 2017 · 7 comments
Closed

Sometimes lose array items #423

romanov-alex opened this issue Nov 11, 2017 · 7 comments

Comments

@romanov-alex
Copy link

romanov-alex commented Nov 11, 2017

I have found strange problem in my smart contract. I use testrpc (v4.1.3) and last MetaMask as local dev environment. Please, see code below (it is short version, just place with problem):

struct PayRecord {
    address sender;
    uint256 sum;
    uint256 blockNumber;
    uint256 status;
}

event PaymentPlaced(address senderAddress, uint256 blockNumber, uint256 payIndex, string guid);

PayRecord[] public payments;

function payForSomething(string guid) payable {
    uint256 newLength = payments.push(PayRecord(msg.sender, msg.value, block.number, 0));
    PaymentPlaced(msg.sender, block.number, newLength-1, guid);
}

function changeSomething(uint256 paymentIndex) {
    if(payments[paymentIndex].status == 0){
        payments[paymentIndex].status == 1;
    }
}

Often everything works fine:

  1. user calls function payForSomething()
  2. user gets event PaymentPlaced in browser
  3. user calls changeSomething()

but...

SOMETIMES I have next problem:

  1. user calls payForSomething()
  2. user gets event PaymentPlaced (for example: blockNumber = 10, payIndex = 5).
  3. user calls changeSomething() - and gets error "invalid opcode"
  4. if user calls payForSomething() again - he gets event PaymentPlaced with data (blockNumber == 15, payIndex = 5)

The same array length, different block numbers, two insertion events...

So...Sometimes it happens, sometimes everything works fine. I always have only one user, only I works with this smart-contract (I'm still developing it).

Why do I lose items from array? Is it problem in testrpc or something else?

@romanov-alex
Copy link
Author

Is this too complicated - or too stupid question?

@benjamincburns
Copy link
Contributor

@romanov-alex I think this is expected behaviour. Likely what is happening is the user is calling changeSomething with an invalid argument, or with a low gas value, and this is triggering a REVERT. However, the REVERT opcode came as part of our update for Byzantium support, which is available in the latest version of TestRPC.

Please reopen if you think I've got something wrong here or if this is happening when valid input is supplied to changeSomething.

@benjamincburns
Copy link
Contributor

Ah, I think I missed the part where payIndex was the same both times.

@romanov-alex I'll see what I can do - at the moment this feels like a duplicate of #403, but I'm not 100% certain. I'm troubleshooting that one at the moment - will come back to this and see if the fix for that fixes this one.

@benjamincburns
Copy link
Contributor

@romanov-alex are you using interval mining by any chance?

@romanov-alex
Copy link
Author

@benjamincburns "interval mining" - are you about —blocktime flag? I always use auto-mining. I call functions manually from web interface. When I tested it I called about every 20-40 seconds. And there were calls to another contract (every 5 second).

Most important things for me: is it problem with testrpc or not? I mean...will I get the same problem in real ethereum network?

@romanov-alex
Copy link
Author

Anybody...
Most important things for me: is it problem with testrpc or not? I mean...will I get the same problem in real ethereum network?

@ccowell
Copy link

ccowell commented Nov 6, 2018

Thanks @romanov-alex for reporting this issue. We tested the contract code snippet and was unable to reproduce the bug where payIndex was not updated. Using the latest version of Ganache and Solidity should fix it.

@ccowell ccowell closed this as completed Nov 6, 2018
@ccowell ccowell reopened this Nov 7, 2018
ccowell referenced this issue in trufflesuite/ganache Nov 14, 2018
Updated shrinkwrap
Cleaned up some helper modules to match issue-678 branch
Updated module references in test
ccowell referenced this issue in trufflesuite/ganache Feb 13, 2019
Merge branch 'develop' into issue-423
@ccowell ccowell closed this as completed Feb 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants