From 2687cd0f461c78d00642a5a258a09bf46556246e Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:41:41 +0300 Subject: [PATCH 1/3] feat: transaction debug mode --- cmd/bee/cmd/cmd.go | 2 ++ cmd/bee/cmd/start.go | 1 + pkg/node/node.go | 1 + 3 files changed, 4 insertions(+) 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 b0c64e21592..e3338ec9c9f 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 ( From 7e970f483b312de3fdc33b70a728fbf465afe02f Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Wed, 10 Jul 2024 02:23:42 +0300 Subject: [PATCH 2/3] chore: changed all contracts --- pkg/node/node.go | 5 +++-- pkg/postage/postagecontract/contract.go | 12 ++++++++++- pkg/postage/postagecontract/contract_test.go | 16 ++++++++++++++ .../redistribution/redistribution.go | 15 ++++++++++--- .../redistribution/redistribution_test.go | 11 ++++++++++ pkg/storageincentives/staking/contract.go | 11 +++++++++- .../staking/contract_test.go | 21 +++++++++++++++++++ 7 files changed, 84 insertions(+), 7 deletions(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index e3338ec9c9f..52baef9af0f 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -655,6 +655,7 @@ func NewBee( post, batchStore, chainEnabled, + o.TrxDebugMode, ) eventListener = listener.New(b.syncingStopped, logger, chainBackend, postageStampContractAddress, postageStampContractABI, o.BlockTime, postageSyncingStallingTimeout, postageSyncingBackoffTimeout) @@ -965,7 +966,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) var ( pullerService *puller.Puller @@ -993,7 +994,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..0df59017966 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 = 1_000_000 + } + 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..2f358e05d90 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 = 1_000_000 + } + 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 823f8a0c050..973780ec728 100644 --- a/pkg/storageincentives/staking/contract.go +++ b/pkg/storageincentives/staking/contract.go @@ -53,6 +53,7 @@ type contract struct { bzzTokenAddress common.Address transactionService transaction.Service overlayNonce common.Hash + gasLimit uint64 } func New( @@ -62,7 +63,14 @@ func New( bzzTokenAddress common.Address, transactionService transaction.Service, nonce common.Hash, + setGasLimit bool, ) Contract { + + var gasLimit uint64 + if setGasLimit { + gasLimit = 1_000_000 + } + return &contract{ owner: owner, stakingContractAddress: stakingContractAddress, @@ -70,6 +78,7 @@ func New( bzzTokenAddress: bzzTokenAddress, transactionService: transactionService, overlayNonce: nonce, + gasLimit: gasLimit, } } @@ -119,7 +128,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 6315e137060..27e3f3aaa44 100644 --- a/pkg/storageincentives/staking/contract_test.go +++ b/pkg/storageincentives/staking/contract_test.go @@ -88,6 +88,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -148,6 +149,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -186,6 +188,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(0)) @@ -217,6 +220,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -248,6 +252,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -285,6 +290,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -333,6 +339,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -393,6 +400,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -451,6 +459,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -476,6 +485,7 @@ func TestDepositStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -520,6 +530,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) stakedAmount, err := contract.GetStake(ctx) @@ -555,6 +566,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.GetStake(ctx) @@ -591,6 +603,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.GetStake(ctx) @@ -613,6 +626,7 @@ func TestGetStake(t *testing.T) { }), ), nonce, + false, ) _, err := contract.GetStake(ctx) @@ -697,6 +711,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -730,6 +745,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -773,6 +789,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -862,6 +879,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -934,6 +952,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -965,6 +984,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) @@ -1006,6 +1026,7 @@ func TestWithdrawStake(t *testing.T) { }), ), nonce, + false, ) _, err = contract.WithdrawAllStake(ctx) From 4f73877d008e532276ebb433b7eb1bb3adcfa117 Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Wed, 10 Jul 2024 02:30:21 +0300 Subject: [PATCH 3/3] fix: default --- pkg/postage/postagecontract/contract.go | 2 +- pkg/storageincentives/redistribution/redistribution.go | 2 +- pkg/storageincentives/staking/contract.go | 2 +- pkg/transaction/transaction.go | 5 ++++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/postage/postagecontract/contract.go b/pkg/postage/postagecontract/contract.go index 0df59017966..29447a5e464 100644 --- a/pkg/postage/postagecontract/contract.go +++ b/pkg/postage/postagecontract/contract.go @@ -85,7 +85,7 @@ func New( var gasLimit uint64 if setGasLimit { - gasLimit = 1_000_000 + gasLimit = transaction.DefaultGasLimit } return &postageContract{ diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index 2f358e05d90..9ee6cb7d33f 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -47,7 +47,7 @@ func New( var gasLimit uint64 if setGasLimit { - gasLimit = 1_000_000 + gasLimit = transaction.DefaultGasLimit } return &contract{ diff --git a/pkg/storageincentives/staking/contract.go b/pkg/storageincentives/staking/contract.go index 973780ec728..4ab80932201 100644 --- a/pkg/storageincentives/staking/contract.go +++ b/pkg/storageincentives/staking/contract.go @@ -68,7 +68,7 @@ func New( var gasLimit uint64 if setGasLimit { - gasLimit = 1_000_000 + gasLimit = transaction.DefaultGasLimit } return &contract{ 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 {