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

services/friendbot: include txhash in logs #4359

Merged
merged 2 commits into from
Apr 29, 2022
Merged
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
21 changes: 13 additions & 8 deletions services/friendbot/internal/minion.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (minion *Minion) Run(destAddress string, resultChan chan SubmitResult) {
}
return
}
txStr, err := minion.makeTx(destAddress)
txHash, txStr, err := minion.makeTx(destAddress)
if err != nil {
resultChan <- SubmitResult{
maybeTransactionSuccess: nil,
Expand All @@ -55,7 +55,7 @@ func (minion *Minion) Run(destAddress string, resultChan chan SubmitResult) {
succ, err := minion.SubmitTransaction(minion, minion.Horizon, txStr)
resultChan <- SubmitResult{
maybeTransactionSuccess: succ,
maybeErr: errors.Wrap(err, "submitting tx to minion"),
maybeErr: errors.Wrapf(err, "submitting tx to minion %x", txHash),
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (minion *Minion) checkHandleBadSequence(err *horizonclient.Error) {
minion.forceRefreshSequence = true
}

func (minion *Minion) makeTx(destAddress string) (string, error) {
func (minion *Minion) makeTx(destAddress string) ([32]byte, string, error) {
createAccountOp := txnbuild.CreateAccount{
Destination: destAddress,
SourceAccount: minion.BotAccount.GetAccountID(),
Expand All @@ -121,23 +121,28 @@ func (minion *Minion) makeTx(destAddress string) (string, error) {
},
)
if err != nil {
return "", errors.Wrap(err, "unable to build tx")
return [32]byte{}, "", errors.Wrap(err, "unable to build tx")
}

tx, err = tx.Sign(minion.Network, minion.Keypair, minion.BotKeypair)
if err != nil {
return "", errors.Wrap(err, "unable to sign tx")
return [32]byte{}, "", errors.Wrap(err, "unable to sign tx")
}

txe, err := tx.Base64()
if err != nil {
return "", errors.Wrap(err, "unable to serialize")
return [32]byte{}, "", errors.Wrap(err, "unable to serialize")
}

txh, err := tx.Hash(minion.Network)
if err != nil {
return [32]byte{}, "", errors.Wrap(err, "unable to hash")
}

// Increment the in-memory sequence number, since the tx will be submitted.
_, err = minion.Account.IncrementSequenceNumber()
if err != nil {
return "", errors.Wrap(err, "incrementing minion seq")
return [32]byte{}, "", errors.Wrap(err, "incrementing minion seq")
}
return txe, err
return txh, txe, err
}