@leofcoin/workers 1.5.41 → 1.5.42
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.
|
@@ -1738,11 +1738,25 @@ const _ = {
|
|
|
1738
1738
|
addLoadedBlock: (block) => {
|
|
1739
1739
|
const size = formatBytes(block.length);
|
|
1740
1740
|
block = JSON.parse(block, jsonParseBigInt);
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1741
|
+
const index = Number(block.index);
|
|
1742
|
+
const tipIndex = Number(lastBlock.index);
|
|
1743
|
+
if (!['number', 'bigint'].includes(typeof block.index) ||
|
|
1744
|
+
!Number.isSafeInteger(index) || index < 0 || typeof block.hash !== 'string' || !block.hash) {
|
|
1745
|
+
throw new Error('Invalid loaded block identity');
|
|
1746
|
+
}
|
|
1747
|
+
if (lastBlock.hash !== '0x0') {
|
|
1748
|
+
if (index < tipIndex)
|
|
1749
|
+
return false;
|
|
1750
|
+
if (index === tipIndex) {
|
|
1751
|
+
if (block.hash === lastBlock.hash)
|
|
1752
|
+
return false;
|
|
1753
|
+
throw new Error(`Loaded block conflict at index ${index}`);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
const expectedIndex = lastBlock.hash === '0x0' ? 0 : tipIndex + 1;
|
|
1757
|
+
if (index !== expectedIndex || block.previousHash !== lastBlock.hash) {
|
|
1758
|
+
throw new Error(`Loaded block does not extend canonical tip at index ${index}`);
|
|
1759
|
+
}
|
|
1746
1760
|
blocks[block.index.toString()] = block;
|
|
1747
1761
|
lastBlock = blocks[blocks.length - 1];
|
|
1748
1762
|
totalBlocks += 1n;
|
|
@@ -1738,11 +1738,25 @@ const _ = {
|
|
|
1738
1738
|
addLoadedBlock: (block) => {
|
|
1739
1739
|
const size = formatBytes(block.length);
|
|
1740
1740
|
block = JSON.parse(block, jsonParseBigInt);
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1741
|
+
const index = Number(block.index);
|
|
1742
|
+
const tipIndex = Number(lastBlock.index);
|
|
1743
|
+
if (!['number', 'bigint'].includes(typeof block.index) ||
|
|
1744
|
+
!Number.isSafeInteger(index) || index < 0 || typeof block.hash !== 'string' || !block.hash) {
|
|
1745
|
+
throw new Error('Invalid loaded block identity');
|
|
1746
|
+
}
|
|
1747
|
+
if (lastBlock.hash !== '0x0') {
|
|
1748
|
+
if (index < tipIndex)
|
|
1749
|
+
return false;
|
|
1750
|
+
if (index === tipIndex) {
|
|
1751
|
+
if (block.hash === lastBlock.hash)
|
|
1752
|
+
return false;
|
|
1753
|
+
throw new Error(`Loaded block conflict at index ${index}`);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
const expectedIndex = lastBlock.hash === '0x0' ? 0 : tipIndex + 1;
|
|
1757
|
+
if (index !== expectedIndex || block.previousHash !== lastBlock.hash) {
|
|
1758
|
+
throw new Error(`Loaded block does not extend canonical tip at index ${index}`);
|
|
1759
|
+
}
|
|
1746
1760
|
blocks[block.index.toString()] = block;
|
|
1747
1761
|
lastBlock = blocks[blocks.length - 1];
|
|
1748
1762
|
totalBlocks += 1n;
|