Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6b7dfa1f
Commit
6b7dfa1f
authored
May 30, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
2ef3a989
17c825f5
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
97 additions
and
58 deletions
+97
-58
state_test.go
ethchain/state_test.go
+0
-1
vm_test.go
ethchain/vm_test.go
+1
-1
ethereum.go
ethereum.go
+20
-3
miner.go
ethminer/miner.go
+3
-2
pub.go
ethpub/pub.go
+18
-24
types.go
ethpub/types.go
+2
-1
big.go
ethutil/big.go
+4
-0
config.go
ethutil/config.go
+41
-13
value.go
ethutil/value.go
+1
-1
peer.go
peer.go
+7
-12
No files found.
ethchain/state_test.go
View file @
6b7dfa1f
package
ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"testing"
...
...
ethchain/vm_test.go
View file @
6b7dfa1f
...
...
@@ -62,7 +62,7 @@ func TestRun4(t *testing.T) {
Diff
:
big
.
NewInt
(
256
),
})
var
ret
[]
byte
ret
,
e
=
callerClosure
.
Call
(
vm
,
nil
,
nil
)
ret
,
_
,
e
=
callerClosure
.
Call
(
vm
,
nil
,
nil
)
if
e
!=
nil
{
fmt
.
Println
(
"error"
,
e
)
}
...
...
ethereum.go
View file @
6b7dfa1f
...
...
@@ -165,6 +165,8 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
ethutil
.
Config
.
Log
.
Debugf
(
"[SERV] Max connected peers reached. Not adding incoming peer."
)
}
}
s
.
reactor
.
Post
(
"peerList"
,
s
.
peers
)
}
func
(
s
*
Ethereum
)
ProcessPeerList
(
addrs
[]
string
)
{
...
...
@@ -236,6 +238,7 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
s
.
peers
.
PushBack
(
peer
)
ethutil
.
Config
.
Log
.
Infof
(
"[SERV] Adding peer (%s) %d / %d
\n
"
,
addr
,
s
.
peers
.
Len
(),
s
.
MaxPeers
)
s
.
reactor
.
Post
(
"peerList"
,
s
.
peers
)
}
return
nil
...
...
@@ -303,12 +306,26 @@ func (s *Ethereum) Peers() *list.List {
}
func
(
s
*
Ethereum
)
reapPeers
()
{
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
e
*
list
.
Element
)
{
if
atomic
.
LoadInt32
(
&
p
.
disconnect
)
==
1
||
(
p
.
inbound
&&
(
time
.
Now
()
.
Unix
()
-
p
.
lastPong
)
>
int64
(
5
*
time
.
Minute
))
{
s
.
removePeerElement
(
e
)
}
})
}
func
(
s
*
Ethereum
)
removePeerElement
(
e
*
list
.
Element
)
{
s
.
peerMut
.
Lock
()
defer
s
.
peerMut
.
Unlock
()
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
e
*
list
.
Element
)
{
if
atomic
.
LoadInt32
(
&
p
.
disconnect
)
==
1
||
(
p
.
inbound
&&
(
time
.
Now
()
.
Unix
()
-
p
.
lastPong
)
>
int64
(
5
*
time
.
Minute
))
{
s
.
peers
.
Remove
(
e
)
s
.
reactor
.
Post
(
"peerList"
,
s
.
peers
)
}
func
(
s
*
Ethereum
)
RemovePeer
(
p
*
Peer
)
{
eachPeer
(
s
.
peers
,
func
(
peer
*
Peer
,
e
*
list
.
Element
)
{
if
peer
==
p
{
s
.
removePeerElement
(
e
)
}
})
}
...
...
ethminer/miner.go
View file @
6b7dfa1f
...
...
@@ -25,6 +25,7 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
reactChan
:=
make
(
chan
ethutil
.
React
,
1
)
// This is the channel that receives 'updates' when ever a new transaction or block comes in
powChan
:=
make
(
chan
[]
byte
,
1
)
// This is the channel that receives valid sha hases for a given block
powQuitChan
:=
make
(
chan
ethutil
.
React
,
1
)
// This is the channel that can exit the miner thread
quitChan
:=
make
(
chan
bool
,
1
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
reactChan
)
...
...
@@ -44,7 +45,7 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
reactChan
:
reactChan
,
powChan
:
powChan
,
powQuitChan
:
powQuitChan
,
quitChan
:
make
(
chan
bool
)
,
quitChan
:
quitChan
,
}
// Insert initial TXs in our little miner 'pool'
...
...
@@ -148,7 +149,7 @@ func (self *Miner) mineNewBlock() {
// Find a valid nonce
self
.
block
.
Nonce
=
self
.
pow
.
Search
(
self
.
block
,
self
.
powQuitChan
)
if
self
.
block
.
Nonce
!=
nil
{
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
tru
e
)
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
fals
e
)
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Infoln
(
err
)
}
else
{
...
...
ethpub/pub.go
View file @
6b7dfa1f
...
...
@@ -4,6 +4,7 @@ import (
"encoding/hex"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strings"
)
...
...
@@ -95,14 +96,30 @@ func (lib *PEthereum) Create(key, valueStr, gasStr, gasPriceStr, script string)
return
lib
.
createTx
(
key
,
""
,
valueStr
,
gasStr
,
gasPriceStr
,
script
)
}
var
namereg
=
ethutil
.
FromHex
(
"bb5f186604d057c1c5240ca2ae0f6430138ac010"
)
func
GetAddressFromNameReg
(
stateManager
*
ethchain
.
StateManager
,
name
string
)
[]
byte
{
recp
:=
new
(
big
.
Int
)
.
SetBytes
([]
byte
(
name
))
object
:=
stateManager
.
CurrentState
()
.
GetStateObject
(
namereg
)
reg
:=
object
.
GetStorage
(
recp
)
return
reg
.
Bytes
()
}
func
(
lib
*
PEthereum
)
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
scriptStr
string
)
(
*
PReceipt
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
if
len
(
recipient
)
==
0
{
contractCreation
=
true
}
else
{
// Check if an address is stored by this address
addr
:=
GetAddressFromNameReg
(
lib
.
stateManager
,
recipient
)
if
len
(
addr
)
>
0
{
hash
=
addr
}
else
{
hash
=
ethutil
.
FromHex
(
recipient
)
}
}
var
keyPair
*
ethutil
.
KeyPair
var
err
error
...
...
@@ -122,29 +139,6 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc
var
tx
*
ethchain
.
Transaction
// Compile and assemble the given data
if
contractCreation
{
/*
var initScript, mainScript []byte
var err error
if ethutil.IsHex(initStr) {
initScript = ethutil.FromHex(initStr[2:])
} else {
initScript, err = ethutil.Compile(initStr)
if err != nil {
return nil, err
}
}
if ethutil.IsHex(scriptStr) {
mainScript = ethutil.FromHex(scriptStr[2:])
} else {
mainScript, err = ethutil.Compile(scriptStr)
if err != nil {
return nil, err
}
}
script := ethchain.AppendScript(initScript, mainScript)
*/
var
script
[]
byte
var
err
error
if
ethutil
.
IsHex
(
scriptStr
)
{
...
...
ethpub/types.go
View file @
6b7dfa1f
...
...
@@ -16,6 +16,7 @@ type PBlock struct {
Hash
string
`json:"hash"`
Transactions
string
`json:"transactions"`
Time
int64
`json:"time"`
Coinbase
string
`json:"coinbase"`
}
// Creates a new QML Block from a chain block
...
...
@@ -34,7 +35,7 @@ func NewPBlock(block *ethchain.Block) *PBlock {
return
nil
}
return
&
PBlock
{
ref
:
block
,
Number
:
int
(
block
.
Number
.
Uint64
()),
Hash
:
ethutil
.
Hex
(
block
.
Hash
()),
Transactions
:
string
(
txJson
),
Time
:
block
.
Time
}
return
&
PBlock
{
ref
:
block
,
Number
:
int
(
block
.
Number
.
Uint64
()),
Hash
:
ethutil
.
Hex
(
block
.
Hash
()),
Transactions
:
string
(
txJson
),
Time
:
block
.
Time
,
Coinbase
:
ethutil
.
Hex
(
block
.
Coinbase
)
}
}
func
(
self
*
PBlock
)
ToString
()
string
{
...
...
ethutil/big.go
View file @
6b7dfa1f
...
...
@@ -49,6 +49,10 @@ func BigD(data []byte) *big.Int {
func
BigToBytes
(
num
*
big
.
Int
,
base
int
)
[]
byte
{
ret
:=
make
([]
byte
,
base
/
8
)
if
len
(
num
.
Bytes
())
>
base
/
8
{
return
num
.
Bytes
()
}
return
append
(
ret
[
:
len
(
ret
)
-
len
(
num
.
Bytes
())],
num
.
Bytes
()
...
)
}
...
...
ethutil/config.go
View file @
6b7dfa1f
...
...
@@ -22,26 +22,54 @@ type config struct {
Identifier
string
}
const
defaultConf
=
`
id = ""
port = 30303
upnp = true
maxpeer = 10
rpc = false
rpcport = 8080
`
var
Config
*
config
// Read config
//
// Initialize the global Config variable with default settings
func
ReadConfig
(
base
string
,
logTypes
LoggerType
,
id
string
)
*
config
{
if
Config
==
nil
{
func
ApplicationFolder
(
base
string
)
string
{
usr
,
_
:=
user
.
Current
()
path
:=
path
.
Join
(
usr
.
HomeDir
,
base
)
p
:=
path
.
Join
(
usr
.
HomeDir
,
base
)
if
len
(
base
)
>
0
{
//Check if the logging directory already exists, create it if not
_
,
err
:=
os
.
Stat
(
path
)
_
,
err
:=
os
.
Stat
(
p
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
log
.
Printf
(
"Debug logging directory %s doesn't exist, creating it
\n
"
,
path
)
os
.
Mkdir
(
path
,
0777
)
log
.
Printf
(
"Debug logging directory %s doesn't exist, creating it
\n
"
,
p
)
os
.
Mkdir
(
p
,
0777
)
}
}
iniFilePath
:=
path
.
Join
(
p
,
"conf.ini"
)
_
,
err
=
os
.
Stat
(
iniFilePath
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
file
,
err
:=
os
.
Create
(
iniFilePath
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
else
{
assetPath
:=
path
.
Join
(
os
.
Getenv
(
"GOPATH"
),
"src"
,
"github.com"
,
"ethereum"
,
"go-ethereum"
,
"ethereal"
,
"assets"
)
file
.
Write
([]
byte
(
defaultConf
+
"
\n
asset_path = "
+
assetPath
))
}
}
}
return
p
}
// Read config
//
// Initialize the global Config variable with default settings
func
ReadConfig
(
base
string
,
logTypes
LoggerType
,
id
string
)
*
config
{
if
Config
==
nil
{
path
:=
ApplicationFolder
(
base
)
Config
=
&
config
{
ExecPath
:
path
,
Debug
:
true
,
Ver
:
"0.5.0 RC11"
}
Config
.
Identifier
=
id
...
...
ethutil/value.go
View file @
6b7dfa1f
...
...
@@ -176,7 +176,7 @@ func (val *Value) Get(idx int) *Value {
}
if
idx
<
0
{
panic
(
"negative idx for Value Get"
)
return
NewValue
(
nil
)
}
return
NewValue
(
d
[
idx
])
...
...
peer.go
View file @
6b7dfa1f
...
...
@@ -2,7 +2,6 @@ package eth
import
(
"bytes"
"container/list"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -440,7 +439,7 @@ func (p *Peer) HandleInbound() {
ethutil
.
Config
.
Log
.
Debugf
(
"[PEER] Found canonical block, returning chain from: %x "
,
parent
.
Hash
())
chain
:=
p
.
ethereum
.
BlockChain
()
.
GetChainFromHash
(
parent
.
Hash
(),
amountOfBlocks
)
if
len
(
chain
)
>
0
{
ethutil
.
Config
.
Log
.
Debugf
(
"[PEER] Returning %d blocks: %x "
,
len
(
chain
),
parent
.
Hash
())
//
ethutil.Config.Log.Debugf("[PEER] Returning %d blocks: %x ", len(chain), parent.Hash())
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
chain
))
}
else
{
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{}))
...
...
@@ -450,10 +449,12 @@ func (p *Peer) HandleInbound() {
//ethutil.Config.Log.Debugf("[PEER] Could not find a similar block")
// If no blocks are found we send back a reply with msg not in chain
// and the last hash from get chain
if
l
>
0
{
lastHash
:=
msg
.
Data
.
Get
(
l
-
1
)
//log.Printf("Sending not in chain with hash %x\n", lastHash.AsRaw())
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgNotInChainTy
,
[]
interface
{}{
lastHash
.
Raw
()}))
}
}
case
ethwire
.
MsgNotInChainTy
:
ethutil
.
Config
.
Log
.
Debugf
(
"Not in chain: %x
\n
"
,
msg
.
Data
.
Get
(
0
)
.
Bytes
())
if
p
.
diverted
==
true
{
...
...
@@ -521,13 +522,7 @@ func (p *Peer) Stop() {
}
// Pre-emptively remove the peer; don't wait for reaping. We already know it's dead if we are here
p
.
ethereum
.
peerMut
.
Lock
()
defer
p
.
ethereum
.
peerMut
.
Unlock
()
eachPeer
(
p
.
ethereum
.
peers
,
func
(
peer
*
Peer
,
e
*
list
.
Element
)
{
if
peer
==
p
{
p
.
ethereum
.
peers
.
Remove
(
e
)
}
})
p
.
ethereum
.
RemovePeer
(
p
)
}
func
(
p
*
Peer
)
pushHandshake
()
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment