Skip to content

Commit

Permalink
feat: adding storage functions
Browse files Browse the repository at this point in the history
  • Loading branch information
praetoriansentry committed Sep 27, 2022
1 parent 3971e7f commit 93f96cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ The loadtest tool works with Avail, but not with the same level of functionality
polycli loadtest --app-id 0 --to-random=true --data-avail --verbosity 700 --chain-id 42 --concurrency 1 --requests 10 --rate-limit 1 --mode t 'http://devnet01.dataavailability.link:8545'
#+end_src

This is a similar test but storing random nonsense hexwords

#+begin_src shell
polycli loadtest --app-id 0 --data-avail --verbosity 700 --chain-id 42 --concurrency 1 --requests 10 --rate-limit 1 --mode s --byte-count 16384 'http://devnet01.dataavailability.link:8545'
#+end_src



* Monitor

Expand Down
50 changes: 47 additions & 3 deletions cmd/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ func runLoadTest(ctx context.Context) error {
}

printResults(loadTestResults)
if *inputLoadTestParams.IsAvail {
log.Trace().Msg("Finished testing avail")
return nil
}

// TODO this doesn't make sense for avail
ptc, err := ec.PendingTransactionCount(ctx)
Expand Down Expand Up @@ -937,7 +941,7 @@ func availLoop(ctx context.Context, c *gsrpc.SubstrateAPI) error {
// this function should probably be abstracted
switch localMode {
case loadTestModeTransaction:
startReq, endReq, err = loadtestSubstrateTransfer(ctx, c, myNonceValue, meta, genesisHash)
startReq, endReq, err = loadtestAvailTransfer(ctx, c, myNonceValue, meta, genesisHash)
break
case loadTestModeDeploy:
startReq, endReq, err = loadtestNotImplemented(ctx, c, myNonceValue)
Expand All @@ -952,7 +956,7 @@ func availLoop(ctx context.Context, c *gsrpc.SubstrateAPI) error {
startReq, endReq, err = loadtestNotImplemented(ctx, c, myNonceValue)
break
case loadTestModeStore:
startReq, endReq, err = loadtestNotImplemented(ctx, c, myNonceValue)
startReq, endReq, err = loadtestAvailStore(ctx, c, myNonceValue, meta, genesisHash)
break
case loadTestModeLong:
startReq, endReq, err = loadtestNotImplemented(ctx, c, myNonceValue)
Expand Down Expand Up @@ -1021,7 +1025,7 @@ func initAvailTestParams(ctx context.Context, c *gsrpc.SubstrateAPI) error {
return nil
}

func loadtestSubstrateTransfer(ctx context.Context, c *gsrpc.SubstrateAPI, nonce uint64, meta *gstypes.Metadata, genesisHash gstypes.Hash) (t1 time.Time, t2 time.Time, err error) {
func loadtestAvailTransfer(ctx context.Context, c *gsrpc.SubstrateAPI, nonce uint64, meta *gstypes.Metadata, genesisHash gstypes.Hash) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

toAddr := *ltp.ToAvailAddress
Expand All @@ -1042,6 +1046,46 @@ func loadtestSubstrateTransfer(ctx context.Context, c *gsrpc.SubstrateAPI, nonce
return
}

ext := gstypes.NewExtrinsic(gsCall)
rv := ltp.AvailRuntime
kp := *inputLoadTestParams.FromAvailAddress

o := gstypes.SignatureOptions{
BlockHash: genesisHash,
Era: gstypes.ExtrinsicEra{IsMortalEra: false},
GenesisHash: genesisHash,
Nonce: gstypes.NewUCompactFromUInt(uint64(nonce)),
SpecVersion: rv.SpecVersion,
Tip: gstypes.NewUCompactFromUInt(100),
TransactionVersion: rv.TransactionVersion,
AppID: gstypes.U32(*ltp.AvailAppID),
}

err = ext.Sign(kp, o)
if err != nil {
return
}

t1 = time.Now()
_, err = c.RPC.Author.SubmitExtrinsic(ext)
t2 = time.Now()
if err != nil {
return
}
return
}

func loadtestAvailStore(ctx context.Context, c *gsrpc.SubstrateAPI, nonce uint64, meta *gstypes.Metadata, genesisHash gstypes.Hash) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

inputData := make([]byte, *ltp.ByteCount, *ltp.ByteCount)
hexwordRead(inputData)

gsCall, err := gstypes.NewCall(meta, "DataAvailability.submit_data", gstypes.NewBytes([]byte(inputData)))
if err != nil {
return
}

// Create the extrinsic
ext := gstypes.NewExtrinsic(gsCall)

Expand Down

0 comments on commit 93f96cb

Please sign in to comment.