Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c1dee151
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,发现更多精彩内容 >>
提交
c1dee151
编写于
1月 05, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BlockManager => BlockProcessor
上级
987119cd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
116 addition
and
36 deletion
+116
-36
cmd/utils/cmd.go
cmd/utils/cmd.go
+1
-1
core/block_processor.go
core/block_processor.go
+12
-12
core/filter.go
core/filter.go
+1
-1
eth/backend.go
eth/backend.go
+9
-9
eth/wallet.go
eth/wallet.go
+80
-0
miner/miner.go
miner/miner.go
+5
-5
xeth/xeth.go
xeth/xeth.go
+8
-8
未找到文件。
cmd/utils/cmd.go
浏览文件 @
c1dee151
...
...
@@ -234,7 +234,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
ParentHash
())
_
,
err
:=
ethereum
.
Block
Manage
r
()
.
TransitionState
(
parent
.
State
(),
parent
,
block
)
_
,
err
:=
ethereum
.
Block
Processo
r
()
.
TransitionState
(
parent
.
State
(),
parent
,
block
)
if
err
!=
nil
{
return
err
}
...
...
core/block_
manage
r.go
→
core/block_
processo
r.go
浏览文件 @
c1dee151
...
...
@@ -22,7 +22,7 @@ import (
var
statelogger
=
logger
.
NewLogger
(
"BLOCK"
)
type
EthManager
interface
{
Block
Manager
()
*
BlockManage
r
Block
Processor
()
*
BlockProcesso
r
ChainManager
()
*
ChainManager
TxPool
()
*
TxPool
PeerCount
()
int
...
...
@@ -35,7 +35,7 @@ type EthManager interface {
EventMux
()
*
event
.
TypeMux
}
type
Block
Manage
r
struct
{
type
Block
Processo
r
struct
{
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex
sync
.
Mutex
// Canonical block chain
...
...
@@ -57,8 +57,8 @@ type BlockManager struct {
eventMux
*
event
.
TypeMux
}
func
NewBlock
Manager
(
txpool
*
TxPool
,
chainManager
*
ChainManager
,
eventMux
*
event
.
TypeMux
)
*
BlockManage
r
{
sm
:=
&
Block
Manage
r
{
func
NewBlock
Processor
(
txpool
*
TxPool
,
chainManager
*
ChainManager
,
eventMux
*
event
.
TypeMux
)
*
BlockProcesso
r
{
sm
:=
&
Block
Processo
r
{
mem
:
make
(
map
[
string
]
*
big
.
Int
),
Pow
:
ezp
.
New
(),
bc
:
chainManager
,
...
...
@@ -69,7 +69,7 @@ func NewBlockManager(txpool *TxPool, chainManager *ChainManager, eventMux *event
return
sm
}
func
(
sm
*
Block
Manage
r
)
TransitionState
(
statedb
*
state
.
StateDB
,
parent
,
block
*
types
.
Block
)
(
receipts
types
.
Receipts
,
err
error
)
{
func
(
sm
*
Block
Processo
r
)
TransitionState
(
statedb
*
state
.
StateDB
,
parent
,
block
*
types
.
Block
)
(
receipts
types
.
Receipts
,
err
error
)
{
coinbase
:=
statedb
.
GetOrNewStateObject
(
block
.
Header
()
.
Coinbase
)
coinbase
.
SetGasPool
(
CalcGasLimit
(
parent
,
block
))
...
...
@@ -82,7 +82,7 @@ func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *t
return
receipts
,
nil
}
func
(
self
*
Block
Manage
r
)
ApplyTransactions
(
coinbase
*
state
.
StateObject
,
state
*
state
.
StateDB
,
block
*
types
.
Block
,
txs
types
.
Transactions
,
transientProcess
bool
)
(
types
.
Receipts
,
types
.
Transactions
,
types
.
Transactions
,
types
.
Transactions
,
error
)
{
func
(
self
*
Block
Processo
r
)
ApplyTransactions
(
coinbase
*
state
.
StateObject
,
state
*
state
.
StateDB
,
block
*
types
.
Block
,
txs
types
.
Transactions
,
transientProcess
bool
)
(
types
.
Receipts
,
types
.
Transactions
,
types
.
Transactions
,
types
.
Transactions
,
error
)
{
var
(
receipts
types
.
Receipts
handled
,
unhandled
types
.
Transactions
...
...
@@ -149,7 +149,7 @@ done:
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
}
func
(
sm
*
Block
Manage
r
)
Process
(
block
*
types
.
Block
)
(
td
*
big
.
Int
,
msgs
state
.
Messages
,
err
error
)
{
func
(
sm
*
Block
Processo
r
)
Process
(
block
*
types
.
Block
)
(
td
*
big
.
Int
,
msgs
state
.
Messages
,
err
error
)
{
// Processing a blocks may never happen simultaneously
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
Unlock
()
...
...
@@ -167,7 +167,7 @@ func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Mes
return
sm
.
ProcessWithParent
(
block
,
parent
)
}
func
(
sm
*
Block
Manage
r
)
ProcessWithParent
(
block
,
parent
*
types
.
Block
)
(
td
*
big
.
Int
,
messages
state
.
Messages
,
err
error
)
{
func
(
sm
*
Block
Processo
r
)
ProcessWithParent
(
block
,
parent
*
types
.
Block
)
(
td
*
big
.
Int
,
messages
state
.
Messages
,
err
error
)
{
sm
.
lastAttemptedBlock
=
block
state
:=
state
.
New
(
parent
.
Trie
()
.
Copy
())
...
...
@@ -234,7 +234,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
}
}
func
(
sm
*
Block
Manage
r
)
CalculateTD
(
block
*
types
.
Block
)
(
*
big
.
Int
,
bool
)
{
func
(
sm
*
Block
Processo
r
)
CalculateTD
(
block
*
types
.
Block
)
(
*
big
.
Int
,
bool
)
{
uncleDiff
:=
new
(
big
.
Int
)
for
_
,
uncle
:=
range
block
.
Uncles
()
{
uncleDiff
=
uncleDiff
.
Add
(
uncleDiff
,
uncle
.
Difficulty
)
...
...
@@ -257,7 +257,7 @@ func (sm *BlockManager) CalculateTD(block *types.Block) (*big.Int, bool) {
// Validates the current block. Returns an error if the block was invalid,
// an uncle or anything that isn't on the current block chain.
// Validation validates easy over difficult (dagger takes longer time = difficult)
func
(
sm
*
Block
Manage
r
)
ValidateBlock
(
block
,
parent
*
types
.
Block
)
error
{
func
(
sm
*
Block
Processo
r
)
ValidateBlock
(
block
,
parent
*
types
.
Block
)
error
{
expd
:=
CalcDifficulty
(
block
,
parent
)
if
expd
.
Cmp
(
block
.
Header
()
.
Difficulty
)
<
0
{
return
fmt
.
Errorf
(
"Difficulty check failed for block %v, %v"
,
block
.
Header
()
.
Difficulty
,
expd
)
...
...
@@ -283,7 +283,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
return
nil
}
func
(
sm
*
Block
Manage
r
)
AccumelateRewards
(
statedb
*
state
.
StateDB
,
block
,
parent
*
types
.
Block
)
error
{
func
(
sm
*
Block
Processo
r
)
AccumelateRewards
(
statedb
*
state
.
StateDB
,
block
,
parent
*
types
.
Block
)
error
{
reward
:=
new
(
big
.
Int
)
.
Set
(
BlockReward
)
knownUncles
:=
set
.
New
()
...
...
@@ -338,7 +338,7 @@ func (sm *BlockManager) AccumelateRewards(statedb *state.StateDB, block, parent
return
nil
}
func
(
sm
*
Block
Manage
r
)
GetMessages
(
block
*
types
.
Block
)
(
messages
[]
*
state
.
Message
,
err
error
)
{
func
(
sm
*
Block
Processo
r
)
GetMessages
(
block
*
types
.
Block
)
(
messages
[]
*
state
.
Message
,
err
error
)
{
if
!
sm
.
bc
.
HasBlock
(
block
.
Header
()
.
ParentHash
)
{
return
nil
,
ParentError
(
block
.
Header
()
.
ParentHash
)
}
...
...
core/filter.go
浏览文件 @
c1dee151
...
...
@@ -104,7 +104,7 @@ func (self *Filter) Find() []*state.Message {
// current parameters
if
self
.
bloomFilter
(
block
)
{
// Get the messages of the block
msgs
,
err
:=
self
.
eth
.
Block
Manage
r
()
.
GetMessages
(
block
)
msgs
,
err
:=
self
.
eth
.
Block
Processo
r
()
.
GetMessages
(
block
)
if
err
!=
nil
{
chainlogger
.
Warnln
(
"err: filter get messages "
,
err
)
...
...
eth/backend.go
浏览文件 @
c1dee151
...
...
@@ -52,11 +52,11 @@ type Ethereum struct {
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
block
Manager
*
core
.
BlockManage
r
txPool
*
core
.
TxPool
chainManager
*
core
.
ChainManager
blockPool
*
BlockPool
whisper
*
whisper
.
Whisper
block
Processor
*
core
.
BlockProcesso
r
txPool
*
core
.
TxPool
chainManager
*
core
.
ChainManager
blockPool
*
BlockPool
whisper
*
whisper
.
Whisper
net
*
p2p
.
Server
eventMux
*
event
.
TypeMux
...
...
@@ -122,8 +122,8 @@ func New(config *Config) (*Ethereum, error) {
eth
.
chainManager
=
core
.
NewChainManager
(
eth
.
EventMux
())
eth
.
txPool
=
core
.
NewTxPool
(
eth
.
EventMux
())
eth
.
block
Manager
=
core
.
NewBlockManage
r
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
EventMux
())
eth
.
chainManager
.
SetProcessor
(
eth
.
block
Manage
r
)
eth
.
block
Processor
=
core
.
NewBlockProcesso
r
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
EventMux
())
eth
.
chainManager
.
SetProcessor
(
eth
.
block
Processo
r
)
eth
.
whisper
=
whisper
.
New
()
hasBlock
:=
eth
.
chainManager
.
HasBlock
...
...
@@ -169,8 +169,8 @@ func (s *Ethereum) ChainManager() *core.ChainManager {
return
s
.
chainManager
}
func
(
s
*
Ethereum
)
Block
Manager
()
*
core
.
BlockManage
r
{
return
s
.
block
Manage
r
func
(
s
*
Ethereum
)
Block
Processor
()
*
core
.
BlockProcesso
r
{
return
s
.
block
Processo
r
}
func
(
s
*
Ethereum
)
TxPool
()
*
core
.
TxPool
{
...
...
eth/wallet.go
0 → 100644
浏览文件 @
c1dee151
package
eth
/*
import (
"crypto/ecdsa"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
)
type Account struct {
w *Wallet
}
func (self *Account) Transact(to *Account, value, gas, price *big.Int, data []byte) error {
return self.w.transact(self, to, value, gas, price, data)
}
func (self *Account) Address() []byte {
return nil
}
func (self *Account) PrivateKey() *ecdsa.PrivateKey {
return nil
}
type Wallet struct{}
func NewWallet() *Wallet {
return &Wallet{}
}
func (self *Wallet) GetAccount(i int) *Account {
}
func (self *Wallet) transact(from, to *Account, value, gas, price *big.Int, data []byte) error {
if from.PrivateKey() == nil {
return errors.New("accounts is not owned (no private key available)")
}
var createsContract bool
if to == nil {
createsContract = true
}
var msg *types.Transaction
if contractCreation {
msg = types.NewContractCreationTx(value, gas, price, data)
} else {
msg = types.NewTransactionMessage(to.Address(), value, gas, price, data)
}
state := self.chainManager.TransState()
nonce := state.GetNonce(key.Address())
msg.SetNonce(nonce)
msg.SignECDSA(from.PriateKey())
// Do some pre processing for our "pre" events and hooks
block := self.chainManager.NewBlock(from.Address())
coinbase := state.GetOrNewStateObject(from.Address())
coinbase.SetGasPool(block.GasLimit())
self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
err := self.obj.TxPool().Add(tx)
if err != nil {
return nil, err
}
state.SetNonce(key.Address(), nonce+1)
if contractCreation {
addr := core.AddressFromMessage(tx)
pipelogger.Infof("Contract addr %x\n", addr)
}
return tx, nil
}
*/
miner/miner.go
浏览文件 @
c1dee151
...
...
@@ -174,9 +174,9 @@ func (self *Miner) reset() {
func
(
self
*
Miner
)
mine
()
{
var
(
block
Manager
=
self
.
eth
.
BlockManage
r
()
chainMan
=
self
.
eth
.
ChainManager
()
block
=
chainMan
.
NewBlock
(
self
.
Coinbase
)
block
Processor
=
self
.
eth
.
BlockProcesso
r
()
chainMan
=
self
.
eth
.
ChainManager
()
block
=
chainMan
.
NewBlock
(
self
.
Coinbase
)
)
// Apply uncles
...
...
@@ -194,7 +194,7 @@ func (self *Miner) mine() {
// Accumulate all valid transactions and apply them to the new state
// Error may be ignored. It's not important during mining
receipts
,
txs
,
_
,
erroneous
,
err
:=
block
Manage
r
.
ApplyTransactions
(
coinbase
,
state
,
block
,
transactions
,
true
)
receipts
,
txs
,
_
,
erroneous
,
err
:=
block
Processo
r
.
ApplyTransactions
(
coinbase
,
state
,
block
,
transactions
,
true
)
if
err
!=
nil
{
minerlogger
.
Debugln
(
err
)
}
...
...
@@ -204,7 +204,7 @@ func (self *Miner) mine() {
block
.
SetReceipts
(
receipts
)
// Accumulate the rewards included for this block
block
Manage
r
.
AccumelateRewards
(
state
,
block
,
parent
)
block
Processo
r
.
AccumelateRewards
(
state
,
block
,
parent
)
state
.
Update
(
ethutil
.
Big0
)
block
.
SetRoot
(
state
.
Root
())
...
...
xeth/
pipe
.go
→
xeth/
xeth
.go
浏览文件 @
c1dee151
...
...
@@ -20,19 +20,19 @@ type VmVars struct {
}
type
XEth
struct
{
obj
core
.
EthManager
block
Manager
*
core
.
BlockManage
r
chainManager
*
core
.
ChainManager
world
*
World
obj
core
.
EthManager
block
Processor
*
core
.
BlockProcesso
r
chainManager
*
core
.
ChainManager
world
*
World
Vm
VmVars
}
func
New
(
obj
core
.
EthManager
)
*
XEth
{
pipe
:=
&
XEth
{
obj
:
obj
,
block
Manager
:
obj
.
BlockManage
r
(),
chainManager
:
obj
.
ChainManager
(),
obj
:
obj
,
block
Processor
:
obj
.
BlockProcesso
r
(),
chainManager
:
obj
.
ChainManager
(),
}
pipe
.
world
=
NewWorld
(
pipe
)
...
...
@@ -141,7 +141,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
block
:=
self
.
chainManager
.
NewBlock
(
key
.
Address
())
coinbase
:=
state
.
GetOrNewStateObject
(
key
.
Address
())
coinbase
.
SetGasPool
(
block
.
GasLimit
())
self
.
block
Manage
r
.
ApplyTransactions
(
coinbase
,
state
,
block
,
types
.
Transactions
{
tx
},
true
)
self
.
block
Processo
r
.
ApplyTransactions
(
coinbase
,
state
,
block
,
types
.
Transactions
{
tx
},
true
)
err
:=
self
.
obj
.
TxPool
()
.
Add
(
tx
)
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录