@leofcoin/chain 1.8.27 → 1.8.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5476,9 +5476,31 @@ class State extends Contract {
5476
5476
  }
5477
5477
  // Use state hash comparison: only resolve if remote hash differs from local state hash
5478
5478
  if (localStateHash !== remoteBlockHash) {
5479
+ if (this.wantList.length > 0) {
5480
+ debug$1(`Fetching ${this.wantList.length} blocks before resolving`);
5481
+ const getBatch = async (batch) => {
5482
+ return Promise.all(batch.map((hash) => this.getAndPutBlock(hash).catch((e) => {
5483
+ console.warn(`failed to fetch block ${hash}`, e);
5484
+ })));
5485
+ };
5486
+ // Process in batches of 50 to avoid overwhelming network/memory
5487
+ for (let i = 0; i < this.wantList.length; i += 50) {
5488
+ const batch = this.wantList.slice(i, i + 50);
5489
+ await getBatch(batch);
5490
+ }
5491
+ }
5479
5492
  // Remote block hash differs from our local state, need to resolve
5480
5493
  debug$1(`Resolving remote block: ${remoteBlockHash} @${remoteIndex} (differs from local state)`);
5494
+ // if we have everything locally, we can load it
5495
+ // if (blocksSynced > 0 && blocksSynced < 1000) {
5496
+ // const promises = []
5497
+ // for (let i = 0; i < blocksSynced; i++) {
5498
+ // promises.push(this.resolveBlock(remoteBlockHash))
5499
+ // }
5500
+ // await Promise.all(promises)
5501
+ // } else {
5481
5502
  await this.resolveBlock(remoteBlockHash);
5503
+ // }
5482
5504
  const blocksSynced = remoteIndex - localIndex;
5483
5505
  debug$1(`Resolved ${blocksSynced} new block(s)`);
5484
5506
  const blocks = this.#blocks;
package/exports/chain.js CHANGED
@@ -1617,9 +1617,31 @@ class State extends Contract {
1617
1617
  }
1618
1618
  // Use state hash comparison: only resolve if remote hash differs from local state hash
1619
1619
  if (localStateHash !== remoteBlockHash) {
1620
+ if (this.wantList.length > 0) {
1621
+ debug$1(`Fetching ${this.wantList.length} blocks before resolving`);
1622
+ const getBatch = async (batch) => {
1623
+ return Promise.all(batch.map((hash) => this.getAndPutBlock(hash).catch((e) => {
1624
+ console.warn(`failed to fetch block ${hash}`, e);
1625
+ })));
1626
+ };
1627
+ // Process in batches of 50 to avoid overwhelming network/memory
1628
+ for (let i = 0; i < this.wantList.length; i += 50) {
1629
+ const batch = this.wantList.slice(i, i + 50);
1630
+ await getBatch(batch);
1631
+ }
1632
+ }
1620
1633
  // Remote block hash differs from our local state, need to resolve
1621
1634
  debug$1(`Resolving remote block: ${remoteBlockHash} @${remoteIndex} (differs from local state)`);
1635
+ // if we have everything locally, we can load it
1636
+ // if (blocksSynced > 0 && blocksSynced < 1000) {
1637
+ // const promises = []
1638
+ // for (let i = 0; i < blocksSynced; i++) {
1639
+ // promises.push(this.resolveBlock(remoteBlockHash))
1640
+ // }
1641
+ // await Promise.all(promises)
1642
+ // } else {
1622
1643
  await this.resolveBlock(remoteBlockHash);
1644
+ // }
1623
1645
  const blocksSynced = remoteIndex - localIndex;
1624
1646
  debug$1(`Resolved ${blocksSynced} new block(s)`);
1625
1647
  const blocks = this.#blocks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.8.27",
3
+ "version": "1.8.28",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {