trac-msb 0.0.52 → 0.0.53

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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/src/index.js +13 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.52",
4
+ "version": "0.0.53",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "assert": "npm:bare-node-assert",
16
- "autobase": "7.2.2",
16
+ "autobase": "7.0.45",
17
17
  "b4a": "1.6.7",
18
18
  "bare": "^1.17.1",
19
19
  "bare-assert": "^1.0.2",
@@ -44,18 +44,18 @@
44
44
  "buffer": "npm:bare-node-buffer",
45
45
  "child_process": "npm:bare-node-child-process",
46
46
  "console": "npm:bare-node-console",
47
- "corestore": "7.1.0",
47
+ "corestore": "7.0.22",
48
48
  "crypto": "npm:bare-node-crypto",
49
49
  "debounceify": "1.1.0",
50
50
  "events": "npm:bare-node-events",
51
51
  "fs": "npm:bare-node-fs",
52
52
  "http": "npm:bare-node-http",
53
53
  "https": "npm:bare-node-https",
54
- "hyperbee": "2.24.1",
55
- "hypercore": "11.1.1",
54
+ "hyperbee": "2.23.0",
55
+ "hypercore": "11.0.48",
56
56
  "hypercore-crypto": "3.4.0",
57
- "hyperdht": "6.20.1",
58
- "hyperswarm": "4.11.1",
57
+ "hyperdht": "6.19.0",
58
+ "hyperswarm": "4.8.4",
59
59
  "inspector": "npm:bare-node-inspector",
60
60
  "is-options": "1.0.2",
61
61
  "module": "npm:bare-node-module",
package/src/index.js CHANGED
@@ -61,11 +61,14 @@ export class MainSettlementBus extends ReadyResource {
61
61
  return _this.bee;
62
62
  },
63
63
  apply: async (nodes, view, base) => {
64
+
65
+ const batch = view.batch();
66
+
64
67
  for (const node of nodes) {
65
68
  const op = node.value;
66
69
  const postTx = op.value;
67
70
  if (op.type === 'tx') {
68
- if (null === await view.get(op.key) &&
71
+ if (null === await batch.get(op.key) &&
69
72
  postTx.op === 'post-tx' &&
70
73
  sanitizeTransaction(postTx) &&
71
74
  hccrypto.verify(b4a.from(postTx.tx + postTx.in, 'utf-8'), b4a.from(postTx.is, 'hex'), b4a.from(postTx.ipk, 'hex')) &&
@@ -73,7 +76,7 @@ export class MainSettlementBus extends ReadyResource {
73
76
  postTx.tx === await _this.generateTx(postTx.bs, this.bootstrap, postTx.w, postTx.i, postTx.ipk, postTx.ch, postTx.in) &&
74
77
  b4a.byteLength(JSON.stringify(postTx)) <= 4096
75
78
  ) {
76
- await view.put(op.key, op.value);
79
+ await batch.put(op.key, op.value);
77
80
  console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
78
81
  }
79
82
  } else if (op.type === 'addWriter') {
@@ -86,6 +89,9 @@ export class MainSettlementBus extends ReadyResource {
86
89
  console.log(`Writer added: ${op.key} non-indexer`);
87
90
  }
88
91
  }
92
+
93
+ await batch.flush();
94
+ await batch.close();
89
95
  }
90
96
  })
91
97
  this.base.on('warning', (e) => console.log(e))
@@ -197,11 +203,13 @@ export class MainSettlementBus extends ReadyResource {
197
203
  while(true){
198
204
  if(this.tx_pool.length > 0){
199
205
  const length = this.tx_pool.length;
206
+ const batch = [];
200
207
  for(let i = 0; i < length; i++){
201
- await this.base.append({ type: 'tx', key: this.tx_pool[i].tx, value: this.tx_pool[i].append_tx });
202
- await this.sleep(5);
208
+ if(i >= 100) break;
209
+ batch.push({ type: 'tx', key: this.tx_pool[i].tx, value: this.tx_pool[i].append_tx });
203
210
  }
204
- this.tx_pool.splice(0, length);
211
+ await this.base.append(batch);
212
+ this.tx_pool.splice(0, batch.length);
205
213
  }
206
214
  await this.sleep(10);
207
215
  }