mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
fix after reviewing
This commit is contained in:
parent
9fc966c7db
commit
7ebdbeed64
6 changed files with 19 additions and 14 deletions
|
|
@ -457,6 +457,8 @@ func (pool *TxPool) SubscribeTxPreEvent(ch chan<- TxPreEvent) event.Subscription
|
||||||
return pool.scope.Track(pool.txFeed.Subscribe(ch))
|
return pool.scope.Track(pool.txFeed.Subscribe(ch))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SubscribeSpecialTxPreEvent registers a subscription of TxPreEvent and
|
||||||
|
// starts sending event to the given channel.
|
||||||
func (pool *TxPool) SubscribeSpecialTxPreEvent(ch chan<- TxPreEvent) event.Subscription {
|
func (pool *TxPool) SubscribeSpecialTxPreEvent(ch chan<- TxPreEvent) event.Subscription {
|
||||||
return pool.scope.Track(pool.specialTxFeed.Subscribe(ch))
|
return pool.scope.Track(pool.specialTxFeed.Subscribe(ch))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -268,11 +268,10 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) IsSpecialTransaction() bool {
|
func (tx *Transaction) IsSpecialTransaction() bool {
|
||||||
to := ""
|
if tx.To() == nil {
|
||||||
if tx.To() != nil {
|
return false
|
||||||
to = tx.To().String()
|
|
||||||
}
|
}
|
||||||
return to == common.RandomizeSMC || to == common.BlockSigners
|
return tx.To().String() == common.RandomizeSMC || tx.To().String() == common.BlockSigners
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) String() string {
|
func (tx *Transaction) String() string {
|
||||||
|
|
@ -403,6 +402,8 @@ type TransactionsByPriceAndNonce struct {
|
||||||
//
|
//
|
||||||
// Note, the input map is reowned so the caller should not interact any more with
|
// Note, the input map is reowned so the caller should not interact any more with
|
||||||
// if after providing it to the constructor.
|
// if after providing it to the constructor.
|
||||||
|
|
||||||
|
// It also classifies special txs and normal txs
|
||||||
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions) (*TransactionsByPriceAndNonce, Transactions) {
|
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions) (*TransactionsByPriceAndNonce, Transactions) {
|
||||||
// Initialize a price based heap with the head transactions
|
// Initialize a price based heap with the head transactions
|
||||||
heads := TxByPrice{}
|
heads := TxByPrice{}
|
||||||
|
|
@ -500,4 +501,4 @@ func (m Message) Value() *big.Int { return m.amount }
|
||||||
func (m Message) Gas() uint64 { return m.gasLimit }
|
func (m Message) Gas() uint64 { return m.gasLimit }
|
||||||
func (m Message) Nonce() uint64 { return m.nonce }
|
func (m Message) Nonce() uint64 { return m.nonce }
|
||||||
func (m Message) Data() []byte { return m.data }
|
func (m Message) Data() []byte { return m.data }
|
||||||
func (m Message) CheckNonce() bool { return m.checkNonce }
|
func (m Message) CheckNonce() bool { return m.checkNonce
|
||||||
|
|
@ -210,6 +210,7 @@ func (pm *ProtocolManager) Start(maxPeers int) {
|
||||||
pm.txSub = pm.txpool.SubscribeTxPreEvent(pm.txCh)
|
pm.txSub = pm.txpool.SubscribeTxPreEvent(pm.txCh)
|
||||||
go pm.txBroadcastLoop()
|
go pm.txBroadcastLoop()
|
||||||
|
|
||||||
|
// broadcast special transactions
|
||||||
pm.specialTxCh = make(chan core.TxPreEvent, txChanSize)
|
pm.specialTxCh = make(chan core.TxPreEvent, txChanSize)
|
||||||
pm.specialTxSub = pm.txpool.SubscribeSpecialTxPreEvent(pm.specialTxCh)
|
pm.specialTxSub = pm.txpool.SubscribeSpecialTxPreEvent(pm.specialTxCh)
|
||||||
go pm.specialTxBroadcastLoop()
|
go pm.specialTxBroadcastLoop()
|
||||||
|
|
|
||||||
12
eth/peer.go
12
eth/peer.go
|
|
@ -56,6 +56,7 @@ type peer struct {
|
||||||
|
|
||||||
*p2p.Peer
|
*p2p.Peer
|
||||||
rw p2p.MsgReadWriter
|
rw p2p.MsgReadWriter
|
||||||
|
pairRw p2p.MsgReadWriter
|
||||||
|
|
||||||
version int // Protocol version negotiated
|
version int // Protocol version negotiated
|
||||||
forkDrop *time.Timer // Timed connection dropper if forks aren't validated in time
|
forkDrop *time.Timer // Timed connection dropper if forks aren't validated in time
|
||||||
|
|
@ -66,7 +67,6 @@ type peer struct {
|
||||||
|
|
||||||
knownTxs *set.Set // Set of transaction hashes known to be known by this peer
|
knownTxs *set.Set // Set of transaction hashes known to be known by this peer
|
||||||
knownBlocks *set.Set // Set of block hashes known to be known by this peer
|
knownBlocks *set.Set // Set of block hashes known to be known by this peer
|
||||||
pairRw p2p.MsgReadWriter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
|
func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
|
||||||
|
|
@ -338,13 +338,13 @@ func (ps *peerSet) Register(p *peer) error {
|
||||||
if ps.closed {
|
if ps.closed {
|
||||||
return errClosed
|
return errClosed
|
||||||
}
|
}
|
||||||
if exitPeer, ok := ps.peers[p.id]; ok {
|
if existPeer, ok := ps.peers[p.id]; ok {
|
||||||
if exitPeer.pairRw != nil {
|
if existPeer.pairRw != nil {
|
||||||
return errAlreadyRegistered
|
return errAlreadyRegistered
|
||||||
}
|
}
|
||||||
exitPeer.PairPeer = p.Peer
|
existPeer.PairPeer = p.Peer
|
||||||
exitPeer.pairRw = p.rw
|
existPeer.pairRw = p.rw
|
||||||
p.PairPeer = exitPeer.Peer
|
p.PairPeer = existPeer.Peer
|
||||||
return p2p.ErrAddPairPeer
|
return p2p.ErrAddPairPeer
|
||||||
}
|
}
|
||||||
ps.peers[p.id] = p
|
ps.peers[p.id] = p
|
||||||
|
|
|
||||||
|
|
@ -627,6 +627,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
|
||||||
|
|
||||||
var coalescedLogs []*types.Log
|
var coalescedLogs []*types.Log
|
||||||
|
|
||||||
|
// first priority for special Txs
|
||||||
for _, tx := range specialTxs {
|
for _, tx := range specialTxs {
|
||||||
if gp.Gas() < params.TxGas && tx.Gas() > 0 {
|
if gp.Gas() < params.TxGas && tx.Gas() > 0 {
|
||||||
log.Trace("Not enough gas for further transactions", "gp", gp)
|
log.Trace("Not enough gas for further transactions", "gp", gp)
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,8 @@ func (s *dialstate) checkDial(n *discover.Node, peers map[discover.NodeID]*Peer)
|
||||||
case dialing:
|
case dialing:
|
||||||
return errAlreadyDialing
|
return errAlreadyDialing
|
||||||
case peers[n.ID] != nil:
|
case peers[n.ID] != nil:
|
||||||
exitPeer := peers[n.ID]
|
exitsPeer := peers[n.ID]
|
||||||
if exitPeer.PairPeer != nil {
|
if exitsPeer.PairPeer != nil {
|
||||||
return errAlreadyConnected
|
return errAlreadyConnected
|
||||||
}
|
}
|
||||||
case s.ntab != nil && n.ID == s.ntab.Self().ID:
|
case s.ntab != nil && n.ID == s.ntab.Self().ID:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue