good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
open
bor
Commits
0ee79663
Commit
0ee79663
authored
Dec 20, 2016
by
Péter Szilágyi
Committed by
Felix Lange
Dec 20, 2016
Browse files
Options
Downloads
Patches
Plain Diff
eth, miner: verify PoW in the remote agent to notify submitter (#3438)
parent
1fe67c12
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
eth/api.go
+1
-1
1 addition, 1 deletion
eth/api.go
miner/remote_agent.go
+21
-12
21 additions, 12 deletions
miner/remote_agent.go
with
22 additions
and
13 deletions
eth/api.go
+
1
−
1
View file @
0ee79663
...
...
@@ -82,7 +82,7 @@ type PublicMinerAPI struct {
// NewPublicMinerAPI create a new PublicMinerAPI instance.
func
NewPublicMinerAPI
(
e
*
Ethereum
)
*
PublicMinerAPI
{
agent
:=
miner
.
NewRemoteAgent
()
agent
:=
miner
.
NewRemoteAgent
(
e
.
Pow
()
)
e
.
Miner
()
.
Register
(
agent
)
return
&
PublicMinerAPI
{
e
,
agent
}
...
...
This diff is collapsed.
Click to expand it.
miner/remote_agent.go
+
21
−
12
View file @
0ee79663
...
...
@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/pow"
)
type
hashrate
struct
{
...
...
@@ -41,6 +42,7 @@ type RemoteAgent struct {
workCh
chan
*
Work
returnCh
chan
<-
*
Result
pow
pow
.
PoW
currentWork
*
Work
work
map
[
common
.
Hash
]
*
Work
...
...
@@ -50,8 +52,9 @@ type RemoteAgent struct {
running
int32
// running indicates whether the agent is active. Call atomically
}
func
NewRemoteAgent
()
*
RemoteAgent
{
func
NewRemoteAgent
(
pow
pow
.
PoW
)
*
RemoteAgent
{
return
&
RemoteAgent
{
pow
:
pow
,
work
:
make
(
map
[
common
.
Hash
]
*
Work
),
hashrate
:
make
(
map
[
common
.
Hash
]
hashrate
),
}
...
...
@@ -126,24 +129,30 @@ func (a *RemoteAgent) GetWork() ([3]string, error) {
return
res
,
errors
.
New
(
"No work available yet, don't panic."
)
}
// Returns true or false, but does not indicate if the PoW was correct
// SubmitWork tries to inject a PoW solution tinto the remote agent, returning
// whether the solution was acceted or not (not can be both a bad PoW as well as
// any other error, like no work pending).
func
(
a
*
RemoteAgent
)
SubmitWork
(
nonce
uint64
,
mixDigest
,
hash
common
.
Hash
)
bool
{
a
.
mu
.
Lock
()
defer
a
.
mu
.
Unlock
()
// Make sure the work submitted is present
if
a
.
work
[
hash
]
!=
nil
{
block
:=
a
.
work
[
hash
]
.
Block
.
WithMiningResult
(
nonce
,
mixDigest
)
a
.
returnCh
<-
&
Result
{
a
.
work
[
hash
],
block
}
work
:=
a
.
work
[
hash
]
if
work
==
nil
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"Work was submitted for %x but no pending work found"
,
hash
)
return
false
}
// Make sure the PoW solutions is indeed valid
block
:=
work
.
Block
.
WithMiningResult
(
nonce
,
mixDigest
)
if
!
a
.
pow
.
Verify
(
block
)
{
glog
.
V
(
logger
.
Warn
)
.
Infof
(
"Invalid PoW submitted for %x"
,
hash
)
return
false
}
// Solutions seems to be valid, return to the miner and notify acceptance
a
.
returnCh
<-
&
Result
{
work
,
block
}
delete
(
a
.
work
,
hash
)
return
true
}
else
{
glog
.
V
(
logger
.
Info
)
.
Infof
(
"Work was submitted for %x but no pending work found
\n
"
,
hash
)
}
return
false
}
// loop monitors mining events on the work and quit channels, updating the internal
...
...
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