Skip to content

Commit

Permalink
Fix game SM error causing infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Nov 12, 2023
1 parent 61bd775 commit 9427cc5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
4 changes: 1 addition & 3 deletions packages/contracts/nft/src/dev/NativeNftSaleUpgradeDev.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import "../NativeNftSale.sol";
import "./UpgradeDev.sol";

/// @dev For testing upgradeability.
contract NativeNftSaleUpgradeDev is UpgradeDev, NativeNftSale {

}
contract NativeNftSaleUpgradeDev is UpgradeDev, NativeNftSale {}
54 changes: 32 additions & 22 deletions packages/engine/paima-sm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const SM: GameStateMachineInitializer = {
const seed = await getSeed(latestChainData, dbTx);
await saveLastBlockHeight.run(
{ block_height: latestChainData.blockNumber, seed: seed },
DBConn
dbTx
);
// Generate Prando object
const randomnessGenerator = new Prando(seed);
Expand All @@ -138,29 +138,39 @@ const SM: GameStateMachineInitializer = {
dbTx
);

// Fetch and execute scheduled input data
const scheduledInputsLength = await processScheduledData(
latestChainData,
dbTx,
gameStateTransition,
randomnessGenerator
);

// Execute user submitted input data
const userInputsLength = await processUserInputs(
latestChainData,
dbTx,
gameStateTransition,
randomnessGenerator
);
const checkpointName = `game_sm_start`;
await dbTx.query(`SAVEPOINT ${checkpointName}`);
try {
// Fetch and execute scheduled input data
const scheduledInputsLength = await processScheduledData(
latestChainData,
dbTx,
gameStateTransition,
randomnessGenerator
);

// Extra logging
if (cdeDataLength + userInputsLength + scheduledInputsLength > 0)
doLog(
`Processed ${userInputsLength} user inputs, ${scheduledInputsLength} scheduled inputs and ${cdeDataLength} CDE events in block #${latestChainData.blockNumber}`
// Execute user submitted input data
const userInputsLength = await processUserInputs(
latestChainData,
dbTx,
gameStateTransition,
randomnessGenerator
);
// Commit finishing of processing to DB
await blockHeightDone.run({ block_height: latestChainData.blockNumber }, dbTx);

// Extra logging
if (cdeDataLength + userInputsLength + scheduledInputsLength > 0)
doLog(
`Processed ${userInputsLength} user inputs, ${scheduledInputsLength} scheduled inputs and ${cdeDataLength} CDE events in block #${latestChainData.blockNumber}`
);
} catch (e) {
await dbTx.query(`ROLLBACK TO SAVEPOINT ${checkpointName}`);
throw e;
} finally {
await dbTx.query(`RELEASE SAVEPOINT ${checkpointName}`);

// Commit finishing of processing to DB
await blockHeightDone.run({ block_height: latestChainData.blockNumber }, dbTx);
}
},
};
},
Expand Down

0 comments on commit 9427cc5

Please sign in to comment.