Skip to content

Commit

Permalink
Add second split cons for end transaction split
Browse files Browse the repository at this point in the history
  • Loading branch information
daria305 committed Apr 20, 2024
1 parent e47b247 commit d6ea6a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
24 changes: 14 additions & 10 deletions pkg/evilwallet/faucetfunds.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
iotago "github.com/iotaledger/iota.go/v4"
)

// EndSplitNumber defines the second split during funds creation for a big wallet,
// it can be large as funds are not splitted further, and it will not increase the congestion.
// So the big wallet size is FaucetSplitNumber * EndSplitNumber.
const EndSplitNumber = 126

// RequestFundsFromFaucet requests funds from the faucet, then track the confirmed status of unspent output,
// also register the alias name for the unspent output if provided.
func (e *EvilWallet) RequestFundsFromFaucet(ctx context.Context) (initWallet *Wallet, err error) {
Expand All @@ -31,7 +36,7 @@ func (e *EvilWallet) RequestFundsFromFaucet(ctx context.Context) (initWallet *Wa
func (e *EvilWallet) RequestFreshBigFaucetWallet(ctx context.Context) error {
initWallet := NewWallet()
receiveWallet := e.NewWallet(Fresh)
_, err := e.requestAndSplitFaucetFunds(ctx, initWallet, receiveWallet)
_, err := e.requestAndSplitFaucetFunds(ctx, initWallet, receiveWallet, e.faucetSplitNumber)
if err != nil {
return ierrors.Wrap(err, "failed to request big funds from faucet")
}
Expand All @@ -53,7 +58,7 @@ func (e *EvilWallet) RequestFreshBigFaucetWallet(ctx context.Context) error {
func (e *EvilWallet) RequestFreshFaucetWallet(ctx context.Context) error {
initWallet := NewWallet()
receiveWallet := e.NewWallet(Fresh)
txID, err := e.requestAndSplitFaucetFunds(ctx, initWallet, receiveWallet)
txID, err := e.requestAndSplitFaucetFunds(ctx, initWallet, receiveWallet, EndSplitNumber)
if err != nil {
return ierrors.Wrap(err, "failed to request funds from faucet")
}
Expand All @@ -65,15 +70,15 @@ func (e *EvilWallet) RequestFreshFaucetWallet(ctx context.Context) error {
return err
}

func (e *EvilWallet) requestAndSplitFaucetFunds(ctx context.Context, initWallet, receiveWallet *Wallet) (txID iotago.TransactionID, err error) {
func (e *EvilWallet) requestAndSplitFaucetFunds(ctx context.Context, initWallet, receiveWallet *Wallet, splitNumber int) (txID iotago.TransactionID, err error) {
splitOutput, err := e.requestFaucetFunds(ctx, initWallet)
if err != nil {
return iotago.EmptyTransactionID, err
}

e.LogDebugf("Faucet funds received, continue spliting output: %s", splitOutput.OutputID.ToHex())

splitTransactionsID, err := e.splitOutput(ctx, splitOutput, initWallet, receiveWallet)
splitTransactionsID, err := e.splitOutput(ctx, splitOutput, initWallet, receiveWallet, splitNumber)
if err != nil {
return iotago.EmptyTransactionID, ierrors.Wrap(err, "failed to split faucet funds")
}
Expand Down Expand Up @@ -103,8 +108,8 @@ func (e *EvilWallet) requestFaucetFunds(ctx context.Context, wallet *Wallet) (ou
return output, nil
}

func (e *EvilWallet) splitOutput(ctx context.Context, splitOutput *models.OutputData, inputWallet, outputWallet *Wallet) (iotago.TransactionID, error) {
outputs, err := e.createSplitOutputs(splitOutput, outputWallet)
func (e *EvilWallet) splitOutput(ctx context.Context, splitOutput *models.OutputData, inputWallet, outputWallet *Wallet, splitNumber int) (iotago.TransactionID, error) {
outputs, err := e.createSplitOutputs(splitOutput, outputWallet, splitNumber)
if err != nil {
return iotago.EmptyTransactionID, ierrors.Wrapf(err, "failed to create splitted outputs")
}
Expand Down Expand Up @@ -161,7 +166,7 @@ func (e *EvilWallet) SplitOutputsInParallel(ctx context.Context, inputWallet, ou
defer wg.Done()

input := inputWallet.UnspentOutput(id)
txID, err := e.splitOutput(ctx, input, inputWallet, outputWallet)
txID, err := e.splitOutput(ctx, input, inputWallet, outputWallet, EndSplitNumber)
if err != nil {
e.LogErrorf("Failed to split output %s: %s", input.OutputID.ToHex(), err)

Expand Down Expand Up @@ -204,7 +209,7 @@ func (e *EvilWallet) SplitOutputsSequentially(ctx context.Context, inputWallet,
// split all outputs stored in the input wallet
for id := range inputWallet.UnspentOutputs() {
input := inputWallet.UnspentOutput(id)
txID, err := e.splitOutput(ctx, input, inputWallet, outputWallet)
txID, err := e.splitOutput(ctx, input, inputWallet, outputWallet, EndSplitNumber)
if err != nil {
e.LogErrorf("Failed to split output %s: %s", input.OutputID.ToHex(), err)
return err
Expand All @@ -218,9 +223,8 @@ func (e *EvilWallet) SplitOutputsSequentially(ctx context.Context, inputWallet,
return nil
}

func (e *EvilWallet) createSplitOutputs(input *models.OutputData, receiveWallet *Wallet) ([]*OutputOption, error) {
func (e *EvilWallet) createSplitOutputs(input *models.OutputData, receiveWallet *Wallet, splitNumber int) ([]*OutputOption, error) {
totalAmount := input.OutputStruct.BaseTokenAmount()
splitNumber := e.faucetSplitNumber
minDeposit := e.minOutputStorageDeposit

// make sure the amount of output covers the min deposit
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var ParamsTool = &ParametersTool{}
type ParametersTool struct {
NodeURLs []string `default:"http://localhost:8050" usage:"API URLs for clients used in test separated with commas"`
FaucetURL string `default:"http://localhost:8088" usage:"Faucet URL used in test"`
FaucetSplitNumber int `default:"20" usage:"Number of outputs to split faucet outputs into, this determine number of txs that are sent per one faucet request. Reduce this number if not all txs are accepted due to congestion. "`
FaucetSplitNumber int `default:"40" usage:"Number of outputs to split faucet outputs into, this determine number of txs that are sent per one faucet request. Reduce this number if not all txs are accepted due to congestion. "`

AccountStatesFile string `default:"wallet.dat" usage:"File to store account states in"`
BlockIssuerPrivateKey string `default:"db39d2fde6301d313b108dc9db1ee724d0f405f6fde966bd776365bc5f4a5fb31e4b21eb51dcddf65c20db1065e1f1514658b23a3ddbf48d30c0efc926a9a648" usage:"Block issuer private key (in hex) to use for genesis account spams"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/spammer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// BigWalletsNeeded calculates how many big wallets needs to be prepared for a spam based on provided spam details.
func BigWalletsNeeded(rate int, duration time.Duration, spammingBatchSize int, splitFactor int) int {
bigWalletSize := splitFactor * splitFactor
bigWalletSize := splitFactor * evilwallet.EndSplitNumber
outputsNeeded := rate * int(duration/time.Second) * spammingBatchSize
walletsNeeded := outputsNeeded/bigWalletSize + 1

Expand Down
8 changes: 4 additions & 4 deletions programs/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
MaxPendingRequestsRunning = 20
MaxPendingRequestsRunning = 10
FaucetFundsAwaitTimeout = 3 * time.Minute
SelectCheckInterval = 1 * time.Second
)
Expand Down Expand Up @@ -46,13 +46,13 @@ func RequestFaucetFunds(ctx context.Context, logger log.Logger, paramsSpammer *s

canSubmit := func() bool {
maxRequests := int32(lo.Min(totalWalletsNeeded, MaxPendingRequestsRunning))
return running.Load() < maxRequests && w.UnspentOutputsLeft(evilwallet.Fresh) <= 2*minFundsDeposit
return running.Load() < maxRequests && w.UnspentOutputsLeft(evilwallet.Fresh) <= 3*minFundsDeposit
}

if paramsSpammer.Duration == spammer.InfiniteDuration {
logger.LogInfof("Wallet size: %d, Infinitely requesting faucet funds in the background...", faucetSplitNumber*faucetSplitNumber)
logger.LogInfof("Wallet size: %d, Infinitely requesting faucet funds in the background...", faucetSplitNumber*evilwallet.EndSplitNumber)
} else {
logger.LogInfof("Requesting faucet funds in the background, total wallets needed %d of size %d", totalWalletsNeeded, faucetSplitNumber*faucetSplitNumber)
logger.LogInfof("Requesting faucet funds in the background, total wallets needed %d of size %d", totalWalletsNeeded, faucetSplitNumber*evilwallet.EndSplitNumber)
}
wp := workerpool.New("Funds Requesting", workerpool.WithWorkerCount(MaxPendingRequestsRunning),
workerpool.WithCancelPendingTasksOnShutdown(true))
Expand Down

0 comments on commit d6ea6a2

Please sign in to comment.