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
8cb2d91f
Commit
8cb2d91f
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Branch switches tests are passing
parent
6ff3bf28
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/pulling.js
+52
-55
52 additions, 55 deletions
app/lib/pulling.js
app/service/BlockchainService.js
+6
-1
6 additions, 1 deletion
app/service/BlockchainService.js
with
58 additions
and
56 deletions
app/lib/pulling.js
+
52
−
55
View file @
8cb2d91f
"
use strict
"
;
const
Q
=
require
(
'
q
'
);
const
co
=
require
(
'
co
'
);
const
_
=
require
(
'
underscore
'
);
const
constant
=
require
(
'
./constants
'
);
...
...
@@ -18,7 +17,7 @@ module.exports = {
*/
dao
.
applyBranch
=
(
blocks
)
=>
co
(
function
*
()
{
for
(
const
block
of
blocks
)
{
yield
dao
.
applyMainBranch
(
block
);
yield
dao
.
applyMainBranch
(
[
block
]
);
}
return
true
;
});
...
...
@@ -29,8 +28,7 @@ module.exports = {
* @param forksize The maximum length we can look at to find common root block.
* @returns {*|Promise}
*/
dao
.
findCommonRoot
=
(
fork
,
forksize
)
=>
{
return
co
(
function
*
()
{
dao
.
findCommonRoot
=
(
fork
,
forksize
)
=>
co
(
function
*
()
{
let
commonRoot
=
null
;
let
localCurrent
=
yield
dao
.
localCurrent
();
...
...
@@ -38,7 +36,7 @@ module.exports = {
// We look between the top block that is known as fork ...
let
topBlock
=
fork
.
block
;
// ... and the bottom which is bounded by `forksize`
let
bottomBlock
=
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
Math
.
max
(
0
,
localCurrent
.
number
-
forksize
));
let
bottomBlock
=
(
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
Math
.
max
(
0
,
localCurrent
.
number
-
forksize
))
)[
0
]
;
let
lookBlock
=
bottomBlock
;
let
localEquivalent
=
yield
dao
.
getLocalBlock
(
bottomBlock
.
number
);
let
isCommonBlock
=
lookBlock
.
hash
==
localEquivalent
.
hash
;
...
...
@@ -56,7 +54,7 @@ module.exports = {
position
=
middle
(
topBlock
.
number
,
bottomBlock
.
number
);
}
else
{
let
upperBlock
=
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
lookBlock
.
number
+
1
);
let
upperBlock
=
(
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
lookBlock
.
number
+
1
)
)[
0
]
;
let
localUpper
=
yield
dao
.
getLocalBlock
(
upperBlock
.
number
);
let
isCommonUpper
=
upperBlock
.
hash
==
localUpper
.
hash
;
if
(
isCommonUpper
)
{
...
...
@@ -79,16 +77,15 @@ module.exports = {
}
if
(
!
wrongRemotechain
)
{
lookBlock
=
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
position
);
lookBlock
=
(
yield
dao
.
getRemoteBlock
(
fork
.
peer
,
position
)
)[
0
]
;
localEquivalent
=
yield
dao
.
getLocalBlock
(
position
);
}
}
while
(
!
commonRoot
&&
!
wrongRemotechain
);
}
// Otherwise common root is unreachable
return
Q
(
commonRoot
);
return
commonRoot
;
});
};
return
dao
;
},
...
...
This diff is collapsed.
Click to expand it.
app/service/BlockchainService.js
+
6
−
1
View file @
8cb2d91f
...
...
@@ -127,7 +127,12 @@ function BlockchainService () {
this
.
submitBlock
=
(
obj
,
doCheck
,
forkAllowed
)
=>
this
.
pushFIFO
(()
=>
checkAndAddBlock
(
obj
,
doCheck
,
forkAllowed
));
const
checkAndAddBlock
=
(
obj
,
doCheck
,
forkAllowed
)
=>
co
(
function
*
()
{
try
{
Transaction
.
statics
.
setIssuers
(
obj
.
transactions
);
}
catch
(
e
)
{
throw
e
;
}
let
existing
=
yield
dal
.
getBlockByNumberAndHashOrNull
(
obj
.
number
,
obj
.
hash
);
if
(
existing
)
{
throw
'
Already processed
'
;
...
...
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