ventureum / VUI

Ventureum User Interface
MIT License
0 stars 0 forks source link

Showing commit stage is active after commit stage's deadline for challengers #60

Closed timothywangdev closed 6 years ago

timothywangdev commented 6 years ago

how to reproduce the problem:

  1. Challenge a project using address A
  2. Commit in the challenge with address A
  3. Wait till commit stage expires
  4. Refresh page
  5. Still shows "Commit" even though we are at reveal stage
  6. Switch to a different address B
  7. Refresh page
  8. Shows "Reveal" correctly
  9. Switch back to address A
  10. Refresh page
  11. Shows "Commit"
timothywangdev commented 6 years ago

Cannot reproduce the problem in VTCR using the following script:

truffle migrate --reset

then

var Registry = artifacts.require("Registry");
var PLCRVoting = artifacts.require("PLCRVoting");
var Sale = artifacts.require("Sale");
var Token = artifacts.require("Token");
var sleep = require('sleep');
web3.eth.getAccountsPromise = function () {
    return new Promise(function (resolve, reject) {
        web3.eth.getAccounts(function (e, accounts) {
            if (e != null) {
                reject(e);
            } else {
                resolve(accounts);
            }
        });
    });
};

module.exports = async function(callback) {
    var accounts = await web3.eth.getAccountsPromise();
    console.log(accounts);
    var registry = await Registry.deployed();
    var sale = await Sale.deployed();
    var tokenAddr = await sale.token.call();
    var token = await Token.at(tokenAddr);;
    var plcrAddr = await registry.voting.call();
    var plcr = PLCRVoting.at(plcrAddr);

    // 500000 for apply, 500000 for challenge
    await token.approve(registry.address, 1000000, {from: accounts[0]});
    await registry.apply("test1", 500000, {from: accounts[0]});

    var rv = await registry.challenge("test1", {from: accounts[0]});
    var pollid = rv.logs[0].args.pollID.c[0];
    console.log(pollid);

    var tt = await plcr.commitStageActive.call(pollid, {from: accounts[0]});
    console.log(tt);
    sleep.sleep(12);
    tt = await plcr.commitStageActive.call(pollid, {from: accounts[0]});
    console.log(tt);
}

Make sure to use 10 seconds as "commitStageLength" in conf/config.json:

{
    "paramDefaults": {
        "minDeposit": 500000,
        "pMinDeposit": 500000,
        "applyStageLength": 600,
        "pApplyStageLength": 1200,
        "commitStageLength": 10,
        "pCommitStageLength": 1200,
        "revealStageLength": 10,
        "pRevealStageLength": 1200,
        "dispensationPct": 50,
        "pDispensationPct": 50,
        "voteQuorum": 50,
        "pVoteQuorum": 50
    },
    "TokenAddress": "0x337cDDa6D41A327c5ad456166CCB781a9722AFf9"
}

output:

# truffle exec test.js
Using network 'development'.

[ '0x959fd7ef9089b7142b6b908dc3a8af7aa8ff0fa1',
  '0x4e90a36b45879f5bae71b57ad525e817afa54890',
  '0xb6a8490101a0521677b66866b8052ee9f9975c17',
  '0xb0201641d9b936eb20155a38439ae6ab07d85fbd',
  '0x301e1528bad61177ef8ff89bd4ad6760581e5409',
  '0x453460d66ebde5f888f999255f9291f1caa83e5b',
  '0x21a0fad034cc95891006e0687892c3434c59521d',
  '0x53af25e00ef5a4a9b0f4c2431bd07a2d18ed5b8b',
  '0xb73614389f815b78217052984d5561bad52a420a',
  '0x35e13c4870077f4610b74f23e887cbb10e21c19f' ]
1
true
false
timothywangdev commented 6 years ago

from the ganache log, for subsequent refreshes, plcr contract calls were not shown. Maybe truffle contract uses cache?

timothywangdev commented 6 years ago

current workaround is to connect Metamask to an other network then reconnect to localhost. Metamask seems to be using cached data.

timothywangdev commented 6 years ago

https://github.com/MetaMask/metamask-extension/issues/3439

timothywangdev commented 6 years ago

https://github.com/MetaMask/metamask-extension/issues/3088

timothywangdev commented 6 years ago

Metamask looks for chain state changes for eth_call, if not changed, then use the cached return value of the last eth_call, if available. This is problematic for time-dependent contract functions, whose return value depends on time relapse, during which chain state may not change, which causes metamask using the old cached incorrect return values.

Solution In Ganache, disable automine, set block time to a few seconds. This ensures the chain stage changes after every block_time, so that metamask will exec a fresh eth_call instead of returning cached values.

Caution Currently, there's an blocktime bug in ganache-cli 6.1.0 see https://github.com/trufflesuite/ganache-cli/issues/506

Please use Ganache gui or the forked ganache-cli

Closed for now.