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
d5efeab8
Commit
d5efeab8
authored
Mar 10, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial smart-miner stuff
parent
be543a6d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
9 deletions
+47
-9
block_chain.go
ethchain/block_chain.go
+1
-0
dagger.go
ethchain/dagger.go
+16
-8
state_manager.go
ethchain/state_manager.go
+15
-0
transaction_pool.go
ethchain/transaction_pool.go
+7
-1
ethereum.go
ethereum.go
+8
-0
No files found.
ethchain/block_chain.go
View file @
d5efeab8
...
...
@@ -136,6 +136,7 @@ func AddTestNetFunds(block *Block) {
"e6716f9544a56c530d868e4bfbacb172315bdead"
,
// Jeffrey
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"
,
// Vit
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4"
,
// Alex
"2ef47100e0787b915105fd5e3f4ff6752079d5cb"
,
// Maran
}
{
//log.Println("2^200 Wei to", addr)
codedAddr
:=
ethutil
.
FromHex
(
addr
)
...
...
ethchain/dagger.go
View file @
d5efeab8
...
...
@@ -11,7 +11,7 @@ import (
)
type
PoW
interface
{
Search
(
block
*
Block
)
[]
byte
Search
(
block
*
Block
,
breakChan
chan
bool
)
[]
byte
Verify
(
hash
[]
byte
,
diff
*
big
.
Int
,
nonce
[]
byte
)
bool
}
...
...
@@ -19,17 +19,25 @@ type EasyPow struct {
hash
*
big
.
Int
}
func
(
pow
*
EasyPow
)
Search
(
block
*
Block
)
[]
byte
{
func
(
pow
*
EasyPow
)
Search
(
block
*
Block
,
breakChan
chan
bool
)
[]
byte
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
hash
:=
block
.
HashNoNonce
()
diff
:=
block
.
Difficulty
for
{
select
{
case
shouldbreak
:=
<-
breakChan
:
if
shouldbreak
{
log
.
Println
(
"Got signal: Breaking out mining."
)
return
nil
}
default
:
sha
:=
ethutil
.
Sha3Bin
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
if
pow
.
Verify
(
hash
,
diff
,
sha
)
{
return
sha
}
}
}
return
nil
}
...
...
@@ -98,9 +106,9 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
go
dag
.
Find
(
obj
,
resChan
)
}
// Wait for each go routine to finish
}
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
// Get the result from the channel. 0 = quit
if
r
:=
<-
resChan
;
r
!=
0
{
...
...
ethchain/state_manager.go
View file @
d5efeab8
...
...
@@ -19,6 +19,7 @@ type EthManager interface {
BlockChain
()
*
BlockChain
TxPool
()
*
TxPool
Broadcast
(
msgType
ethwire
.
MsgType
,
data
[]
interface
{})
Reactor
()
*
ethutil
.
ReactorEngine
}
// TODO rename to state manager
...
...
@@ -50,6 +51,9 @@ type StateManager struct {
// Comparative state it used for comparing and validating end
// results
compState
*
State
// Mining state, solely used for mining
miningState
*
State
}
func
NewStateManager
(
ethereum
EthManager
)
*
StateManager
{
...
...
@@ -69,6 +73,10 @@ func (sm *StateManager) ProcState() *State {
return
sm
.
procState
}
func
(
sm
*
StateManager
)
MiningState
()
*
State
{
return
sm
.
miningState
}
// Watches any given address and puts it in the address state store
func
(
sm
*
StateManager
)
WatchAddr
(
addr
[]
byte
)
*
AccountState
{
//FIXME account := sm.procState.GetAccount(addr)
...
...
@@ -97,6 +105,8 @@ func (sm *StateManager) MakeContract(tx *Transaction) {
sm
.
procState
.
states
[
string
(
tx
.
Hash
()[
12
:
])]
=
contract
.
state
}
}
func
(
sm
*
StateManager
)
ApplyTransaction
(
block
*
Block
,
tx
*
Transaction
)
{
}
func
(
sm
*
StateManager
)
ApplyTransactions
(
block
*
Block
,
txs
[]
*
Transaction
)
{
// Process each transaction/contract
...
...
@@ -126,6 +136,10 @@ func (sm *StateManager) Prepare(processer *State, comparative *State) {
sm
.
procState
=
processer
}
func
(
sm
*
StateManager
)
PrepareMiningState
()
{
sm
.
miningState
=
sm
.
BlockChain
()
.
CurrentBlock
.
State
()
}
// Default prepare function
func
(
sm
*
StateManager
)
PrepareDefault
(
block
*
Block
)
{
sm
.
Prepare
(
sm
.
BlockChain
()
.
CurrentBlock
.
State
(),
block
.
State
())
...
...
@@ -193,6 +207,7 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
}
ethutil
.
Config
.
Log
.
Infof
(
"[smGR] Added block #%d (%x)
\n
"
,
block
.
BlockInfo
()
.
Number
,
block
.
Hash
())
sm
.
Ethereum
.
Reactor
()
.
Post
(
"newBlock"
,
block
)
}
else
{
fmt
.
Println
(
"total diff failed"
)
}
...
...
ethchain/transaction_pool.go
View file @
d5efeab8
...
...
@@ -91,6 +91,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
// Process transaction validates the Tx and processes funds from the
// sender to the recipient.
func
(
pool
*
TxPool
)
ProcessTransaction
(
tx
*
Transaction
,
block
*
Block
)
(
err
error
)
{
log
.
Println
(
"Processing TX"
)
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
log
.
Println
(
r
)
...
...
@@ -137,7 +138,6 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
log
.
Printf
(
"[TXPL] Processed Tx %x
\n
"
,
tx
.
Hash
())
// Notify the subscribers
pool
.
notifySubscribers
(
TxPost
,
tx
)
return
...
...
@@ -174,6 +174,7 @@ out:
for
{
select
{
case
tx
:=
<-
pool
.
queueChan
:
log
.
Println
(
"Received new Tx to queue"
)
hash
:=
tx
.
Hash
()
foundTx
:=
FindTx
(
pool
.
pool
,
func
(
tx
*
Transaction
,
e
*
list
.
Element
)
bool
{
return
bytes
.
Compare
(
tx
.
Hash
(),
hash
)
==
0
...
...
@@ -190,9 +191,14 @@ out:
log
.
Println
(
"Validating Tx failed"
,
err
)
}
}
else
{
log
.
Println
(
"Transaction ok, adding"
)
// Call blocking version. At this point it
// doesn't matter since this is a goroutine
pool
.
addTransaction
(
tx
)
log
.
Println
(
"Added"
)
// Notify the subscribers
pool
.
Ethereum
.
Reactor
()
.
Post
(
"newTx"
,
tx
)
// Notify the subscribers
pool
.
notifySubscribers
(
TxPre
,
tx
)
...
...
ethereum.go
View file @
d5efeab8
...
...
@@ -60,6 +60,8 @@ type Ethereum struct {
// Specifies the desired amount of maximum peers
MaxPeers
int
reactor
*
ethutil
.
ReactorEngine
}
func
New
(
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
...
...
@@ -89,6 +91,8 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
serverCaps
:
caps
,
nat
:
nat
,
}
ethereum
.
reactor
=
ethutil
.
NewReactorEngine
()
ethereum
.
txPool
=
ethchain
.
NewTxPool
(
ethereum
)
ethereum
.
blockChain
=
ethchain
.
NewBlockChain
(
ethereum
)
ethereum
.
stateManager
=
ethchain
.
NewStateManager
(
ethereum
)
...
...
@@ -99,6 +103,10 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
return
ethereum
,
nil
}
func
(
s
*
Ethereum
)
Reactor
()
*
ethutil
.
ReactorEngine
{
return
s
.
reactor
}
func
(
s
*
Ethereum
)
BlockChain
()
*
ethchain
.
BlockChain
{
return
s
.
blockChain
}
...
...
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