diff --git a/orchestrator/orchestrator/src/oracle_resync.rs b/orchestrator/orchestrator/src/oracle_resync.rs index 5ea518256..3b27b124d 100644 --- a/orchestrator/orchestrator/src/oracle_resync.rs +++ b/orchestrator/orchestrator/src/oracle_resync.rs @@ -169,11 +169,11 @@ pub async fn get_last_checked_block( // no other events can come before it, therefore either there's been a parsing error // or no events have been submitted on this chain yet. if valset.valset_nonce == 0 && last_event_nonce == 1u8.into() { - return latest_block; + return event.block_number.unwrap(); } // if we're looking for a later event nonce and we find the deployment of the contract // we must have failed to parse the event we're looking for. The oracle can not start - if valset.valset_nonce == 0 && last_event_nonce > 1u8.into() { + else if valset.valset_nonce == 0 && last_event_nonce > 1u8.into() { panic!("Could not find the last event relayed by {}, Last Event nonce is {} but no event matching that could be found!", our_cosmos_address, last_event_nonce) } } @@ -183,6 +183,8 @@ pub async fn get_last_checked_block( current_block = end_search; } + // we should exit above when we find the zero valset, if we have the wrong contract address through we could be at it a while as we go over + // the entire history to 'prove' it. panic!("You have reached the end of block history without finding the Gravity contract deploy event! You must have the wrong contract address!"); } diff --git a/solidity/contracts/Gravity.sol b/solidity/contracts/Gravity.sol index 64509c8fe..f000be684 100644 --- a/solidity/contracts/Gravity.sol +++ b/solidity/contracts/Gravity.sol @@ -35,7 +35,9 @@ contract Gravity is ReentrancyGuard { mapping(address => uint256) public state_lastBatchNonces; mapping(bytes32 => uint256) public state_invalidationMapping; uint256 public state_lastValsetNonce = 0; - uint256 public state_lastEventNonce = 0; + // event nonce zero is reserved by the Cosmos module as a special + // value indicating that no events have yet been submitted + uint256 public state_lastEventNonce = 1; // These are set once at initialization bytes32 public state_gravityId; diff --git a/solidity/test/deployERC20.ts b/solidity/test/deployERC20.ts index 75320833e..d28b0de6d 100644 --- a/solidity/test/deployERC20.ts +++ b/solidity/test/deployERC20.ts @@ -63,7 +63,7 @@ async function runTest(opts: {}) { _name: 'Atom', _symbol: 'ATOM', _decimals: 6, - _eventNonce: BigNumber.from(1) + _eventNonce: BigNumber.from(2) }) diff --git a/solidity/test/sendToCosmos.ts b/solidity/test/sendToCosmos.ts index 3ff46c880..8be707fe2 100644 --- a/solidity/test/sendToCosmos.ts +++ b/solidity/test/sendToCosmos.ts @@ -45,11 +45,11 @@ async function runTest(opts: {}) { await signers[0].getAddress(), ethers.utils.formatBytes32String("myCosmosAddress"), 1000, - 1 + 2 ); expect((await testERC20.functions.balanceOf(gravity.address))[0]).to.equal(1000); - expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(1); + expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(2); @@ -65,11 +65,11 @@ async function runTest(opts: {}) { await signers[0].getAddress(), ethers.utils.formatBytes32String("myCosmosAddress"), 1000, - 2 + 3 ); expect((await testERC20.functions.balanceOf(gravity.address))[0]).to.equal(2000); - expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(2); + expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(3); } describe("sendToCosmos tests", function () {