Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
063b68d9
Commit
063b68d9
authored
9 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Fix
#239
and
#235
confusion between branch/fork block lookups
parent
8cf4e5b8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/dal/fileDALs/BlockDAL.js
+13
-11
13 additions, 11 deletions
app/lib/dal/fileDALs/BlockDAL.js
with
13 additions
and
11 deletions
app/lib/dal/fileDALs/BlockDAL.js
+
13
−
11
View file @
063b68d9
...
...
@@ -19,6 +19,7 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
let
collection
=
loki
.
getCollection
(
'
blocks
'
)
||
loki
.
addCollection
(
'
blocks
'
,
{
indices
:
[
'
fork
'
,
'
number
'
,
'
hash
'
]
});
let
blocksDB
=
getView
();
let
forksDB
=
getForkView
();
let
current
=
null
;
let
that
=
this
;
...
...
@@ -67,7 +68,7 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
this
.
collection
=
collection
;
this
.
getBlocks
=
(
start
,
end
)
=>
{
let
lowerInLoki
=
collection
.
chain
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
let
lowerInLoki
=
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
let
lokiBlocks
=
blocksDB
.
branchResultset
().
find
({
$and
:
[{
number
:
{
$gte
:
start
}
...
...
@@ -95,12 +96,7 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
};
this
.
getForkBlocks
=
()
=>
Q
(
this
.
collection
.
find
({
$and
:
[
{
fork
:
true
},
{
wrong
:
false
}
]
}));
Q
(
forksDB
.
branchResultset
().
find
({
wrong
:
false
}).
data
());
this
.
saveBunch
=
(
blocks
,
inFiles
)
=>
{
if
(
!
inFiles
)
{
...
...
@@ -175,8 +171,8 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
collection
.
update
(
found
);
});
current
=
previousBlock
;
let
lowerInLoki
=
collection
.
chain
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
if
(
lowerInLoki
.
number
>
0
)
{
let
lowerInLoki
=
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
if
(
lowerInLoki
&&
lowerInLoki
.
number
>
0
)
{
let
newLower
=
yield
that
.
getBlock
(
lowerInLoki
.
number
-
1
);
yield
rootFS
.
remove
(
pathOfBlock
(
newLower
.
number
)
+
blockFileName
(
newLower
.
number
)
+
'
.json
'
);
collection
.
insert
(
newLower
);
...
...
@@ -187,7 +183,7 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
let
number
=
yield
getLowerWindowBlock
();
logger
.
debug
(
"
Clean some blocks from memory to disk...
"
);
logger
.
debug
(
"
Lower block = %s
"
,
number
);
let
lowerInLoki
=
collection
.
chain
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
let
lowerInLoki
=
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
if
(
!
lowerInLoki
)
{
return
;
}
...
...
@@ -212,7 +208,7 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
yield
rootFS
.
writeJSON
(
pathOfBlock
(
block
.
number
)
+
blockFileName
(
block
.
number
)
+
'
.json
'
,
block
);
collection
.
remove
(
block
);
}
lowerInLoki
=
collection
.
chain
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
lowerInLoki
=
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
).
limit
(
1
).
data
()[
0
];
logger
.
debug
(
"
Lower in loki now = %s
"
,
lowerInLoki
.
number
);
logger
.
debug
(
"
LastUD in loki = %s
"
,
that
.
lastBlockWithDividend
().
number
);
}
...
...
@@ -227,6 +223,12 @@ function BlockDAL(loki, rootFS, getLowerWindowBlock) {
return
view
;
}
function
getForkView
()
{
let
view
=
collection
.
addDynamicView
(
'
forks
'
);
view
.
applyFind
({
fork
:
true
});
return
view
;
}
function
folderOfBlock
(
blockNumber
)
{
return
(
Math
.
floor
(
blockNumber
/
BLOCK_FOLDER_SIZE
)
+
1
)
*
BLOCK_FOLDER_SIZE
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment