Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements in the tx-tracker service #517

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tx-tracker/cmd/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func newSqsConsumer(ctx context.Context, cfg *config.ServiceSettings) (*sqs.Cons
// of traffic (e.g.: dozens of VAAs being emitted in the same minute), and
// also when a we have to retry fetching transaction metadata many times
// (due to finality delay, out-of-sync nodes, etc).
sqs.WithVisibilityTimeout(15*60),
sqs.WithVisibilityTimeout(20*60),
)
return consumer, err
}
Expand Down
18 changes: 1 addition & 17 deletions tx-tracker/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/wormhole-foundation/wormhole-explorer/txtracker/config"
"github.com/wormhole-foundation/wormhole-explorer/txtracker/queue"
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -57,28 +56,13 @@ func (c *Consumer) producerLoop(ctx context.Context) {

for msg := range ch {

event := msg.Data()

// Check if message is expired.
if msg.IsExpired() {
c.logger.Warn("Message with VAA expired", zap.String("id", event.ID))
msg.Failed()
continue
}

// Do not process messages from PythNet
if event.ChainID == sdk.ChainIDPythNet {
msg.Done()
continue
}

// Send the VAA to the worker pool.
//
// The worker pool is responsible for calling `msg.Done()`
err := c.workerPool.Push(ctx, msg)
if err != nil {
c.logger.Warn("failed to push message into worker pool",
zap.String("vaaId", event.ID),
zap.String("vaaId", msg.Data().ID),
zap.Error(err),
)
msg.Failed()
Expand Down
1 change: 0 additions & 1 deletion tx-tracker/consumer/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func ProcessSourceTx(
p := UpsertDocumentParams{
VaaId: params.VaaId,
ChainId: params.ChainId,
TxHash: params.TxHash,
TxDetail: txDetail,
TxStatus: txStatus,
}
Expand Down
1 change: 0 additions & 1 deletion tx-tracker/consumer/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func NewRepository(logger *zap.Logger, db *mongo.Database) *Repository {
type UpsertDocumentParams struct {
VaaId string
ChainId sdk.ChainID
TxHash string
TxDetail *chains.TxDetail
TxStatus domain.SourceTxStatus
}
Expand Down
25 changes: 22 additions & 3 deletions tx-tracker/consumer/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/wormhole-foundation/wormhole-explorer/txtracker/chains"
"github.com/wormhole-foundation/wormhole-explorer/txtracker/config"
"github.com/wormhole-foundation/wormhole-explorer/txtracker/queue"
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -101,6 +102,23 @@ func (w *WorkerPool) process(msg queue.ConsumerMessage) {

event := msg.Data()

// Check if the message is expired
if msg.IsExpired() {
w.logger.Warn("Message with VAA expired",
zap.String("vaaId", event.ID),
zap.Bool("isExpired", msg.IsExpired()),
)
msg.Failed()
return
}

// Do not process messages from PythNet
if event.ChainID == sdk.ChainIDPythNet {
msg.Done()
return
}

// Process the VAA
p := ProcessSourceTxParams{
VaaId: event.ID,
ChainId: event.ChainID,
Expand All @@ -110,17 +128,18 @@ func (w *WorkerPool) process(msg queue.ConsumerMessage) {
}
err := ProcessSourceTx(w.ctx, w.logger, w.rpcProviderSettings, w.repository, &p)

// Log a message informing the processing status
if err == chains.ErrChainNotSupported {
w.logger.Debug("Skipping VAA - chain not supported",
w.logger.Info("Skipping VAA - chain not supported",
zap.String("vaaId", event.ID),
)
} else if err != nil {
w.logger.Error("Failed to upsert source transaction details",
w.logger.Error("Failed to process originTx",
zap.String("vaaId", event.ID),
zap.Error(err),
)
} else {
w.logger.Info("Updated source transaction details in the database",
w.logger.Info("Updated originTx in the database",
zap.String("id", event.ID),
)
}
Expand Down
7 changes: 6 additions & 1 deletion tx-tracker/queue/vaa_sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ func (m *sqsConsumerMessage) Data() *VaaEvent {

func (m *sqsConsumerMessage) Done() {
if err := m.consumer.DeleteMessage(m.ctx, m.id); err != nil {
m.logger.Error("Error deleting message from SQS", zap.Error(err))
m.logger.Error("Error deleting message from SQS",
zap.String("vaaId", m.data.ID),
zap.Bool("isExpired", m.IsExpired()),
zap.Time("expiredAt", m.expiredAt),
zap.Error(err),
)
}
m.wg.Done()
}
Expand Down