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
c32073b1
Commit
c32073b1
authored
Aug 6, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
miner, rpc: added submit hashrate for remote agents
parent
82ef26f6
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
miner/miner.go
+9
-2
9 additions, 2 deletions
miner/miner.go
miner/remote_agent.go
+35
-2
35 additions, 2 deletions
miner/remote_agent.go
rpc/api/eth.go
+10
-0
10 additions, 0 deletions
rpc/api/eth.go
rpc/api/eth_args.go
+31
-0
31 additions, 0 deletions
rpc/api/eth_args.go
with
85 additions
and
4 deletions
miner/miner.go
+
9
−
2
View file @
c32073b1
...
@@ -139,8 +139,15 @@ func (self *Miner) Mining() bool {
...
@@ -139,8 +139,15 @@ func (self *Miner) Mining() bool {
return
atomic
.
LoadInt32
(
&
self
.
mining
)
>
0
return
atomic
.
LoadInt32
(
&
self
.
mining
)
>
0
}
}
func
(
self
*
Miner
)
HashRate
()
int64
{
func
(
self
*
Miner
)
HashRate
()
(
tot
int64
)
{
return
self
.
pow
.
GetHashrate
()
tot
+=
self
.
pow
.
GetHashrate
()
// do we care this might race? is it worth we're rewriting some
// aspects of the worker/locking up agents so we can get an accurate
// hashrate?
for
_
,
agent
:=
range
self
.
worker
.
agents
{
tot
+=
agent
.
GetHashRate
()
}
return
}
}
func
(
self
*
Miner
)
SetExtra
(
extra
[]
byte
)
{
func
(
self
*
Miner
)
SetExtra
(
extra
[]
byte
)
{
...
...
This diff is collapsed.
Click to expand it.
miner/remote_agent.go
+
35
−
2
View file @
c32073b1
...
@@ -27,6 +27,11 @@ import (
...
@@ -27,6 +27,11 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
)
)
type
hashrate
struct
{
ping
time
.
Time
rate
uint64
}
type
RemoteAgent
struct
{
type
RemoteAgent
struct
{
mu
sync
.
Mutex
mu
sync
.
Mutex
...
@@ -36,14 +41,24 @@ type RemoteAgent struct {
...
@@ -36,14 +41,24 @@ type RemoteAgent struct {
currentWork
*
Work
currentWork
*
Work
work
map
[
common
.
Hash
]
*
Work
work
map
[
common
.
Hash
]
*
Work
hashrateMu
sync
.
RWMutex
hashrate
map
[
common
.
Hash
]
hashrate
}
}
func
NewRemoteAgent
()
*
RemoteAgent
{
func
NewRemoteAgent
()
*
RemoteAgent
{
agent
:=
&
RemoteAgent
{
work
:
make
(
map
[
common
.
Hash
]
*
Work
)}
agent
:=
&
RemoteAgent
{
work
:
make
(
map
[
common
.
Hash
]
*
Work
)
,
hashrate
:
make
(
map
[
common
.
Hash
]
hashrate
)
}
return
agent
return
agent
}
}
func
(
a
*
RemoteAgent
)
SubmitHashrate
(
id
common
.
Hash
,
rate
uint64
)
{
a
.
hashrateMu
.
Lock
()
defer
a
.
hashrateMu
.
Unlock
()
a
.
hashrate
[
id
]
=
hashrate
{
time
.
Now
(),
rate
}
}
func
(
a
*
RemoteAgent
)
Work
()
chan
<-
*
Work
{
func
(
a
*
RemoteAgent
)
Work
()
chan
<-
*
Work
{
return
a
.
workCh
return
a
.
workCh
}
}
...
@@ -63,7 +78,17 @@ func (a *RemoteAgent) Stop() {
...
@@ -63,7 +78,17 @@ func (a *RemoteAgent) Stop() {
close
(
a
.
workCh
)
close
(
a
.
workCh
)
}
}
func
(
a
*
RemoteAgent
)
GetHashRate
()
int64
{
return
0
}
// GetHashRate returns the accumulated hashrate of all identifier combined
func
(
a
*
RemoteAgent
)
GetHashRate
()
(
tot
int64
)
{
a
.
hashrateMu
.
RLock
()
defer
a
.
hashrateMu
.
RUnlock
()
// this could overflow
for
_
,
hashrate
:=
range
a
.
hashrate
{
tot
+=
int64
(
hashrate
.
rate
)
}
return
}
func
(
a
*
RemoteAgent
)
GetWork
()
[
3
]
string
{
func
(
a
*
RemoteAgent
)
GetWork
()
[
3
]
string
{
a
.
mu
.
Lock
()
a
.
mu
.
Lock
()
...
@@ -131,6 +156,14 @@ out:
...
@@ -131,6 +156,14 @@ out:
}
}
}
}
a
.
mu
.
Unlock
()
a
.
mu
.
Unlock
()
a
.
hashrateMu
.
Lock
()
for
id
,
hashrate
:=
range
a
.
hashrate
{
if
time
.
Since
(
hashrate
.
ping
)
>
10
*
time
.
Second
{
delete
(
a
.
hashrate
,
id
)
}
}
a
.
hashrateMu
.
Unlock
()
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
rpc/api/eth.go
+
10
−
0
View file @
c32073b1
...
@@ -92,6 +92,7 @@ var (
...
@@ -92,6 +92,7 @@ var (
"eth_hashrate"
:
(
*
ethApi
)
.
Hashrate
,
"eth_hashrate"
:
(
*
ethApi
)
.
Hashrate
,
"eth_getWork"
:
(
*
ethApi
)
.
GetWork
,
"eth_getWork"
:
(
*
ethApi
)
.
GetWork
,
"eth_submitWork"
:
(
*
ethApi
)
.
SubmitWork
,
"eth_submitWork"
:
(
*
ethApi
)
.
SubmitWork
,
"eth_submitHashrate"
:
(
*
ethApi
)
.
SubmitHashrate
,
"eth_resend"
:
(
*
ethApi
)
.
Resend
,
"eth_resend"
:
(
*
ethApi
)
.
Resend
,
"eth_pendingTransactions"
:
(
*
ethApi
)
.
PendingTransactions
,
"eth_pendingTransactions"
:
(
*
ethApi
)
.
PendingTransactions
,
"eth_getTransactionReceipt"
:
(
*
ethApi
)
.
GetTransactionReceipt
,
"eth_getTransactionReceipt"
:
(
*
ethApi
)
.
GetTransactionReceipt
,
...
@@ -573,6 +574,15 @@ func (self *ethApi) SubmitWork(req *shared.Request) (interface{}, error) {
...
@@ -573,6 +574,15 @@ func (self *ethApi) SubmitWork(req *shared.Request) (interface{}, error) {
return
self
.
xeth
.
RemoteMining
()
.
SubmitWork
(
args
.
Nonce
,
common
.
HexToHash
(
args
.
Digest
),
common
.
HexToHash
(
args
.
Header
)),
nil
return
self
.
xeth
.
RemoteMining
()
.
SubmitWork
(
args
.
Nonce
,
common
.
HexToHash
(
args
.
Digest
),
common
.
HexToHash
(
args
.
Header
)),
nil
}
}
func
(
self
*
ethApi
)
SubmitHashrate
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
SubmitHashRateArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
self
.
xeth
.
RemoteMining
()
.
SubmitHashrate
(
common
.
HexToHash
(
args
.
Id
),
args
.
Rate
)
return
nil
,
nil
}
func
(
self
*
ethApi
)
Resend
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
ethApi
)
Resend
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
ResendArgs
)
args
:=
new
(
ResendArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
rpc/api/eth_args.go
+
31
−
0
View file @
c32073b1
...
@@ -169,6 +169,37 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -169,6 +169,37 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
return
nil
return
nil
}
}
type
SubmitHashRateArgs
struct
{
Id
string
Rate
uint64
}
func
(
args
*
SubmitHashRateArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
2
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
arg0
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"hash"
,
"not a string"
)
}
args
.
Id
=
arg0
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"rate"
,
"not a string"
)
}
args
.
Rate
=
common
.
String2Big
(
arg1
)
.
Uint64
()
return
nil
}
type
HashArgs
struct
{
type
HashArgs
struct
{
Hash
string
Hash
string
}
}
...
...
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