Skip to content

Commit

Permalink
add more log
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-lai committed Aug 26, 2024
1 parent faa1a2f commit d34a16c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
}
log.Info("[Liam] [runReorg] get Lock")
pool.mu.Lock()
log.Info("[Liam] [runReorg] got Lock")
if reset != nil {
// Reset from the old head to the new, rescheduling any reorged transactions
pool.reset(reset.oldHead, reset.newHead)
Expand Down Expand Up @@ -1260,19 +1261,25 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt

// Notify subsystems for newly added transactions
for _, tx := range promoted {
log.Info("[Liam] [runReorg] get tx", "tx", tx.Hash())
addr, _ := types.Sender(pool.signer, tx)
if _, ok := events[addr]; !ok {
events[addr] = newTxSortedMap()
}
log.Info("[Liam] [runReorg] Put tx")
events[addr].Put(tx)
}
log.Info("[Liam] [runReorg] finish put events into address map", "lenEvents", len(events))
if len(events) > 0 {
var txs []*types.Transaction
for _, set := range events {
txs = append(txs, set.Flatten()...)
}
log.Info("[Liam] [runReorg] Send Txs Events")
pool.txFeed.Send(NewTxsEvent{txs})
log.Info("[Liam] [runReorg] Finsh Sent Events")
}
log.Info("[Liam] [runReorg] finish")
}

// reset retrieves the current state of the blockchain and ensures the content
Expand Down
16 changes: 15 additions & 1 deletion event/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"errors"
"reflect"
"sync"

"github.com/XinFinOrg/XDPoSChain/log"
)

var errBadChannel = errors.New("event: Subscribe argument does not have sendable channel type")
Expand Down Expand Up @@ -130,18 +132,24 @@ func (f *Feed) Send(value interface{}) (nsent int) {
rvalue := reflect.ValueOf(value)

f.once.Do(f.init)
<-f.sendLock

log.Info("[Liam] [Send] release object in sendLock")
<-f.sendLock
log.Info("[Liam] [Send] finished release object in channel sendLock")
log.Info("[Liam] [Send] get mu lock")
// Add new cases from the inbox after taking the send lock.
f.mu.Lock()
log.Info("[Liam] [Send] got mu lock")
f.sendCases = append(f.sendCases, f.inbox...)
f.inbox = nil

if !f.typecheck(rvalue.Type()) {
log.Info("[Liam] [Send] going to panic and send someting to mu lock")
f.sendLock <- struct{}{}
panic(feedTypeError{op: "Send", got: rvalue.Type(), want: f.etype})
}
f.mu.Unlock()
log.Info("[Liam] [Send] unlock mu lock")

// Set the sent value on all channels.
for i := firstSubSendCase; i < len(f.sendCases); i++ {
Expand All @@ -150,17 +158,20 @@ func (f *Feed) Send(value interface{}) (nsent int) {

// Send until all channels except removeSub have been chosen.
cases := f.sendCases
log.Info("[Liam] [Send] going to loop try to send", "lenCases", len(cases))
for {
// Fast path: try sending without blocking before adding to the select set.
// This should usually succeed if subscribers are fast enough and have free
// buffer space.
for i := firstSubSendCase; i < len(cases); i++ {
log.Info("[Liam] [Send] try send")
if cases[i].Chan.TrySend(rvalue) {
nsent++
cases = cases.deactivate(i)
i--
}
}
log.Info("[Liam] [Send] finish try to send", "lenCases", len(cases))
if len(cases) == firstSubSendCase {
break
}
Expand All @@ -178,11 +189,14 @@ func (f *Feed) Send(value interface{}) (nsent int) {
}
}

log.Info("[Liam] [Send] reset Send")
// Forget about the sent value and hand off the send lock.
for i := firstSubSendCase; i < len(f.sendCases); i++ {
f.sendCases[i].Send = reflect.Value{}
}
log.Info("[Liam] [Send] send object in sendLock")
f.sendLock <- struct{}{}
log.Info("[Liam] [Send] finished send object in sendLock")
return nsent
}

Expand Down

0 comments on commit d34a16c

Please sign in to comment.