@leofcoin/chain 1.7.127 → 1.7.128
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 +30 -20
- package/exports/chain.js +30 -20
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -5131,29 +5131,39 @@ class State extends Contract {
|
|
|
5131
5131
|
}
|
|
5132
5132
|
// @ts-ignore
|
|
5133
5133
|
promises = await this.promiseRequests(promises);
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5134
|
+
const candidates = promises.sort((a, b) => b.value.index - a.value.index);
|
|
5135
|
+
for (const { value, peer } of candidates) {
|
|
5136
|
+
if (!value?.hash || value.hash === '0x0')
|
|
5137
|
+
continue;
|
|
5138
|
+
try {
|
|
5139
|
+
let message = await globalThis.peernet.get(value.hash, 'block');
|
|
5140
|
+
message = await new BlockMessage(message);
|
|
5141
|
+
const hash = await message.hash();
|
|
5142
|
+
if (hash !== value.hash) {
|
|
5143
|
+
throw new Error(`invalid block hash for candidate ${value.hash}`);
|
|
5144
|
+
}
|
|
5145
|
+
const latest = { ...message.decoded, hash };
|
|
5146
|
+
if (peer?.connected && peer.version === this.version) {
|
|
5147
|
+
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
5148
|
+
request: 'knownBlocks'
|
|
5149
|
+
});
|
|
5150
|
+
let node = await globalThis.peernet.prepareMessage(data);
|
|
5151
|
+
let response = await peer.request(node.encode());
|
|
5152
|
+
response = await new globalThis.peernet.protos['peernet-response'](response);
|
|
5153
|
+
this.knownBlocks = response.decoded.response;
|
|
5154
|
+
}
|
|
5155
|
+
return latest;
|
|
5156
|
+
}
|
|
5157
|
+
catch (error) {
|
|
5158
|
+
console.warn('[state] ignoring invalid lastBlock candidate', {
|
|
5159
|
+
error,
|
|
5160
|
+
hash: value?.hash,
|
|
5161
|
+
index: value?.index
|
|
5149
5162
|
});
|
|
5150
|
-
|
|
5151
|
-
let message = await peer.request(node.encode());
|
|
5152
|
-
message = await new globalThis.peernet.protos['peernet-response'](message);
|
|
5153
|
-
this.knownBlocks = message.decoded.response;
|
|
5163
|
+
continue;
|
|
5154
5164
|
}
|
|
5155
5165
|
}
|
|
5156
|
-
return
|
|
5166
|
+
return { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
5157
5167
|
}
|
|
5158
5168
|
#loadBlockTransactions;
|
|
5159
5169
|
#getLastTransactions;
|
package/exports/chain.js
CHANGED
|
@@ -1258,29 +1258,39 @@ class State extends Contract {
|
|
|
1258
1258
|
}
|
|
1259
1259
|
// @ts-ignore
|
|
1260
1260
|
promises = await this.promiseRequests(promises);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1261
|
+
const candidates = promises.sort((a, b) => b.value.index - a.value.index);
|
|
1262
|
+
for (const { value, peer } of candidates) {
|
|
1263
|
+
if (!value?.hash || value.hash === '0x0')
|
|
1264
|
+
continue;
|
|
1265
|
+
try {
|
|
1266
|
+
let message = await globalThis.peernet.get(value.hash, 'block');
|
|
1267
|
+
message = await new BlockMessage(message);
|
|
1268
|
+
const hash = await message.hash();
|
|
1269
|
+
if (hash !== value.hash) {
|
|
1270
|
+
throw new Error(`invalid block hash for candidate ${value.hash}`);
|
|
1271
|
+
}
|
|
1272
|
+
const latest = { ...message.decoded, hash };
|
|
1273
|
+
if (peer?.connected && peer.version === this.version) {
|
|
1274
|
+
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1275
|
+
request: 'knownBlocks'
|
|
1276
|
+
});
|
|
1277
|
+
let node = await globalThis.peernet.prepareMessage(data);
|
|
1278
|
+
let response = await peer.request(node.encode());
|
|
1279
|
+
response = await new globalThis.peernet.protos['peernet-response'](response);
|
|
1280
|
+
this.knownBlocks = response.decoded.response;
|
|
1281
|
+
}
|
|
1282
|
+
return latest;
|
|
1283
|
+
}
|
|
1284
|
+
catch (error) {
|
|
1285
|
+
console.warn('[state] ignoring invalid lastBlock candidate', {
|
|
1286
|
+
error,
|
|
1287
|
+
hash: value?.hash,
|
|
1288
|
+
index: value?.index
|
|
1276
1289
|
});
|
|
1277
|
-
|
|
1278
|
-
let message = await peer.request(node.encode());
|
|
1279
|
-
message = await new globalThis.peernet.protos['peernet-response'](message);
|
|
1280
|
-
this.knownBlocks = message.decoded.response;
|
|
1290
|
+
continue;
|
|
1281
1291
|
}
|
|
1282
1292
|
}
|
|
1283
|
-
return
|
|
1293
|
+
return { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1284
1294
|
}
|
|
1285
1295
|
#loadBlockTransactions;
|
|
1286
1296
|
#getLastTransactions;
|