Skip to content

Commit

Permalink
chore(transactor): Fix nil pointer dereference issue (#81)
Browse files Browse the repository at this point in the history
* Fix

* comment nit
  • Loading branch information
calbera authored Mar 22, 2024
1 parent bb9c6f7 commit 80ff8fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/transactor/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (t *TxrV2) retrieveBatch(ctx context.Context) types.Requests {

// fire processes the tracked tx response. If requested to build, it will first batch the messages.
// Then it sends the batch as one tx and asynchronously tracks the tx for its status.
// NOTE: if toBuild is false, resp.Transaction must be a valid, non-nil tx.
// NOTE: if toBuild is false, resp.Transaction must be a valid, signed tx.
func (t *TxrV2) fire(
ctx context.Context, resp *tracker.Response, toBuild bool, msgs ...*ethereum.CallMsg,
) {
Expand Down
39 changes: 34 additions & 5 deletions core/transactor/tracker/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tracker
import (
"time"

"github.com/ethereum/go-ethereum/common"
coretypes "github.com/ethereum/go-ethereum/core/types"
)

Expand All @@ -20,21 +21,49 @@ type Response struct {
}

// Status returns the current status of a transaction owned by the transactor.
func (t *Response) Status() Status {
if t.Error != nil {
func (r *Response) Status() Status {
if r.Error != nil {
return StatusError
}

if t.receipt == nil {
if t.isStale {
if r.receipt == nil {
if r.isStale {
return StatusStale
}
return StatusPending
}

if t.receipt.Status == 1 {
if r.receipt.Status == 1 {
return StatusSuccess
}

return StatusReverted
}

// Nonce overrides the method on Transaction to avoid dereferencing a nil pointer.
func (r *Response) Nonce() uint64 {
if r.Transaction != nil {
return r.Transaction.Nonce()
}

return 0
}

// To overrides the method on Transaction to avoid dereferencing a nil pointer.
func (r *Response) To() *common.Address {
if r.Transaction != nil {
return r.Transaction.To()
}

zeroAddr := common.Address{}
return &zeroAddr
}

// Hash overrides the method on Transaction to avoid dereferencing a nil pointer.
func (r *Response) Hash() common.Hash {
if r.Transaction != nil {
return r.Transaction.Hash()
}

return common.Hash{}
}
6 changes: 1 addition & 5 deletions core/transactor/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,13 @@ func (t *Tracker) markPending(ctx context.Context, resp *Response) {
// Remove from the noncer inFlight set since we know the tx has reached the mempool as
// executable/pending.
t.noncer.RemoveInFlight(resp.Nonce())

t.waitMined(ctx, resp, true)
}

// markConfirmed is called once a transaction has been included in the canonical chain.
func (t *Tracker) markConfirmed(resp *Response, receipt *coretypes.Receipt) {
// Set the contract address field on the receipt since geth doesn't do this.
if contractAddr := resp.To(); contractAddr != nil && receipt != nil {
receipt.ContractAddress = *contractAddr
}

receipt.ContractAddress = *resp.To()
resp.receipt = receipt
t.dispatchTx(resp)
}
Expand Down

0 comments on commit 80ff8fe

Please sign in to comment.