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

Allow dependent tx issuance over the wallet API #1413

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Changes from 1 commit
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
58 changes: 53 additions & 5 deletions vms/avm/wallet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,36 @@ type WalletService struct {
}

func (w *WalletService) decided(txID ids.ID) {
if _, ok := w.pendingTxs.Get(txID); !ok {
return
}

w.vm.ctx.Log.Info("tx decided over wallet API",
zap.Stringer("txID", txID),
)
w.pendingTxs.Delete(txID)

for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document or just help me understand, why pop off oldest transaction only once, and exit the for-loop on success? Trying to understand how decided function relates to this operation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To rephrase my question,

Allow dependent tx issuance

In what cases, dependent tx failed to be issued, so we need another tx issuance to trigger the tx issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user is issuing virtuous txs - verification will never fail. However, I didn't want to just have the node crash (or fall into an infinite loop) in this situation... So instead I dropped the tx and logged a warning.

In all likelihood - if one tx is dropped they all will be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... didn't want .. or fall into an infinite loop

Oh makes sense.

txID, tx, ok := w.pendingTxs.Oldest()
if !ok {
return
}

txBytes := tx.Bytes()
_, err := w.vm.IssueTx(txBytes)
if err == nil {
w.vm.ctx.Log.Info("issued tx to mempool over wallet API",
zap.Stringer("txID", txID),
)
return
}

w.pendingTxs.Delete(txID)
w.vm.ctx.Log.Warn("dropping tx issued over wallet API",
zap.Stringer("txID", txID),
zap.Error(err),
)
}
}

func (w *WalletService) issue(txBytes []byte) (ids.ID, error) {
Expand All @@ -37,15 +66,34 @@ func (w *WalletService) issue(txBytes []byte) (ids.ID, error) {
return ids.ID{}, err
}

txID, err := w.vm.IssueTx(txBytes)
if err != nil {
return ids.ID{}, err
txID := tx.ID()
w.vm.ctx.Log.Info("issuing tx over wallet API",
zap.Stringer("txID", txID),
)

if _, ok := w.pendingTxs.Get(txID); ok {
w.vm.ctx.Log.Warn("issuing duplicate tx over wallet API",
zap.Stringer("txID", txID),
)
return txID, nil
}

if _, ok := w.pendingTxs.Get(txID); !ok {
w.pendingTxs.Put(txID, tx)
if w.pendingTxs.Len() == 0 {
_, err := w.vm.IssueTx(txBytes)
if err != nil {
return ids.ID{}, err
}

w.vm.ctx.Log.Info("issued tx to mempool over wallet API",
zap.Stringer("txID", txID),
)
} else {
w.vm.ctx.Log.Info("enqueueing tx over wallet API",
zap.Stringer("txID", txID),
)
}

w.pendingTxs.Put(txID, tx)
return txID, nil
}

Expand Down