@@ -4,19 +4,15 @@ import { Trie as BaseTrie } from './baseTrie'
4
4
* Adds checkpointing to the {@link BaseTrie}
5
5
*/
6
6
export class CheckpointTrie extends BaseTrie {
7
- _checkpoints : Buffer [ ]
8
-
9
7
constructor ( ...args : any ) {
10
8
super ( ...args )
11
- // Roots of trie at the moment of checkpoint
12
- this . _checkpoints = [ ]
13
9
}
14
10
15
11
/**
16
12
* Is the trie during a checkpoint phase?
17
13
*/
18
14
get isCheckpoint ( ) {
19
- return this . _checkpoints . length > 0
15
+ return this . db . checkpoints . length > 0
20
16
}
21
17
22
18
/**
@@ -25,7 +21,7 @@ export class CheckpointTrie extends BaseTrie {
25
21
*/
26
22
checkpoint ( ) {
27
23
const wasCheckpoint = this . isCheckpoint
28
- this . _checkpoints . push ( this . root )
24
+ this . db . checkpoints . push ( { root : this . root , operations : [ ] } )
29
25
30
26
// Entering checkpoint mode is not necessary for nested checkpoints
31
27
if ( ! wasCheckpoint && this . isCheckpoint ) {
@@ -45,7 +41,7 @@ export class CheckpointTrie extends BaseTrie {
45
41
46
42
await this . lock . wait ( )
47
43
48
- this . _checkpoints . pop ( )
44
+ this . db . checkpoints . pop ( )
49
45
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
50
46
if ( ! this . isCheckpoint ) {
51
47
await this . _exitCpMode ( true )
@@ -63,7 +59,8 @@ export class CheckpointTrie extends BaseTrie {
63
59
await this . lock . wait ( )
64
60
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65
61
if ( this . isCheckpoint ) {
66
- this . root = this . _checkpoints . pop ( ) !
62
+ const { root } = this . db . checkpoints . pop ( ) !
63
+ this . root = root
67
64
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
68
65
if ( ! this . isCheckpoint ) {
69
66
await this . _exitCpMode ( false )
@@ -80,7 +77,7 @@ export class CheckpointTrie extends BaseTrie {
80
77
const db = this . db . copy ( )
81
78
const trie = new CheckpointTrie ( db . _leveldb , this . root )
82
79
if ( includeCheckpoints && this . isCheckpoint ) {
83
- trie . _checkpoints = this . _checkpoints . slice ( )
80
+ trie . db . checkpoints = this . db . checkpoints . slice ( )
84
81
}
85
82
return trie
86
83
}
0 commit comments