Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
e456451a
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,发现更多精彩内容 >>
提交
e456451a
编写于
4月 11, 2016
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2440 from karalabe/update-ethash
Update ethash
上级
8abf06d3
bf1f6203
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
36 addition
and
36 deletion
+36
-36
Godeps/Godeps.json
Godeps/Godeps.json
+4
-5
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
+13
-10
Godeps/_workspace/src/github.com/ethereum/ethash/ethash_opencl.go
...workspace/src/github.com/ethereum/ethash/ethash_opencl.go
+15
-16
Godeps/_workspace/src/github.com/rs/xhandler/chain.go
Godeps/_workspace/src/github.com/rs/xhandler/chain.go
+1
-1
Godeps/_workspace/src/github.com/rs/xhandler/middleware.go
Godeps/_workspace/src/github.com/rs/xhandler/middleware.go
+1
-1
Godeps/_workspace/src/github.com/rs/xhandler/xhandler.go
Godeps/_workspace/src/github.com/rs/xhandler/xhandler.go
+1
-1
eth/gpu_mining.go
eth/gpu_mining.go
+1
-2
未找到文件。
Godeps/Godeps.json
浏览文件 @
e456451a
{
"ImportPath"
:
"github.com/ethereum/go-ethereum"
,
"GoVersion"
:
"go1.5.2"
,
"GodepVersion"
:
"v60"
,
"Packages"
:
[
"./..."
],
...
...
@@ -21,8 +20,8 @@
},
{
"ImportPath"
:
"github.com/ethereum/ethash"
,
"Comment"
:
"v23.1-24
2-gbc9ba4d
"
,
"Rev"
:
"
bc9ba4d6a83a0fe308fefd8c6001b8ed1607137f
"
"Comment"
:
"v23.1-24
5-g25b32de
"
,
"Rev"
:
"
25b32de0c0271065c28c3719c2bfe86959d72f0c
"
},
{
"ImportPath"
:
"github.com/fatih/color"
,
...
...
@@ -145,8 +144,8 @@
"Rev"
:
"53221230c215611a90762720c9042ac782ef74ee"
},
{
"ImportPath"
:
"github.com/rs/cors"
,
"Rev"
:
"5950cf11d77f8a61b432a25dd4d444b4ced01379"
"ImportPath"
:
"github.com/rs/cors"
,
"Rev"
:
"5950cf11d77f8a61b432a25dd4d444b4ced01379"
},
{
"ImportPath"
:
"github.com/syndtr/goleveldb/leveldb"
,
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
浏览文件 @
e456451a
...
...
@@ -105,6 +105,15 @@ func freeCache(cache *cache) {
cache
.
ptr
=
nil
}
func
(
cache
*
cache
)
compute
(
dagSize
uint64
,
hash
common
.
Hash
,
nonce
uint64
)
(
ok
bool
,
mixDigest
,
result
common
.
Hash
)
{
ret
:=
C
.
ethash_light_compute_internal
(
cache
.
ptr
,
C
.
uint64_t
(
dagSize
),
hashToH256
(
hash
),
C
.
uint64_t
(
nonce
))
// Make sure cache is live until after the C call.
// This is important because a GC might happen and execute
// the finalizer before the call completes.
_
=
cache
return
bool
(
ret
.
success
),
h256ToHash
(
ret
.
mix_hash
),
h256ToHash
(
ret
.
result
)
}
// Light implements the Verify half of the proof of work. It uses a few small
// in-memory caches to verify the nonces found by Full.
type
Light
struct
{
...
...
@@ -140,29 +149,23 @@ func (l *Light) Verify(block pow.Block) bool {
cache
:=
l
.
getCache
(
blockNum
)
dagSize
:=
C
.
ethash_get_datasize
(
C
.
uint64_t
(
blockNum
))
if
l
.
test
{
dagSize
=
dagSizeForTesting
}
// Recompute the hash using the cache.
hash
:=
hashToH256
(
block
.
HashNoNonce
())
ret
:=
C
.
ethash_light_compute_internal
(
cache
.
ptr
,
dagSize
,
hash
,
C
.
uint64_t
(
block
.
Nonce
()))
if
!
ret
.
success
{
ok
,
mixDigest
,
result
:=
cache
.
compute
(
uint64
(
dagSize
),
block
.
HashNoNonce
(),
block
.
Nonce
())
if
!
ok
{
return
false
}
// avoid mixdigest malleability as it's not included in a block's "hashNononce"
if
block
.
MixDigest
()
!=
h256ToHash
(
ret
.
mix_hash
)
{
if
block
.
MixDigest
()
!=
mixDigest
{
return
false
}
// Make sure cache is live until after the C call.
// This is important because a GC might happen and execute
// the finalizer before the call completes.
_
=
cache
// The actual check.
target
:=
new
(
big
.
Int
)
.
Div
(
maxUint256
,
difficulty
)
return
h256ToHash
(
ret
.
result
)
.
Big
()
.
Cmp
(
target
)
<=
0
return
result
.
Big
()
.
Cmp
(
target
)
<=
0
}
func
h256ToHash
(
in
C
.
ethash_h256_t
)
common
.
Hash
{
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/ethash_opencl.go
浏览文件 @
e456451a
...
...
@@ -138,7 +138,7 @@ func PrintDevices() {
platforms
,
err
:=
cl
.
GetPlatforms
()
if
err
!=
nil
{
fmt
.
Println
(
"Plaform error (check your OpenCL installation):
%v
"
,
err
)
fmt
.
Println
(
"Plaform error (check your OpenCL installation):"
,
err
)
return
}
...
...
@@ -267,13 +267,13 @@ func initCLDevice(deviceId int, device *cl.Device, c *OpenCLMiner) error {
context
,
err
:=
cl
.
CreateContext
([]
*
cl
.
Device
{
device
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed creating context:"
,
err
)
return
fmt
.
Errorf
(
"failed creating context:
%v
"
,
err
)
}
// TODO: test running with CL_QUEUE_PROFILING_ENABLE for profiling?
queue
,
err
:=
context
.
CreateCommandQueue
(
device
,
0
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"command queue err:"
,
err
)
return
fmt
.
Errorf
(
"command queue err:
%v
"
,
err
)
}
// See [4] section 3.2 and [3] "clBuildProgram".
...
...
@@ -287,7 +287,7 @@ func initCLDevice(deviceId int, device *cl.Device, c *OpenCLMiner) error {
program
,
err
:=
context
.
CreateProgramWithSource
([]
string
{
kernelCode
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"program err:"
,
err
)
return
fmt
.
Errorf
(
"program err:
%v
"
,
err
)
}
/* if using AMD OpenCL impl, you can set this to debug on x86 CPU device.
...
...
@@ -303,7 +303,7 @@ func initCLDevice(deviceId int, device *cl.Device, c *OpenCLMiner) error {
buildOpts
:=
""
err
=
program
.
BuildProgram
([]
*
cl
.
Device
{
device
},
buildOpts
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"program build err:"
,
err
)
return
fmt
.
Errorf
(
"program build err:
%v
"
,
err
)
}
var
searchKernelName
,
hashKernelName
string
...
...
@@ -313,7 +313,7 @@ func initCLDevice(deviceId int, device *cl.Device, c *OpenCLMiner) error {
searchKernel
,
err
:=
program
.
CreateKernel
(
searchKernelName
)
hashKernel
,
err
:=
program
.
CreateKernel
(
hashKernelName
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"kernel err:"
,
err
)
return
fmt
.
Errorf
(
"kernel err:
%v
"
,
err
)
}
// TODO: when this DAG size appears, patch the Go bindings
...
...
@@ -328,28 +328,28 @@ func initCLDevice(deviceId int, device *cl.Device, c *OpenCLMiner) error {
dagBuf
:=
*
(
new
(
*
cl
.
MemObject
))
dagBuf
,
err
=
context
.
CreateEmptyBuffer
(
cl
.
MemReadOnly
,
int
(
c
.
dagSize
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"allocating dag buf failed: "
,
err
)
return
fmt
.
Errorf
(
"allocating dag buf failed:
%v
"
,
err
)
}
// write DAG to device mem
dagPtr
:=
unsafe
.
Pointer
(
c
.
ethash
.
Full
.
current
.
ptr
.
data
)
_
,
err
=
queue
.
EnqueueWriteBuffer
(
dagBuf
,
true
,
0
,
int
(
c
.
dagSize
),
dagPtr
,
nil
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"writing to dag buf failed: "
,
err
)
return
fmt
.
Errorf
(
"writing to dag buf failed:
%v
"
,
err
)
}
searchBuffers
:=
make
([]
*
cl
.
MemObject
,
searchBufSize
)
for
i
:=
0
;
i
<
searchBufSize
;
i
++
{
searchBuff
,
err
:=
context
.
CreateEmptyBuffer
(
cl
.
MemWriteOnly
,
(
1
+
maxSearchResults
)
*
SIZEOF_UINT32
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"search buffer err:"
,
err
)
return
fmt
.
Errorf
(
"search buffer err:
%v
"
,
err
)
}
searchBuffers
[
i
]
=
searchBuff
}
headerBuf
,
err
:=
context
.
CreateEmptyBuffer
(
cl
.
MemReadOnly
,
32
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"header buffer err:"
,
err
)
return
fmt
.
Errorf
(
"header buffer err:
%v
"
,
err
)
}
// Unique, random nonces are crucial for mining efficieny.
...
...
@@ -556,13 +556,13 @@ func (c *OpenCLMiner) Search(block pow.Block, stop <-chan struct{}, index int) (
upperNonce
:=
uint64
(
binary
.
LittleEndian
.
Uint32
(
results
[
lo
:
hi
]))
checkNonce
=
p
.
startNonce
+
upperNonce
if
checkNonce
!=
0
{
cn
:=
C
.
uint64_t
(
checkNonce
)
ds
:=
C
.
uint64_t
(
c
.
dagSize
)
// We verify that the nonce is indeed a solution by
// executing the Ethash verification function (on the CPU).
ret
:=
C
.
ethash_light_compute_internal
(
c
.
ethash
.
Light
.
current
.
ptr
,
ds
,
hashToH256
(
headerHash
),
cn
)
cache
:=
c
.
ethash
.
Light
.
getCache
(
block
.
NumberU64
())
ok
,
mixDigest
,
result
:=
cache
.
compute
(
c
.
dagSize
,
headerHash
,
checkNonce
)
// TODO: return result first
if
ret
.
success
&&
h256ToHash
(
ret
.
result
)
.
Big
()
.
Cmp
(
target256
)
<=
0
{
if
ok
&&
result
.
Big
()
.
Cmp
(
target256
)
<=
0
{
_
,
err
=
d
.
queue
.
EnqueueUnmapMemObject
(
d
.
searchBuffers
[
p
.
bufIndex
],
cres
,
nil
)
if
err
!=
nil
{
fmt
.
Println
(
"Error in Search clEnqueueUnmapMemObject: "
,
err
)
...
...
@@ -573,9 +573,8 @@ func (c *OpenCLMiner) Search(block pow.Block, stop <-chan struct{}, index int) (
fmt
.
Println
(
"Error in Search WaitForEvents: "
,
err
)
}
}
return
checkNonce
,
C
.
GoBytes
(
unsafe
.
Pointer
(
&
ret
.
mix_hash
),
C
.
int
(
32
)
)
return
checkNonce
,
mixDigest
.
Bytes
(
)
}
_
,
err
:=
d
.
queue
.
EnqueueWriteBuffer
(
d
.
searchBuffers
[
p
.
bufIndex
],
false
,
0
,
4
,
unsafe
.
Pointer
(
&
zero
),
nil
)
if
err
!=
nil
{
fmt
.
Println
(
"Error in Search cl: EnqueueWriteBuffer"
,
err
)
...
...
Godeps/_workspace/src/github.com/rs/xhandler/chain.go
浏览文件 @
e456451a
...
...
@@ -3,7 +3,7 @@ package xhandler
import
(
"net/http"
"g
ithub.com/ethereum/go-ethereum/Godeps/_workspace/src/g
olang.org/x/net/context"
"golang.org/x/net/context"
)
// Chain is an helper to chain middleware handlers together for an easier
...
...
Godeps/_workspace/src/github.com/rs/xhandler/middleware.go
浏览文件 @
e456451a
...
...
@@ -4,7 +4,7 @@ import (
"net/http"
"time"
"g
ithub.com/ethereum/go-ethereum/Godeps/_workspace/src/g
olang.org/x/net/context"
"golang.org/x/net/context"
)
// CloseHandler returns a Handler cancelling the context when the client
...
...
Godeps/_workspace/src/github.com/rs/xhandler/xhandler.go
浏览文件 @
e456451a
...
...
@@ -14,7 +14,7 @@ package xhandler
import
(
"net/http"
"g
ithub.com/ethereum/go-ethereum/Godeps/_workspace/src/g
olang.org/x/net/context"
"golang.org/x/net/context"
)
// HandlerC is a net/context aware http.Handler
...
...
eth/gpu_mining.go
浏览文件 @
e456451a
...
...
@@ -56,8 +56,7 @@ func (s *Ethereum) StartMining(threads int, gpus string) error {
}
// TODO: re-creating miner is a bit ugly
cl
:=
ethash
.
NewCL
(
ids
)
s
.
miner
=
miner
.
New
(
s
,
s
.
EventMux
(),
cl
)
s
.
miner
=
miner
.
New
(
s
,
s
.
chainConfig
,
s
.
EventMux
(),
ethash
.
NewCL
(
ids
))
go
s
.
miner
.
Start
(
eb
,
len
(
ids
))
return
nil
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录