From 2d86d70c8e1698243124c11b0e356221bbdd608a Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:14:16 +0300 Subject: [PATCH] revert: "fix: include the reason when the redistribution contract call fails (#4358)" This reverts commit 81e6e04f48691083f7e817044ffac997ccfbe12b. --- pkg/postage/postagecontract/contract.go | 15 +++++++++------ pkg/storageincentives/agent.go | 2 +- .../redistribution/redistribution.go | 6 ++---- pkg/transaction/mock/transaction.go | 4 ---- pkg/transaction/transaction.go | 18 ------------------ 5 files changed, 12 insertions(+), 33 deletions(-) diff --git a/pkg/postage/postagecontract/contract.go b/pkg/postage/postagecontract/contract.go index 666037c39d6..94c3dc99061 100644 --- a/pkg/postage/postagecontract/contract.go +++ b/pkg/postage/postagecontract/contract.go @@ -178,7 +178,7 @@ func (c *postageContract) sendApproveTransaction(ctx context.Context, amount *bi return receipt, nil } -func (c *postageContract) sendTransaction(ctx context.Context, callData []byte, desc string) (receipt *types.Receipt, err error) { +func (c *postageContract) sendTransaction(ctx context.Context, callData []byte, desc string) (*types.Receipt, error) { request := &transaction.TxRequest{ To: &c.postageStampContractAddress, Data: callData, @@ -187,22 +187,25 @@ func (c *postageContract) sendTransaction(ctx context.Context, callData []byte, Value: big.NewInt(0), Description: desc, } - defer func() { - err = c.transactionService.UnwrapRevertReason(ctx, request, err) - }() txHash, err := c.transactionService.Send(ctx, request, transaction.DefaultTipBoostPercent) if err != nil { return nil, err } - receipt, err = c.transactionService.WaitForReceipt(ctx, txHash) + receipt, err := c.transactionService.WaitForReceipt(ctx, txHash) if err != nil { return nil, err } if receipt.Status == 0 { - return nil, transaction.ErrTransactionReverted + err := transaction.ErrTransactionReverted + if res, cErr := c.transactionService.Call(ctx, request); cErr == nil { + if reason, uErr := abi.UnpackRevert(res); uErr == nil { + err = fmt.Errorf("%w: reason: %s", err, reason) + } + } + return nil, err } return receipt, nil diff --git a/pkg/storageincentives/agent.go b/pkg/storageincentives/agent.go index 16e7770c859..b856625025e 100644 --- a/pkg/storageincentives/agent.go +++ b/pkg/storageincentives/agent.go @@ -24,7 +24,7 @@ import ( "github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storageincentives/redistribution" "github.com/ethersphere/bee/pkg/storageincentives/staking" - "github.com/ethersphere/bee/pkg/storer" + storer "github.com/ethersphere/bee/pkg/storer" "github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/transaction" ) diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index ce0692da943..2c163f5a76c 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -180,10 +180,8 @@ func (c *contract) ReserveSalt(ctx context.Context) ([]byte, error) { return salt[:], nil } -func (c *contract) sendAndWait(ctx context.Context, request *transaction.TxRequest, boostPercent int) (txHash common.Hash, err error) { - defer func() { err = c.txService.UnwrapRevertReason(ctx, request, err) }() - - txHash, err = c.txService.Send(ctx, request, boostPercent) +func (c *contract) sendAndWait(ctx context.Context, request *transaction.TxRequest, boostPercent int) (common.Hash, error) { + txHash, err := c.txService.Send(ctx, request, boostPercent) if err != nil { return txHash, err } diff --git a/pkg/transaction/mock/transaction.go b/pkg/transaction/mock/transaction.go index 6110dfeea1d..f9a557f00be 100644 --- a/pkg/transaction/mock/transaction.go +++ b/pkg/transaction/mock/transaction.go @@ -97,10 +97,6 @@ func (m *transactionServiceMock) TransactionFee(ctx context.Context, txHash comm return big.NewInt(0), nil } -func (m *transactionServiceMock) UnwrapRevertReason(_ context.Context, _ *transaction.TxRequest, err error) error { - return err -} - // Option is the option passed to the mock Chequebook service type Option interface { apply(*transactionServiceMock) diff --git a/pkg/transaction/transaction.go b/pkg/transaction/transaction.go index c4246631023..d8cb6d797d3 100644 --- a/pkg/transaction/transaction.go +++ b/pkg/transaction/transaction.go @@ -14,7 +14,6 @@ import ( "time" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethersphere/bee/pkg/crypto" @@ -95,9 +94,6 @@ type Service interface { CancelTransaction(ctx context.Context, originalTxHash common.Hash) (common.Hash, error) // TransactionFee retrieves the transaction fee TransactionFee(ctx context.Context, txHash common.Hash) (*big.Int, error) - // UnwrapRevertReason tries to unwrap the revert reason if the given error is not nil. - // The original error is wrapped in case the revert reason exists. - UnwrapRevertReason(ctx context.Context, req *TxRequest, err error) error } type transactionService struct { @@ -588,17 +584,3 @@ func (t *transactionService) TransactionFee(ctx context.Context, txHash common.H } return trx.Cost(), nil } - -func (t *transactionService) UnwrapRevertReason(ctx context.Context, req *TxRequest, err error) error { - if err == nil { - return nil - } - - if res, cErr := t.Call(ctx, req); cErr == nil { - if reason, uErr := abi.UnpackRevert(res); uErr == nil { - err = fmt.Errorf("%w: reason: %s", err, reason) - } - } - - return err -}