diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/block_manager.go | 8 | ||||
-rw-r--r-- | core/chain_manager.go | 9 | ||||
-rw-r--r-- | core/events.go | 3 | ||||
-rw-r--r-- | core/transaction_pool.go | 30 | ||||
-rw-r--r-- | core/types/common.go | 5 |
5 files changed, 31 insertions, 24 deletions
diff --git a/core/block_manager.go b/core/block_manager.go index 8d319f84e..85b4891a5 100644 --- a/core/block_manager.go +++ b/core/block_manager.go @@ -2,7 +2,6 @@ package core import ( "bytes" - "container/list" "errors" "fmt" "math/big" @@ -14,10 +13,10 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow/ezp" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/wire" ) var statelogger = logger.NewLogger("BLOCK") @@ -38,13 +37,12 @@ type EthManager interface { BlockManager() *BlockManager ChainManager() *ChainManager TxPool() *TxPool - Broadcast(msgType wire.MsgType, data []interface{}) PeerCount() int IsMining() bool IsListening() bool - Peers() *list.List + Peers() []*p2p.Peer KeyManager() *crypto.KeyManager - ClientIdentity() wire.ClientIdentity + ClientIdentity() p2p.ClientIdentity Db() ethutil.Database EventMux() *event.TypeMux } diff --git a/core/chain_manager.go b/core/chain_manager.go index 794ae0011..e6268c01e 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -100,6 +100,13 @@ func NewChainManager(mux *event.TypeMux) *ChainManager { return bc } +func (self *ChainManager) Status() (td *big.Int, currentBlock []byte, genesisBlock []byte) { + self.mu.RLock() + defer self.mu.RUnlock() + + return self.td, self.currentBlock.Hash(), self.Genesis().Hash() +} + func (self *ChainManager) SetProcessor(proc types.BlockProcessor) { self.processor = proc } @@ -221,7 +228,7 @@ func (bc *ChainManager) HasBlock(hash []byte) bool { return len(data) != 0 } -func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) { +func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain [][]byte) { block := self.GetBlock(hash) if block == nil { return diff --git a/core/events.go b/core/events.go index deeba3e98..fe106da49 100644 --- a/core/events.go +++ b/core/events.go @@ -10,3 +10,6 @@ type TxPostEvent struct{ Tx *types.Transaction } // NewBlockEvent is posted when a block has been imported. type NewBlockEvent struct{ Block *types.Block } + +// NewMinedBlockEvent is posted when a block has been imported. +type NewMinedBlockEvent struct{ Block *types.Block } diff --git a/core/transaction_pool.go b/core/transaction_pool.go index 58c2255a4..17fcdb86a 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/wire" ) var txplogger = logger.NewLogger("TXP") @@ -19,7 +18,9 @@ var txplogger = logger.NewLogger("TXP") const txPoolQueueSize = 50 type TxPoolHook chan *types.Transaction -type TxMsgTy byte +type TxMsg struct { + Tx *types.Transaction +} const ( minGasPrice = 1000000 @@ -27,11 +28,6 @@ const ( var MinGasPrice = big.NewInt(10000000000000) -type TxMsg struct { - Tx *types.Transaction - Type TxMsgTy -} - func EachTx(pool *list.List, it func(*types.Transaction, *list.Element) bool) { for e := pool.Front(); e != nil; e = e.Next() { if it(e.Value.(*types.Transaction), e) { @@ -76,19 +72,17 @@ type TxPool struct { subscribers []chan TxMsg - broadcaster types.Broadcaster chainManager *ChainManager eventMux *event.TypeMux } -func NewTxPool(chainManager *ChainManager, broadcaster types.Broadcaster, eventMux *event.TypeMux) *TxPool { +func NewTxPool(chainManager *ChainManager, eventMux *event.TypeMux) *TxPool { return &TxPool{ pool: list.New(), queueChan: make(chan *types.Transaction, txPoolQueueSize), quit: make(chan bool), chainManager: chainManager, eventMux: eventMux, - broadcaster: broadcaster, } } @@ -100,7 +94,7 @@ func (pool *TxPool) addTransaction(tx *types.Transaction) { pool.pool.PushBack(tx) // Broadcast the transaction to the rest of the peers - pool.broadcaster.Broadcast(wire.MsgTxTy, []interface{}{tx.RlpData()}) + pool.eventMux.Post(TxPreEvent{tx}) } func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { @@ -166,7 +160,17 @@ func (self *TxPool) Size() int { return self.pool.Len() } -func (pool *TxPool) CurrentTransactions() []*types.Transaction { +func (self *TxPool) AddTransactions(txs []*types.Transaction) { + for _, tx := range txs { + if err := self.Add(tx); err != nil { + txplogger.Infoln(err) + } else { + txplogger.Infof("tx %x\n", tx.Hash()[0:4]) + } + } +} + +func (pool *TxPool) GetTransactions() []*types.Transaction { pool.mutex.Lock() defer pool.mutex.Unlock() @@ -213,7 +217,7 @@ func (self *TxPool) RemoveSet(txs types.Transactions) { } func (pool *TxPool) Flush() []*types.Transaction { - txList := pool.CurrentTransactions() + txList := pool.GetTransactions() // Recreate a new list all together // XXX Is this the fastest way? diff --git a/core/types/common.go b/core/types/common.go index 89cb5f498..ba88b77e1 100644 --- a/core/types/common.go +++ b/core/types/common.go @@ -4,13 +4,8 @@ import ( "math/big" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/wire" ) type BlockProcessor interface { Process(*Block) (*big.Int, state.Messages, error) } - -type Broadcaster interface { - Broadcast(wire.MsgType, []interface{}) -} |