Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
9e2f071d
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9e2f071d
编写于
10月 29, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed events from the state manager
上级
fb4113da
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
63 addition
and
83 deletion
+63
-83
block_pool.go
block_pool.go
+5
-1
cmd/ethereum/main.go
cmd/ethereum/main.go
+2
-0
ethchain/block.go
ethchain/block.go
+11
-23
ethchain/bloom9.go
ethchain/bloom9.go
+4
-5
ethchain/chain_manager.go
ethchain/chain_manager.go
+0
-2
ethchain/filter.go
ethchain/filter.go
+0
-6
ethchain/state_manager.go
ethchain/state_manager.go
+3
-12
ethchain/state_transition.go
ethchain/state_transition.go
+1
-1
ethminer/miner.go
ethminer/miner.go
+17
-16
ethtrie/trie.go
ethtrie/trie.go
+20
-17
未找到文件。
block_pool.go
浏览文件 @
9e2f071d
...
@@ -309,9 +309,13 @@ out:
...
@@ -309,9 +309,13 @@ out:
}
}
}
}
// TODO figure out whether we were catching up
// If caught up and just a new block has been propagated:
// sm.eth.EventMux().Post(NewBlockEvent{block})
// otherwise process and don't emit anything
var
err
error
var
err
error
for
i
,
block
:=
range
blocks
{
for
i
,
block
:=
range
blocks
{
err
=
self
.
eth
.
StateManager
()
.
Process
(
block
,
false
)
err
=
self
.
eth
.
StateManager
()
.
Process
(
block
)
if
err
!=
nil
{
if
err
!=
nil
{
poollogger
.
Infoln
(
err
)
poollogger
.
Infoln
(
err
)
poollogger
.
Debugf
(
"Block #%v failed (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
poollogger
.
Debugf
(
"Block #%v failed (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
...
...
cmd/ethereum/main.go
浏览文件 @
9e2f071d
...
@@ -98,6 +98,8 @@ func main() {
...
@@ -98,6 +98,8 @@ func main() {
// Leave the Println. This needs clean output for piping
// Leave the Println. This needs clean output for piping
fmt
.
Printf
(
"%s
\n
"
,
block
.
State
()
.
Dump
())
fmt
.
Printf
(
"%s
\n
"
,
block
.
State
()
.
Dump
())
fmt
.
Println
(
block
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
...
...
ethchain/block.go
浏览文件 @
9e2f071d
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"fmt"
"fmt"
"math/big"
"math/big"
"sort"
"sort"
_
"strconv"
"time"
"time"
"github.com/ethereum/go-ethereum/ethcrypto"
"github.com/ethereum/go-ethereum/ethcrypto"
...
@@ -240,15 +239,19 @@ func (block *Block) SetUncles(uncles []*Block) {
...
@@ -240,15 +239,19 @@ func (block *Block) SetUncles(uncles []*Block) {
block
.
UncleSha
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
block
.
UncleSha
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
}
}
func
(
self
*
Block
)
SetReceipts
(
receipts
[]
*
Receipt
,
txs
[]
*
Transaction
)
{
func
(
self
*
Block
)
SetReceipts
(
receipts
Receipts
)
{
self
.
receipts
=
receipts
self
.
receipts
=
receipts
self
.
SetReceiptHash
(
receipts
)
}
func
(
self
*
Block
)
SetTransactions
(
txs
Transactions
)
{
self
.
setTransactions
(
txs
)
self
.
setTransactions
(
txs
)
self
.
SetTransactionHash
(
txs
)
}
}
func
(
block
*
Block
)
setTransactions
(
txs
[]
*
Transaction
)
{
func
(
block
*
Block
)
setTransactions
(
txs
Transactions
)
{
block
.
transactions
=
txs
block
.
transactions
=
txs
block
.
LogsBloom
=
CreateBloom
(
block
)
block
.
LogsBloom
=
CreateBloom
(
txs
)
}
}
func
(
self
*
Block
)
SetTransactionHash
(
transactions
Transactions
)
{
func
(
self
*
Block
)
SetTransactionHash
(
transactions
Transactions
)
{
...
@@ -424,22 +427,7 @@ func (self *Block) Size() ethutil.StorageSize {
...
@@ -424,22 +427,7 @@ func (self *Block) Size() ethutil.StorageSize {
return
ethutil
.
StorageSize
(
len
(
self
.
RlpEncode
()))
return
ethutil
.
StorageSize
(
len
(
self
.
RlpEncode
()))
}
}
/*
// Implement RlpEncodable
func DeriveReceiptHash(receipts Receipts) (sha []byte) {
func
(
self
*
Block
)
RlpData
()
interface
{}
{
trie := ethtrie.New(ethutil.Config.Db, "")
return
self
.
Value
()
.
Val
for i, receipt := range receipts {
trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode()))
}
switch trie.Root.(type) {
case string:
sha = []byte(trie.Root.(string))
case []byte:
sha = trie.Root.([]byte)
default:
panic(fmt.Sprintf("invalid root type %T", trie.Root))
}
return sha
}
}
*/
ethchain/bloom9.go
浏览文件 @
9e2f071d
...
@@ -6,9 +6,10 @@ import (
...
@@ -6,9 +6,10 @@ import (
"github.com/ethereum/go-ethereum/vm"
"github.com/ethereum/go-ethereum/vm"
)
)
func
CreateBloom
(
txs
Transactions
)
[]
byte
{
func
CreateBloom
(
block
*
Block
)
[]
byte
{
bin
:=
new
(
big
.
Int
)
bin
:=
new
(
big
.
Int
)
for
_
,
tx
:=
range
txs
{
bin
.
Or
(
bin
,
bloom9
(
block
.
Coinbase
))
for
_
,
tx
:=
range
block
.
Transactions
()
{
bin
.
Or
(
bin
,
LogsBloom
(
tx
.
logs
))
bin
.
Or
(
bin
,
LogsBloom
(
tx
.
logs
))
}
}
...
@@ -36,9 +37,7 @@ func bloom9(b []byte) *big.Int {
...
@@ -36,9 +37,7 @@ func bloom9(b []byte) *big.Int {
r
:=
new
(
big
.
Int
)
r
:=
new
(
big
.
Int
)
for
_
,
i
:=
range
[]
int
{
0
,
2
,
4
}
{
for
_
,
i
:=
range
[]
int
{
0
,
2
,
4
}
{
t
:=
big
.
NewInt
(
1
)
t
:=
big
.
NewInt
(
1
)
r
.
Or
(
r
,
t
.
Lsh
(
t
,
uint
(
b
[
i
+
1
])
+
256
*
(
uint
(
b
[
i
])
&
1
)))
//r |= 1 << (uint64(b[i+1]) + 256*(uint64(b[i])&1))
r
.
Or
(
r
,
t
.
Rsh
(
t
,
uint
(
b
[
i
+
1
])
+
256
*
(
uint
(
b
[
i
])
&
1
)))
}
}
return
r
return
r
...
...
ethchain/chain_manager.go
浏览文件 @
9e2f071d
...
@@ -87,8 +87,6 @@ func (bc *ChainManager) Reset() {
...
@@ -87,8 +87,6 @@ func (bc *ChainManager) Reset() {
bc
.
genesisBlock
.
state
.
Trie
.
Sync
()
bc
.
genesisBlock
.
state
.
Trie
.
Sync
()
// Prepare the genesis block
// Prepare the genesis block
bc
.
Add
(
bc
.
genesisBlock
)
bc
.
Add
(
bc
.
genesisBlock
)
//fk := append([]byte("bloom"), bc.genesisBlock.Hash()...)
//bc.Ethereum.Db().Put(fk, make([]byte, 255))
bc
.
CurrentBlock
=
bc
.
genesisBlock
bc
.
CurrentBlock
=
bc
.
genesisBlock
bc
.
SetTotalDifficulty
(
ethutil
.
Big
(
"0"
))
bc
.
SetTotalDifficulty
(
ethutil
.
Big
(
"0"
))
...
...
ethchain/filter.go
浏览文件 @
9e2f071d
...
@@ -170,12 +170,6 @@ func (self *Filter) FilterMessages(msgs []*ethstate.Message) []*ethstate.Message
...
@@ -170,12 +170,6 @@ func (self *Filter) FilterMessages(msgs []*ethstate.Message) []*ethstate.Message
}
}
func
(
self
*
Filter
)
bloomFilter
(
block
*
Block
)
bool
{
func
(
self
*
Filter
)
bloomFilter
(
block
*
Block
)
bool
{
//fk := append([]byte("bloom"), block.Hash()...)
//bin, err := self.eth.Db().Get(fk)
//if err != nil {
// fmt.Println(err)
//}
// TODO update to the new bloom filter
// TODO update to the new bloom filter
bloom
:=
NewBloomFilter
(
nil
)
bloom
:=
NewBloomFilter
(
nil
)
...
...
ethchain/state_manager.go
浏览文件 @
9e2f071d
...
@@ -101,7 +101,7 @@ func (self *StateManager) Stop() {
...
@@ -101,7 +101,7 @@ func (self *StateManager) Stop() {
func
(
self
*
StateManager
)
updateThread
()
{
func
(
self
*
StateManager
)
updateThread
()
{
for
ev
:=
range
self
.
events
.
Chan
()
{
for
ev
:=
range
self
.
events
.
Chan
()
{
for
_
,
block
:=
range
ev
.
(
Blocks
)
{
for
_
,
block
:=
range
ev
.
(
Blocks
)
{
err
:=
self
.
Process
(
block
,
false
)
err
:=
self
.
Process
(
block
)
if
err
!=
nil
{
if
err
!=
nil
{
statelogger
.
Infoln
(
err
)
statelogger
.
Infoln
(
err
)
statelogger
.
Debugf
(
"Block #%v failed (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
statelogger
.
Debugf
(
"Block #%v failed (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
...
@@ -206,7 +206,7 @@ done:
...
@@ -206,7 +206,7 @@ done:
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
}
}
func
(
sm
*
StateManager
)
Process
(
block
*
Block
,
dontReact
bool
)
(
err
error
)
{
func
(
sm
*
StateManager
)
Process
(
block
*
Block
)
(
err
error
)
{
// Processing a blocks may never happen simultaneously
// Processing a blocks may never happen simultaneously
sm
.
mutex
.
Lock
()
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
Unlock
()
defer
sm
.
mutex
.
Unlock
()
...
@@ -281,18 +281,9 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
...
@@ -281,18 +281,9 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
sm
.
transState
=
state
.
Copy
()
sm
.
transState
=
state
.
Copy
()
// Create a bloom bin for this block
//filter := sm.createBloomFilter(state)
// Persist the data
//fk := append([]byte("bloom"), block.Hash()...)
//sm.eth.Db().Put(fk, filter.Bin())
statelogger
.
Infof
(
"Imported block #%d (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
statelogger
.
Infof
(
"Imported block #%d (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
if
dontReact
==
false
{
sm
.
eth
.
EventMux
()
.
Post
(
NewBlockEvent
{
block
})
state
.
Manifest
()
.
Reset
()
state
.
Manifest
()
.
Reset
()
}
sm
.
eth
.
TxPool
()
.
RemoveSet
(
block
.
Transactions
())
sm
.
eth
.
TxPool
()
.
RemoveSet
(
block
.
Transactions
())
}
else
{
}
else
{
...
...
ethchain/state_transition.go
浏览文件 @
9e2f071d
...
@@ -231,7 +231,7 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -231,7 +231,7 @@ func (self *StateTransition) TransitionState() (err error) {
msg
.
Output
=
ret
msg
.
Output
=
ret
}
else
{
}
else
{
// Add default LOG. Default = big(sender.addr) + 1
// Add default LOG. Default = big(sender.addr) + 1
addr
:=
ethutil
.
BigD
(
send
er
.
Address
())
addr
:=
ethutil
.
BigD
(
receiv
er
.
Address
())
tx
.
addLog
(
vm
.
Log
{
sender
.
Address
(),
[][]
byte
{
addr
.
Add
(
addr
,
ethutil
.
Big1
)
.
Bytes
()},
nil
})
tx
.
addLog
(
vm
.
Log
{
sender
.
Address
(),
[][]
byte
{
addr
.
Add
(
addr
,
ethutil
.
Big1
)
.
Bytes
()},
nil
})
}
}
}
}
...
...
ethminer/miner.go
浏览文件 @
9e2f071d
...
@@ -85,11 +85,7 @@ func (miner *Miner) listener() {
...
@@ -85,11 +85,7 @@ func (miner *Miner) listener() {
for
{
for
{
select
{
select
{
case
event
,
isopen
:=
<-
miner
.
events
.
Chan
()
:
case
event
:=
<-
miner
.
events
.
Chan
()
:
if
!
isopen
{
return
}
switch
event
:=
event
.
(
type
)
{
switch
event
:=
event
.
(
type
)
{
case
ethchain
.
NewBlockEvent
:
case
ethchain
.
NewBlockEvent
:
miner
.
stopMining
()
miner
.
stopMining
()
...
@@ -114,16 +110,13 @@ func (miner *Miner) listener() {
...
@@ -114,16 +110,13 @@ func (miner *Miner) listener() {
}
}
}
}
miner
.
txs
=
newtxs
miner
.
txs
=
newtxs
// Setup a fresh state to mine on
//miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase, miner.txs)
}
else
{
}
else
{
if
bytes
.
Compare
(
block
.
PrevHash
,
miner
.
ethereum
.
ChainManager
()
.
CurrentBlock
.
PrevHash
)
==
0
{
if
bytes
.
Compare
(
block
.
PrevHash
,
miner
.
ethereum
.
ChainManager
()
.
CurrentBlock
.
PrevHash
)
==
0
{
logger
.
Infoln
(
"Adding uncle block"
)
logger
.
Infoln
(
"Adding uncle block"
)
miner
.
uncles
=
append
(
miner
.
uncles
,
block
)
miner
.
uncles
=
append
(
miner
.
uncles
,
block
)
}
}
}
}
miner
.
startMining
()
case
ethchain
.
TxEvent
:
case
ethchain
.
TxEvent
:
if
event
.
Type
==
ethchain
.
TxPre
{
if
event
.
Type
==
ethchain
.
TxPre
{
...
@@ -141,6 +134,8 @@ func (miner *Miner) listener() {
...
@@ -141,6 +134,8 @@ func (miner *Miner) listener() {
// Apply new transactions
// Apply new transactions
miner
.
txs
=
append
(
miner
.
txs
,
event
.
Tx
)
miner
.
txs
=
append
(
miner
.
txs
,
event
.
Tx
)
}
}
miner
.
startMining
()
}
}
}
}
...
@@ -159,8 +154,12 @@ func (miner *Miner) startMining() {
...
@@ -159,8 +154,12 @@ func (miner *Miner) startMining() {
}
}
func
(
miner
*
Miner
)
stopMining
()
{
func
(
miner
*
Miner
)
stopMining
()
{
println
(
"stop mining"
)
_
,
isopen
:=
<-
miner
.
powQuitChan
if
isopen
{
close
(
miner
.
powQuitChan
)
close
(
miner
.
powQuitChan
)
<-
miner
.
powDone
}
//<-miner.powDone
}
}
func
(
self
*
Miner
)
mineNewBlock
()
{
func
(
self
*
Miner
)
mineNewBlock
()
{
...
@@ -187,10 +186,9 @@ func (self *Miner) mineNewBlock() {
...
@@ -187,10 +186,9 @@ func (self *Miner) mineNewBlock() {
}
}
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
erroneous
)
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
erroneous
)
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
block
.
SetReceiptHash
(
receipts
)
// Set the transactions to the block so the new SHA3 can be calculated
self
.
block
.
SetReceipts
(
receipts
)
self
.
block
.
Set
Receipts
(
receipts
,
txs
)
self
.
block
.
Set
Transactions
(
txs
)
// Accumulate the rewards included for this block
// Accumulate the rewards included for this block
stateManager
.
AccumelateRewards
(
self
.
block
.
State
(),
self
.
block
,
parent
)
stateManager
.
AccumelateRewards
(
self
.
block
.
State
(),
self
.
block
,
parent
)
...
@@ -203,7 +201,7 @@ func (self *Miner) mineNewBlock() {
...
@@ -203,7 +201,7 @@ func (self *Miner) mineNewBlock() {
nonce
:=
self
.
pow
.
Search
(
self
.
block
,
self
.
powQuitChan
)
nonce
:=
self
.
pow
.
Search
(
self
.
block
,
self
.
powQuitChan
)
if
nonce
!=
nil
{
if
nonce
!=
nil
{
self
.
block
.
Nonce
=
nonce
self
.
block
.
Nonce
=
nonce
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
false
)
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Infoln
(
err
)
logger
.
Infoln
(
err
)
}
else
{
}
else
{
...
@@ -212,7 +210,10 @@ func (self *Miner) mineNewBlock() {
...
@@ -212,7 +210,10 @@ func (self *Miner) mineNewBlock() {
logger
.
Infoln
(
self
.
block
)
logger
.
Infoln
(
self
.
block
)
// Gather the new batch of transactions currently in the tx pool
// Gather the new batch of transactions currently in the tx pool
self
.
txs
=
self
.
ethereum
.
TxPool
()
.
CurrentTransactions
()
self
.
txs
=
self
.
ethereum
.
TxPool
()
.
CurrentTransactions
()
self
.
ethereum
.
EventMux
()
.
Post
(
ethchain
.
NewBlockEvent
{
self
.
block
})
}
}
// Continue mining on the next block
self
.
startMining
()
}
}
self
.
powDone
<-
struct
{}{}
}
}
ethtrie/trie.go
浏览文件 @
9e2f071d
...
@@ -168,7 +168,24 @@ func New(db ethutil.Database, Root interface{}) *Trie {
...
@@ -168,7 +168,24 @@ func New(db ethutil.Database, Root interface{}) *Trie {
r
:=
copyRoot
(
Root
)
r
:=
copyRoot
(
Root
)
p
:=
copyRoot
(
Root
)
p
:=
copyRoot
(
Root
)
return
&
Trie
{
cache
:
NewCache
(
db
),
Root
:
r
,
prevRoot
:
p
}
trie
:=
&
Trie
{
cache
:
NewCache
(
db
),
Root
:
r
,
prevRoot
:
p
}
trie
.
setRoot
(
Root
)
return
trie
}
func
(
self
*
Trie
)
setRoot
(
root
interface
{})
{
switch
t
:=
root
.
(
type
)
{
case
string
:
if
t
==
""
{
root
=
ethcrypto
.
Sha3
([]
byte
(
""
))
}
self
.
Root
=
root
case
[]
byte
:
self
.
Root
=
root
default
:
self
.
Root
=
self
.
cache
.
PutValue
(
root
,
true
)
}
}
}
/*
/*
...
@@ -182,14 +199,7 @@ func (t *Trie) Update(key, value string) {
...
@@ -182,14 +199,7 @@ func (t *Trie) Update(key, value string) {
k
:=
CompactHexDecode
(
key
)
k
:=
CompactHexDecode
(
key
)
root
:=
t
.
UpdateState
(
t
.
Root
,
k
,
value
)
root
:=
t
.
UpdateState
(
t
.
Root
,
k
,
value
)
switch
root
.
(
type
)
{
t
.
setRoot
(
root
)
case
string
:
t
.
Root
=
root
case
[]
byte
:
t
.
Root
=
root
default
:
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
}
}
func
(
t
*
Trie
)
Get
(
key
string
)
string
{
func
(
t
*
Trie
)
Get
(
key
string
)
string
{
...
@@ -209,14 +219,7 @@ func (t *Trie) Delete(key string) {
...
@@ -209,14 +219,7 @@ func (t *Trie) Delete(key string) {
k
:=
CompactHexDecode
(
key
)
k
:=
CompactHexDecode
(
key
)
root
:=
t
.
deleteState
(
t
.
Root
,
k
)
root
:=
t
.
deleteState
(
t
.
Root
,
k
)
switch
root
.
(
type
)
{
t
.
setRoot
(
root
)
case
string
:
t
.
Root
=
root
case
[]
byte
:
t
.
Root
=
root
default
:
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
}
}
func
(
self
*
Trie
)
GetRoot
()
[]
byte
{
func
(
self
*
Trie
)
GetRoot
()
[]
byte
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录