@leofcoin/chain 1.5.21 → 1.5.23

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.
@@ -1677,15 +1677,33 @@ class Chain extends State {
1677
1677
  async clearPool() {
1678
1678
  await globalThis.transactionPoolStore.clear();
1679
1679
  }
1680
+ /**
1681
+ * drastic measurement, removes everything!
1682
+ */
1683
+ async #clearAll() {
1684
+ await globalThis.accountsStore.clear();
1685
+ await globalThis.chainStore.clear();
1686
+ await globalThis.blockStore.clear();
1687
+ await globalThis.transactionPoolStore.clear();
1688
+ }
1680
1689
  async #init() {
1681
1690
  try {
1682
1691
  const version = await globalThis.chainStore.get('version');
1683
1692
  this.version = new TextDecoder().decode(version);
1693
+ /**
1694
+ * protocol version control!
1695
+ * note v1 and 1.1 delete everything because of big changes, this is not what we want in the future
1696
+ * in the future we want newer nodes to handle the new changes and still confirm old version transactions
1697
+ * unless there is a security issue!
1698
+ */
1684
1699
  if (this.version !== '1.0.0') {
1685
1700
  this.version = '1.0.0';
1686
- await globalThis.chainStore.clear();
1687
- await globalThis.blockStore.clear();
1688
- await globalThis.transactionPoolStore.clear();
1701
+ await this.#clearAll();
1702
+ await globalThis.chainStore.put('version', this.version);
1703
+ }
1704
+ else if (this.version !== '1.1.1') {
1705
+ this.version = '1.1.1';
1706
+ await this.#clearAll();
1689
1707
  await globalThis.chainStore.put('version', this.version);
1690
1708
  }
1691
1709
  // if (version)
@@ -1693,9 +1711,7 @@ class Chain extends State {
1693
1711
  catch (e) {
1694
1712
  console.log(e);
1695
1713
  this.version = '1.0.0';
1696
- await globalThis.chainStore.clear();
1697
- await globalThis.blockStore.clear();
1698
- await globalThis.transactionPoolStore.clear();
1714
+ await this.#clearAll();
1699
1715
  await globalThis.chainStore.put('version', new TextEncoder().encode(this.version));
1700
1716
  }
1701
1717
  // this.node = await new Node()
@@ -1750,6 +1766,8 @@ class Chain extends State {
1750
1766
  return response.decoded.response;
1751
1767
  }
1752
1768
  async #peerConnected(peer) {
1769
+ // todo handle version changes
1770
+ // for now just do nothing if version doesn't match
1753
1771
  if (!peer.version || peer.version !== this.version)
1754
1772
  return;
1755
1773
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
package/exports/chain.js CHANGED
@@ -1113,15 +1113,33 @@ class Chain extends State {
1113
1113
  async clearPool() {
1114
1114
  await globalThis.transactionPoolStore.clear();
1115
1115
  }
1116
+ /**
1117
+ * drastic measurement, removes everything!
1118
+ */
1119
+ async #clearAll() {
1120
+ await globalThis.accountsStore.clear();
1121
+ await globalThis.chainStore.clear();
1122
+ await globalThis.blockStore.clear();
1123
+ await globalThis.transactionPoolStore.clear();
1124
+ }
1116
1125
  async #init() {
1117
1126
  try {
1118
1127
  const version = await globalThis.chainStore.get('version');
1119
1128
  this.version = new TextDecoder().decode(version);
1129
+ /**
1130
+ * protocol version control!
1131
+ * note v1 and 1.1 delete everything because of big changes, this is not what we want in the future
1132
+ * in the future we want newer nodes to handle the new changes and still confirm old version transactions
1133
+ * unless there is a security issue!
1134
+ */
1120
1135
  if (this.version !== '1.0.0') {
1121
1136
  this.version = '1.0.0';
1122
- await globalThis.chainStore.clear();
1123
- await globalThis.blockStore.clear();
1124
- await globalThis.transactionPoolStore.clear();
1137
+ await this.#clearAll();
1138
+ await globalThis.chainStore.put('version', this.version);
1139
+ }
1140
+ else if (this.version !== '1.1.1') {
1141
+ this.version = '1.1.1';
1142
+ await this.#clearAll();
1125
1143
  await globalThis.chainStore.put('version', this.version);
1126
1144
  }
1127
1145
  // if (version)
@@ -1129,9 +1147,7 @@ class Chain extends State {
1129
1147
  catch (e) {
1130
1148
  console.log(e);
1131
1149
  this.version = '1.0.0';
1132
- await globalThis.chainStore.clear();
1133
- await globalThis.blockStore.clear();
1134
- await globalThis.transactionPoolStore.clear();
1150
+ await this.#clearAll();
1135
1151
  await globalThis.chainStore.put('version', new TextEncoder().encode(this.version));
1136
1152
  }
1137
1153
  // this.node = await new Node()
@@ -1186,6 +1202,8 @@ class Chain extends State {
1186
1202
  return response.decoded.response;
1187
1203
  }
1188
1204
  async #peerConnected(peer) {
1205
+ // todo handle version changes
1206
+ // for now just do nothing if version doesn't match
1189
1207
  if (!peer.version || peer.version !== this.version)
1190
1208
  return;
1191
1209
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.21",
3
+ "version": "1.5.23",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {