Skip to content

Commit

Permalink
Add timetrack to SendCheckMsgs (hyperledger-labs#118)
Browse files Browse the repository at this point in the history
* Add timetrack to SendCheckMsgs

Signed-off-by: Dongri Jin <[email protected]>

* Fix logger.TimeTrack

Signed-off-by: Dongri Jin <[email protected]>

* Add "queried_chain" attribute

Signed-off-by: Dongri Jin <[email protected]>

---------

Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie authored Nov 1, 2023
1 parent 9e602df commit 0f26fb7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
36 changes: 32 additions & 4 deletions core/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader
eg.Go(func() error {
return retry.Do(func() error {
var err error
now := time.Now()
srcPackets, err = src.QueryUnfinalizedRelayPackets(srcCtx, dst)
return err
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnfinalizedRelayPackets", "queried_chain", "src", "num_packets", len(srcPackets))
return nil
}, rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
logger.Info(
"retrying to query unfinalized packet relays",
Expand All @@ -115,8 +120,13 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader
eg.Go(func() error {
return retry.Do(func() error {
var err error
now := time.Now()
dstPackets, err = dst.QueryUnfinalizedRelayPackets(dstCtx, src)
return err
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnfinalizedRelayPackets", "queried_chain", "dst", "num_packets", len(dstPackets))
return nil
}, rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
logger.Info(
"retrying to query unfinalized packet relays",
Expand Down Expand Up @@ -155,19 +165,23 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader
}

eg.Go(func() error {
now := time.Now()
seqs, err := dst.QueryUnreceivedPackets(dstCtx, srcPackets.ExtractSequenceList())
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnreceivedPackets", "queried_chain", "dst", "num_seqs", len(seqs))
srcPackets = srcPackets.Filter(seqs)
return nil
})

eg.Go(func() error {
now := time.Now()
seqs, err := src.QueryUnreceivedPackets(srcCtx, dstPackets.ExtractSequenceList())
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnreceivedPackets", "queried_chain", "src", "num_seqs", len(seqs))
dstPackets = dstPackets.Filter(seqs)
return nil
})
Expand Down Expand Up @@ -264,8 +278,13 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S
eg.Go(func() error {
return retry.Do(func() error {
var err error
now := time.Now()
srcAcks, err = src.QueryUnfinalizedRelayAcknowledgements(srcCtx, dst)
return err
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnfinalizedRelayAcknowledgements", "queried_chain", "src", "num_packets", len(srcAcks))
return nil
}, rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
logger.Info(
"retrying to query unfinalized ack relays",
Expand All @@ -284,8 +303,13 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S
eg.Go(func() error {
return retry.Do(func() error {
var err error
now := time.Now()
dstAcks, err = dst.QueryUnfinalizedRelayAcknowledgements(dstCtx, src)
return err
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnfinalizedRelayAcknowledgements", "queried_chain", "dst", "num_packets", len(dstAcks))
return nil
}, rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
logger.Info(
"retrying to query unfinalized ack relays",
Expand Down Expand Up @@ -323,21 +347,25 @@ func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh S

if !st.dstNoAck {
eg.Go(func() error {
now := time.Now()
seqs, err := dst.QueryUnreceivedAcknowledgements(dstCtx, srcAcks.ExtractSequenceList())
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnreceivedAcknowledgements", "queried_chain", "dst", "num_seqs", len(seqs))
srcAcks = srcAcks.Filter(seqs)
return nil
})
}

if !st.srcNoAck {
eg.Go(func() error {
now := time.Now()
seqs, err := src.QueryUnreceivedAcknowledgements(srcCtx, dstAcks.ExtractSequenceList())
if err != nil {
return err
}
logger.TimeTrack(now, "QueryUnreceivedAcknowledgements", "queried_chain", "src", "num_seqs", len(seqs))
dstAcks = dstAcks.Filter(seqs)
return nil
})
Expand Down
3 changes: 3 additions & 0 deletions core/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (

// SendCheckMsgs is an utility function that executes `Chain::SendMsgs` and checks the execution results of all the messages.
func SendCheckMsgs(chain Chain, msgs []types.Msg) bool {
logger := GetChainLogger(chain)
now := time.Now()
if _, err := chain.SendMsgs(msgs); err != nil {
GetChainLogger(chain).Error("failed to send msgs", err, "msgs", msgs)
return false
}
logger.TimeTrack(now, "SendMsgs", "num_msgs", len(msgs))
return true
}

Expand Down

0 comments on commit 0f26fb7

Please sign in to comment.