Skip to content

Commit

Permalink
clear out storage each time, improve logging in script
Browse files Browse the repository at this point in the history
  • Loading branch information
geoknee committed Nov 7, 2024
1 parent 7fee788 commit af0af7b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
48 changes: 30 additions & 18 deletions script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,48 @@ async function main() {

// call entrypoint
const interopPoW = new ethers.Contract(interopPoWAddress, interopPoWContractArtifact.abi, wallet0)
// const tx = await interopPoW.run(workerAddress, [11473209, 21473209]) // launch everything
const tx = await interopPoW.run(workerAddress, [21473209]) // launch only on the remote chain. the xdm does not allow sending to your own chain
const tx = await interopPoW.run(workerAddress, [11473209, 21473209], {
gasLimit: 800_000,
}) // launch everything
// const tx = await interopPoW.run(workerAddress, [21473209]) // launch only on the remote chain. the xdm does not allow sending to your own chain
console.log("🗳️ interopPoW.run() tx launching with hash", tx.hash)
await tx.wait()
console.log("⚒️ tx confirmed")

// wait for event
// event subscriptions are not supported, so we resort
// to short polling
console.log("🗣️ polling for state every 1s...")

let counter = 0;
const interval = setInterval(async () => {
// Code to run every 1 second
console.log("\nQuerying results...", counter++);
async function queryState() {
console.log("\nQuerying results...", period * counter++, "ms");

const log0 = await worker0.localResultLog()
console.log("worker0 (LOCAL) cached result:", log0)
console.log("worker0 (LOCAL) cached results have length:", log0.slice(2).length)

const log1 = await worker1.localResultLog()
console.log("worker1 (REMOTE) cached result:", log1)
console.log("worker1 (REMOTE) cached results have length:", log1.slice(2).length)

const aR = await interopPoW.allResults()
console.log("allResults:", aR)
console.log("InteropPoW.allResults has length:", aR.slice(2).length)

// Stop the interval after 10 executions
if (counter >= 10) {
clearInterval(interval);
console.log("Finished after 10 seconds");
}
// wait for event
// event subscriptions are not supported, so we resort
// to short polling
const period = 500; // ms
console.log("🗣️ polling for state every", period, "ms...")
let counter = 0;

async function runInterval() {
try {
const result = await queryState();
console.log(result);
} catch (error) {
console.error("Error:", error);
} finally {
setTimeout(runInterval, period); // Schedule the next run after completion
}
}, 2000); // 1000 ms = 1 second
}

// Start the first interval
runInterval();

}

Expand Down
3 changes: 3 additions & 0 deletions src/InteropPow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract InteropPoW is IInteropPoW {
bytes public allResults; // currently this is append only

function run(address workerAddress, uint256[] memory chainIds) public {
delete(allResults);
for (uint8 i = 0; i < chainIds.length; i++) {
runOnChain(workerAddress, chainIds[i]);
}
Expand Down Expand Up @@ -56,6 +57,8 @@ contract Worker is IWorker {
bytes32 constant difficulty = bytes32(uint256(2 ** 250 - 1));

function run(uint256 returnDestination, address returnAddress) public {
delete(localResultLog);

// Do the computation
bytes memory results = compute();

Expand Down

0 comments on commit af0af7b

Please sign in to comment.