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
96fcc1da
Commit
96fcc1da
authored
Mar 10, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial smart-miner stuff
parent
fbd53f0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
19 deletions
+74
-19
ethereum.go
ethereum.go
+73
-18
ui_lib.go
ui/ui_lib.go
+1
-1
No files found.
ethereum.go
View file @
96fcc1da
package
main
package
main
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
...
@@ -172,6 +173,16 @@ func main() {
...
@@ -172,6 +173,16 @@ func main() {
RegisterInterupts
(
ethereum
)
RegisterInterupts
(
ethereum
)
ethereum
.
Start
()
ethereum
.
Start
()
minerChan
:=
make
(
chan
ethutil
.
React
,
5
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
minerChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx"
,
minerChan
)
minerChan2
:=
make
(
chan
ethutil
.
React
,
5
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
minerChan2
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx"
,
minerChan2
)
ethereum
.
StateManager
()
.
PrepareMiningState
()
if
StartMining
{
if
StartMining
{
log
.
Printf
(
"Miner started
\n
"
)
log
.
Printf
(
"Miner started
\n
"
)
...
@@ -181,26 +192,70 @@ func main() {
...
@@ -181,26 +192,70 @@ func main() {
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
keyRing
:=
ethutil
.
NewValueFromBytes
(
data
)
keyRing
:=
ethutil
.
NewValueFromBytes
(
data
)
addr
:=
keyRing
.
Get
(
1
)
.
Bytes
()
addr
:=
keyRing
.
Get
(
1
)
.
Bytes
()
txs
:=
ethereum
.
TxPool
()
.
Flush
()
block
:=
ethereum
.
BlockChain
()
.
NewBlock
(
addr
,
txs
)
for
{
for
{
txs
:=
ethereum
.
TxPool
()
.
Flush
()
select
{
// Create a new block which we're going to mine
case
chanMessage
:=
<-
minerChan
:
block
:=
ethereum
.
BlockChain
()
.
NewBlock
(
addr
,
txs
)
log
.
Println
(
"REACTOR: Got new block"
)
log
.
Println
(
"Mining on new block. Includes"
,
len
(
block
.
Transactions
()),
"transactions"
)
// Apply all transactions to the block
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
ethereum
.
StateManager
()
.
ApplyTransactions
(
block
,
block
.
Transactions
())
if
bytes
.
Compare
(
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
block
.
Hash
())
==
0
{
// TODO: Perhaps continue mining to get some uncle rewards
ethereum
.
StateManager
()
.
AccumelateRewards
(
block
,
block
)
log
.
Println
(
"New top block found resetting state"
)
// Reapplies the latest block to the mining state, thus resetting
// Search the nonce
ethereum
.
StateManager
()
.
PrepareMiningState
()
block
.
Nonce
=
pow
.
Search
(
block
)
block
=
ethereum
.
BlockChain
()
.
NewBlock
(
addr
,
txs
)
ethereum
.
Broadcast
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{
block
.
Value
()
.
Val
})
log
.
Println
(
"Block set"
)
err
:=
ethereum
.
StateManager
()
.
ProcessBlock
(
block
)
}
else
{
if
err
!=
nil
{
if
bytes
.
Compare
(
block
.
PrevHash
,
ethereum
.
BlockChain
()
.
CurrentBlock
.
PrevHash
)
==
0
{
log
.
Println
(
err
)
log
.
Println
(
"HELLO UNCLE"
)
}
else
{
// TODO: Add uncle to block
//log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockChain().CurrentBlock)
}
log
.
Printf
(
"🔨 Mined block %x
\n
"
,
block
.
Hash
())
}
}
if
tx
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Transaction
);
ok
{
log
.
Println
(
"REACTOR: Got new transaction"
,
tx
)
found
:=
false
for
_
,
ctx
:=
range
txs
{
if
found
=
bytes
.
Compare
(
ctx
.
Hash
(),
tx
.
Hash
())
==
0
;
found
{
break
}
}
if
found
==
false
{
log
.
Println
(
"We did not know about this transaction, adding"
)
txs
=
append
(
txs
,
tx
)
}
else
{
log
.
Println
(
"We already had this transaction, ignoring"
)
}
}
log
.
Println
(
"Sending block reset"
)
// Start mining over
log
.
Println
(
"Block reset done"
)
default
:
// Create a new block which we're going to mine
log
.
Println
(
"Mining on block. Includes"
,
len
(
txs
),
"transactions"
)
// Apply all transactions to the block
ethereum
.
StateManager
()
.
ApplyTransactions
(
block
,
txs
)
ethereum
.
StateManager
()
.
AccumelateRewards
(
block
,
block
)
// Search the nonce
block
.
Nonce
=
pow
.
Search
(
block
,
minerChan2
)
if
block
.
Nonce
!=
nil
{
ethereum
.
Broadcast
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{
block
.
Value
()
.
Val
})
err
:=
ethereum
.
StateManager
()
.
ProcessBlock
(
block
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
else
{
//log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockChain().CurrentBlock)
log
.
Printf
(
"🔨 Mined block %x
\n
"
,
block
.
Hash
())
block
=
ethereum
.
BlockChain
()
.
NewBlock
(
addr
,
txs
)
}
}
}
}
}
}
}()
}()
...
...
ui/ui_lib.go
View file @
96fcc1da
...
@@ -54,7 +54,7 @@ func AssetPath(p string) string {
...
@@ -54,7 +54,7 @@ func AssetPath(p string) string {
// Get Binary Directory
// Get Binary Directory
exedir
,
_
:=
osext
.
ExecutableFolder
()
exedir
,
_
:=
osext
.
ExecutableFolder
()
base
=
filepath
.
Join
(
exedir
,
"../Resources"
)
base
=
filepath
.
Join
(
exedir
,
"../Resources"
)
base
=
"/Users/
jeffrey
/go/src/github.com/ethereum/go-ethereum"
base
=
"/Users/
maranhidskes/projects
/go/src/github.com/ethereum/go-ethereum"
case
"linux"
:
case
"linux"
:
base
=
"/usr/share/ethereal"
base
=
"/usr/share/ethereal"
case
"window"
:
case
"window"
:
...
...
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