@leofcoin/chain 1.8.26 → 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.
- package/exports/browser/chain.js +25 -0
- package/exports/chain.js +25 -0
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -5286,6 +5286,9 @@ class State extends Contract {
|
|
|
5286
5286
|
}
|
|
5287
5287
|
try {
|
|
5288
5288
|
const block = await this.getAndPutBlock(hash);
|
|
5289
|
+
if (block.decoded.previousHash !== '0x0' && block.decoded.previousHash !== localHash) {
|
|
5290
|
+
setImmediate(() => this.resolveBlock(block.decoded.previousHash));
|
|
5291
|
+
}
|
|
5289
5292
|
await Promise.all(block.decoded.transactions
|
|
5290
5293
|
.filter((hash) => Boolean(hash))
|
|
5291
5294
|
.map(async (hash) => {
|
|
@@ -5473,9 +5476,31 @@ class State extends Contract {
|
|
|
5473
5476
|
}
|
|
5474
5477
|
// Use state hash comparison: only resolve if remote hash differs from local state hash
|
|
5475
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
|
+
}
|
|
5476
5492
|
// Remote block hash differs from our local state, need to resolve
|
|
5477
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 {
|
|
5478
5502
|
await this.resolveBlock(remoteBlockHash);
|
|
5503
|
+
// }
|
|
5479
5504
|
const blocksSynced = remoteIndex - localIndex;
|
|
5480
5505
|
debug$1(`Resolved ${blocksSynced} new block(s)`);
|
|
5481
5506
|
const blocks = this.#blocks;
|
package/exports/chain.js
CHANGED
|
@@ -1427,6 +1427,9 @@ class State extends Contract {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
try {
|
|
1429
1429
|
const block = await this.getAndPutBlock(hash);
|
|
1430
|
+
if (block.decoded.previousHash !== '0x0' && block.decoded.previousHash !== localHash) {
|
|
1431
|
+
setImmediate(() => this.resolveBlock(block.decoded.previousHash));
|
|
1432
|
+
}
|
|
1430
1433
|
await Promise.all(block.decoded.transactions
|
|
1431
1434
|
.filter((hash) => Boolean(hash))
|
|
1432
1435
|
.map(async (hash) => {
|
|
@@ -1614,9 +1617,31 @@ class State extends Contract {
|
|
|
1614
1617
|
}
|
|
1615
1618
|
// Use state hash comparison: only resolve if remote hash differs from local state hash
|
|
1616
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
|
+
}
|
|
1617
1633
|
// Remote block hash differs from our local state, need to resolve
|
|
1618
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 {
|
|
1619
1643
|
await this.resolveBlock(remoteBlockHash);
|
|
1644
|
+
// }
|
|
1620
1645
|
const blocksSynced = remoteIndex - localIndex;
|
|
1621
1646
|
debug$1(`Resolved ${blocksSynced} new block(s)`);
|
|
1622
1647
|
const blocks = this.#blocks;
|