Skip to content

Commit

Permalink
feat: transaction debug mode (#4708)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Jul 16, 2024
1 parent 88d27bd commit 62eed01
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const (
optionNameTargetNeighborhood = "target-neighborhood"
optionNameNeighborhoodSuggester = "neighborhood-suggester"
optionNameWhitelistedWithdrawalAddress = "withdrawal-addresses-whitelist"
optionNameTransactionDebugMode = "transaction-debug-mode"
)

// nolint:gochecknoinits
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type Options struct {
TargetNeighborhood string
NeighborhoodSuggester string
WhitelistedWithdrawalAddress []string
TrxDebugMode bool
}

const (
Expand Down Expand Up @@ -656,6 +657,7 @@ func NewBee(
post,
batchStore,
chainEnabled,
o.TrxDebugMode,
)

eventListener = listener.New(b.syncingStopped, logger, chainBackend, postageStampContractAddress, postageStampContractABI, o.BlockTime, postageSyncingStallingTimeout, postageSyncingBackoffTimeout)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion pkg/postage/postagecontract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type postageContract struct {
batchCreatedTopic common.Hash
batchTopUpTopic common.Hash
batchDepthIncreaseTopic common.Hash

gasLimit uint64
}

func New(
Expand All @@ -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,
Expand All @@ -92,6 +100,8 @@ func New(
batchCreatedTopic: postageStampContractABI.Events["BatchCreated"].ID,
batchTopUpTopic: postageStampContractABI.Events["BatchTopUp"].ID,
batchDepthIncreaseTopic: postageStampContractABI.Events["BatchDepthIncrease"].ID,

gasLimit: gasLimit,
}
}

Expand Down Expand Up @@ -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,
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/postage/postagecontract/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestCreateBatch(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

_, returnedID, err := contract.CreateBatch(ctx, initialBalance, depth, false, label)
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestCreateBatch(t *testing.T) {
postageMock.New(),
postagestoreMock.New(),
true,
false,
)

_, _, err := contract.CreateBatch(ctx, initialBalance, depth, false, label)
Expand Down Expand Up @@ -183,6 +185,7 @@ func TestCreateBatch(t *testing.T) {
postageMock.New(),
postagestoreMock.New(),
true,
false,
)

_, _, err := contract.CreateBatch(ctx, initialBalance, depth, false, label)
Expand Down Expand Up @@ -290,6 +293,7 @@ func TestTopUpBatch(t *testing.T) {
postageMock,
batchStoreMock,
true,
false,
)

_, err = contract.TopUpBatch(ctx, batch.ID, topupBalance)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -347,6 +352,7 @@ func TestTopUpBatch(t *testing.T) {
postageMock.New(),
batchStoreMock,
true,
false,
)

_, err := contract.TopUpBatch(ctx, batch.ID, topupBalance)
Expand Down Expand Up @@ -476,6 +482,7 @@ func TestDiluteBatch(t *testing.T) {
postageMock,
batchStoreMock,
true,
false,
)

_, err = contract.DiluteBatch(ctx, batch.ID, newDepth)
Expand Down Expand Up @@ -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))
Expand All @@ -526,6 +534,7 @@ func TestDiluteBatch(t *testing.T) {
postageMock.New(),
batchStoreMock,
true,
false,
)

_, err := contract.DiluteBatch(ctx, batch.ID, batch.Depth-1)
Expand Down Expand Up @@ -602,6 +611,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -635,6 +645,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -668,6 +679,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -744,6 +756,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -778,6 +791,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -814,6 +828,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down Expand Up @@ -863,6 +878,7 @@ func TestBatchExpirer(t *testing.T) {
postageMock,
postagestoreMock.New(),
true,
false,
)

err = contract.ExpireBatches(ctx)
Expand Down
15 changes: 12 additions & 3 deletions pkg/storageincentives/redistribution/redistribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type contract struct {
txService transaction.Service
incentivesContractAddress common.Address
incentivesContractABI abi.ABI
gasLimit uint64
}

func New(
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions pkg/storageincentives/redistribution/redistribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

isPlaying, err := contract.IsPlaying(ctx, depth)
Expand Down Expand Up @@ -115,6 +116,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

isPlaying, err := contract.IsPlaying(ctx, depth)
Expand Down Expand Up @@ -143,6 +145,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

isWinner, err := contract.IsWinner(ctx)
Expand All @@ -169,6 +172,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

isWinner, err := contract.IsWinner(ctx)
Expand Down Expand Up @@ -213,6 +217,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err = contract.Claim(ctx, proofs)
Expand Down Expand Up @@ -253,6 +258,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err = contract.Claim(ctx, proofs)
Expand Down Expand Up @@ -294,6 +300,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err = contract.Commit(ctx, testobfus, 0)
Expand Down Expand Up @@ -337,6 +344,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err = contract.Reveal(ctx, depth, common.Hex2Bytes("hash"), common.Hex2Bytes("nonce"))
Expand All @@ -362,6 +370,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

salt, err := contract.ReserveSalt(ctx)
Expand Down Expand Up @@ -390,6 +399,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err := contract.IsPlaying(ctx, depth)
Expand Down Expand Up @@ -421,6 +431,7 @@ func TestRedistribution(t *testing.T) {
),
redistributionContractAddress,
redistributionContractABI,
false,
)

_, err = contract.Commit(ctx, common.Hex2Bytes("hash"), 0)
Expand Down
Loading

0 comments on commit 62eed01

Please sign in to comment.