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
c0457341
Commit
c0457341
authored
Aug 24, 2014
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
Implemented PoW difficulty rule
parent
2a30e11b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/keyblock.js
+10
-0
10 additions, 0 deletions
app/models/keyblock.js
app/service/KeychainService.js
+31
-3
31 additions, 3 deletions
app/service/KeychainService.js
with
41 additions
and
3 deletions
app/models/keyblock.js
+
10
−
0
View file @
c0457341
...
@@ -236,6 +236,16 @@ KeyBlockSchema.statics.nextNumber = function (done) {
...
@@ -236,6 +236,16 @@ KeyBlockSchema.statics.nextNumber = function (done) {
});
});
};
};
KeyBlockSchema
.
statics
.
lastOfIssuer
=
function
(
issuer
,
done
)
{
this
.
find
({
issuer
:
issuer
})
.
sort
({
'
number
'
:
-
1
})
.
limit
(
1
)
.
exec
(
function
(
err
,
blocks
)
{
done
(
err
,
(
blocks
&&
blocks
.
length
==
1
)
?
blocks
[
0
]
:
null
);
});
};
KeyBlockSchema
.
statics
.
current
=
function
(
done
)
{
KeyBlockSchema
.
statics
.
current
=
function
(
done
)
{
this
.
find
({}).
sort
({
number
:
-
1
}).
limit
(
1
).
exec
(
function
(
err
,
blocks
)
{
this
.
find
({}).
sort
({
number
:
-
1
}).
limit
(
1
).
exec
(
function
(
err
,
blocks
)
{
...
...
This diff is collapsed.
Click to expand it.
app/service/KeychainService.js
+
31
−
3
View file @
c0457341
...
@@ -27,7 +27,8 @@ function KeyService (conn, conf, PublicKeyService) {
...
@@ -27,7 +27,8 @@ function KeyService (conn, conf, PublicKeyService) {
var
Link
=
conn
.
model
(
'
Link
'
);
var
Link
=
conn
.
model
(
'
Link
'
);
var
Key
=
conn
.
model
(
'
Key
'
);
var
Key
=
conn
.
model
(
'
Key
'
);
var
MINIMUM_ZERO_START
=
0
;
var
MINIMUM_ZERO_START
=
1
;
var
PROOF_OF_WORK_PERIOD
=
1
// Value 1 allows for continuous single-member writing with minimum difficulty
var
LINK_QUANTITY_MIN
=
1
;
var
LINK_QUANTITY_MIN
=
1
;
var
MAX_STEPS
=
1
;
var
MAX_STEPS
=
1
;
var
MAX_LINK_VALIDITY
=
3600
*
24
*
30
;
// 30 days
var
MAX_LINK_VALIDITY
=
3600
*
24
*
30
;
// 30 days
...
@@ -478,8 +479,35 @@ function KeyService (conn, conf, PublicKeyService) {
...
@@ -478,8 +479,35 @@ function KeyService (conn, conf, PublicKeyService) {
var
powRegexp
=
new
RegExp
(
'
^0{
'
+
MINIMUM_ZERO_START
+
'
}
'
);
var
powRegexp
=
new
RegExp
(
'
^0{
'
+
MINIMUM_ZERO_START
+
'
}
'
);
if
(
!
block
.
hash
.
match
(
powRegexp
))
if
(
!
block
.
hash
.
match
(
powRegexp
))
done
(
'
Not a proof-of-work
'
);
done
(
'
Not a proof-of-work
'
);
else
else
{
done
();
// Compute exactly how much zeros are required for this block's issuer
var
lastBlockPenality
=
0
;
var
nbWaitedPeriods
=
0
;
async
.
waterfall
([
function
(
next
){
KeyBlock
.
lastOfIssuer
(
block
.
issuer
,
next
);
},
function
(
last
,
next
){
if
(
last
)
{
var
leadingZeros
=
last
.
hash
.
match
(
/^0+/
)[
0
];
lastBlockPenality
=
leadingZeros
.
length
-
MINIMUM_ZERO_START
+
1
;
nbWaitedPeriods
=
Math
.
floor
((
block
.
number
-
last
.
number
)
/
PROOF_OF_WORK_PERIOD
);
next
();
}
else
{
next
();
}
},
function
(
next
){
var
nbZeros
=
Math
.
max
(
MINIMUM_ZERO_START
,
MINIMUM_ZERO_START
+
lastBlockPenality
-
nbWaitedPeriods
);
var
powRegexp
=
new
RegExp
(
'
^0{
'
+
nbZeros
+
'
,}
'
);
if
(
!
block
.
hash
.
match
(
powRegexp
))
next
(
'
Wrong proof-of-work level: given
'
+
block
.
hash
.
match
(
/^0+/
)[
0
].
length
+
'
zeros, required was
'
+
nbZeros
+
'
zeros
'
);
else
{
next
();
}
},
],
done
);
}
}
}
function
checkKicked
(
block
,
newLinks
,
done
)
{
function
checkKicked
(
block
,
newLinks
,
done
)
{
...
...
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
sign in
to comment