Skip to content

Commit

Permalink
Fix args And add attribute to time track
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Oct 25, 2023
1 parent 5a6c77e commit 5ab8667
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions core/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getQueryContext(chain *ProvableChain, sh SyncHeaders, useFinalizedHeader bo

func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "UnrelayedPackets")
now := time.Now()
var (
eg = new(errgroup.Group)
srcPackets PacketInfoList
Expand Down Expand Up @@ -131,6 +131,8 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader
return nil, err
}

defer logger.TimeTrack(now, "UnrelayedPackets", "num_src", len(srcPackets), "num_dst", len(dstPackets))

if err := st.updateBacklogMetrics(context.TODO(), src, dst, srcPackets, dstPackets); err != nil {
return nil, err
}
Expand Down Expand Up @@ -179,7 +181,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader

func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "RelayPackets")
defer logger.TimeTrack(time.Now(), "RelayPackets", "num_src", len(rp.Src), "num_dst", len(rp.Dst))
// set the maximum relay transaction constraints
msgs := &RelayMsgs{
Src: []sdk.Msg{},
Expand Down Expand Up @@ -278,7 +280,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets,

func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "UnrelayedAcknowledgements")
now := time.Now()
var (
eg = new(errgroup.Group)
srcAcks PacketInfoList
Expand Down Expand Up @@ -342,6 +344,8 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S
return nil, err
}

defer logger.TimeTrack(now, "UnrelayedAcknowledgements", "num_src", len(srcAcks), "num_dst", len(dstAcks))

// If includeRelayedButUnfinalized is true, this function should return packets of which AcknowledgePacket is not finalized yet.
// In this case, filtering packets by QueryUnreceivedAcknowledgements is not needed because QueryUnfinalizedRelayAcknowledgements
// has already returned packets that completely match this condition.
Expand Down Expand Up @@ -421,7 +425,7 @@ func logPacketsRelayed(src, dst Chain, num int, obj string, dir string) {

func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "RelayAcknowledgements")
defer logger.TimeTrack(time.Now(), "RelayAcknowledgements", "num_src", len(rp.Src), "num_dst", len(rp.Dst))
// set the maximum relay transaction constraints
msgs := &RelayMsgs{
Src: []sdk.Msg{},
Expand Down
3 changes: 2 additions & 1 deletion log/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,6 @@ func (rl *RelayLogger) WithModule(

func (rl *RelayLogger) TimeTrack(start time.Time, name string, otherArgs ...any) {
elapsed := time.Since(start)
rl.Logger.Info("time track", "name", name, "elapsed", elapsed.Nanoseconds(), otherArgs)
allArgs := append([]any{"name", name, "elapsed", elapsed.Nanoseconds()}, otherArgs...)
rl.Logger.Info("time track", allArgs...)
}

0 comments on commit 5ab8667

Please sign in to comment.