Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Spam Broadcast Functionality #1653

Merged
merged 37 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a93ecf1
move into seperate package
samliok Oct 2, 2024
56cf0b7
extract cli prompting
samliok Oct 2, 2024
9d8a718
hang condition
samliok Oct 2, 2024
fa42146
take out close database
samliok Oct 3, 2024
2e878a3
strip out all spam into seperate package
samliok Oct 3, 2024
781b29a
remove get factory from handler, potentially could move into auth
samliok Oct 3, 2024
596d48c
pull out pacer and distribute funds
samliok Oct 3, 2024
0aefe39
redundant unit prices
samliok Oct 3, 2024
39b682c
seperate logging go routine
samliok Oct 3, 2024
f99c260
remove defer stop for logging
samliok Oct 3, 2024
e18d659
remove unused errors
samliok Oct 3, 2024
ba476cd
save
samliok Oct 3, 2024
0ef4f90
seperate auth and spam helper
samliok Oct 3, 2024
6ae8f3c
spam script working
samliok Oct 4, 2024
7db9c3e
get factory into auth
samliok Oct 4, 2024
7dfde55
added defaults to cli
samliok Oct 4, 2024
bc72196
remove deploydevnetscript.sh
samliok Oct 4, 2024
deb18b4
dont hardcode balance
samliok Oct 4, 2024
e1328bc
e2e tests working
samliok Oct 4, 2024
974ed4d
remove old debugging
samliok Oct 4, 2024
787fff8
rename to throughput
samliok Oct 4, 2024
bbdc3f4
update imports
samliok Oct 4, 2024
eda116d
fmt somethings
samliok Oct 4, 2024
8ef31af
uncomment e2e
samliok Oct 4, 2024
1add5d0
merge conflicts but now returning funds not working
samliok Oct 4, 2024
0249c6a
fix log
samliok Oct 4, 2024
ccdcd7c
funds bug
samliok Oct 4, 2024
4448232
fix lint script
samliok Oct 4, 2024
7fef415
move logging into issuer
samliok Oct 7, 2024
b9f1074
update funds map correctly
samliok Oct 7, 2024
d00518b
remove lookup balance
samliok Oct 7, 2024
9e30569
vmwithcontracts lint
samliok Oct 8, 2024
02ba233
pr comments: moving packages, updated lint, nits
samliok Oct 10, 2024
b913e83
seperate broadcast txs
samliok Oct 10, 2024
4038440
include cancel
samliok Oct 10, 2024
cd657d9
uncomment
samliok Oct 10, 2024
4cd6a4e
Merge branch 'main' into broadcast
aaronbuchwald Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions throughput/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
return err
}

var fundsL sync.Mutex
// distribute funds
accounts, funds, factories, err := s.distributeFunds(ctx, cli, parser, feePerTx, sh)
if err != nil {
Expand All @@ -148,23 +147,47 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
return err
}

// make sure we can exit gracefully & return funds
signals := make(chan os.Signal, 2)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

cctx, cancel := context.WithCancel(ctx)
defer cancel()

for _, issuer := range issuers {
issuer.Start(cctx)
}

// set logging
issuers[0].logStats(cctx)

// Broadcast txs
// broadcast transactions
s.broadcast(cctx, cancel, sh, accounts, funds, factories, issuers, feePerTx, terminate)

maxUnits, err = chain.EstimateUnits(parser.Rules(time.Now().UnixMilli()), actions, factory)
if err != nil {
return err
}
return s.returnFunds(ctx, cli, parser, maxUnits, sh, accounts, factories, funds, symbol)
}

func (s Spammer) broadcast(
ctx context.Context,
cancel context.CancelFunc,
sh SpamHelper,
accounts []*auth.PrivateKey,

funds map[codec.Address]uint64,
factories []chain.AuthFactory,
issuers []*issuer,

feePerTx uint64,
terminate bool,
) {
// make sure we can exit gracefully & return funds
signals := make(chan os.Signal, 2)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

var (
// Do not call this function concurrently (math.Rand is not safe for concurrent use)
z = rand.NewZipf(s.zipfSeed, s.sZipf, s.vZipf, uint64(s.numAccounts)-1)
z = rand.NewZipf(s.zipfSeed, s.sZipf, s.vZipf, uint64(s.numAccounts)-1)
fundsL = sync.Mutex{}

it = time.NewTimer(0)
currentTarget = min(s.txsPerSecond, s.minTxsPerSecond)
Expand Down Expand Up @@ -226,7 +249,7 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo

// Send transaction
actions := sh.GetTransfer(recipient, amountToTransfer, uniqueBytes())
return issuer.Send(cctx, actions, factory, feePerTx)
return issuer.Send(ctx, actions, factory, feePerTx)
})
}

Expand Down Expand Up @@ -256,7 +279,7 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
utils.Outf("{{cyan}}increasing target tps:{{/}} %d\n", currentTarget)
consecutiveUnderBacklog = 0
}
case <-cctx.Done():
case <-ctx.Done():
stop = true
utils.Outf("{{yellow}}context canceled{{/}}\n")
case <-signals:
Expand All @@ -265,14 +288,10 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
cancel()
}
}

// Wait for all issuers to finish
utils.Outf("{{yellow}}waiting for issuers to return{{/}}\n")
issuerWg.Wait()
maxUnits, err = chain.EstimateUnits(parser.Rules(time.Now().UnixMilli()), actions, factory)
if err != nil {
return err
}
return s.returnFunds(ctx, cli, parser, maxUnits, sh, accounts, factories, funds, symbol)
}

func (s *Spammer) logZipf(zipfSeed *rand.Rand) {
Expand Down
Loading