diff options
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/LICENSE | 25 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/README.md | 12 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/mmap.go | 112 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/mmap_unix.go | 67 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/mmap_windows.go | 125 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/msync_netbsd.go | 8 | ||||
-rw-r--r-- | vendor/github.com/edsrzf/mmap-go/msync_unix.go | 14 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/CMakeLists.txt | 14 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/MANIFEST.in | 17 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/Makefile | 6 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/README.md | 22 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/Vagrantfile | 7 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/appveyor.yml | 43 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/ethash.go | 440 | ||||
-rw-r--r-- | vendor/github.com/ethereum/ethash/ethashc.go | 51 | ||||
-rwxr-xr-x | vendor/github.com/ethereum/ethash/setup.py | 47 | ||||
-rw-r--r-- | vendor/vendor.json | 8 |
17 files changed, 367 insertions, 651 deletions
diff --git a/vendor/github.com/edsrzf/mmap-go/LICENSE b/vendor/github.com/edsrzf/mmap-go/LICENSE new file mode 100644 index 000000000..8f05f338a --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2011, Evan Shaw <edsrzf@gmail.com> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/vendor/github.com/edsrzf/mmap-go/README.md b/vendor/github.com/edsrzf/mmap-go/README.md new file mode 100644 index 000000000..4cc2bfe1c --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/README.md @@ -0,0 +1,12 @@ +mmap-go +======= + +mmap-go is a portable mmap package for the [Go programming language](http://golang.org). +It has been tested on Linux (386, amd64), OS X, and Windows (386). It should also +work on other Unix-like platforms, but hasn't been tested with them. I'm interested +to hear about the results. + +I haven't been able to add more features without adding significant complexity, +so mmap-go doesn't support mprotect, mincore, and maybe a few other things. +If you're running on a Unix-like platform and need some of these features, +I suggest Gustavo Niemeyer's [gommap](http://labix.org/gommap). diff --git a/vendor/github.com/edsrzf/mmap-go/mmap.go b/vendor/github.com/edsrzf/mmap-go/mmap.go new file mode 100644 index 000000000..7bb4965ed --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/mmap.go @@ -0,0 +1,112 @@ +// Copyright 2011 Evan Shaw. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file defines the common package interface and contains a little bit of +// factored out logic. + +// Package mmap allows mapping files into memory. It tries to provide a simple, reasonably portable interface, +// but doesn't go out of its way to abstract away every little platform detail. +// This specifically means: +// * forked processes may or may not inherit mappings +// * a file's timestamp may or may not be updated by writes through mappings +// * specifying a size larger than the file's actual size can increase the file's size +// * If the mapped file is being modified by another process while your program's running, don't expect consistent results between platforms +package mmap + +import ( + "errors" + "os" + "reflect" + "unsafe" +) + +const ( + // RDONLY maps the memory read-only. + // Attempts to write to the MMap object will result in undefined behavior. + RDONLY = 0 + // RDWR maps the memory as read-write. Writes to the MMap object will update the + // underlying file. + RDWR = 1 << iota + // COPY maps the memory as copy-on-write. Writes to the MMap object will affect + // memory, but the underlying file will remain unchanged. + COPY + // If EXEC is set, the mapped memory is marked as executable. + EXEC +) + +const ( + // If the ANON flag is set, the mapped memory will not be backed by a file. + ANON = 1 << iota +) + +// MMap represents a file mapped into memory. +type MMap []byte + +// Map maps an entire file into memory. +// If ANON is set in flags, f is ignored. +func Map(f *os.File, prot, flags int) (MMap, error) { + return MapRegion(f, -1, prot, flags, 0) +} + +// MapRegion maps part of a file into memory. +// The offset parameter must be a multiple of the system's page size. +// If length < 0, the entire file will be mapped. +// If ANON is set in flags, f is ignored. +func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MMap, error) { + var fd uintptr + if flags&ANON == 0 { + fd = uintptr(f.Fd()) + if length < 0 { + fi, err := f.Stat() + if err != nil { + return nil, err + } + length = int(fi.Size()) + } + } else { + if length <= 0 { + return nil, errors.New("anonymous mapping requires non-zero length") + } + fd = ^uintptr(0) + } + return mmap(length, uintptr(prot), uintptr(flags), fd, offset) +} + +func (m *MMap) header() *reflect.SliceHeader { + return (*reflect.SliceHeader)(unsafe.Pointer(m)) +} + +// Lock keeps the mapped region in physical memory, ensuring that it will not be +// swapped out. +func (m MMap) Lock() error { + dh := m.header() + return lock(dh.Data, uintptr(dh.Len)) +} + +// Unlock reverses the effect of Lock, allowing the mapped region to potentially +// be swapped out. +// If m is already unlocked, aan error will result. +func (m MMap) Unlock() error { + dh := m.header() + return unlock(dh.Data, uintptr(dh.Len)) +} + +// Flush synchronizes the mapping's contents to the file's contents on disk. +func (m MMap) Flush() error { + dh := m.header() + return flush(dh.Data, uintptr(dh.Len)) +} + +// Unmap deletes the memory mapped region, flushes any remaining changes, and sets +// m to nil. +// Trying to read or write any remaining references to m after Unmap is called will +// result in undefined behavior. +// Unmap should only be called on the slice value that was originally returned from +// a call to Map. Calling Unmap on a derived slice may cause errors. +func (m *MMap) Unmap() error { + dh := m.header() + err := unmap(dh.Data, uintptr(dh.Len)) + *m = nil + return err +} diff --git a/vendor/github.com/edsrzf/mmap-go/mmap_unix.go b/vendor/github.com/edsrzf/mmap-go/mmap_unix.go new file mode 100644 index 000000000..4af98420d --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/mmap_unix.go @@ -0,0 +1,67 @@ +// Copyright 2011 Evan Shaw. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin dragonfly freebsd linux openbsd solaris netbsd + +package mmap + +import ( + "syscall" +) + +func mmap(len int, inprot, inflags, fd uintptr, off int64) ([]byte, error) { + flags := syscall.MAP_SHARED + prot := syscall.PROT_READ + switch { + case inprot© != 0: + prot |= syscall.PROT_WRITE + flags = syscall.MAP_PRIVATE + case inprot&RDWR != 0: + prot |= syscall.PROT_WRITE + } + if inprot&EXEC != 0 { + prot |= syscall.PROT_EXEC + } + if inflags&ANON != 0 { + flags |= syscall.MAP_ANON + } + + b, err := syscall.Mmap(int(fd), off, len, prot, flags) + if err != nil { + return nil, err + } + return b, nil +} + +func flush(addr, len uintptr) error { + _, _, errno := syscall.Syscall(_SYS_MSYNC, addr, len, _MS_SYNC) + if errno != 0 { + return syscall.Errno(errno) + } + return nil +} + +func lock(addr, len uintptr) error { + _, _, errno := syscall.Syscall(syscall.SYS_MLOCK, addr, len, 0) + if errno != 0 { + return syscall.Errno(errno) + } + return nil +} + +func unlock(addr, len uintptr) error { + _, _, errno := syscall.Syscall(syscall.SYS_MUNLOCK, addr, len, 0) + if errno != 0 { + return syscall.Errno(errno) + } + return nil +} + +func unmap(addr, len uintptr) error { + _, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, addr, len, 0) + if errno != 0 { + return syscall.Errno(errno) + } + return nil +} diff --git a/vendor/github.com/edsrzf/mmap-go/mmap_windows.go b/vendor/github.com/edsrzf/mmap-go/mmap_windows.go new file mode 100644 index 000000000..c3d2d02d3 --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/mmap_windows.go @@ -0,0 +1,125 @@ +// Copyright 2011 Evan Shaw. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mmap + +import ( + "errors" + "os" + "sync" + "syscall" +) + +// mmap on Windows is a two-step process. +// First, we call CreateFileMapping to get a handle. +// Then, we call MapviewToFile to get an actual pointer into memory. +// Because we want to emulate a POSIX-style mmap, we don't want to expose +// the handle -- only the pointer. We also want to return only a byte slice, +// not a struct, so it's convenient to manipulate. + +// We keep this map so that we can get back the original handle from the memory address. +var handleLock sync.Mutex +var handleMap = map[uintptr]syscall.Handle{} + +func mmap(len int, prot, flags, hfile uintptr, off int64) ([]byte, error) { + flProtect := uint32(syscall.PAGE_READONLY) + dwDesiredAccess := uint32(syscall.FILE_MAP_READ) + switch { + case prot© != 0: + flProtect = syscall.PAGE_WRITECOPY + dwDesiredAccess = syscall.FILE_MAP_COPY + case prot&RDWR != 0: + flProtect = syscall.PAGE_READWRITE + dwDesiredAccess = syscall.FILE_MAP_WRITE + } + if prot&EXEC != 0 { + flProtect <<= 4 + dwDesiredAccess |= syscall.FILE_MAP_EXECUTE + } + + // The maximum size is the area of the file, starting from 0, + // that we wish to allow to be mappable. It is the sum of + // the length the user requested, plus the offset where that length + // is starting from. This does not map the data into memory. + maxSizeHigh := uint32((off + int64(len)) >> 32) + maxSizeLow := uint32((off + int64(len)) & 0xFFFFFFFF) + // TODO: Do we need to set some security attributes? It might help portability. + h, errno := syscall.CreateFileMapping(syscall.Handle(hfile), nil, flProtect, maxSizeHigh, maxSizeLow, nil) + if h == 0 { + return nil, os.NewSyscallError("CreateFileMapping", errno) + } + + // Actually map a view of the data into memory. The view's size + // is the length the user requested. + fileOffsetHigh := uint32(off >> 32) + fileOffsetLow := uint32(off & 0xFFFFFFFF) + addr, errno := syscall.MapViewOfFile(h, dwDesiredAccess, fileOffsetHigh, fileOffsetLow, uintptr(len)) + if addr == 0 { + return nil, os.NewSyscallError("MapViewOfFile", errno) + } + handleLock.Lock() + handleMap[addr] = h + handleLock.Unlock() + + m := MMap{} + dh := m.header() + dh.Data = addr + dh.Len = len + dh.Cap = dh.Len + + return m, nil +} + +func flush(addr, len uintptr) error { + errno := syscall.FlushViewOfFile(addr, len) + if errno != nil { + return os.NewSyscallError("FlushViewOfFile", errno) + } + + handleLock.Lock() + defer handleLock.Unlock() + handle, ok := handleMap[addr] + if !ok { + // should be impossible; we would've errored above + return errors.New("unknown base address") + } + + errno = syscall.FlushFileBuffers(handle) + return os.NewSyscallError("FlushFileBuffers", errno) +} + +func lock(addr, len uintptr) error { + errno := syscall.VirtualLock(addr, len) + return os.NewSyscallError("VirtualLock", errno) +} + +func unlock(addr, len uintptr) error { + errno := syscall.VirtualUnlock(addr, len) + return os.NewSyscallError("VirtualUnlock", errno) +} + +func unmap(addr, len uintptr) error { + flush(addr, len) + // Lock the UnmapViewOfFile along with the handleMap deletion. + // As soon as we unmap the view, the OS is free to give the + // same addr to another new map. We don't want another goroutine + // to insert and remove the same addr into handleMap while + // we're trying to remove our old addr/handle pair. + handleLock.Lock() + defer handleLock.Unlock() + err := syscall.UnmapViewOfFile(addr) + if err != nil { + return err + } + + handle, ok := handleMap[addr] + if !ok { + // should be impossible; we would've errored above + return errors.New("unknown base address") + } + delete(handleMap, addr) + + e := syscall.CloseHandle(syscall.Handle(handle)) + return os.NewSyscallError("CloseHandle", e) +} diff --git a/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go b/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go new file mode 100644 index 000000000..a64b003e2 --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/msync_netbsd.go @@ -0,0 +1,8 @@ +// Copyright 2011 Evan Shaw. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mmap + +const _SYS_MSYNC = 277 +const _MS_SYNC = 0x04 diff --git a/vendor/github.com/edsrzf/mmap-go/msync_unix.go b/vendor/github.com/edsrzf/mmap-go/msync_unix.go new file mode 100644 index 000000000..91ee5f40f --- /dev/null +++ b/vendor/github.com/edsrzf/mmap-go/msync_unix.go @@ -0,0 +1,14 @@ +// Copyright 2011 Evan Shaw. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin dragonfly freebsd linux openbsd solaris + +package mmap + +import ( + "syscall" +) + +const _SYS_MSYNC = syscall.SYS_MSYNC +const _MS_SYNC = syscall.MS_SYNC diff --git a/vendor/github.com/ethereum/ethash/CMakeLists.txt b/vendor/github.com/ethereum/ethash/CMakeLists.txt deleted file mode 100644 index 807c43e96..000000000 --- a/vendor/github.com/ethereum/ethash/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 2.8.7) -project(ethash) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") -set(ETHHASH_LIBS ethash) - -if (WIN32 AND WANT_CRYPTOPP) - add_subdirectory(cryptopp) -endif() - -add_subdirectory(src/libethash) - -add_subdirectory(src/benchmark EXCLUDE_FROM_ALL) -add_subdirectory(test/c) diff --git a/vendor/github.com/ethereum/ethash/MANIFEST.in b/vendor/github.com/ethereum/ethash/MANIFEST.in deleted file mode 100644 index 74e73c8be..000000000 --- a/vendor/github.com/ethereum/ethash/MANIFEST.in +++ /dev/null @@ -1,17 +0,0 @@ -include setup.py - -# C sources -include src/libethash/internal.c -include src/libethash/sha3.c -include src/libethash/util.c -include src/python/core.c - -# Headers -include src/libethash/compiler.h -include src/libethash/data_sizes.h -include src/libethash/endian.h -include src/libethash/ethash.h -include src/libethash/fnv.h -include src/libethash/internal.h -include src/libethash/sha3.h -include src/libethash/util.h diff --git a/vendor/github.com/ethereum/ethash/Makefile b/vendor/github.com/ethereum/ethash/Makefile deleted file mode 100644 index 741d3b56d..000000000 --- a/vendor/github.com/ethereum/ethash/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -.PHONY: clean test -test: - ./test/test.sh - -clean: - rm -rf *.so pyethash.egg-info/ build/ test/python/python-virtual-env/ test/c/build/ pyethash.so test/python/*.pyc dist/ MANIFEST diff --git a/vendor/github.com/ethereum/ethash/README.md b/vendor/github.com/ethereum/ethash/README.md deleted file mode 100644 index 2b2c3b544..000000000 --- a/vendor/github.com/ethereum/ethash/README.md +++ /dev/null @@ -1,22 +0,0 @@ -[![Build Status](https://travis-ci.org/ethereum/ethash.svg?branch=master)](https://travis-ci.org/ethereum/ethash) -[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/debris/ethash?branch=master&svg=true)](https://ci.appveyor.com/project/debris/ethash-nr37r/branch/master) - -# Ethash - -For details on this project, please see the Ethereum wiki: -https://github.com/ethereum/wiki/wiki/Ethash - -### Coding Style for C++ code: - -Follow the same exact style as in [cpp-ethereum](https://github.com/ethereum/cpp-ethereum/blob/develop/CodingStandards.txt) - -### Coding Style for C code: - -The main thing above all is code consistency. - -- Tabs for indentation. A tab is 4 spaces -- Try to stick to the [K&R](http://en.wikipedia.org/wiki/Indent_style#K.26R_style), - especially for the C code. -- Keep the line lengths reasonable. No hard limit on 80 characters but don't go further - than 110. Some people work with multiple buffers next to each other. - Make them like you :) diff --git a/vendor/github.com/ethereum/ethash/Vagrantfile b/vendor/github.com/ethereum/ethash/Vagrantfile deleted file mode 100644 index 03891653f..000000000 --- a/vendor/github.com/ethereum/ethash/Vagrantfile +++ /dev/null @@ -1,7 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure(2) do |config| - config.vm.box = "Ubuntu 12.04" - config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" -end diff --git a/vendor/github.com/ethereum/ethash/appveyor.yml b/vendor/github.com/ethereum/ethash/appveyor.yml deleted file mode 100644 index ac36a0626..000000000 --- a/vendor/github.com/ethereum/ethash/appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: 1.0.0.{build} - -environment: - BOOST_ROOT: "c:/projects/ethash/deps/boost" - -branches: - only: - - master - - develop - -os: Windows Server 2012 R2 - -clone_folder: c:\projects\ethash - -#platform: Any CPU -#configuration: Debug - -install: - # by default, all script lines are interpreted as batch - -# scripts to run before build -before_build: - - echo "Downloading boost..." - - mkdir c:\projects\ethash\deps - - cd c:\projects\ethash\deps - - curl -O https://build.ethdev.com/builds/windows-precompiled/boost.tar.gz - - echo "Unzipping boost..." - - 7z x boost.tar.gz > nul - - 7z x boost.tar > nul - - ls - - echo "Running cmake..." - - cd c:\projects\ethash - - cmake . - -build: - project: ALL_BUILD.vcxproj # path to Visual Studio solution or project - -after_build: - - echo "Running tests..." - - cd c:\projects\ethash\test\c\Debug - - Test.exe - - echo "Finished!" - diff --git a/vendor/github.com/ethereum/ethash/ethash.go b/vendor/github.com/ethereum/ethash/ethash.go deleted file mode 100644 index 8e5cd8128..000000000 --- a/vendor/github.com/ethereum/ethash/ethash.go +++ /dev/null @@ -1,440 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// Copyright 2015 Lefteris Karapetsas <lefteris@refu.co> -// Copyright 2015 Matthew Wampler-Doty <matthew.wampler.doty@gmail.com> -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package ethash - -/* -#include "src/libethash/internal.h" - -int ethashGoCallback_cgo(unsigned); -*/ -import "C" - -import ( - "errors" - "fmt" - "io/ioutil" - "math/big" - "math/rand" - "os" - "os/user" - "path/filepath" - "runtime" - "sync" - "sync/atomic" - "time" - "unsafe" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/pow" -) - -var ( - maxUint256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0)) - sharedLight = new(Light) -) - -const ( - epochLength uint64 = 30000 - cacheSizeForTesting C.uint64_t = 1024 - dagSizeForTesting C.uint64_t = 1024 * 32 -) - -var DefaultDir = defaultDir() - -func defaultDir() string { - home := os.Getenv("HOME") - if user, err := user.Current(); err == nil { - home = user.HomeDir - } - if runtime.GOOS == "windows" { - return filepath.Join(home, "AppData", "Ethash") - } - return filepath.Join(home, ".ethash") -} - -// cache wraps an ethash_light_t with some metadata -// and automatic memory management. -type cache struct { - epoch uint64 - used time.Time - test bool - - gen sync.Once // ensures cache is only generated once. - ptr *C.struct_ethash_light -} - -// generate creates the actual cache. it can be called from multiple -// goroutines. the first call will generate the cache, subsequent -// calls wait until it is generated. -func (cache *cache) generate() { - cache.gen.Do(func() { - started := time.Now() - seedHash := makeSeedHash(cache.epoch) - log.Debug(fmt.Sprintf("Generating cache for epoch %d (%x)", cache.epoch, seedHash)) - size := C.ethash_get_cachesize(C.uint64_t(cache.epoch * epochLength)) - if cache.test { - size = cacheSizeForTesting - } - cache.ptr = C.ethash_light_new_internal(size, (*C.ethash_h256_t)(unsafe.Pointer(&seedHash[0]))) - runtime.SetFinalizer(cache, freeCache) - log.Debug(fmt.Sprintf("Done generating cache for epoch %d, it took %v", cache.epoch, time.Since(started))) - }) -} - -func freeCache(cache *cache) { - C.ethash_light_delete(cache.ptr) - 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 { - test bool // If set, use a smaller cache size - - mu sync.Mutex // Protects the per-epoch map of verification caches - caches map[uint64]*cache // Currently maintained verification caches - future *cache // Pre-generated cache for the estimated future DAG - - NumCaches int // Maximum number of caches to keep before eviction (only init, don't modify) -} - -// Verify checks whether the block's nonce is valid. -func (l *Light) Verify(block pow.Block) bool { - // TODO: do ethash_quick_verify before getCache in order - // to prevent DOS attacks. - blockNum := block.NumberU64() - if blockNum >= epochLength*2048 { - log.Debug(fmt.Sprintf("block number %d too high, limit is %d", epochLength*2048)) - return false - } - - difficulty := block.Difficulty() - /* Cannot happen if block header diff is validated prior to PoW, but can - happen if PoW is checked first due to parallel PoW checking. - We could check the minimum valid difficulty but for SoC we avoid (duplicating) - Ethereum protocol consensus rules here which are not in scope of Ethash - */ - if difficulty.Cmp(common.Big0) == 0 { - log.Debug(fmt.Sprintf("invalid block difficulty")) - return false - } - - cache := l.getCache(blockNum) - dagSize := C.ethash_get_datasize(C.uint64_t(blockNum)) - if l.test { - dagSize = dagSizeForTesting - } - // Recompute the hash using the cache. - 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() != mixDigest { - return false - } - - // The actual check. - target := new(big.Int).Div(maxUint256, difficulty) - return result.Big().Cmp(target) <= 0 -} - -func h256ToHash(in C.ethash_h256_t) common.Hash { - return *(*common.Hash)(unsafe.Pointer(&in.b)) -} - -func hashToH256(in common.Hash) C.ethash_h256_t { - return C.ethash_h256_t{b: *(*[32]C.uint8_t)(unsafe.Pointer(&in[0]))} -} - -func (l *Light) getCache(blockNum uint64) *cache { - var c *cache - epoch := blockNum / epochLength - - // If we have a PoW for that epoch, use that - l.mu.Lock() - if l.caches == nil { - l.caches = make(map[uint64]*cache) - } - if l.NumCaches == 0 { - l.NumCaches = 3 - } - c = l.caches[epoch] - if c == nil { - // No cached DAG, evict the oldest if the cache limit was reached - if len(l.caches) >= l.NumCaches { - var evict *cache - for _, cache := range l.caches { - if evict == nil || evict.used.After(cache.used) { - evict = cache - } - } - log.Debug(fmt.Sprintf("Evicting DAG for epoch %d in favour of epoch %d", evict.epoch, epoch)) - delete(l.caches, evict.epoch) - } - // If we have the new DAG pre-generated, use that, otherwise create a new one - if l.future != nil && l.future.epoch == epoch { - log.Debug(fmt.Sprintf("Using pre-generated DAG for epoch %d", epoch)) - c, l.future = l.future, nil - } else { - log.Debug(fmt.Sprintf("No pre-generated DAG available, creating new for epoch %d", epoch)) - c = &cache{epoch: epoch, test: l.test} - } - l.caches[epoch] = c - - // If we just used up the future cache, or need a refresh, regenerate - if l.future == nil || l.future.epoch <= epoch { - log.Debug(fmt.Sprintf("Pre-generating DAG for epoch %d", epoch+1)) - l.future = &cache{epoch: epoch + 1, test: l.test} - go l.future.generate() - } - } - c.used = time.Now() - l.mu.Unlock() - - // Wait for generation finish and return the cache - c.generate() - return c -} - -// dag wraps an ethash_full_t with some metadata -// and automatic memory management. -type dag struct { - epoch uint64 - test bool - dir string - - gen sync.Once // ensures DAG is only generated once. - ptr *C.struct_ethash_full -} - -// generate creates the actual DAG. it can be called from multiple -// goroutines. the first call will generate the DAG, subsequent -// calls wait until it is generated. -func (d *dag) generate() { - d.gen.Do(func() { - var ( - started = time.Now() - seedHash = makeSeedHash(d.epoch) - blockNum = C.uint64_t(d.epoch * epochLength) - cacheSize = C.ethash_get_cachesize(blockNum) - dagSize = C.ethash_get_datasize(blockNum) - ) - if d.test { - cacheSize = cacheSizeForTesting - dagSize = dagSizeForTesting - } - if d.dir == "" { - d.dir = DefaultDir - } - log.Info(fmt.Sprintf("Generating DAG for epoch %d (size %d) (%x)", d.epoch, dagSize, seedHash)) - // Generate a temporary cache. - // TODO: this could share the cache with Light - cache := C.ethash_light_new_internal(cacheSize, (*C.ethash_h256_t)(unsafe.Pointer(&seedHash[0]))) - defer C.ethash_light_delete(cache) - // Generate the actual DAG. - d.ptr = C.ethash_full_new_internal( - C.CString(d.dir), - hashToH256(seedHash), - dagSize, - cache, - (C.ethash_callback_t)(unsafe.Pointer(C.ethashGoCallback_cgo)), - ) - if d.ptr == nil { - panic("ethash_full_new IO or memory error") - } - runtime.SetFinalizer(d, freeDAG) - log.Info(fmt.Sprintf("Done generating DAG for epoch %d, it took %v", d.epoch, time.Since(started))) - }) -} - -func freeDAG(d *dag) { - C.ethash_full_delete(d.ptr) - d.ptr = nil -} - -func (d *dag) Ptr() unsafe.Pointer { - return unsafe.Pointer(d.ptr.data) -} - -//export ethashGoCallback -func ethashGoCallback(percent C.unsigned) C.int { - log.Info(fmt.Sprintf("Generating DAG: %d%%", percent)) - return 0 -} - -// MakeDAG pre-generates a DAG file for the given block number in the -// given directory. If dir is the empty string, the default directory -// is used. -func MakeDAG(blockNum uint64, dir string) error { - d := &dag{epoch: blockNum / epochLength, dir: dir} - if blockNum >= epochLength*2048 { - return fmt.Errorf("block number too high, limit is %d", epochLength*2048) - } - d.generate() - if d.ptr == nil { - return errors.New("failed") - } - return nil -} - -// Full implements the Search half of the proof of work. -type Full struct { - Dir string // use this to specify a non-default DAG directory - - test bool // if set use a smaller DAG size - turbo bool - hashRate int32 - - mu sync.Mutex // protects dag - current *dag // current full DAG -} - -func (pow *Full) getDAG(blockNum uint64) (d *dag) { - epoch := blockNum / epochLength - pow.mu.Lock() - if pow.current != nil && pow.current.epoch == epoch { - d = pow.current - } else { - d = &dag{epoch: epoch, test: pow.test, dir: pow.Dir} - pow.current = d - } - pow.mu.Unlock() - // wait for it to finish generating. - d.generate() - return d -} - -func (pow *Full) Search(block pow.Block, stop <-chan struct{}, index int) (nonce uint64, mixDigest []byte) { - dag := pow.getDAG(block.NumberU64()) - - r := rand.New(rand.NewSource(time.Now().UnixNano())) - diff := block.Difficulty() - - i := int64(0) - starti := i - start := time.Now().UnixNano() - previousHashrate := int32(0) - - nonce = uint64(r.Int63()) - hash := hashToH256(block.HashNoNonce()) - target := new(big.Int).Div(maxUint256, diff) - for { - select { - case <-stop: - atomic.AddInt32(&pow.hashRate, -previousHashrate) - return 0, nil - default: - i++ - - // we don't have to update hash rate on every nonce, so update after - // first nonce check and then after 2^X nonces - if i == 2 || ((i % (1 << 16)) == 0) { - elapsed := time.Now().UnixNano() - start - hashes := (float64(1e9) / float64(elapsed)) * float64(i-starti) - hashrateDiff := int32(hashes) - previousHashrate - previousHashrate = int32(hashes) - atomic.AddInt32(&pow.hashRate, hashrateDiff) - } - - ret := C.ethash_full_compute(dag.ptr, hash, C.uint64_t(nonce)) - result := h256ToHash(ret.result).Big() - - // TODO: disagrees with the spec https://github.com/ethereum/wiki/wiki/Ethash#mining - if ret.success && result.Cmp(target) <= 0 { - mixDigest = C.GoBytes(unsafe.Pointer(&ret.mix_hash), C.int(32)) - atomic.AddInt32(&pow.hashRate, -previousHashrate) - return nonce, mixDigest - } - nonce += 1 - } - - if !pow.turbo { - time.Sleep(20 * time.Microsecond) - } - } -} - -func (pow *Full) GetHashrate() int64 { - return int64(atomic.LoadInt32(&pow.hashRate)) -} - -func (pow *Full) Turbo(on bool) { - // TODO: this needs to use an atomic operation. - pow.turbo = on -} - -// Ethash combines block verification with Light and -// nonce searching with Full into a single proof of work. -type Ethash struct { - *Light - *Full -} - -// New creates an instance of the proof of work. -func New() *Ethash { - return &Ethash{new(Light), &Full{turbo: true}} -} - -// NewShared creates an instance of the proof of work., where a single instance -// of the Light cache is shared across all instances created with NewShared. -func NewShared() *Ethash { - return &Ethash{sharedLight, &Full{turbo: true}} -} - -// NewForTesting creates a proof of work for use in unit tests. -// It uses a smaller DAG and cache size to keep test times low. -// DAG files are stored in a temporary directory. -// -// Nonces found by a testing instance are not verifiable with a -// regular-size cache. -func NewForTesting() (*Ethash, error) { - dir, err := ioutil.TempDir("", "ethash-test") - if err != nil { - return nil, err - } - return &Ethash{&Light{test: true}, &Full{Dir: dir, test: true}}, nil -} - -func GetSeedHash(blockNum uint64) ([]byte, error) { - if blockNum >= epochLength*2048 { - return nil, fmt.Errorf("block number too high, limit is %d", epochLength*2048) - } - sh := makeSeedHash(blockNum / epochLength) - return sh[:], nil -} - -func makeSeedHash(epoch uint64) (sh common.Hash) { - for ; epoch > 0; epoch-- { - sh = crypto.Sha3Hash(sh[:]) - } - return sh -} diff --git a/vendor/github.com/ethereum/ethash/ethashc.go b/vendor/github.com/ethereum/ethash/ethashc.go deleted file mode 100644 index 1d2ba1613..000000000 --- a/vendor/github.com/ethereum/ethash/ethashc.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package ethash - -/* - -mno-stack-arg-probe disables stack probing which avoids the function - __chkstk_ms being linked. this avoids a clash of this symbol as we also - separately link the secp256k1 lib which ends up defining this symbol - - 1. https://gcc.gnu.org/onlinedocs/gccint/Stack-Checking.html - 2. https://groups.google.com/forum/#!msg/golang-dev/v1bziURSQ4k/88fXuJ24e-gJ - 3. https://groups.google.com/forum/#!topic/golang-nuts/VNP6Mwz_B6o - -*/ - -/* -#cgo CFLAGS: -std=gnu99 -Wall -#cgo windows CFLAGS: -mno-stack-arg-probe -#cgo LDFLAGS: -lm - -#include "src/libethash/internal.c" -#include "src/libethash/sha3.c" -#include "src/libethash/io.c" - -#ifdef _WIN32 -# include "src/libethash/io_win32.c" -# include "src/libethash/mmap_win32.c" -#else -# include "src/libethash/io_posix.c" -#endif - -// 'gateway function' for calling back into go. -extern int ethashGoCallback(unsigned); -int ethashGoCallback_cgo(unsigned percent) { return ethashGoCallback(percent); } - -*/ -import "C" diff --git a/vendor/github.com/ethereum/ethash/setup.py b/vendor/github.com/ethereum/ethash/setup.py deleted file mode 100755 index 18aa20f6d..000000000 --- a/vendor/github.com/ethereum/ethash/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -import os -from distutils.core import setup, Extension -sources = [ - 'src/python/core.c', - 'src/libethash/io.c', - 'src/libethash/internal.c', - 'src/libethash/sha3.c'] -if os.name == 'nt': - sources += [ - 'src/libethash/util_win32.c', - 'src/libethash/io_win32.c', - 'src/libethash/mmap_win32.c', - ] -else: - sources += [ - 'src/libethash/io_posix.c' - ] -depends = [ - 'src/libethash/ethash.h', - 'src/libethash/compiler.h', - 'src/libethash/data_sizes.h', - 'src/libethash/endian.h', - 'src/libethash/ethash.h', - 'src/libethash/io.h', - 'src/libethash/fnv.h', - 'src/libethash/internal.h', - 'src/libethash/sha3.h', - 'src/libethash/util.h', -] -pyethash = Extension('pyethash', - sources=sources, - depends=depends, - extra_compile_args=["-Isrc/", "-std=gnu99", "-Wall"]) - -setup( - name='pyethash', - author="Matthew Wampler-Doty", - author_email="matthew.wampler.doty@gmail.com", - license='GPL', - version='0.1.23', - url='https://github.com/ethereum/ethash', - download_url='https://github.com/ethereum/ethash/tarball/v23', - description=('Python wrappers for ethash, the ethereum proof of work' - 'hashing function'), - ext_modules=[pyethash], -) diff --git a/vendor/vendor.json b/vendor/vendor.json index e28ab243b..58bbd82ff 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -35,10 +35,10 @@ "revisionTime": "2016-10-29T20:57:26Z" }, { - "checksumSHA1": "HdOu+ISNyVWMyBao7vDI21uZH6U=", - "path": "github.com/ethereum/ethash", - "revision": "214d4c008e101d4f7b18318389fb8c2e00323f24", - "revisionTime": "2016-10-25T09:19:48Z" + "checksumSHA1": "zYnPsNAVm1/ViwCkN++dX2JQhBo=", + "path": "github.com/edsrzf/mmap-go", + "revision": "935e0e8a636ca4ba70b713f3e38a19e1b77739e8", + "revisionTime": "2016-05-12T03:30:02Z" }, { "checksumSHA1": "7oFpbmDfGobwKsFLIf6wMUvVoKw=", |