From 93f96cb5d6683c5ef4d01bf7f01ecdb8362279c3 Mon Sep 17 00:00:00 2001 From: John Hilliard Date: Tue, 27 Sep 2022 09:14:10 -0400 Subject: [PATCH] feat: adding storage functions --- README.org | 7 +++++++ cmd/loadtest.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index e6e4763b..34e1409f 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/cmd/loadtest.go b/cmd/loadtest.go index 87b26b4c..cc78f189 100644 --- a/cmd/loadtest.go +++ b/cmd/loadtest.go @@ -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) @@ -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) @@ -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) @@ -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 @@ -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)