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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
aa974544
Commit
aa974544
authored
7 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#1059
Add --submit-local option
parent
2814ef18
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/modules/prover/index.ts
+47
-35
47 additions, 35 deletions
app/modules/prover/index.ts
app/modules/wizard.ts
+1
-1
1 addition, 1 deletion
app/modules/wizard.ts
with
48 additions
and
36 deletions
app/modules/prover/index.ts
+
47
−
35
View file @
aa974544
...
...
@@ -6,6 +6,7 @@ import {Prover} from "./lib/prover"
import
{
Contacter
}
from
"
../crawler/lib/contacter
"
import
{
parsers
}
from
"
../../lib/common-libs/parsers/index
"
import
{
PeerDTO
}
from
"
../../lib/dto/PeerDTO
"
import
{
Server
}
from
"
../../../server
"
;
const
async
=
require
(
'
async
'
);
...
...
@@ -63,34 +64,33 @@ export const ProverDependency = {
/*********** CLI gen-next + gen-root **************/
cliOptions
:
[
{
value
:
'
--show
'
,
desc
:
'
With gen-next or gen-root commands, displays the generated block.
'
},
{
value
:
'
--check
'
,
desc
:
'
With gen-next: just check validity of generated block.
'
},
{
value
:
'
--show
'
,
desc
:
'
With gen-* commands, displays the generated block.
'
},
{
value
:
'
--check
'
,
desc
:
'
With gen-* commands: just check validity of generated block.
'
},
{
value
:
'
--submit-local
'
,
desc
:
'
With gen-* commands: the generated block is submitted to this node only.
'
},
{
value
:
'
--submit-host <host>
'
,
desc
:
'
With gen-* commands: the generated block is submitted to `submit-host` node.
'
},
{
value
:
'
--submit-port <port>
'
,
desc
:
'
With gen-* commands: the generated block is submitted to `submit-host` node with port `submit-port`.
'
},
{
value
:
'
--at <medianTime>
'
,
desc
:
'
With gen-next --show --check: allows to try in a future time.
'
,
parser
:
parseInt
}
],
cli
:
[{
name
:
'
gen-next
[host] [port]
[difficulty]
'
,
name
:
'
gen-next [difficulty]
'
,
desc
:
'
Tries to generate the next block of the blockchain.
'
,
onDatabaseExecute
:
async
(
server
:
any
,
conf
:
ConfDTO
,
program
:
any
,
params
:
any
)
=>
{
const
host
=
params
[
0
];
const
port
=
params
[
1
];
const
difficulty
=
params
[
2
];
const
difficulty
=
params
[
0
]
const
generator
=
new
BlockGeneratorWhichProves
(
server
,
null
);
return
generateAndSend
(
program
,
host
,
port
,
difficulty
,
server
,
()
=>
()
=>
generator
.
nextBlock
())
return
generateAndSend
(
program
,
difficulty
,
server
,
()
=>
()
=>
generator
.
nextBlock
())
}
},
{
name
:
'
gen-root
[host] [port]
[difficulty]
'
,
name
:
'
gen-root [difficulty]
'
,
desc
:
'
Tries to generate the next block of the blockchain.
'
,
preventIfRunning
:
true
,
onDatabaseExecute
:
async
(
server
:
any
,
conf
:
ConfDTO
,
program
:
any
,
params
:
any
)
=>
{
const
host
=
params
[
0
];
const
port
=
params
[
1
];
const
difficulty
=
params
[
2
];
const
difficulty
=
params
[
0
]
const
generator
=
new
BlockGeneratorWhichProves
(
server
,
null
);
let
toDelete
,
catched
=
true
;
do
{
try
{
await
generateAndSend
(
program
,
host
,
port
,
difficulty
,
server
,
()
=>
()
=>
generator
.
nextBlock
())
await
generateAndSend
(
program
,
difficulty
,
server
,
()
=>
()
=>
generator
.
nextBlock
())
catched
=
false
;
}
catch
(
e
)
{
toDelete
=
await
server
.
dal
.
idtyDAL
.
query
(
'
SELECT * FROM idty i WHERE 5 > (SELECT count(*) from cert c where c.`to` = i.pubkey)
'
);
...
...
@@ -103,32 +103,35 @@ export const ProverDependency = {
console
.
log
(
'
Done
'
);
}
},
{
name
:
'
gen-root-choose
[host] [port]
[difficulty]
'
,
name
:
'
gen-root-choose [difficulty]
'
,
desc
:
'
Tries to generate root block, with choice of root members.
'
,
preventIfRunning
:
true
,
onDatabaseExecute
:
async
(
server
:
any
,
conf
:
ConfDTO
,
program
:
any
,
params
:
any
)
=>
{
const
host
=
params
[
0
];
const
port
=
params
[
1
];
const
difficulty
=
params
[
2
];
if
(
!
host
)
{
throw
'
Host is required.
'
;
}
if
(
!
port
)
{
throw
'
Port is required.
'
;
}
const
difficulty
=
params
[
0
]
if
(
!
difficulty
)
{
throw
'
Difficulty is required.
'
;
}
const
generator
=
new
BlockGenerator
(
server
);
return
generateAndSend
(
program
,
host
,
port
,
difficulty
,
server
,
()
=>
generator
.
manualRoot
);
return
generateAndSend
(
program
,
difficulty
,
server
,
()
=>
generator
.
manualRoot
);
}
}]
}
}
function
generateAndSend
(
program
:
any
,
host
:
string
,
port
:
string
,
difficulty
:
string
,
server
:
any
,
getGenerationMethod
:
any
)
{
function
generateAndSend
(
program
:
any
,
difficulty
:
string
,
server
:
any
,
getGenerationMethod
:
any
)
{
const
logger
=
server
.
logger
;
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
program
.
submitLocal
)
{
if
(
!
program
.
submitHost
)
{
throw
'
Option --submitHost is required.
'
}
if
(
!
program
.
submitPort
)
{
throw
'
Option --submitPort is required.
'
}
if
(
isNaN
(
parseInt
(
program
.
submitPort
)))
{
throw
'
Option --submitPort must be a number.
'
}
}
async
.
waterfall
([
function
(
next
:
any
)
{
const
method
=
getGenerationMethod
(
server
);
...
...
@@ -162,7 +165,7 @@ function generateAndSend(program:any, host:string, port:string, difficulty:strin
logger
.
debug
(
'
Block to be sent: %s
'
,
block
.
getRawInnerPart
());
async
.
waterfall
([
function
(
subNext
:
any
)
{
proveAndSend
(
program
,
server
,
block
,
server
.
conf
.
pair
.
pub
,
parseInt
(
difficulty
),
host
,
parseInt
(
port
),
subNext
);
proveAndSend
(
program
,
server
,
block
,
server
.
conf
.
pair
.
pub
,
parseInt
(
difficulty
),
subNext
);
}
],
next
);
}
...
...
@@ -174,7 +177,7 @@ function generateAndSend(program:any, host:string, port:string, difficulty:strin
});
}
function
proveAndSend
(
program
:
any
,
server
:
any
,
block
:
any
,
issuer
:
any
,
difficulty
:
any
,
host
:
any
,
port
:
any
,
done
:
any
)
{
function
proveAndSend
(
program
:
any
,
server
:
Server
,
block
:
any
,
issuer
:
any
,
difficulty
:
any
,
done
:
any
)
{
const
logger
=
server
.
logger
;
async
.
waterfall
([
function
(
next
:
any
)
{
...
...
@@ -182,8 +185,15 @@ function proveAndSend(program:any, server:any, block:any, issuer:any, difficulty
program
.
show
&&
console
.
log
(
block
.
getRawSigned
());
(
async
()
=>
{
try
{
const
host
:
string
=
program
.
submitHost
const
port
:
string
=
program
.
submitPort
const
trialLevel
=
isNaN
(
difficulty
)
?
await
server
.
getBcContext
().
getIssuerPersonalizedDifficulty
(
server
.
PeeringService
.
selfPubkey
)
:
difficulty
const
prover
=
new
BlockProver
(
server
);
const
proven
=
await
prover
.
prove
(
block
,
difficulty
);
const
proven
=
await
prover
.
prove
(
block
,
trialLevel
);
if
(
program
.
submitLocal
)
{
await
server
.
writeBlock
(
proven
)
next
()
}
else
{
const
peer
=
PeerDTO
.
fromJSONObject
({
endpoints
:
[[
'
BASIC_MERKLED_API
'
,
host
,
port
].
join
(
'
'
)]
});
...
...
@@ -192,6 +202,8 @@ function proveAndSend(program:any, server:any, block:any, issuer:any, difficulty
const
p
=
PeerDTO
.
fromJSONObject
(
peer
);
const
contact
=
new
Contacter
(
p
.
getHostPreferDNS
(),
p
.
getPort
());
await
contact
.
postBlock
(
proven
.
getRawSigned
());
next
()
}
}
catch
(
e
)
{
next
(
e
);
}
...
...
This diff is collapsed.
Click to expand it.
app/modules/wizard.ts
+
1
−
1
View file @
aa974544
...
...
@@ -25,7 +25,7 @@ module.exports = {
if
(
!
task
)
{
throw
'
Unknown task
'
;
}
await
task
(
conf
)
await
task
(
conf
,
program
)
}
// Check config
await
server
.
checkConfig
();
...
...
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