Skip to content

Commit

Permalink
revert: "fix(transaction): swallow estimate gas error (#4366)"
Browse files Browse the repository at this point in the history
This reverts commit c5af787.
  • Loading branch information
istae committed Oct 3, 2023
1 parent cf9835b commit 584c7d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 128 deletions.
10 changes: 5 additions & 5 deletions pkg/storageincentives/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase ui
phaseEvents := newEvents()
defer phaseEvents.Close()

logErr := func(phase PhaseType, round uint64, err error) {
logPhaseResult := func(phase PhaseType, round uint64, err error) {
if err != nil {
a.logger.Error(err, "phase failed", "phase", phase, "round", round)
}
Expand All @@ -142,27 +142,27 @@ func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase ui

round, _ := a.state.currentRoundAndPhase()
err := a.handleCommit(ctx, round)
logErr(commit, round, err)
logPhaseResult(commit, round, err)
})

phaseEvents.On(reveal, func(ctx context.Context) {
phaseEvents.Cancel(commit, sample)
round, _ := a.state.currentRoundAndPhase()
logErr(reveal, round, a.handleReveal(ctx, round))
logPhaseResult(reveal, round, a.handleReveal(ctx, round))
})

phaseEvents.On(claim, func(ctx context.Context) {
phaseEvents.Cancel(reveal)
phaseEvents.Publish(sample)

round, _ := a.state.currentRoundAndPhase()
logErr(claim, round, a.handleClaim(ctx, round))
logPhaseResult(claim, round, a.handleClaim(ctx, round))
})

phaseEvents.On(sample, func(ctx context.Context) {
round, _ := a.state.currentRoundAndPhase()
isPhasePlayed, err := a.handleSample(ctx, round)
logErr(sample, round, err)
logPhaseResult(sample, round, err)

// Sample handled could potentially take long time, therefore it could overlap with commit
// phase of next round. When that case happens commit event needs to be triggered once more
Expand Down
3 changes: 1 addition & 2 deletions pkg/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ func (t *transactionService) prepareTransaction(ctx context.Context, request *Tx
Data: request.Data,
})
if err != nil {
t.logger.Debug("estimage gas failed", "error", err)
gasLimit = request.MinEstimatedGasLimit
return nil, err
}

gasLimit += gasLimit / 4 // add 25% on top
Expand Down
121 changes: 0 additions & 121 deletions pkg/transaction/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package transaction_test
import (
"bytes"
"context"
"errors"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -214,126 +213,6 @@ func TestTransactionSend(t *testing.T) {
}
})

t.Run("send with estimate error", func(t *testing.T) {
t.Parallel()

signedTx := types.NewTx(&types.DynamicFeeTx{
ChainID: chainID,
Nonce: nonce,
To: &recipient,
Value: value,
Gas: estimatedGasLimit,
GasFeeCap: defaultGasFee,
GasTipCap: suggestedGasTip,
Data: txData,
})
request := &transaction.TxRequest{
To: &recipient,
Data: txData,
Value: value,
MinEstimatedGasLimit: estimatedGasLimit,
}
store := storemock.NewStateStore()
err := store.Put(nonceKey(sender), nonce)
if err != nil {
t.Fatal(err)
}

transactionService, err := transaction.NewService(logger,
backendmock.New(
backendmock.WithSendTransactionFunc(func(ctx context.Context, tx *types.Transaction) error {
if tx != signedTx {
t.Fatal("not sending signed transaction")
}
return nil
}),
backendmock.WithEstimateGasFunc(func(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
return 0, errors.New("estimate failure")
}),
backendmock.WithSuggestGasPriceFunc(func(ctx context.Context) (*big.Int, error) {
return suggestedGasPrice, nil
}),
backendmock.WithPendingNonceAtFunc(func(ctx context.Context, account common.Address) (uint64, error) {
return nonce - 1, nil
}),
backendmock.WithSuggestGasTipCapFunc(func(ctx context.Context) (*big.Int, error) {
return suggestedGasTip, nil
}),
),
signerMockForTransaction(t, signedTx, sender, chainID),
store,
chainID,
monitormock.New(
monitormock.WithWatchTransactionFunc(func(txHash common.Hash, nonce uint64) (<-chan types.Receipt, <-chan error, error) {
return nil, nil, nil
}),
),
)
if err != nil {
t.Fatal(err)
}
testutil.CleanupCloser(t, transactionService)

txHash, err := transactionService.Send(context.Background(), request, 0)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal(txHash.Bytes(), signedTx.Hash().Bytes()) {
t.Fatal("returning wrong transaction hash")
}

var storedNonce uint64
err = store.Get(nonceKey(sender), &storedNonce)
if err != nil {
t.Fatal(err)
}
if storedNonce != nonce+1 {
t.Fatalf("nonce not stored correctly: want %d, got %d", nonce+1, storedNonce)
}

storedTransaction, err := transactionService.StoredTransaction(txHash)
if err != nil {
t.Fatal(err)
}

if storedTransaction.To == nil || *storedTransaction.To != recipient {
t.Fatalf("got wrong recipient in stored transaction. wanted %x, got %x", recipient, storedTransaction.To)
}

if !bytes.Equal(storedTransaction.Data, request.Data) {
t.Fatalf("got wrong data in stored transaction. wanted %x, got %x", request.Data, storedTransaction.Data)
}

if storedTransaction.Description != request.Description {
t.Fatalf("got wrong description in stored transaction. wanted %x, got %x", request.Description, storedTransaction.Description)
}

if storedTransaction.GasLimit != estimatedGasLimit {
t.Fatalf("got wrong gas limit in stored transaction. wanted %d, got %d", estimatedGasLimit, storedTransaction.GasLimit)
}

if defaultGasFee.Cmp(storedTransaction.GasPrice) != 0 {
t.Fatalf("got wrong gas price in stored transaction. wanted %d, got %d", defaultGasFee, storedTransaction.GasPrice)
}

if storedTransaction.Nonce != nonce {
t.Fatalf("got wrong nonce in stored transaction. wanted %d, got %d", nonce, storedTransaction.Nonce)
}

pending, err := transactionService.PendingTransactions()
if err != nil {
t.Fatal(err)
}
if len(pending) != 1 {
t.Fatalf("expected one pending transaction, got %d", len(pending))
}

if pending[0] != txHash {
t.Fatalf("got wrong pending transaction. wanted %x, got %x", txHash, pending[0])
}
})

t.Run("sendWithBoost", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 584c7d2

Please sign in to comment.