diff --git a/cmd/bee/cmd/cmd.go b/cmd/bee/cmd/cmd.go index f6028e878ec..7a6fa05c806 100644 --- a/cmd/bee/cmd/cmd.go +++ b/cmd/bee/cmd/cmd.go @@ -82,6 +82,7 @@ const ( optionNameTargetNeighborhood = "target-neighborhood" optionNameNeighborhoodSuggester = "neighborhood-suggester" optionNameWhitelistedWithdrawalAddress = "withdrawal-addresses-whitelist" + optionNameTransactionDebugMode = "transaction-debug-mode" ) // nolint:gochecknoinits @@ -292,6 +293,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) { cmd.Flags().String(optionNameTargetNeighborhood, "", "neighborhood to target in binary format (ex: 111111001) for mining the initial overlay") cmd.Flags().String(optionNameNeighborhoodSuggester, "https://api.swarmscan.io/v1/network/neighborhoods/suggestion", "suggester for target neighborhood") cmd.Flags().StringSlice(optionNameWhitelistedWithdrawalAddress, []string{}, "withdrawal target addresses") + cmd.Flags().Bool(optionNameTransactionDebugMode, false, "skips the gas estimate step for contract transactions") } func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) { diff --git a/cmd/bee/cmd/start.go b/cmd/bee/cmd/start.go index 56dda6a2591..6a4c7c4a857 100644 --- a/cmd/bee/cmd/start.go +++ b/cmd/bee/cmd/start.go @@ -337,6 +337,7 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo TargetNeighborhood: c.config.GetString(optionNameTargetNeighborhood), NeighborhoodSuggester: neighborhoodSuggester, WhitelistedWithdrawalAddress: c.config.GetStringSlice(optionNameWhitelistedWithdrawalAddress), + TrxDebugMode: c.config.GetBool(optionNameTransactionDebugMode), }) return b, err diff --git a/pkg/node/node.go b/pkg/node/node.go index 066c893fef5..f7e5f1f0ae1 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -167,6 +167,7 @@ type Options struct { TargetNeighborhood string NeighborhoodSuggester string WhitelistedWithdrawalAddress []string + TrxDebugMode bool } const ( @@ -656,6 +657,7 @@ func NewBee( post, batchStore, chainEnabled, + o.TrxDebugMode, ) eventListener = listener.New(b.syncingStopped, logger, chainBackend, postageStampContractAddress, postageStampContractABI, o.BlockTime, postageSyncingStallingTimeout, postageSyncingBackoffTimeout) @@ -966,7 +968,7 @@ func NewBee( stakingContractAddress = common.HexToAddress(o.StakingContractAddress) } - stakingContract := staking.New(overlayEthAddress, stakingContractAddress, abiutil.MustParseABI(chainCfg.StakingABI), bzzTokenAddress, transactionService, common.BytesToHash(nonce)) + stakingContract := staking.New(overlayEthAddress, stakingContractAddress, abiutil.MustParseABI(chainCfg.StakingABI), bzzTokenAddress, transactionService, common.BytesToHash(nonce), o.TrxDebugMode) if chainEnabled && changedOverlay { stake, err := stakingContract.GetStake(ctx) @@ -1009,7 +1011,7 @@ func NewBee( return localStore.ReserveSize() >= reserveTreshold && pullerService.SyncRate() == 0 } - redistributionContract := redistribution.New(overlayEthAddress, logger, transactionService, redistributionContractAddress, abiutil.MustParseABI(chainCfg.RedistributionABI)) + redistributionContract := redistribution.New(overlayEthAddress, logger, transactionService, redistributionContractAddress, abiutil.MustParseABI(chainCfg.RedistributionABI), o.TrxDebugMode) agent, err = storageincentives.New( swarmAddress, overlayEthAddress, diff --git a/pkg/postage/postagecontract/contract.go b/pkg/postage/postagecontract/contract.go index 35c36888856..29447a5e464 100644 --- a/pkg/postage/postagecontract/contract.go +++ b/pkg/postage/postagecontract/contract.go @@ -64,6 +64,8 @@ type postageContract struct { batchCreatedTopic common.Hash batchTopUpTopic common.Hash batchDepthIncreaseTopic common.Hash + + gasLimit uint64 } func New( @@ -75,11 +77,17 @@ func New( postageService postage.Service, postageStorer postage.Storer, chainEnabled bool, + setGasLimit bool, ) Interface { if !chainEnabled { return new(noOpPostageContract) } + var gasLimit uint64 + if setGasLimit { + gasLimit = transaction.DefaultGasLimit + } + return &postageContract{ owner: owner, postageStampContractAddress: postageStampContractAddress, @@ -92,6 +100,8 @@ func New( batchCreatedTopic: postageStampContractABI.Events["BatchCreated"].ID, batchTopUpTopic: postageStampContractABI.Events["BatchTopUp"].ID, batchDepthIncreaseTopic: postageStampContractABI.Events["BatchDepthIncrease"].ID, + + gasLimit: gasLimit, } } @@ -194,7 +204,7 @@ func (c *postageContract) sendTransaction(ctx context.Context, callData []byte, To: &c.postageStampContractAddress, Data: callData, GasPrice: sctx.GetGasPrice(ctx), - GasLimit: sctx.GetGasLimit(ctx), + GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit), Value: big.NewInt(0), Description: desc, } diff --git a/pkg/postage/postagecontract/contract_test.go b/pkg/postage/postagecontract/contract_test.go index dd47d44affe..18ade6aaba4 100644 --- a/pkg/postage/postagecontract/contract_test.go +++ b/pkg/postage/postagecontract/contract_test.go @@ -122,6 +122,7 @@ func TestCreateBatch(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) _, returnedID, err := contract.CreateBatch(ctx, initialBalance, depth, false, label) @@ -155,6 +156,7 @@ func TestCreateBatch(t *testing.T) { postageMock.New(), postagestoreMock.New(), true, + false, ) _, _, err := contract.CreateBatch(ctx, initialBalance, depth, false, label) @@ -183,6 +185,7 @@ func TestCreateBatch(t *testing.T) { postageMock.New(), postagestoreMock.New(), true, + false, ) _, _, err := contract.CreateBatch(ctx, initialBalance, depth, false, label) @@ -290,6 +293,7 @@ func TestTopUpBatch(t *testing.T) { postageMock, batchStoreMock, true, + false, ) _, err = contract.TopUpBatch(ctx, batch.ID, topupBalance) @@ -318,6 +322,7 @@ func TestTopUpBatch(t *testing.T) { postageMock.New(), postagestoreMock.New(postagestoreMock.WithGetErr(errNotFound, 0)), true, + false, ) _, err := contract.TopUpBatch(ctx, postagetesting.MustNewID(), topupBalance) @@ -347,6 +352,7 @@ func TestTopUpBatch(t *testing.T) { postageMock.New(), batchStoreMock, true, + false, ) _, err := contract.TopUpBatch(ctx, batch.ID, topupBalance) @@ -476,6 +482,7 @@ func TestDiluteBatch(t *testing.T) { postageMock, batchStoreMock, true, + false, ) _, err = contract.DiluteBatch(ctx, batch.ID, newDepth) @@ -504,6 +511,7 @@ func TestDiluteBatch(t *testing.T) { postageMock.New(), postagestoreMock.New(postagestoreMock.WithGetErr(errNotFound, 0)), true, + false, ) _, err := contract.DiluteBatch(ctx, postagetesting.MustNewID(), uint8(17)) @@ -526,6 +534,7 @@ func TestDiluteBatch(t *testing.T) { postageMock.New(), batchStoreMock, true, + false, ) _, err := contract.DiluteBatch(ctx, batch.ID, batch.Depth-1) @@ -602,6 +611,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -635,6 +645,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -668,6 +679,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -744,6 +756,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -778,6 +791,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -814,6 +828,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) @@ -863,6 +878,7 @@ func TestBatchExpirer(t *testing.T) { postageMock, postagestoreMock.New(), true, + false, ) err = contract.ExpireBatches(ctx) diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index 51dfd099ded..9ee6cb7d33f 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -33,6 +33,7 @@ type contract struct { txService transaction.Service incentivesContractAddress common.Address incentivesContractABI abi.ABI + gasLimit uint64 } func New( @@ -41,13 +42,21 @@ func New( txService transaction.Service, incentivesContractAddress common.Address, incentivesContractABI abi.ABI, + setGasLimit bool, ) Contract { + + var gasLimit uint64 + if setGasLimit { + gasLimit = transaction.DefaultGasLimit + } + return &contract{ owner: owner, logger: logger.WithName(loggerName).Register(), txService: txService, incentivesContractAddress: incentivesContractAddress, incentivesContractABI: incentivesContractABI, + gasLimit: gasLimit, } } @@ -100,7 +109,7 @@ func (c *contract) Claim(ctx context.Context, proofs ChunkInclusionProofs) (comm To: &c.incentivesContractAddress, Data: callData, GasPrice: sctx.GetGasPrice(ctx), - GasLimit: sctx.GetGasLimit(ctx), + GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit), MinEstimatedGasLimit: 500_000, Value: big.NewInt(0), Description: "claim win transaction", @@ -123,7 +132,7 @@ func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint64) ( To: &c.incentivesContractAddress, Data: callData, GasPrice: sctx.GetGasPrice(ctx), - GasLimit: sctx.GetGasLimit(ctx), + GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit), MinEstimatedGasLimit: 500_000, Value: big.NewInt(0), Description: "commit transaction", @@ -146,7 +155,7 @@ func (c *contract) Reveal(ctx context.Context, storageDepth uint8, reserveCommit To: &c.incentivesContractAddress, Data: callData, GasPrice: sctx.GetGasPrice(ctx), - GasLimit: sctx.GetGasLimit(ctx), + GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit), MinEstimatedGasLimit: 500_000, Value: big.NewInt(0), Description: "reveal transaction", diff --git a/pkg/storageincentives/redistribution/redistribution_test.go b/pkg/storageincentives/redistribution/redistribution_test.go index be43308df6d..e2d2356cfbd 100644 --- a/pkg/storageincentives/redistribution/redistribution_test.go +++ b/pkg/storageincentives/redistribution/redistribution_test.go @@ -85,6 +85,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) isPlaying, err := contract.IsPlaying(ctx, depth) @@ -115,6 +116,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) isPlaying, err := contract.IsPlaying(ctx, depth) @@ -143,6 +145,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) isWinner, err := contract.IsWinner(ctx) @@ -169,6 +172,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) isWinner, err := contract.IsWinner(ctx) @@ -213,6 +217,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err = contract.Claim(ctx, proofs) @@ -253,6 +258,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err = contract.Claim(ctx, proofs) @@ -294,6 +300,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err = contract.Commit(ctx, testobfus, 0) @@ -337,6 +344,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err = contract.Reveal(ctx, depth, common.Hex2Bytes("hash"), common.Hex2Bytes("nonce")) @@ -362,6 +370,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) salt, err := contract.ReserveSalt(ctx) @@ -390,6 +399,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err := contract.IsPlaying(ctx, depth) @@ -421,6 +431,7 @@ func TestRedistribution(t *testing.T) { ), redistributionContractAddress, redistributionContractABI, + false, ) _, err = contract.Commit(ctx, common.Hex2Bytes("hash"), 0) diff --git a/pkg/storageincentives/staking/contract.go b/pkg/storageincentives/staking/contract.go index ca533ade35d..736d86c4216 100644 --- a/pkg/storageincentives/staking/contract.go +++ b/pkg/storageincentives/staking/contract.go @@ -54,6 +54,7 @@ type contract struct { bzzTokenAddress common.Address transactionService transaction.Service overlayNonce common.Hash + gasLimit uint64 } func New( @@ -63,7 +64,14 @@ func New( bzzTokenAddress common.Address, transactionService transaction.Service, nonce common.Hash, + setGasLimit bool, ) Contract { + + var gasLimit uint64 + if setGasLimit { + gasLimit = transaction.DefaultGasLimit + } + return &contract{ owner: owner, stakingContractAddress: stakingContractAddress, @@ -71,6 +79,7 @@ func New( bzzTokenAddress: bzzTokenAddress, transactionService: transactionService, overlayNonce: nonce, + gasLimit: gasLimit, } } @@ -120,7 +129,7 @@ func (c *contract) sendTransaction(ctx context.Context, callData []byte, desc st To: &c.stakingContractAddress, Data: callData, GasPrice: sctx.GetGasPrice(ctx), - GasLimit: sctx.GetGasLimit(ctx), + GasLimit: max(sctx.GetGasLimit(ctx), c.gasLimit), Value: big.NewInt(0), Description: desc, } diff --git a/pkg/storageincentives/staking/contract_test.go b/pkg/storageincentives/staking/contract_test.go index b4a5ad841a6..5156a47ee3c 100644 --- a/pkg/storageincentives/staking/contract_test.go +++ b/pkg/storageincentives/staking/contract_test.go @@ -89,6 +89,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -149,6 +150,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -187,6 +189,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(0)) @@ -218,6 +221,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -249,6 +253,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -286,6 +291,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -334,6 +340,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -394,6 +401,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -452,6 +460,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -477,6 +486,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -716,6 +726,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) stakedAmount, err := contract.GetStake(ctx) @@ -751,6 +762,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.GetStake(ctx) @@ -787,6 +799,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.GetStake(ctx) @@ -809,6 +822,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.GetStake(ctx) @@ -893,6 +907,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -926,6 +941,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -969,6 +985,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -1058,6 +1075,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -1130,6 +1148,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -1161,6 +1180,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -1202,6 +1222,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) diff --git a/pkg/transaction/transaction.go b/pkg/transaction/transaction.go index 2774aad95af..ea07ebb114b 100644 --- a/pkg/transaction/transaction.go +++ b/pkg/transaction/transaction.go @@ -43,7 +43,10 @@ var ( ErrAlreadyImported = errors.New("already imported") ) -const DefaultTipBoostPercent = 20 +const ( + DefaultTipBoostPercent = 20 + DefaultGasLimit = 1_000_000 +) // TxRequest describes a request for a transaction that can be executed. type TxRequest struct {