aeternity / aeproject

Testing framework for Sophia Smart Contract development.
https://docs.aeternity.com/aeproject
ISC License
28 stars 18 forks source link

`utils.rollbackHeight` rolls back to wrong height #493

Closed marc0olo closed 6 months ago

marc0olo commented 1 year ago

Describe the bug Following testcode:

    // rollback to first keyblock
    await utils.rollbackHeight(aeSdk, 1);
    assert.equal(await aeSdk.getHeight(), 1);

Fails with:

AssertionError: expected 2 to equal 1
      + expected - actual

      -2
      +1

Expected behavior I expect the assertion to pass, currently it fails.

Please tell us about your environment:

thepiwo commented 1 year ago

currently it awaits an extra block as otherwise there are some issues where state is not available immediately after rollback

thepiwo commented 1 year ago

https://github.com/aeternity/aeproject/pull/483/files

thepiwo commented 1 year ago

It will need some additional debugging to know where exactly the need for this workaround is originating

marc0olo commented 1 year ago

ahhh, now I remember we already had some discussion about that 😅

marc0olo commented 1 year ago

I get a consistent behavior (fresh node start + already started node at a later height) in my tests when executing the following code sequence in my tests:

    // rollback to first keyblock
    await utils.rollbackHeight(aeSdk, 0);
    // stupid but strange, opened an issue here: https://github.com/aeternity/aeproject/issues/493
    assert.equal(await aeSdk.getHeight(), 2);

    // activate iris
    await utils.awaitKeyBlocks(aeSdk, 3);
    assert.equal(await aeSdk.getHeight(), 5);
    let nodeInfo = await aeSdk.getNodeInfo();
    assert.equal(nodeInfo.consensusProtocolVersion, 5);

it seems like the node is setting keyblock = 1 when performing the rollback to height 0, given that rollbackHeight in aeproject executes following logic:

export const rollbackHeight = async (aeSdk, height) => {
  const currentBlockHeight = await aeSdk.getHeight();
  if (currentBlockHeight > height) {
    await get(`http://localhost:3001/rollback?height=${height}`);
    await awaitKeyBlocks(aeSdk, 1);
  }
};
thepiwo commented 7 months ago

this still seems to happen, experienced it again, also @hanssv did, using await awaitKeyBlocks(aeSdk, 1); after creating the snapshot seems to help, will investigate as I think the issue is in the underlaying devmode