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
30025700
Commit
30025700
authored
Mar 20, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mining rework
parent
07734c1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
89 deletions
+9
-89
ethereum.go
ethereum.go
+5
-86
library.go
ui/library.go
+4
-3
No files found.
ethereum.go
View file @
30025700
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"
"github.com/ethereum/eth-go/ethminer"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/go-ethereum/ui"
"github.com/ethereum/go-ethereum/ui"
"github.com/niemeyer/qml"
"github.com/niemeyer/qml"
"github.com/obscuren/secp256k1-go"
"github.com/obscuren/secp256k1-go"
...
@@ -173,97 +172,17 @@ func main() {
...
@@ -173,97 +172,17 @@ func main() {
RegisterInterupts
(
ethereum
)
RegisterInterupts
(
ethereum
)
ethereum
.
Start
()
ethereum
.
Start
()
minerChan
:=
make
(
chan
ethutil
.
React
,
1
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
minerChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx"
,
minerChan
)
minerChan2
:=
make
(
chan
ethutil
.
React
,
1
)
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
"
)
go
func
()
{
go
func
()
{
pow
:=
&
ethchain
.
EasyPow
{}
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
)
miner
:=
ethminer
.
NewDefaultMiner
(
addr
,
ethereum
)
var
uncles
[]
*
ethchain
.
Block
miner
.
Start
()
for
{
select
{
case
chanMessage
:=
<-
minerChan
:
log
.
Println
(
"REACTOR: Got new block"
)
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
if
bytes
.
Compare
(
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
block
.
Hash
())
==
0
{
// TODO: Perhaps continue mining to get some uncle rewards
log
.
Println
(
"New top block found resetting state"
)
// TODO: We probably want to skip this if it's our own block
// Reapplies the latest block to the mining state, thus resetting
ethereum
.
StateManager
()
.
PrepareMiningState
()
block
=
ethereum
.
BlockChain
()
.
NewBlock
(
addr
,
txs
)
log
.
Println
(
"Block set"
)
}
else
{
if
bytes
.
Compare
(
block
.
PrevHash
,
ethereum
.
BlockChain
()
.
CurrentBlock
.
PrevHash
)
==
0
{
log
.
Println
(
"HELLO UNCLE"
)
// TODO: Add uncle to block
uncles
=
append
(
uncles
,
block
)
}
}
}
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
=
ethereum
.
TxPool
()
.
Flush
()
}
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 uncles
if
len
(
uncles
)
>
0
{
block
.
SetUncles
(
uncles
)
}
// 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
())
}
}
}
}
}()
}()
}
}
...
...
ui/library.go
View file @
30025700
...
@@ -27,14 +27,15 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string {
...
@@ -27,14 +27,15 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string {
}
}
k
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
k
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
key
Ring
:=
ethutil
.
NewValue
FromBytes
(
k
)
key
Pair
:=
ethutil
.
NewKey
FromBytes
(
k
)
amount
:=
ethutil
.
Big
(
a
)
amount
:=
ethutil
.
Big
(
a
)
code
:=
ethchain
.
Compile
(
strings
.
Split
(
data
,
"
\n
"
))
code
:=
ethchain
.
Compile
(
strings
.
Split
(
data
,
"
\n
"
))
tx
:=
ethchain
.
NewTransaction
(
hash
,
amount
,
code
)
tx
:=
ethchain
.
NewTransaction
(
hash
,
amount
,
code
)
tx
.
Nonce
=
lib
.
stateManager
.
GetAddrState
(
keyRing
.
Get
(
1
)
.
Bytes
())
.
Nonce
tx
.
Nonce
=
lib
.
stateManager
.
GetAddrState
(
keyPair
.
Address
())
.
Nonce
tx
.
Sign
(
keyPair
.
PrivateKey
)
tx
.
Sign
(
keyRing
.
Get
(
0
)
.
Bytes
())
ethutil
.
Config
.
Log
.
Infof
(
"nonce: %x"
,
tx
.
Nonce
)
ethutil
.
Config
.
Log
.
Infof
(
"nonce: %x"
,
tx
.
Nonce
)
lib
.
txPool
.
QueueTransaction
(
tx
)
lib
.
txPool
.
QueueTransaction
(
tx
)
...
...
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