From 0751c354fd17fabba46e90926aa9c8cad1e1a42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 12:31:08 +0200 Subject: [PATCH 01/10] Simplify guava scenario layout --- pkg/evilwallet/customscenarios.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/evilwallet/customscenarios.go b/pkg/evilwallet/customscenarios.go index e67d893..dcf2fc1 100644 --- a/pkg/evilwallet/customscenarios.go +++ b/pkg/evilwallet/customscenarios.go @@ -89,8 +89,6 @@ func Scenario1() EvilBatch { []ScenarioAlias{ {Inputs: []string{"2"}, Outputs: []string{"4"}}, {Inputs: []string{"2"}, Outputs: []string{"5"}}, - }, - []ScenarioAlias{ {Inputs: []string{"3"}, Outputs: []string{"6"}}, {Inputs: []string{"3"}, Outputs: []string{"7"}}, }, From acf1f44f0d1cc4262e302d2c3dfe92754e8ac395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 12:36:21 +0200 Subject: [PATCH 02/10] Add debug for fresh outputs consumption --- pkg/spammer/spamming_functions.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/spammer/spamming_functions.go b/pkg/spammer/spamming_functions.go index 9c6dfbd..ba3bc19 100644 --- a/pkg/spammer/spamming_functions.go +++ b/pkg/spammer/spamming_functions.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/iotaledger/evil-tools/pkg/evilwallet" "github.com/iotaledger/evil-tools/pkg/models" "github.com/iotaledger/evil-tools/pkg/utils" "github.com/iotaledger/hive.go/ierrors" @@ -40,6 +41,7 @@ func CustomConflictSpammingFunc(ctx context.Context, s *Spammer) error { return err } + s.Logger.LogDebugf("Check the fresh output consumption: Starting next batch, Unspent outputs: %d\n", s.EvilWallet.UnspentOutputsLeft(evilwallet.Fresh)) for _, payloadsIssuanceData := range conflictBatch { clients := s.Clients.GetClients(len(payloadsIssuanceData)) if len(payloadsIssuanceData) > len(clients) { From 46b8fa12ebbf7550d1ad96abf82df198484648f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 12:37:25 +0200 Subject: [PATCH 03/10] Fix: tempID mismatch as we were not using the just built output --- pkg/evilwallet/evilwallet.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index 123e73a..71fb9c3 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -260,14 +260,14 @@ func (e *EvilWallet) CreateTransaction(ctx context.Context, options ...Option) ( TransactionBuilder: e.prepareTransactionBuild(inputs, outputs, buildOptions.inputWallet), } - addedOutputs := e.addOutputsToOutputManager(outputs, buildOptions.outputWallet, tempWallet, tempAddresses) + addedOutputs := e.addOutputsToOutputManager(outputs, buildOptions.outputWallet, tempWallet, tempAddresses, addrAliasMap) e.registerOutputAliases(addedOutputs, addrAliasMap) return issuanceData, nil } // addOutputsToOutputManager adds output to the OutputManager. -func (e *EvilWallet) addOutputsToOutputManager(outputs []iotago.Output, outWallet, tmpWallet *Wallet, tempAddresses map[string]types.Empty) []*models.OutputData { +func (e *EvilWallet) addOutputsToOutputManager(outputs []iotago.Output, outWallet, tmpWallet *Wallet, tempAddresses map[string]types.Empty, tempIDAliasMap map[models.TempOutputID]string) []*models.OutputData { modelOutputs := make([]*models.OutputData, 0) for _, out := range outputs { if out.UnlockConditionSet().Address() == nil { @@ -282,6 +282,9 @@ func (e *EvilWallet) addOutputsToOutputManager(outputs []iotago.Output, outWalle //only outputs that are not used in the scenario structure are added to the outWaller and can be reused. if _, ok := tempAddresses[addr.String()]; ok { output = e.outputManager.AddOutput(e.connector.GetClient().LatestAPI(), tmpWallet, out) + if _, found := tempIDAliasMap[output.TempID]; !found { + panic("tempID is different than provided in tempIDAliasMap") + } } else { output = e.outputManager.AddOutput(e.connector.GetClient().LatestAPI(), outWallet, out) } @@ -325,6 +328,9 @@ func (e *EvilWallet) registerOutputAliases(outputs []*models.OutputData, idAlias for _, out := range outputs { tempID := lo.PanicOnErr(models.NewTempOutputID(e.connector.GetClient().LatestAPI(), out.OutputStruct)) + if tempID != out.TempID { + panic("tempID is different than provided in output") + } // register output alias e.aliasManager.AddOutputAlias(out, idAliasMap[tempID]) @@ -416,37 +422,40 @@ func (e *EvilWallet) useFreshIfInputWalletNotProvided(buildOptions *Options) (*W // Thus, they are tracker in address to alias map. If the scenario is used, the outputBatchAliases map is provided // that indicates which outputs should be saved to the outputWallet. All other outputs are created with temporary wallet, // and their addresses are stored in tempAddresses. -func (e *EvilWallet) matchOutputsWithAliases(ctx context.Context, buildOptions *Options, tempWallet *Wallet) ([]iotago.Output, map[models.TempOutputID]string, map[string]types.Empty, error) { +func (e *EvilWallet) matchOutputsWithAliases(ctx context.Context, buildOptions *Options, batchWallet *Wallet) ([]iotago.Output, map[models.TempOutputID]string, map[string]types.Empty, error) { if err := e.updateOutputBalances(ctx, buildOptions); err != nil { return nil, nil, nil, err } outputs := make([]iotago.Output, 0) idAliasMap := make(map[models.TempOutputID]string) - tempAddresses := make(map[string]types.Empty) + batchReuseAddresses := make(map[string]types.Empty) for alias, output := range buildOptions.aliasOutputs { var addr *iotago.Ed25519Address if _, ok := buildOptions.outputBatchAliases[alias]; ok { addr = buildOptions.outputWallet.Address() - } else { - addr = tempWallet.Address() - tempAddresses[addr.String()] = types.Void + } else { // case for inner batch reuse, this output will be consumed in some of the next transaction of this batch + addr = batchWallet.Address() + batchReuseAddresses[addr.String()] = types.Void } - + var builtAgainOutput iotago.Output switch output.Type() { case iotago.OutputBasic: outputBuilder := builder.NewBasicOutputBuilder(addr, output.BaseTokenAmount()). Mana(output.StoredMana()) - outputs = append(outputs, outputBuilder.MustBuild()) + // TODO why do we build for the second time? Maybe we can reuse the one built in NewOptions + builtAgainOutput = outputBuilder.MustBuild() + outputs = append(outputs, builtAgainOutput) case iotago.OutputAccount: outputBuilder := builder.NewAccountOutputBuilder(addr, output.BaseTokenAmount()) - outputs = append(outputs, outputBuilder.MustBuild()) + builtAgainOutput = outputBuilder.MustBuild() + outputs = append(outputs, builtAgainOutput) } - tempID := lo.PanicOnErr(models.NewTempOutputID(e.connector.GetClient().LatestAPI(), output)) + tempID := lo.PanicOnErr(models.NewTempOutputID(e.connector.GetClient().LatestAPI(), builtAgainOutput)) idAliasMap[tempID] = alias } - return outputs, idAliasMap, tempAddresses, nil + return outputs, idAliasMap, batchReuseAddresses, nil } func (e *EvilWallet) prepareRemainderOutput(inputs []*models.OutputData, outputs []iotago.Output) (alias string, remainderOutput iotago.Output, added bool) { @@ -594,6 +603,7 @@ func (e *EvilWallet) prepareConflictSliceForScenario(scenario *EvilScenario) ([] conflicts := make([][]Option, 0) for _, aliases := range conflictMap { outs := genOutputOptions(aliases.Outputs) + // WithOutputBatchAliases indicates outputs that can be added to reuse wallet option := []Option{WithInputs(aliases.Inputs), WithOutputs(outs), WithOutputBatchAliases(batchOutputs)} if scenario.OutputWallet != nil { option = append(option, WithOutputWallet(scenario.OutputWallet)) From 8a5fd8a91100bfe1f63f3582a18b15d2aabba83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 16:07:27 +0200 Subject: [PATCH 04/10] Fix: move tx.build() after we set OutputIDs --- pkg/evilwallet/evilwallet.go | 34 +++++++++++++------------------ pkg/spammer/spamming_functions.go | 18 ++++++++-------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index 71fb9c3..e55867f 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -140,7 +140,7 @@ func (e *EvilWallet) PrepareAndPostBlockWithPayload(ctx context.Context, clt mod return blockID, nil } -func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account) (iotago.BlockID, *iotago.Transaction, error) { +func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account, strongParents ...iotago.BlockID) (iotago.BlockID, *iotago.Transaction, error) { congestionResp, issuerResp, version, err := e.accManager.RequestBlockIssuanceData(ctx, clt, issuer) if err != nil { return iotago.EmptyBlockID, nil, ierrors.Wrap(err, "failed to get block built data") @@ -163,10 +163,11 @@ func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt return iotago.EmptyBlockID, nil, ierrors.Wrapf(err, "failed to set output ids for transaction %s", txID.String()) } - blockID, err := e.accManager.PostWithBlock(ctx, clt, signedTx, issuer, congestionResp, issuerResp, version) - if err != nil { - return iotago.EmptyBlockID, nil, err - } + blockID, err := e.accManager.PostWithBlock(ctx, clt, signedTx, issuer, congestionResp, issuerResp, version, strongParents...) + //fmt.Printf("Transaction sent:\n%s\n", utils.SprintTransaction(clt.LatestAPI(), signedTx)) + //if err != nil { + // return iotago.EmptyBlockID, nil, err + //} return blockID, signedTx.Transaction, nil } @@ -203,17 +204,13 @@ func (e *EvilWallet) ClearAllAliases() { e.aliasManager.ClearAllAliases() } -func (e *EvilWallet) PrepareCustomConflicts(ctx context.Context, conflictsMaps []ConflictSlice) (conflictBatch [][]*models.PayloadIssuanceData, err error) { - for _, conflictMap := range conflictsMaps { - var txsData []*models.PayloadIssuanceData - for _, conflictOptions := range conflictMap { - issuanceData, err2 := e.CreateTransaction(ctx, conflictOptions...) - if err2 != nil { - return nil, err2 - } - txsData = append(txsData, issuanceData) +func (e *EvilWallet) PrepareCustomConflicts(ctx context.Context, conflicts ConflictSlice) (conflictBatch []*models.PayloadIssuanceData, err error) { + for _, conflictOptions := range conflicts { + issuanceData, err2 := e.CreateTransaction(ctx, conflictOptions...) + if err2 != nil { + return nil, err2 } - conflictBatch = append(conflictBatch, txsData) + conflictBatch = append(conflictBatch, issuanceData) } return conflictBatch, nil @@ -571,11 +568,8 @@ func (e *EvilWallet) prepareTransactionBuild(inputs []*models.OutputData, output return txBuilder } -func (e *EvilWallet) PrepareCustomConflictsSpam(ctx context.Context, scenario *EvilScenario) (txsData [][]*models.PayloadIssuanceData, allAliases ScenarioAlias, err error) { - conflicts, allAliases := e.prepareConflictSliceForScenario(scenario) - txsData, err = e.PrepareCustomConflicts(ctx, conflicts) - - return txsData, allAliases, err +func (e *EvilWallet) PrepareCustomConflictsSpam(scenario *EvilScenario) ([]ConflictSlice, ScenarioAlias) { + return e.prepareConflictSliceForScenario(scenario) } func (e *EvilWallet) PrepareAccountSpam(ctx context.Context, scenario *EvilScenario) (*models.PayloadIssuanceData, ScenarioAlias, error) { diff --git a/pkg/spammer/spamming_functions.go b/pkg/spammer/spamming_functions.go index ba3bc19..41f608f 100644 --- a/pkg/spammer/spamming_functions.go +++ b/pkg/spammer/spamming_functions.go @@ -33,16 +33,18 @@ func DataSpammingFunction(ctx context.Context, s *Spammer) error { } func CustomConflictSpammingFunc(ctx context.Context, s *Spammer) error { - conflictBatch, aliases, err := s.EvilWallet.PrepareCustomConflictsSpam(ctx, s.EvilScenario) - if err != nil { - s.LogDebug(ierrors.Wrap(ErrFailToPrepareBatch, err.Error()).Error()) - s.ErrCounter.CountError(ierrors.Wrap(ErrFailToPrepareBatch, err.Error())) - - return err - } + conflictBatch, aliases := s.EvilWallet.PrepareCustomConflictsSpam(s.EvilScenario) s.Logger.LogDebugf("Check the fresh output consumption: Starting next batch, Unspent outputs: %d\n", s.EvilWallet.UnspentOutputsLeft(evilwallet.Fresh)) - for _, payloadsIssuanceData := range conflictBatch { + for _, conflictSlice := range conflictBatch { + payloadsIssuanceData, err := s.EvilWallet.PrepareCustomConflicts(ctx, conflictSlice) + if err != nil { + s.LogDebug(ierrors.Wrap(ErrFailToPrepareBatch, err.Error()).Error()) + s.ErrCounter.CountError(ierrors.Wrap(ErrFailToPrepareBatch, err.Error())) + + return err + } + clients := s.Clients.GetClients(len(payloadsIssuanceData)) if len(payloadsIssuanceData) > len(clients) { s.LogDebug(ErrFailToPrepareBatch.Error()) From 70dc57bea446c4da9c5177237fc6cb2181dcd9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 17:44:46 +0200 Subject: [PATCH 05/10] Fixes, and rename --- pkg/evilwallet/evilwallet.go | 17 ++++++++--------- pkg/spammer/spammer.go | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index e55867f..4d64dda 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -164,10 +164,9 @@ func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt } blockID, err := e.accManager.PostWithBlock(ctx, clt, signedTx, issuer, congestionResp, issuerResp, version, strongParents...) - //fmt.Printf("Transaction sent:\n%s\n", utils.SprintTransaction(clt.LatestAPI(), signedTx)) - //if err != nil { - // return iotago.EmptyBlockID, nil, err - //} + if err != nil { + return iotago.EmptyBlockID, nil, err + } return blockID, signedTx.Transaction, nil } @@ -239,7 +238,7 @@ func (e *EvilWallet) CreateTransaction(ctx context.Context, options ...Option) ( return nil, err } - outputs, addrAliasMap, tempAddresses, err := e.prepareOutputs(ctx, buildOptions, tempWallet) + outputs, tempIDAlias, tempAddresses, err := e.prepareOutputs(ctx, buildOptions, tempWallet) if err != nil { return nil, err } @@ -247,9 +246,9 @@ func (e *EvilWallet) CreateTransaction(ctx context.Context, options ...Option) ( alias, remainder, hasRemainder := e.prepareRemainderOutput(inputs, outputs) if hasRemainder { outputs = append(outputs, remainder) - if alias != "" && addrAliasMap != nil { + if alias != "" && tempIDAlias != nil { tempID := lo.PanicOnErr(models.NewTempOutputID(e.connector.GetClient().LatestAPI(), remainder)) - addrAliasMap[tempID] = alias + tempIDAlias[tempID] = alias } } issuanceData := &models.PayloadIssuanceData{ @@ -257,8 +256,8 @@ func (e *EvilWallet) CreateTransaction(ctx context.Context, options ...Option) ( TransactionBuilder: e.prepareTransactionBuild(inputs, outputs, buildOptions.inputWallet), } - addedOutputs := e.addOutputsToOutputManager(outputs, buildOptions.outputWallet, tempWallet, tempAddresses, addrAliasMap) - e.registerOutputAliases(addedOutputs, addrAliasMap) + addedOutputs := e.addOutputsToOutputManager(outputs, buildOptions.outputWallet, tempWallet, tempAddresses, tempIDAlias) + e.registerOutputAliases(addedOutputs, tempIDAlias) return issuanceData, nil } diff --git a/pkg/spammer/spammer.go b/pkg/spammer/spammer.go index 42158d3..a1d19dc 100644 --- a/pkg/spammer/spammer.go +++ b/pkg/spammer/spammer.go @@ -174,7 +174,7 @@ func (s *Spammer) Spam(ctx context.Context) { s.LogInfo("Maximum spam duration exceeded, stopping spammer....") return case <-s.State.spamTicker.C: - if goroutineCount.Load() > 100 { + if goroutineCount.Load() > 1500 { break } go func(newContext context.Context, s *Spammer) { From cc50de2e8f450154f46de8652492778a4f7f3756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 17:45:28 +0200 Subject: [PATCH 06/10] Await for the tx acceptance before going to the next batch level --- pkg/evilwallet/evilwallet.go | 14 ++++++++++++++ pkg/spammer/spammer.go | 8 ++++++-- pkg/spammer/spamming_functions.go | 2 +- pkg/utils/await.go | 27 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index 4d64dda..87668c3 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -140,6 +140,20 @@ func (e *EvilWallet) PrepareAndPostBlockWithPayload(ctx context.Context, clt mod return blockID, nil } +func (e *EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account, strongParents ...iotago.BlockID) (iotago.BlockID, error) { + blockID, _, err := e.PrepareAndPostBlockWithTxBuildData(ctx, clt, txBuilder, issuer, strongParents...) + if err != nil { + return iotago.EmptyBlockID, err + } + + err = utils.AwaitBlockAcceptance(ctx, e.Logger, clt, blockID) + if err != nil { + return iotago.EmptyBlockID, err + } + + return blockID, nil +} + func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account, strongParents ...iotago.BlockID) (iotago.BlockID, *iotago.Transaction, error) { congestionResp, issuerResp, version, err := e.accManager.RequestBlockIssuanceData(ctx, clt, issuer) if err != nil { diff --git a/pkg/spammer/spammer.go b/pkg/spammer/spammer.go index a1d19dc..a0f6e6b 100644 --- a/pkg/spammer/spammer.go +++ b/pkg/spammer/spammer.go @@ -252,7 +252,7 @@ func (s *Spammer) PrepareBlock(ctx context.Context, issuanceData *models.Payload return block } -func (s *Spammer) PrepareAndPostBlock(ctx context.Context, issuanceData *models.PayloadIssuanceData, clt models.Client) iotago.BlockID { +func (s *Spammer) PrepareAndPostBlock(ctx context.Context, issuanceData *models.PayloadIssuanceData, clt models.Client, awaitAcceptance ...bool) iotago.BlockID { if issuanceData.Payload == nil && issuanceData.TransactionBuilder == nil { s.logError(ErrPayloadIsNil) s.ErrCounter.CountError(ErrPayloadIsNil) @@ -273,7 +273,11 @@ func (s *Spammer) PrepareAndPostBlock(ctx context.Context, issuanceData *models. case iotago.PayloadTaggedData: blockID, err = s.EvilWallet.PrepareAndPostBlockWithPayload(ctx, clt, issuanceData.Payload, issuerAccount) case iotago.PayloadSignedTransaction: - blockID, _, err = s.EvilWallet.PrepareAndPostBlockWithTxBuildData(ctx, clt, issuanceData.TransactionBuilder, issuerAccount) + if awaitAcceptance != nil && awaitAcceptance[0] { + blockID, err = s.EvilWallet.PrepareAndPostBlockWithTxBuildDataAwait(ctx, clt, issuanceData.TransactionBuilder, issuerAccount) + } else { + blockID, _, err = s.EvilWallet.PrepareAndPostBlockWithTxBuildData(ctx, clt, issuanceData.TransactionBuilder, issuerAccount) + } default: // unknown payload type s.logError(ErrUnknownPayloadType) diff --git a/pkg/spammer/spamming_functions.go b/pkg/spammer/spamming_functions.go index 41f608f..3f1c8bb 100644 --- a/pkg/spammer/spamming_functions.go +++ b/pkg/spammer/spamming_functions.go @@ -62,7 +62,7 @@ func CustomConflictSpammingFunc(ctx context.Context, s *Spammer) error { //nolint:gosec time.Sleep(time.Duration(rand.Float64()*100) * time.Millisecond) - s.PrepareAndPostBlock(ctx, tx, clt) + s.PrepareAndPostBlock(ctx, tx, clt, true) }(clients[i], issuanceData) } wg.Wait() diff --git a/pkg/utils/await.go b/pkg/utils/await.go index 0c1eaba..f04093c 100644 --- a/pkg/utils/await.go +++ b/pkg/utils/await.go @@ -121,6 +121,33 @@ func AwaitBlockWithTransactionToBeAccepted(ctx context.Context, logger log.Logge return ierrors.Errorf("Transaction %s not accepted in time", txID) } +func AwaitBlockAcceptance(ctx context.Context, logger log.Logger, clt models.Client, blockID iotago.BlockID) error { + logger.LogDebugf("Await for the acceptance of block %s", blockID.String()) + for t := time.Now(); time.Since(t) < MaxAcceptanceAwait; time.Sleep(AwaitInterval) { + resp, err := clt.GetBlockConfirmationState(ctx, blockID) + if err != nil { + logger.LogDebugf("Failed to get block confirmation state: %s", err) + + continue + } + + if isBlockStateAtLeastAccepted(resp.BlockState) { + logger.LogDebugf("Block %s issuance success, status: %s", blockID.ToHex(), resp.BlockState) + + return nil + } + + if isBlockStateFailure(resp.BlockState) { + logger.LogDebugf("Block %s issuance failure, block failure reason: %s", blockID.ToHex(), resp.BlockState.String()) + + return ierrors.Errorf("block %s issuance failure, block failure reason: %s", blockID.ToHex(), resp.BlockState.String()) + } + } + + return ierrors.Errorf("failed to await block %s acceptance", blockID.ToHex()) + +} + // AwaitAddressUnspentOutputToBeAccepted awaits for acceptance of an output created for an address, based on the status of the transaction. func AwaitAddressUnspentOutputToBeAccepted(ctx context.Context, logger log.Logger, clt models.Client, addr iotago.Address) (outputID iotago.OutputID, output iotago.Output, err error) { addrBech := addr.Bech32(clt.CommittedAPI().ProtocolParameters().Bech32HRP()) From 7c6b2f4bcff7c1b7aef5c1b39d4b332eaf4f1fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 23 Apr 2024 18:12:15 +0200 Subject: [PATCH 07/10] Do not print errors, as they are expected for the deep conflict spam --- pkg/spammer/spammer.go | 5 +++-- pkg/walletmanager/faucet.go | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/spammer/spammer.go b/pkg/spammer/spammer.go index a0f6e6b..158264f 100644 --- a/pkg/spammer/spammer.go +++ b/pkg/spammer/spammer.go @@ -243,7 +243,7 @@ func (s *Spammer) PrepareBlock(ctx context.Context, issuanceData *models.Payload } block, err := s.EvilWallet.CreateBlock(ctx, clt, issuanceData.Payload, issuerAccount, strongParents...) if err != nil { - s.logError(ierrors.Wrap(err, ErrFailPostBlock.Error())) + //s.logError(ierrors.Wrap(err, ErrFailPostBlock.Error())) s.ErrCounter.CountError(ierrors.Wrap(err, ErrFailPostBlock.Error())) return nil @@ -287,7 +287,8 @@ func (s *Spammer) PrepareAndPostBlock(ctx context.Context, issuanceData *models. } if err != nil { - s.logError(ierrors.Wrap(err, ErrFailPostBlock.Error())) + // for the conflicting spams we will see errors and that's fine, so that's why we are not printing + s.LogDebugf("error: %v", ierrors.Wrap(err, ErrFailPostBlock.Error())) s.ErrCounter.CountError(ierrors.Wrap(err, ErrFailPostBlock.Error())) return iotago.EmptyBlockID diff --git a/pkg/walletmanager/faucet.go b/pkg/walletmanager/faucet.go index 243fc33..a18f72f 100644 --- a/pkg/walletmanager/faucet.go +++ b/pkg/walletmanager/faucet.go @@ -93,14 +93,12 @@ func (m *Manager) RequestFaucetFunds(ctx context.Context, clt models.Client, rec func (m *Manager) PostWithBlock(ctx context.Context, clt models.Client, payload iotago.Payload, issuer wallet.Account, congestionResp *api.CongestionResponse, issuerResp *api.IssuanceBlockHeaderResponse, version iotago.Version, strongParents ...iotago.BlockID) (iotago.BlockID, error) { signedBlock, err := m.CreateBlock(clt, payload, issuer, congestionResp, issuerResp, version, strongParents...) if err != nil { - m.LogErrorf("failed to create block: %s", err) return iotago.EmptyBlockID, err } blockID, err := clt.PostBlock(ctx, signedBlock) if err != nil { - m.LogErrorf("failed to post block: %s", err) return iotago.EmptyBlockID, err } From ebb4cda74877689172bb8f0b2c5840a3c8db5780 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Wed, 24 Apr 2024 14:14:19 +0800 Subject: [PATCH 08/10] Fix linter error: remove new lines --- pkg/utils/await.go | 1 - pkg/walletmanager/faucet.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/pkg/utils/await.go b/pkg/utils/await.go index f04093c..91249ad 100644 --- a/pkg/utils/await.go +++ b/pkg/utils/await.go @@ -145,7 +145,6 @@ func AwaitBlockAcceptance(ctx context.Context, logger log.Logger, clt models.Cli } return ierrors.Errorf("failed to await block %s acceptance", blockID.ToHex()) - } // AwaitAddressUnspentOutputToBeAccepted awaits for acceptance of an output created for an address, based on the status of the transaction. diff --git a/pkg/walletmanager/faucet.go b/pkg/walletmanager/faucet.go index a18f72f..169f4b8 100644 --- a/pkg/walletmanager/faucet.go +++ b/pkg/walletmanager/faucet.go @@ -93,13 +93,11 @@ func (m *Manager) RequestFaucetFunds(ctx context.Context, clt models.Client, rec func (m *Manager) PostWithBlock(ctx context.Context, clt models.Client, payload iotago.Payload, issuer wallet.Account, congestionResp *api.CongestionResponse, issuerResp *api.IssuanceBlockHeaderResponse, version iotago.Version, strongParents ...iotago.BlockID) (iotago.BlockID, error) { signedBlock, err := m.CreateBlock(clt, payload, issuer, congestionResp, issuerResp, version, strongParents...) if err != nil { - return iotago.EmptyBlockID, err } blockID, err := clt.PostBlock(ctx, signedBlock) if err != nil { - return iotago.EmptyBlockID, err } From 57a89f670f6e343b098abe982bd4d033965c91ce Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Wed, 24 Apr 2024 14:24:47 +0800 Subject: [PATCH 09/10] Remove unused changes --- pkg/evilwallet/evilwallet.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index 87668c3..a0c9706 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -140,8 +140,8 @@ func (e *EvilWallet) PrepareAndPostBlockWithPayload(ctx context.Context, clt mod return blockID, nil } -func (e *EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account, strongParents ...iotago.BlockID) (iotago.BlockID, error) { - blockID, _, err := e.PrepareAndPostBlockWithTxBuildData(ctx, clt, txBuilder, issuer, strongParents...) +func (e *EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account) (iotago.BlockID, error) { + blockID, _, err := e.PrepareAndPostBlockWithTxBuildData(ctx, clt, txBuilder, issuer) if err != nil { return iotago.EmptyBlockID, err } @@ -154,7 +154,7 @@ func (e *EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait(ctx context.Context return blockID, nil } -func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account, strongParents ...iotago.BlockID) (iotago.BlockID, *iotago.Transaction, error) { +func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account) (iotago.BlockID, *iotago.Transaction, error) { congestionResp, issuerResp, version, err := e.accManager.RequestBlockIssuanceData(ctx, clt, issuer) if err != nil { return iotago.EmptyBlockID, nil, ierrors.Wrap(err, "failed to get block built data") @@ -177,7 +177,7 @@ func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt return iotago.EmptyBlockID, nil, ierrors.Wrapf(err, "failed to set output ids for transaction %s", txID.String()) } - blockID, err := e.accManager.PostWithBlock(ctx, clt, signedTx, issuer, congestionResp, issuerResp, version, strongParents...) + blockID, err := e.accManager.PostWithBlock(ctx, clt, signedTx, issuer, congestionResp, issuerResp, version) if err != nil { return iotago.EmptyBlockID, nil, err } From e5bec42474faa2ba8889c7d7029e260f60747487 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Wed, 24 Apr 2024 14:36:46 +0800 Subject: [PATCH 10/10] Improve log messages --- pkg/spammer/spammer.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/spammer/spammer.go b/pkg/spammer/spammer.go index 158264f..057986e 100644 --- a/pkg/spammer/spammer.go +++ b/pkg/spammer/spammer.go @@ -243,7 +243,7 @@ func (s *Spammer) PrepareBlock(ctx context.Context, issuanceData *models.Payload } block, err := s.EvilWallet.CreateBlock(ctx, clt, issuanceData.Payload, issuerAccount, strongParents...) if err != nil { - //s.logError(ierrors.Wrap(err, ErrFailPostBlock.Error())) + s.LogDebugf("failed at PrepareBlock: %v", ierrors.Wrap(err, ErrFailPostBlock.Error())) s.ErrCounter.CountError(ierrors.Wrap(err, ErrFailPostBlock.Error())) return nil @@ -287,8 +287,7 @@ func (s *Spammer) PrepareAndPostBlock(ctx context.Context, issuanceData *models. } if err != nil { - // for the conflicting spams we will see errors and that's fine, so that's why we are not printing - s.LogDebugf("error: %v", ierrors.Wrap(err, ErrFailPostBlock.Error())) + // for the conflicting spams we will see errors and that's fine, so that's why we are not printing them s.ErrCounter.CountError(ierrors.Wrap(err, ErrFailPostBlock.Error())) return iotago.EmptyBlockID