fix after reviewing

This commit is contained in:
parmarrushabh 2018-11-09 13:07:34 +05:30
parent 9fc966c7db
commit 7ebdbeed64
6 changed files with 19 additions and 14 deletions

View file

@ -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))
} }

View file

@ -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

View file

@ -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()

View file

@ -55,7 +55,8 @@ type peer struct {
id string id string
*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

View file

@ -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)

View file

@ -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: