Merge branch 'release/0.6.4'
This commit is contained in:
commit
fb90ecc8bc
@ -6,7 +6,7 @@ Ethereum
|
|||||||
Ethereum Go Development package (C) Jeffrey Wilcke
|
Ethereum Go Development package (C) Jeffrey Wilcke
|
||||||
|
|
||||||
Ethereum is currently in its testing phase. The current state is "Proof
|
Ethereum is currently in its testing phase. The current state is "Proof
|
||||||
of Concept 0.6.3". For build instructions see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)).
|
of Concept 0.6.4". For build instructions see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)).
|
||||||
|
|
||||||
Ethereum Go is split up in several sub packages Please refer to each
|
Ethereum Go is split up in several sub packages Please refer to each
|
||||||
individual package for more information.
|
individual package for more information.
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package ethchain
|
package ethchain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"hash"
|
||||||
|
"math/big"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/eth-go/ethcrypto"
|
"github.com/ethereum/eth-go/ethcrypto"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethreact"
|
"github.com/ethereum/eth-go/ethreact"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/obscuren/sha3"
|
"github.com/obscuren/sha3"
|
||||||
"hash"
|
|
||||||
"math/big"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var powlogger = ethlog.NewLogger("POW")
|
var powlogger = ethlog.NewLogger("POW")
|
||||||
@ -18,23 +19,30 @@ type PoW interface {
|
|||||||
Search(block *Block, reactChan chan ethreact.Event) []byte
|
Search(block *Block, reactChan chan ethreact.Event) []byte
|
||||||
Verify(hash []byte, diff *big.Int, nonce []byte) bool
|
Verify(hash []byte, diff *big.Int, nonce []byte) bool
|
||||||
GetHashrate() int64
|
GetHashrate() int64
|
||||||
|
Turbo(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EasyPow struct {
|
type EasyPow struct {
|
||||||
hash *big.Int
|
hash *big.Int
|
||||||
HashRate int64
|
HashRate int64
|
||||||
|
turbo bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pow *EasyPow) GetHashrate() int64 {
|
func (pow *EasyPow) GetHashrate() int64 {
|
||||||
return pow.HashRate
|
return pow.HashRate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pow *EasyPow) Turbo(on bool) {
|
||||||
|
pow.turbo = on
|
||||||
|
}
|
||||||
|
|
||||||
func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
|
func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
|
||||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
hash := block.HashNoNonce()
|
hash := block.HashNoNonce()
|
||||||
diff := block.Difficulty
|
diff := block.Difficulty
|
||||||
i := int64(0)
|
i := int64(0)
|
||||||
start := time.Now().UnixNano()
|
start := time.Now().UnixNano()
|
||||||
|
t := time.Now()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -43,11 +51,14 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
|
|||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
i++
|
i++
|
||||||
if i%1234567 == 0 {
|
|
||||||
|
if time.Since(t) > (1 * time.Second) {
|
||||||
elapsed := time.Now().UnixNano() - start
|
elapsed := time.Now().UnixNano() - start
|
||||||
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
|
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
|
||||||
pow.HashRate = int64(hashes)
|
pow.HashRate = int64(hashes)
|
||||||
powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash")
|
powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash")
|
||||||
|
|
||||||
|
t = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())
|
sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())
|
||||||
@ -55,6 +66,10 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethreact.Event) []byte {
|
|||||||
return sha
|
return sha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !pow.turbo {
|
||||||
|
time.Sleep(20 * time.Microsecond)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -28,7 +28,7 @@ var GenesisHeader = []interface{}{
|
|||||||
"",
|
"",
|
||||||
// Difficulty
|
// Difficulty
|
||||||
//ethutil.BigPow(2, 22),
|
//ethutil.BigPow(2, 22),
|
||||||
big.NewInt(4096),
|
big.NewInt(131072),
|
||||||
// Number
|
// Number
|
||||||
ethutil.Big0,
|
ethutil.Big0,
|
||||||
// Block minimum gas price
|
// Block minimum gas price
|
||||||
|
@ -2,11 +2,12 @@ package ethminer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethreact"
|
"github.com/ethereum/eth-go/ethreact"
|
||||||
"github.com/ethereum/eth-go/ethwire"
|
"github.com/ethereum/eth-go/ethwire"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("MINER")
|
var logger = ethlog.NewLogger("MINER")
|
||||||
@ -22,6 +23,8 @@ type Miner struct {
|
|||||||
powChan chan []byte
|
powChan chan []byte
|
||||||
powQuitChan chan ethreact.Event
|
powQuitChan chan ethreact.Event
|
||||||
quitChan chan chan error
|
quitChan chan chan error
|
||||||
|
|
||||||
|
turbo bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) GetPow() ethchain.PoW {
|
func (self *Miner) GetPow() ethchain.PoW {
|
||||||
@ -38,6 +41,12 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) *Miner {
|
|||||||
return &miner
|
return &miner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Miner) ToggleTurbo() {
|
||||||
|
self.turbo = !self.turbo
|
||||||
|
|
||||||
|
self.pow.Turbo(self.turbo)
|
||||||
|
}
|
||||||
|
|
||||||
func (miner *Miner) Start() {
|
func (miner *Miner) Start() {
|
||||||
miner.reactChan = make(chan ethreact.Event, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in
|
miner.reactChan = make(chan ethreact.Event, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in
|
||||||
miner.powChan = make(chan []byte, 1) // This is the channel that receives valid sha hashes for a given block
|
miner.powChan = make(chan []byte, 1) // This is the channel that receives valid sha hashes for a given block
|
||||||
|
@ -64,6 +64,18 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
|
|||||||
return ints[0], ints[1]
|
return ints[0], ints[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *Stack) Swapn(n int) (*big.Int, *big.Int) {
|
||||||
|
st.data[n], st.data[0] = st.data[0], st.data[n]
|
||||||
|
|
||||||
|
return st.data[n], st.data[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *Stack) Dupn(n int) *big.Int {
|
||||||
|
st.Push(st.data[n])
|
||||||
|
|
||||||
|
return st.Peek()
|
||||||
|
}
|
||||||
|
|
||||||
func (st *Stack) Push(d *big.Int) {
|
func (st *Stack) Push(d *big.Int) {
|
||||||
st.data = append(st.data, new(big.Int).Set(d))
|
st.data = append(st.data, new(big.Int).Set(d))
|
||||||
}
|
}
|
||||||
|
132
ethvm/types.go
132
ethvm/types.go
@ -27,10 +27,12 @@ const (
|
|||||||
NOT = 0x0f
|
NOT = 0x0f
|
||||||
|
|
||||||
// 0x10 range - bit ops
|
// 0x10 range - bit ops
|
||||||
AND = 0x10
|
AND = 0x10
|
||||||
OR = 0x11
|
OR = 0x11
|
||||||
XOR = 0x12
|
XOR = 0x12
|
||||||
BYTE = 0x13
|
BYTE = 0x13
|
||||||
|
ADDMOD = 0x14
|
||||||
|
MULMOD = 0x15
|
||||||
|
|
||||||
// 0x20 range - crypto
|
// 0x20 range - crypto
|
||||||
SHA3 = 0x20
|
SHA3 = 0x20
|
||||||
@ -105,6 +107,40 @@ const (
|
|||||||
PUSH31 = 0x7e
|
PUSH31 = 0x7e
|
||||||
PUSH32 = 0x7f
|
PUSH32 = 0x7f
|
||||||
|
|
||||||
|
DUP1 = 0x80
|
||||||
|
DUP2 = 0x81
|
||||||
|
DUP3 = 0x82
|
||||||
|
DUP4 = 0x83
|
||||||
|
DUP5 = 0x84
|
||||||
|
DUP6 = 0x85
|
||||||
|
DUP7 = 0x86
|
||||||
|
DUP8 = 0x87
|
||||||
|
DUP9 = 0x88
|
||||||
|
DUP10 = 0x89
|
||||||
|
DUP11 = 0x8a
|
||||||
|
DUP12 = 0x8b
|
||||||
|
DUP13 = 0x8c
|
||||||
|
DUP14 = 0x8d
|
||||||
|
DUP15 = 0x8e
|
||||||
|
DUP16 = 0x8f
|
||||||
|
|
||||||
|
SWAP1 = 0x90
|
||||||
|
SWAP2 = 0x91
|
||||||
|
SWAP3 = 0x92
|
||||||
|
SWAP4 = 0x93
|
||||||
|
SWAP5 = 0x94
|
||||||
|
SWAP6 = 0x95
|
||||||
|
SWAP7 = 0x96
|
||||||
|
SWAP8 = 0x97
|
||||||
|
SWAP9 = 0x98
|
||||||
|
SWAP10 = 0x99
|
||||||
|
SWAP11 = 0x9a
|
||||||
|
SWAP12 = 0x9b
|
||||||
|
SWAP13 = 0x9c
|
||||||
|
SWAP14 = 0x9d
|
||||||
|
SWAP15 = 0x9e
|
||||||
|
SWAP16 = 0x9f
|
||||||
|
|
||||||
// 0xf0 range - closures
|
// 0xf0 range - closures
|
||||||
CREATE = 0xf0
|
CREATE = 0xf0
|
||||||
CALL = 0xf1
|
CALL = 0xf1
|
||||||
@ -136,10 +172,12 @@ var opCodeToString = map[OpCode]string{
|
|||||||
NOT: "NOT",
|
NOT: "NOT",
|
||||||
|
|
||||||
// 0x10 range - bit ops
|
// 0x10 range - bit ops
|
||||||
AND: "AND",
|
AND: "AND",
|
||||||
OR: "OR",
|
OR: "OR",
|
||||||
XOR: "XOR",
|
XOR: "XOR",
|
||||||
BYTE: "BYTE",
|
BYTE: "BYTE",
|
||||||
|
ADDMOD: "ADDMOD",
|
||||||
|
MULMOD: "MULMOD",
|
||||||
|
|
||||||
// 0x20 range - crypto
|
// 0x20 range - crypto
|
||||||
SHA3: "SHA3",
|
SHA3: "SHA3",
|
||||||
@ -214,6 +252,40 @@ var opCodeToString = map[OpCode]string{
|
|||||||
PUSH31: "PUSH31",
|
PUSH31: "PUSH31",
|
||||||
PUSH32: "PUSH32",
|
PUSH32: "PUSH32",
|
||||||
|
|
||||||
|
DUP1: "DUP1",
|
||||||
|
DUP2: "DUP2",
|
||||||
|
DUP3: "DUP3",
|
||||||
|
DUP4: "DUP4",
|
||||||
|
DUP5: "DUP5",
|
||||||
|
DUP6: "DUP6",
|
||||||
|
DUP7: "DUP7",
|
||||||
|
DUP8: "DUP8",
|
||||||
|
DUP9: "DUP9",
|
||||||
|
DUP10: "DUP10",
|
||||||
|
DUP11: "DUP11",
|
||||||
|
DUP12: "DUP12",
|
||||||
|
DUP13: "DUP13",
|
||||||
|
DUP14: "DUP14",
|
||||||
|
DUP15: "DUP15",
|
||||||
|
DUP16: "DUP16",
|
||||||
|
|
||||||
|
SWAP1: "SWAP1",
|
||||||
|
SWAP2: "SWAP2",
|
||||||
|
SWAP3: "SWAP3",
|
||||||
|
SWAP4: "SWAP4",
|
||||||
|
SWAP5: "SWAP5",
|
||||||
|
SWAP6: "SWAP6",
|
||||||
|
SWAP7: "SWAP7",
|
||||||
|
SWAP8: "SWAP8",
|
||||||
|
SWAP9: "SWAP9",
|
||||||
|
SWAP10: "SWAP10",
|
||||||
|
SWAP11: "SWAP11",
|
||||||
|
SWAP12: "SWAP12",
|
||||||
|
SWAP13: "SWAP13",
|
||||||
|
SWAP14: "SWAP14",
|
||||||
|
SWAP15: "SWAP15",
|
||||||
|
SWAP16: "SWAP16",
|
||||||
|
|
||||||
// 0xf0 range
|
// 0xf0 range
|
||||||
CREATE: "CREATE",
|
CREATE: "CREATE",
|
||||||
CALL: "CALL",
|
CALL: "CALL",
|
||||||
@ -252,10 +324,12 @@ var OpCodes = map[string]byte{
|
|||||||
"NOT": 0x0d,
|
"NOT": 0x0d,
|
||||||
|
|
||||||
// 0x10 range - bit ops
|
// 0x10 range - bit ops
|
||||||
"AND": 0x10,
|
"AND": 0x10,
|
||||||
"OR": 0x11,
|
"OR": 0x11,
|
||||||
"XOR": 0x12,
|
"XOR": 0x12,
|
||||||
"BYTE": 0x13,
|
"BYTE": 0x13,
|
||||||
|
"ADDMOD": 0x14,
|
||||||
|
"MULMOD": 0x15,
|
||||||
|
|
||||||
// 0x20 range - crypto
|
// 0x20 range - crypto
|
||||||
"SHA3": 0x20,
|
"SHA3": 0x20,
|
||||||
@ -326,6 +400,40 @@ var OpCodes = map[string]byte{
|
|||||||
"PUSH31": 0x7e,
|
"PUSH31": 0x7e,
|
||||||
"PUSH32": 0x7f,
|
"PUSH32": 0x7f,
|
||||||
|
|
||||||
|
"DUP1": 0x80,
|
||||||
|
"DUP2": 0x81,
|
||||||
|
"DUP3": 0x82,
|
||||||
|
"DUP4": 0x83,
|
||||||
|
"DUP5": 0x84,
|
||||||
|
"DUP6": 0x85,
|
||||||
|
"DUP7": 0x86,
|
||||||
|
"DUP8": 0x87,
|
||||||
|
"DUP9": 0x88,
|
||||||
|
"DUP10": 0x89,
|
||||||
|
"DUP11": 0x8a,
|
||||||
|
"DUP12": 0x8b,
|
||||||
|
"DUP13": 0x8c,
|
||||||
|
"DUP14": 0x8d,
|
||||||
|
"DUP15": 0x8e,
|
||||||
|
"DUP16": 0x8f,
|
||||||
|
|
||||||
|
"SWAP1": 0x90,
|
||||||
|
"SWAP2": 0x91,
|
||||||
|
"SWAP3": 0x92,
|
||||||
|
"SWAP4": 0x93,
|
||||||
|
"SWAP5": 0x94,
|
||||||
|
"SWAP6": 0x95,
|
||||||
|
"SWAP7": 0x96,
|
||||||
|
"SWAP8": 0x97,
|
||||||
|
"SWAP9": 0x98,
|
||||||
|
"SWAP10": 0x99,
|
||||||
|
"SWAP11": 0x9a,
|
||||||
|
"SWAP12": 0x9b,
|
||||||
|
"SWAP13": 0x9c,
|
||||||
|
"SWAP14": 0x9d,
|
||||||
|
"SWAP15": 0x9e,
|
||||||
|
"SWAP16": 0x9f,
|
||||||
|
|
||||||
// 0xf0 range - closures
|
// 0xf0 range - closures
|
||||||
"CREATE": 0xf0,
|
"CREATE": 0xf0,
|
||||||
"CALL": 0xf1,
|
"CALL": 0xf1,
|
||||||
|
50
ethvm/vm.go
50
ethvm/vm.go
@ -439,6 +439,36 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
|
|||||||
} else {
|
} else {
|
||||||
stack.Push(ethutil.BigFalse)
|
stack.Push(ethutil.BigFalse)
|
||||||
}
|
}
|
||||||
|
case ADDMOD:
|
||||||
|
require(3)
|
||||||
|
|
||||||
|
x := stack.Pop()
|
||||||
|
y := stack.Pop()
|
||||||
|
z := stack.Pop()
|
||||||
|
|
||||||
|
base.Add(x, y)
|
||||||
|
base.Mod(base, z)
|
||||||
|
|
||||||
|
ensure256(base)
|
||||||
|
|
||||||
|
self.Printf(" = %v", base)
|
||||||
|
|
||||||
|
stack.Push(base)
|
||||||
|
case MULMOD:
|
||||||
|
require(3)
|
||||||
|
|
||||||
|
x := stack.Pop()
|
||||||
|
y := stack.Pop()
|
||||||
|
z := stack.Pop()
|
||||||
|
|
||||||
|
base.Mul(x, y)
|
||||||
|
base.Mod(base, z)
|
||||||
|
|
||||||
|
ensure256(base)
|
||||||
|
|
||||||
|
self.Printf(" = %v", base)
|
||||||
|
|
||||||
|
stack.Push(base)
|
||||||
|
|
||||||
// 0x20 range
|
// 0x20 range
|
||||||
case SHA3:
|
case SHA3:
|
||||||
@ -600,16 +630,20 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
|
|||||||
case POP:
|
case POP:
|
||||||
require(1)
|
require(1)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
case DUP:
|
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
||||||
require(1)
|
n := int(op - DUP1 + 1)
|
||||||
stack.Push(stack.Peek())
|
stack.Dupn(n)
|
||||||
|
|
||||||
self.Printf(" => 0x%x", stack.Peek().Bytes())
|
self.Printf(" => [%d] 0x%x", n, stack.Peek().Bytes())
|
||||||
|
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
|
||||||
|
n := int(op - SWAP1 + 1)
|
||||||
|
x, y := stack.Swapn(n)
|
||||||
|
|
||||||
|
self.Printf(" => [%d] %x [0] %x", n, x.Bytes(), y.Bytes())
|
||||||
|
case DUP:
|
||||||
|
// NOP
|
||||||
case SWAP:
|
case SWAP:
|
||||||
require(2)
|
// NOP
|
||||||
x, y := stack.Popn()
|
|
||||||
stack.Push(y)
|
|
||||||
stack.Push(x)
|
|
||||||
case MLOAD:
|
case MLOAD:
|
||||||
require(1)
|
require(1)
|
||||||
offset := stack.Pop()
|
offset := stack.Pop()
|
||||||
|
2
peer.go
2
peer.go
@ -24,7 +24,7 @@ const (
|
|||||||
// The size of the output buffer for writing messages
|
// The size of the output buffer for writing messages
|
||||||
outputBufferSize = 50
|
outputBufferSize = 50
|
||||||
// Current protocol version
|
// Current protocol version
|
||||||
ProtocolVersion = 27
|
ProtocolVersion = 28
|
||||||
// Interval for ping/pong message
|
// Interval for ping/pong message
|
||||||
pingPongTimer = 2 * time.Second
|
pingPongTimer = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user