Skip to content

Commit fc5cac5

Browse files
committed
previous transaction index (v0.2)
1 parent 3aadb53 commit fc5cac5

13 files changed

+60
-22
lines changed

dist/lib/BlockStorage.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/BlockStorage.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/MergeHandler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/MergeHandler.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/Transaction.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/Transaction.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/messages.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ function defineTransactionMarker () {
257257
var len = encodings.varint.encodingLength(obj.timestamp)
258258
length += 1 + len
259259
}
260+
if (defined(obj.previous)) {
261+
var len = encodings.varint.encodingLength(obj.previous)
262+
length += 1 + len
263+
}
260264
return length
261265
}
262266

@@ -277,6 +281,11 @@ function defineTransactionMarker () {
277281
encodings.varint.encode(obj.timestamp, buf, offset)
278282
offset += encodings.varint.encode.bytes
279283
}
284+
if (defined(obj.previous)) {
285+
buf[offset++] = 32
286+
encodings.varint.encode(obj.previous, buf, offset)
287+
offset += encodings.varint.encode.bytes
288+
}
280289
encode.bytes = offset - oldOffset
281290
return buf
282291
}
@@ -289,7 +298,8 @@ function defineTransactionMarker () {
289298
var obj = {
290299
sequenceNr: 0,
291300
objectCtr: 0,
292-
timestamp: 0
301+
timestamp: 0,
302+
previous: 0
293303
}
294304
var found0 = false
295305
var found1 = false
@@ -317,6 +327,10 @@ function defineTransactionMarker () {
317327
obj.timestamp = encodings.varint.decode(buf, offset)
318328
offset += encodings.varint.decode.bytes
319329
break
330+
case 4:
331+
obj.previous = encodings.varint.decode(buf, offset)
332+
offset += encodings.varint.decode.bytes
333+
break
320334
default:
321335
offset = skip(prefix & 7, buf, offset)
322336
}

lib/BlockStorage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class BlockStorage {
2424
const indexNode = self.createIndexNode(0)
2525
await feed.criticalSection(async lockKey => {
2626
const buf = self.encodeIndexNode(indexNode)
27-
const marker = self.createTransactionMarker(1, 0)
27+
const marker = self.createTransactionMarker(1, 0, 0)
2828
await feed.append([buf, marker], { lockKey })
2929
})
3030
}
@@ -45,7 +45,6 @@ export default class BlockStorage {
4545
}
4646

4747
async getIndexNodeForObjectId(id: number, head?: number): Promise<IndexNode> {
48-
const self = this
4948
const prefix = id >> BUCKET_WIDTH
5049
return this.getIndexNode(prefix, head)
5150
}
@@ -195,15 +194,16 @@ export default class BlockStorage {
195194
parent.children[slot] = node.index
196195
}
197196
}
198-
bulk.push(this.createTransactionMarker(lastTransaction.sequenceNr + 1, objectCtr + 1))
197+
bulk.push(this.createTransactionMarker(lastTransaction.sequenceNr + 1, objectCtr + 1, head + 1))
199198
await this.feed.append(bulk, { lockKey })
200199
}
201200

202-
createTransactionMarker(sequenceNr: number, objectCtr: number) {
201+
createTransactionMarker(sequenceNr: number, objectCtr: number, previous: number) {
203202
const marker = {
204203
sequenceNr,
205204
objectCtr,
206-
timestamp: Date.now()
205+
timestamp: Date.now(),
206+
previous
207207
}
208208
return this.encodeTransactionBlock(marker)
209209
}

0 commit comments

Comments
 (0)