Skip to content

Commit

Permalink
Merge pull request #111 from DIG-Network/release/v0.0.1-alpha.122
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.122
  • Loading branch information
MichaelTaylor3D authored Oct 4, 2024
2 parents bf5c007 + 76e2c58 commit 26590bb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.122](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.121...v0.0.1-alpha.122) (2024-10-04)


### Bug Fixes

* additional logging ([d21b141](https://github.com/DIG-Network/dig-chia-sdk/commit/d21b1411d69a4a667279216aa906daef7203a02f))

### [0.0.1-alpha.121](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.120...v0.0.1-alpha.121) (2024-10-03)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.121",
"version": "0.0.1-alpha.122",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
30 changes: 17 additions & 13 deletions src/blockchain/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class DataStore {
public static async monitorStoreIndefinitely(storeId: string): Promise<void> {
// Check if a monitor is already running for this storeId
if (this.activeMonitors.get(storeId)) {
console.log(`Monitor already running for storeId: ${storeId}`);
console.log("Monitor:", `Monitor already running for storeId: ${storeId}`);
return;
}

Expand All @@ -338,19 +338,19 @@ export class DataStore {
}>(`stores`);

// Clear the cache at the start
console.log(`Clearing cache for storeId: ${storeId}`);
console.log("Monitor:", `Clearing cache for storeId: ${storeId}`);
storeCoinCache.delete(storeId);

while (true) {
try {
console.log(`Connecting to peer for storeId: ${storeId}`);
console.log("Monitor:", `Connecting to peer for storeId: ${storeId}`);
const peer = await FullNodePeer.connect();
const cachedInfo = storeCoinCache.get(storeId);

if (cachedInfo) {
// Log cached store info retrieval
console.log(
`Cached store info found for storeId: ${storeId}, syncing...`
"Monitor:", `Cached store info found for storeId: ${storeId}, syncing...`
);

// Deserialize cached info and wait for the coin to be spent
Expand All @@ -361,16 +361,20 @@ export class DataStore {
});

console.log(
`Waiting for coin to be spent for storeId: ${storeId}...`
"Monitor:", `Waiting for coin to be spent for storeId: ${storeId}...`
);

const dataStore = DataStore.from(storeId);
const { createdAtHeight, createdAtHash } = await dataStore.getCreationHeight();

await peer.waitForCoinToBeSpent(
getCoinId(previousStore.latestStore.coin),
previousStore.latestHeight,
previousStore.latestHash
createdAtHeight,
createdAtHash
);

// Sync store and get updated details
console.log(`Syncing store for storeId: ${storeId}`);
console.log("Monitor:", `Syncing store for storeId: ${storeId}`);
const { latestStore, latestHeight } = await peer.syncStore(
previousStore.latestStore,
previousStore.latestHeight,
Expand All @@ -386,7 +390,7 @@ export class DataStore {
latestHash
).serialize();

console.log(`Caching updated store info for storeId: ${storeId}`);
console.log("Monitor:", `Caching updated store info for storeId: ${storeId}`);
storeCoinCache.set(storeId, {
latestStore: serializedLatestStore,
latestHeight,
Expand All @@ -398,14 +402,14 @@ export class DataStore {

// If no cached info exists, log and sync from the creation height
console.log(
`No cached info found for storeId: ${storeId}. Retrieving creation height.`
"Monitor:", `No cached info found for storeId: ${storeId}. Retrieving creation height.`
);

const dataStore = DataStore.from(storeId);
const { createdAtHeight, createdAtHash } = await dataStore.getCreationHeight();

// Sync store from the peer using launcher ID
console.log(`Syncing store from launcher ID for storeId: ${storeId}`);
console.log("Monitor:", `Syncing store from launcher ID for storeId: ${storeId}`);
const { latestStore, latestHeight } = await peer.syncStoreFromLauncherId(
Buffer.from(storeId, "hex"),
createdAtHeight,
Expand All @@ -422,15 +426,15 @@ export class DataStore {
latestHash
).serialize();

console.log(`Caching new store info for storeId: ${storeId}`);
console.log("Monitor:", `Caching new store info for storeId: ${storeId}`);
storeCoinCache.set(storeId, {
latestStore: serializedLatestStore,
latestHeight,
latestHash: latestHash.toString("hex"),
});
} catch (error: any) {
console.error(
`Error in monitorStoreIndefinitely for storeId: ${storeId} - ${error.message}`
"Monitor:", `Error in monitorStoreIndefinitely for storeId: ${storeId} - ${error.message}`
);

// Delay before restarting to avoid rapid retries
Expand Down

0 comments on commit 26590bb

Please sign in to comment.