Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
ab6311c1
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab6311c1
编写于
3月 23, 2015
作者:
T
Taylor Gerring
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move remote mining agent to XEth
上级
d76e8cb1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
9 deletion
+93
-9
rpc/api.go
rpc/api.go
+4
-9
xeth/miner_agent.go
xeth/miner_agent.go
+81
-0
xeth/xeth.go
xeth/xeth.go
+8
-0
未找到文件。
rpc/api.go
浏览文件 @
ab6311c1
...
...
@@ -17,20 +17,15 @@ type EthereumApi struct {
eth
*
xeth
.
XEth
xethMu
sync
.
RWMutex
db
common
.
Database
// Miner agent
agent
*
Agent
}
func
NewEthereumApi
(
xeth
*
xeth
.
XEth
,
dataDir
string
)
*
EthereumApi
{
// What about when dataDir is empty?
db
,
_
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"dapps"
))
api
:=
&
EthereumApi
{
eth
:
xeth
,
db
:
db
,
agent
:
NewAgent
(),
eth
:
xeth
,
db
:
db
,
}
xeth
.
Backend
()
.
Miner
()
.
Register
(
api
.
agent
)
return
api
}
...
...
@@ -349,13 +344,13 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
*
reply
=
NewLogsRes
(
api
.
xeth
()
.
AllLogs
(
opts
))
case
"eth_getWork"
:
api
.
xeth
()
.
SetMining
(
true
)
*
reply
=
api
.
agent
.
GetWork
()
*
reply
=
api
.
xeth
()
.
RemoteMining
()
.
GetWork
()
case
"eth_submitWork"
:
args
:=
new
(
SubmitWorkArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
api
.
agent
.
SetResult
(
args
.
Nonce
,
args
.
Digest
,
args
.
Header
)
*
reply
=
api
.
xeth
()
.
RemoteMining
()
.
SubmitWork
(
args
.
Nonce
,
args
.
Digest
,
args
.
Header
)
case
"db_putString"
:
args
:=
new
(
DbArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
xeth/miner_agent.go
0 → 100644
浏览文件 @
ab6311c1
package
xeth
import
(
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/miner"
)
type
Agent
struct
{
work
*
types
.
Block
currentWork
*
types
.
Block
quit
chan
struct
{}
workCh
chan
*
types
.
Block
returnCh
chan
<-
miner
.
Work
}
func
NewAgent
()
*
Agent
{
agent
:=
&
Agent
{}
go
agent
.
run
()
return
agent
}
func
(
a
*
Agent
)
Work
()
chan
<-
*
types
.
Block
{
return
a
.
workCh
}
func
(
a
*
Agent
)
SetWorkCh
(
returnCh
chan
<-
miner
.
Work
)
{
a
.
returnCh
=
returnCh
}
func
(
a
*
Agent
)
Start
()
{
a
.
quit
=
make
(
chan
struct
{})
a
.
workCh
=
make
(
chan
*
types
.
Block
,
1
)
}
func
(
a
*
Agent
)
Stop
()
{
close
(
a
.
quit
)
close
(
a
.
workCh
)
}
func
(
a
*
Agent
)
GetHashRate
()
int64
{
return
0
}
func
(
a
*
Agent
)
run
()
{
out
:
for
{
select
{
case
<-
a
.
quit
:
break
out
case
work
:=
<-
a
.
workCh
:
a
.
work
=
work
}
}
}
func
(
a
*
Agent
)
GetWork
()
[
3
]
string
{
// TODO return HashNoNonce, DAGSeedHash, Difficulty
var
res
[
3
]
string
// XXX Wait here untill work != nil ?.
if
a
.
work
!=
nil
{
res
[
0
]
=
a
.
work
.
HashNoNonce
()
.
Hex
()
// Header Hash No Nonce
res
[
1
]
=
common
.
Hash
{}
.
Hex
()
// DAG Seed
res
[
2
]
=
common
.
Hash
{}
.
Hex
()
// Difficulty
}
return
res
}
func
(
a
*
Agent
)
SubmitWork
(
nonce
uint64
,
mixDigest
,
seedHash
common
.
Hash
)
bool
{
// Return true or false, but does not indicate if the PoW was correct
// Make sure the external miner was working on the right hash
if
a
.
currentWork
!=
nil
&&
a
.
work
!=
nil
&&
a
.
currentWork
.
Hash
()
==
a
.
work
.
Hash
()
{
a
.
returnCh
<-
miner
.
Work
{
a
.
currentWork
.
Number
()
.
Uint64
(),
nonce
,
mixDigest
.
Bytes
(),
seedHash
.
Bytes
()}
return
true
}
return
false
}
xeth/xeth.go
浏览文件 @
ab6311c1
...
...
@@ -100,6 +100,9 @@ type XEth struct {
// regmut sync.Mutex
// register map[string][]*interface{} // TODO improve return type
// Miner agent
agent
*
Agent
}
// New creates an XEth that uses the given frontend.
...
...
@@ -117,7 +120,10 @@ func New(eth Backend, frontend Frontend) *XEth {
frontend
:
frontend
,
logs
:
make
(
map
[
int
]
*
logFilter
),
messages
:
make
(
map
[
int
]
*
whisperFilter
),
agent
:
NewAgent
(),
}
eth
.
Miner
()
.
Register
(
xeth
.
agent
)
if
frontend
==
nil
{
xeth
.
frontend
=
dummyFrontend
{}
}
...
...
@@ -164,6 +170,8 @@ func (self *XEth) stop() {
func
(
self
*
XEth
)
DefaultGas
()
*
big
.
Int
{
return
defaultGas
}
func
(
self
*
XEth
)
DefaultGasPrice
()
*
big
.
Int
{
return
defaultGasPrice
}
func
(
self
*
XEth
)
RemoteMining
()
*
Agent
{
return
self
.
agent
}
func
(
self
*
XEth
)
AtStateNum
(
num
int64
)
*
XEth
{
chain
:=
self
.
Backend
()
.
ChainManager
()
var
block
*
types
.
Block
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录