Compare commits
9 Commits
683db0dd49
...
20100c0841
Author | SHA1 | Date |
---|---|---|
Aniket Prajapati | 20100c0841 | |
aniketfuryrocks | 29a059230a | |
aniketfuryrocks | 05599bf699 | |
aniketfuryrocks | 36bc1b9d3e | |
aniketfuryrocks | f0d21ce57f | |
aniketfuryrocks | 0039c7bbd2 | |
aniketfuryrocks | 64e7cf13ca | |
aniketfuryrocks | f62773c9ef | |
aniketfuryrocks | 4712676fd1 |
|
@ -2,3 +2,4 @@
|
|||
node_modules
|
||||
package-lock.json
|
||||
**/config.json
|
||||
out.json
|
||||
|
|
|
@ -318,9 +318,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
|
|||
|
||||
[[package]]
|
||||
name = "async-compression"
|
||||
version = "0.3.15"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a"
|
||||
checksum = "5b0122885821398cc923ece939e24d1056a2384ee719432397fa9db87230ff11"
|
||||
dependencies = [
|
||||
"brotli",
|
||||
"flate2",
|
||||
|
@ -1283,6 +1283,21 @@ version = "1.0.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
|
@ -1626,15 +1641,28 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.23.2"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
|
||||
checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7"
|
||||
dependencies = [
|
||||
"http",
|
||||
"hyper",
|
||||
"rustls",
|
||||
"rustls 0.21.1",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-rustls 0.24.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hyper",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1991,6 +2019,24 @@ dependencies = [
|
|||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.25.1"
|
||||
|
@ -2182,12 +2228,50 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69b3f656a17a6cbc115b5c7a40c616947d213ba182135b014d6051b73ab6f019"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.56",
|
||||
"quote 1.0.27",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2ce0f250f34a308dcfdbb351f511359857d4ed2134ba715a4eadd46e1ffd617"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.5.0"
|
||||
|
@ -2422,7 +2506,7 @@ dependencies = [
|
|||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
|
@ -2439,7 +2523,7 @@ dependencies = [
|
|||
"rand 0.8.5",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"rustls-native-certs",
|
||||
"slab",
|
||||
"thiserror",
|
||||
|
@ -2630,9 +2714,9 @@ checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
|
|||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.17"
|
||||
version = "0.11.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91"
|
||||
checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"base64 0.21.0",
|
||||
|
@ -2645,20 +2729,23 @@ dependencies = [
|
|||
"http-body",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-tls",
|
||||
"ipnet",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls",
|
||||
"rustls 0.21.1",
|
||||
"rustls-pemfile",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-native-tls",
|
||||
"tokio-rustls 0.24.1",
|
||||
"tokio-util",
|
||||
"tower-service",
|
||||
"url",
|
||||
|
@ -2770,6 +2857,18 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.21.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e"
|
||||
dependencies = [
|
||||
"log",
|
||||
"ring",
|
||||
"rustls-webpki",
|
||||
"sct",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-native-certs"
|
||||
version = "0.6.2"
|
||||
|
@ -2791,6 +2890,16 @@ dependencies = [
|
|||
"base64 0.21.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.100.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.12"
|
||||
|
@ -3476,7 +3585,7 @@ dependencies = [
|
|||
"quinn",
|
||||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"solana-connection-cache",
|
||||
"solana-measure",
|
||||
"solana-metrics",
|
||||
|
@ -3601,6 +3710,7 @@ dependencies = [
|
|||
"pretty_env_logger",
|
||||
"rand 0.8.5",
|
||||
"rand_chacha 0.3.1",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"solana-client",
|
||||
|
@ -3701,7 +3811,7 @@ dependencies = [
|
|||
"quinn-udp",
|
||||
"rand 0.7.3",
|
||||
"rcgen",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"solana-metrics",
|
||||
"solana-perf",
|
||||
"solana-sdk",
|
||||
|
@ -4188,17 +4298,37 @@ dependencies = [
|
|||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.23.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
|
||||
dependencies = [
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"tokio",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
|
||||
dependencies = [
|
||||
"rustls 0.21.1",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.14"
|
||||
|
@ -4218,9 +4348,9 @@ checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181"
|
|||
dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-rustls 0.23.4",
|
||||
"tungstenite",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
|
@ -4350,7 +4480,7 @@ dependencies = [
|
|||
"httparse",
|
||||
"log",
|
||||
"rand 0.8.5",
|
||||
"rustls",
|
||||
"rustls 0.20.8",
|
||||
"sha-1",
|
||||
"thiserror",
|
||||
"url",
|
||||
|
@ -4474,6 +4604,12 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
|
|
|
@ -34,3 +34,4 @@ spl-token = "3.5.0"
|
|||
|
||||
solana-client = "1.15.2"
|
||||
itertools = "0.10.5"
|
||||
reqwest = "0.11.18"
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import { command, number, option, string, run, boolean, flag } from "cmd-ts";
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
|
||||
import programs from "./programs.json";
|
||||
import {
|
||||
Commitment,
|
||||
Connection,
|
||||
Keypair,
|
||||
LAMPORTS_PER_SOL,
|
||||
Transaction,
|
||||
Commitment,
|
||||
Connection,
|
||||
LAMPORTS_PER_SOL,
|
||||
} from "@solana/web3.js";
|
||||
import { getKeypairFromFile } from "./common_utils";
|
||||
import { deploy_programs } from "./deploy_programs";
|
||||
|
@ -19,286 +18,286 @@ import { MintUtils } from "./general/mint_utils";
|
|||
import { OpenbookConfigurator } from "./openbook-v2/configure_openbook";
|
||||
|
||||
const numberOfAccountsToBeCreated = option({
|
||||
type: number,
|
||||
defaultValue: () => 100,
|
||||
long: "number-of-accounts",
|
||||
type: number,
|
||||
defaultValue: () => 100,
|
||||
long: "number-of-accounts",
|
||||
});
|
||||
|
||||
const endpoint = option({
|
||||
type: string,
|
||||
defaultValue: () => "http://127.0.0.1:8899",
|
||||
long: "url",
|
||||
short: "u",
|
||||
description: "RPC url",
|
||||
type: string,
|
||||
defaultValue: () => "http://127.0.0.1:8899",
|
||||
long: "url",
|
||||
short: "u",
|
||||
description: "RPC url",
|
||||
});
|
||||
|
||||
const authority = option({
|
||||
type: string,
|
||||
defaultValue: () => "~/.config/solana/id.json",
|
||||
long: "authority",
|
||||
short: "a",
|
||||
type: string,
|
||||
defaultValue: () => `${os.homedir()}/.config/solana/id.json`,
|
||||
long: "authority",
|
||||
short: "a",
|
||||
});
|
||||
|
||||
const nbPayers = option({
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-payers",
|
||||
short: "p",
|
||||
description: "Number of payers used for testing",
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-payers",
|
||||
short: "p",
|
||||
description: "Number of payers used for testing",
|
||||
});
|
||||
|
||||
const balancePerPayer = option({
|
||||
type: number,
|
||||
defaultValue: () => 1,
|
||||
long: "payer-balance",
|
||||
short: "b",
|
||||
description: "Balance of payer in SOLs",
|
||||
type: number,
|
||||
defaultValue: () => 1,
|
||||
long: "payer-balance",
|
||||
short: "b",
|
||||
description: "Balance of payer in SOLs",
|
||||
});
|
||||
|
||||
const nbMints = option({
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-mints",
|
||||
short: "m",
|
||||
description: "Number of mints",
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-mints",
|
||||
short: "m",
|
||||
description: "Number of mints",
|
||||
});
|
||||
|
||||
const nbMarkerOrderPerSide = option({
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-market-orders-per-user",
|
||||
short: "o",
|
||||
description: "Number of of market orders per user on each side",
|
||||
type: number,
|
||||
defaultValue: () => 10,
|
||||
long: "number-of-market-orders-per-user",
|
||||
short: "o",
|
||||
description: "Number of of market orders per user on each side",
|
||||
});
|
||||
|
||||
const skipProgramDeployment = flag({
|
||||
type: boolean,
|
||||
defaultValue: () => false,
|
||||
long: "skip-program-deployment",
|
||||
short: "s",
|
||||
description: "Skip deploying programs",
|
||||
type: boolean,
|
||||
defaultValue: () => false,
|
||||
long: "skip-program-deployment",
|
||||
short: "s",
|
||||
description: "Skip deploying programs",
|
||||
});
|
||||
|
||||
const outFile = option({
|
||||
type: string,
|
||||
defaultValue: () => "configure/config.json",
|
||||
long: "output-file",
|
||||
short: "o",
|
||||
type: string,
|
||||
defaultValue: () => "configure/config.json",
|
||||
long: "output-file",
|
||||
short: "o",
|
||||
});
|
||||
|
||||
const app = command({
|
||||
name: "configure",
|
||||
args: {
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile,
|
||||
},
|
||||
handler: ({
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile,
|
||||
}) => {
|
||||
console.log("configuring a new test instance");
|
||||
configure(
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile
|
||||
).then((_) => {
|
||||
console.log("configuration finished");
|
||||
});
|
||||
},
|
||||
name: "configure",
|
||||
args: {
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile,
|
||||
},
|
||||
handler: ({
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile,
|
||||
}) => {
|
||||
console.log("configuring a new test instance");
|
||||
configure(
|
||||
endpoint,
|
||||
numberOfAccountsToBeCreated,
|
||||
authority,
|
||||
nbPayers,
|
||||
balancePerPayer,
|
||||
nbMints,
|
||||
skipProgramDeployment,
|
||||
nbMarkerOrderPerSide,
|
||||
outFile
|
||||
).then((_) => {
|
||||
console.log("configuration finished");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
run(app, process.argv.slice(2));
|
||||
|
||||
// configure part
|
||||
async function configure(
|
||||
endpoint: String,
|
||||
numberOfAccountsToBeCreated: number,
|
||||
authorityFile: String,
|
||||
nbPayers: number,
|
||||
balancePerPayer: number,
|
||||
nbMints: number,
|
||||
skipProgramDeployment: boolean,
|
||||
nbMarkerOrderPerSide: number,
|
||||
outFile: String
|
||||
endpoint: String,
|
||||
numberOfAccountsToBeCreated: number,
|
||||
authorityFile: String,
|
||||
nbPayers: number,
|
||||
balancePerPayer: number,
|
||||
nbMints: number,
|
||||
skipProgramDeployment: boolean,
|
||||
nbMarkerOrderPerSide: number,
|
||||
outFile: String
|
||||
) {
|
||||
// create connections
|
||||
const connection = new Connection(
|
||||
endpoint.toString(),
|
||||
"confirmed" as Commitment
|
||||
);
|
||||
|
||||
// configure authority
|
||||
const authority = getKeypairFromFile(authorityFile);
|
||||
const authorityBalance = await connection.getBalance(authority.publicKey);
|
||||
const requiredBalance =
|
||||
nbPayers * (balancePerPayer * LAMPORTS_PER_SOL) + 100 * LAMPORTS_PER_SOL;
|
||||
if (authorityBalance < requiredBalance) {
|
||||
console.log(
|
||||
"authority may have low balance balance " +
|
||||
authorityBalance +
|
||||
" required balance " +
|
||||
requiredBalance
|
||||
// create connections
|
||||
const connection = new Connection(
|
||||
endpoint.toString(),
|
||||
"confirmed" as Commitment
|
||||
);
|
||||
}
|
||||
|
||||
let programOutputData = programs.map((x) => {
|
||||
let kp = getKeypairFromFile(x.programKeyPath);
|
||||
let emptyCommands: Command[] = [];
|
||||
return {
|
||||
name: x.name,
|
||||
program_id: kp.publicKey,
|
||||
commands: emptyCommands,
|
||||
};
|
||||
});
|
||||
// configure authority
|
||||
const authority = getKeypairFromFile(authorityFile);
|
||||
const authorityBalance = await connection.getBalance(authority.publicKey);
|
||||
const requiredBalance =
|
||||
nbPayers * (balancePerPayer * LAMPORTS_PER_SOL) + 100 * LAMPORTS_PER_SOL;
|
||||
if (authorityBalance < requiredBalance) {
|
||||
console.log(
|
||||
"authority may have low balance balance " +
|
||||
authorityBalance +
|
||||
" required balance " +
|
||||
requiredBalance
|
||||
);
|
||||
}
|
||||
|
||||
let programIds = programOutputData.map((x) => {
|
||||
return x.program_id;
|
||||
});
|
||||
if (!skipProgramDeployment) {
|
||||
console.log("starting program deployment");
|
||||
await deploy_programs(endpoint, authorityFile.toString(), programs);
|
||||
console.log("programs deployed");
|
||||
}
|
||||
|
||||
console.log("Creating Mints");
|
||||
let mintUtils = new MintUtils(connection, authority);
|
||||
let mints = await mintUtils.createMints(nbMints);
|
||||
console.log("Mints created");
|
||||
|
||||
console.log("Configuring openbook-v2");
|
||||
let index = programs.findIndex((x) => x.name === "openbook_v2");
|
||||
let openbookProgramId = programOutputData[index].program_id;
|
||||
let openbookConfigurator = new OpenbookConfigurator(
|
||||
connection,
|
||||
authority,
|
||||
mintUtils,
|
||||
openbookProgramId
|
||||
);
|
||||
let markets = await openbookConfigurator.configureOpenbookV2(mints);
|
||||
programOutputData[index].commands = await openbookConfigurator.getCommands();
|
||||
console.log("Finished configuring openbook");
|
||||
|
||||
console.log("Creating users");
|
||||
|
||||
const chunkSize = 10;
|
||||
console.log("creating " + nbPayers + " in batches of " + chunkSize);
|
||||
let userData : User[] = [];
|
||||
|
||||
for (let i = 0; i < nbPayers; i += chunkSize) {
|
||||
let users = await Promise.all(
|
||||
Array.from(Array(chunkSize).keys()).map((_) =>
|
||||
createUser(connection, authority, balancePerPayer)
|
||||
)
|
||||
);
|
||||
let tokenAccounts = await Promise.all(
|
||||
users.map(
|
||||
/// user is richer than bill gates, but not as rich as certain world leaders
|
||||
async (user) =>
|
||||
await mintUser(
|
||||
connection,
|
||||
authority,
|
||||
mints,
|
||||
mintUtils,
|
||||
user.publicKey,
|
||||
100_000_000_000_000_000
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
let userOpenOrders = await Promise.all(
|
||||
users.map(
|
||||
/// user is crazy betting all his money in crypto market
|
||||
async (user) =>
|
||||
await openbookConfigurator.configureMarketForUser(user, markets)
|
||||
)
|
||||
);
|
||||
|
||||
let userDataBatch = users.map((user, i) => {
|
||||
let programOutputData = programs.map((x) => {
|
||||
let kp = getKeypairFromFile(x.programKeyPath);
|
||||
let emptyCommands: Command[] = [];
|
||||
return {
|
||||
secret: Array.from(user.secretKey),
|
||||
open_orders: userOpenOrders[i],
|
||||
token_data: tokenAccounts[i],
|
||||
name: x.name,
|
||||
program_id: kp.publicKey,
|
||||
commands: emptyCommands,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
userData = userData.concat(userDataBatch);
|
||||
let programIds = programOutputData.map((x) => {
|
||||
return x.program_id;
|
||||
});
|
||||
if (!skipProgramDeployment) {
|
||||
console.log("starting program deployment");
|
||||
await deploy_programs(endpoint, authorityFile.toString(), programs);
|
||||
console.log("programs deployed");
|
||||
}
|
||||
|
||||
console.log("Users created");
|
||||
console.log("Creating Mints");
|
||||
let mintUtils = new MintUtils(connection, authority);
|
||||
let mints = await mintUtils.createMints(nbMints);
|
||||
console.log("Mints created");
|
||||
|
||||
console.log("Filling up orderbook");
|
||||
await Promise.all(
|
||||
userDataBatch.map(async (user, i) => {
|
||||
for (const market of markets) {
|
||||
await openbookConfigurator.fillOrderBook(user, users[i], market, nbMarkerOrderPerSide);
|
||||
}
|
||||
})
|
||||
);
|
||||
console.log("Orderbook filled");
|
||||
console.log("Configuring openbook-v2");
|
||||
let index = programs.findIndex((x) => x.name === "openbook_v2");
|
||||
let openbookProgramId = programOutputData[index].program_id;
|
||||
let openbookConfigurator = new OpenbookConfigurator(
|
||||
connection,
|
||||
authority,
|
||||
mintUtils,
|
||||
openbookProgramId
|
||||
);
|
||||
let markets = await openbookConfigurator.configureOpenbookV2(mints);
|
||||
programOutputData[index].commands = await openbookConfigurator.getCommands();
|
||||
console.log("Finished configuring openbook");
|
||||
|
||||
}
|
||||
console.log("Creating users");
|
||||
|
||||
console.log("Creating accounts");
|
||||
let accounts = await configure_accounts(
|
||||
connection,
|
||||
authority,
|
||||
numberOfAccountsToBeCreated,
|
||||
programIds
|
||||
);
|
||||
const chunkSize = 10;
|
||||
console.log("creating " + nbPayers + " in batches of " + chunkSize);
|
||||
let userData: User[] = [];
|
||||
|
||||
// adding known accounts
|
||||
const marketAccountsList = markets
|
||||
.map((market) => [
|
||||
market.asks,
|
||||
market.bids,
|
||||
market.market_pk,
|
||||
market.oracle,
|
||||
market.quote_vault,
|
||||
market.base_vault,
|
||||
market.base_mint,
|
||||
market.quote_mint,
|
||||
])
|
||||
.flat();
|
||||
const userAccountsList = userData
|
||||
.map((user) => {
|
||||
const allOpenOrdersAccounts = user.open_orders
|
||||
.map((x) => x.open_orders)
|
||||
for (let i = 0; i < nbPayers; i += chunkSize) {
|
||||
let users = await Promise.all(
|
||||
Array.from(Array(chunkSize).keys()).map((_) =>
|
||||
createUser(connection, authority, balancePerPayer)
|
||||
)
|
||||
);
|
||||
let tokenAccounts = await Promise.all(
|
||||
users.map(
|
||||
/// user is richer than bill gates, but not as rich as certain world leaders
|
||||
async (user) =>
|
||||
await mintUser(
|
||||
connection,
|
||||
authority,
|
||||
mints,
|
||||
mintUtils,
|
||||
user.publicKey,
|
||||
100_000_000_000_000_000
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
let userOpenOrders = await Promise.all(
|
||||
users.map(
|
||||
/// user is crazy betting all his money in crypto market
|
||||
async (user) =>
|
||||
await openbookConfigurator.configureMarketForUser(user, markets)
|
||||
)
|
||||
);
|
||||
|
||||
let userDataBatch = users.map((user, i) => {
|
||||
return {
|
||||
secret: Array.from(user.secretKey),
|
||||
open_orders: userOpenOrders[i],
|
||||
token_data: tokenAccounts[i],
|
||||
};
|
||||
});
|
||||
|
||||
userData = userData.concat(userDataBatch);
|
||||
|
||||
console.log("Users created");
|
||||
|
||||
console.log("Filling up orderbook");
|
||||
await Promise.all(
|
||||
userDataBatch.map(async (user, i) => {
|
||||
for (const market of markets) {
|
||||
await openbookConfigurator.fillOrderBook(user, users[i], market, nbMarkerOrderPerSide);
|
||||
}
|
||||
})
|
||||
);
|
||||
console.log("Orderbook filled");
|
||||
|
||||
}
|
||||
|
||||
console.log("Creating accounts");
|
||||
let accounts = await configure_accounts(
|
||||
connection,
|
||||
authority,
|
||||
numberOfAccountsToBeCreated,
|
||||
programIds
|
||||
);
|
||||
|
||||
// adding known accounts
|
||||
const marketAccountsList = markets
|
||||
.map((market) => [
|
||||
market.asks,
|
||||
market.bids,
|
||||
market.market_pk,
|
||||
market.oracle,
|
||||
market.quote_vault,
|
||||
market.base_vault,
|
||||
market.base_mint,
|
||||
market.quote_mint,
|
||||
])
|
||||
.flat();
|
||||
const allTokenAccounts = user.token_data.map((x) => x.token_account);
|
||||
return allOpenOrdersAccounts.concat(allTokenAccounts);
|
||||
})
|
||||
.flat();
|
||||
accounts = accounts.concat(marketAccountsList).concat(userAccountsList);
|
||||
const userAccountsList = userData
|
||||
.map((user) => {
|
||||
const allOpenOrdersAccounts = user.open_orders
|
||||
.map((x) => x.open_orders)
|
||||
.flat();
|
||||
const allTokenAccounts = user.token_data.map((x) => x.token_account);
|
||||
return allOpenOrdersAccounts.concat(allTokenAccounts);
|
||||
})
|
||||
.flat();
|
||||
accounts = accounts.concat(marketAccountsList).concat(userAccountsList);
|
||||
|
||||
console.log("Accounts created");
|
||||
console.log("Accounts created");
|
||||
|
||||
let outputFile: OutputFile = {
|
||||
programs: programOutputData,
|
||||
known_accounts: accounts,
|
||||
users: userData,
|
||||
mints,
|
||||
markets,
|
||||
};
|
||||
let outputFile: OutputFile = {
|
||||
programs: programOutputData,
|
||||
known_accounts: accounts,
|
||||
users: userData,
|
||||
mints,
|
||||
markets,
|
||||
};
|
||||
|
||||
console.log("creating output file");
|
||||
fs.writeFileSync(outFile.toString(), JSON.stringify(outputFile));
|
||||
console.log("creating output file");
|
||||
fs.writeFileSync(outFile.toString(), JSON.stringify(outputFile));
|
||||
}
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
use crate::cli::Args;
|
||||
use crate::{cli::Args, rpc_client::CustomRpcClient};
|
||||
use itertools::Itertools;
|
||||
use rand::rngs::StdRng;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||
use serde::Serialize;
|
||||
use solana_program::hash::Hash;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub type BlockHashGetter = Arc<RwLock<Hash>>;
|
||||
use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait Benchmark: Clone + Send + 'static {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: Duration,
|
||||
random_number: u64,
|
||||
) -> anyhow::Result<Run>;
|
||||
) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize)]
|
||||
|
@ -54,19 +51,22 @@ impl Bencher {
|
|||
let start = Instant::now();
|
||||
let mut random = StdRng::seed_from_u64(0);
|
||||
let futs = (0..args.threads).map(|_| {
|
||||
let rpc_client = args.get_rpc_client();
|
||||
let mut rpc_client = args.get_rpc_client();
|
||||
let duration = args.get_duration_to_run_test();
|
||||
let random_number = random.gen();
|
||||
let instance = instant.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
instance
|
||||
.run(rpc_client.clone(), duration, random_number)
|
||||
.run(&mut rpc_client, duration, random_number)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
rpc_client.into()
|
||||
})
|
||||
});
|
||||
|
||||
let all_results = futures::future::try_join_all(futs).await?;
|
||||
let all_results: Vec<Run> = futures::future::try_join_all(futs).await?;
|
||||
|
||||
let time = start.elapsed();
|
||||
|
||||
|
@ -88,7 +88,7 @@ impl Bencher {
|
|||
.sorted_by_key(|(_e, c)| *c)
|
||||
.rev()
|
||||
.take(5)
|
||||
.map(|(e, c)| ((*e).clone(), c.clone()))
|
||||
.map(|(e, c)| ((*e).clone(), *c))
|
||||
.collect_vec();
|
||||
|
||||
Ok(Stats {
|
||||
|
|
16
src/cli.rs
16
src/cli.rs
|
@ -5,12 +5,13 @@ use futures::StreamExt;
|
|||
use solana_client::{
|
||||
nonblocking::pubsub_client::PubsubClient, rpc_config::RpcTransactionLogsConfig,
|
||||
};
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
|
||||
use solana_sdk::hash::Hash;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{
|
||||
openbook::simulate_place_orders::SimulateOpenbookV2PlaceOrder,
|
||||
rpc_client::CustomRpcClient,
|
||||
solana_runtime::{
|
||||
accounts_fetching::AccountsFetchingTests, get_block::GetBlockTest, get_slot::GetSlotTest,
|
||||
send_and_get_status_memo::SendAndConfrimTesting,
|
||||
|
@ -76,13 +77,10 @@ impl Args {
|
|||
match res {
|
||||
Ok((mut stream, _)) => loop {
|
||||
let log = stream.next().await;
|
||||
match log {
|
||||
Some(log) => {
|
||||
for log_s in log.value.logs {
|
||||
println!("{}", log_s);
|
||||
}
|
||||
if let Some(log) = log {
|
||||
for log_s in log.value.logs {
|
||||
println!("{}", log_s);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
|
@ -125,7 +123,7 @@ impl Args {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_rpc_client(&self) -> Arc<RpcClient> {
|
||||
Arc::new(RpcClient::new(self.rpc_addr.clone()))
|
||||
pub fn get_rpc_client(&self) -> CustomRpcClient {
|
||||
CustomRpcClient::new(self.rpc_addr.clone())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,12 +83,3 @@ pub struct Config {
|
|||
pub mints: Vec<String>,
|
||||
pub markets: Vec<Market>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn get_payers(&self) -> Vec<Keypair> {
|
||||
self.users
|
||||
.iter()
|
||||
.map(|x| Keypair::from_bytes(x.secret.as_slice()).unwrap())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
pub mod bencher;
|
||||
mod bencher;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod openbook;
|
||||
mod rpc_client;
|
||||
mod solana_runtime;
|
||||
mod test_registry;
|
||||
mod utils;
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
use crate::bencher::{Bencher, Benchmark, Run, Stats};
|
||||
use crate::config::{Market, User};
|
||||
use crate::test_registry::TestingTask;
|
||||
use crate::utils::noop;
|
||||
use crate::{
|
||||
bencher::{Bencher, Benchmark, Stats},
|
||||
config::{Market, User},
|
||||
rpc_client::CustomRpcClient,
|
||||
test_registry::TestingTask,
|
||||
utils::noop,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use rand::rngs::StdRng;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::compute_budget;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::{
|
||||
compute_budget,
|
||||
hash::Hash,
|
||||
instruction::{AccountMeta, Instruction},
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signer::Signer,
|
||||
transaction::Transaction,
|
||||
};
|
||||
use std::mem::size_of;
|
||||
use std::{str::FromStr, sync::Arc, time::Instant};
|
||||
use std::{mem::size_of, str::FromStr, sync::Arc, time::Instant};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -86,7 +85,7 @@ impl TestingTask for SimulateOpenbookV2PlaceOrder {
|
|||
}
|
||||
|
||||
fn get_name(&self) -> String {
|
||||
format!("Simulating openbook place orders")
|
||||
"Simulating openbook place orders".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,14 +102,13 @@ pub struct SimulateOpenbookV2PlaceOrderBench {
|
|||
impl Benchmark for SimulateOpenbookV2PlaceOrderBench {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: std::time::Duration,
|
||||
random_number: u64,
|
||||
) -> anyhow::Result<crate::bencher::Run> {
|
||||
let mut result = Run::default();
|
||||
|
||||
) -> anyhow::Result<()> {
|
||||
let mut rng = StdRng::seed_from_u64(random_number);
|
||||
let start = Instant::now();
|
||||
|
||||
while start.elapsed() < duration {
|
||||
let mut place_order_ix = self.place_order_cmd.clone();
|
||||
let market = self.markets.choose(&mut rng).cloned().unwrap();
|
||||
|
@ -148,9 +146,7 @@ impl Benchmark for SimulateOpenbookV2PlaceOrderBench {
|
|||
assert!(bytes.len() + 8 == place_order_ix.len());
|
||||
|
||||
// copy the instruction data
|
||||
for i in 0..bytes.len() {
|
||||
place_order_ix[8 + i] = bytes[i];
|
||||
}
|
||||
place_order_ix[8..(bytes.len() + 8)].copy_from_slice(&bytes[..]);
|
||||
|
||||
let token_account = if side {
|
||||
base_token_account
|
||||
|
@ -189,18 +185,9 @@ impl Benchmark for SimulateOpenbookV2PlaceOrderBench {
|
|||
recent_blockhash,
|
||||
);
|
||||
|
||||
match rpc_client.simulate_transaction(&transaction).await {
|
||||
Ok(_) => {
|
||||
result.requests_completed += 1;
|
||||
result.bytes_received += 0;
|
||||
}
|
||||
Err(e) => {
|
||||
result.requests_failed += 1;
|
||||
result.errors.push(format!("{:?}", e.kind()));
|
||||
}
|
||||
}
|
||||
result.bytes_sent += 0;
|
||||
rpc_client.raw_simulate_transaction(transaction).await;
|
||||
}
|
||||
Ok(result)
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use bytes::Bytes;
|
||||
use reqwest::header::CONTENT_TYPE;
|
||||
use serde_json::{json, Value};
|
||||
use solana_client::rpc_request::RpcRequest;
|
||||
use solana_program::pubkey::Pubkey;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_rpc_client::rpc_client::SerializableTransaction;
|
||||
|
||||
use crate::bencher::Run;
|
||||
|
||||
#[derive(derive_more::Deref)]
|
||||
pub struct CustomRpcClient {
|
||||
client: reqwest::Client,
|
||||
url: String,
|
||||
id: AtomicU64,
|
||||
metric: Run,
|
||||
#[deref]
|
||||
rpc_client: RpcClient,
|
||||
}
|
||||
|
||||
// Don't transfer id and bytes_sent
|
||||
impl Clone for CustomRpcClient {
|
||||
fn clone(&self) -> Self {
|
||||
Self::new(self.url.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CustomRpcClient> for Run {
|
||||
fn from(val: CustomRpcClient) -> Self {
|
||||
val.metric
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomRpcClient {
|
||||
pub fn new(url: String) -> Self {
|
||||
let client = reqwest::Client::new();
|
||||
Self {
|
||||
client,
|
||||
rpc_client: RpcClient::new(url.clone()),
|
||||
url,
|
||||
id: 1.into(),
|
||||
metric: Run::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn raw_get_slot(&mut self) {
|
||||
self.send(RpcRequest::GetSlot, Value::Null).await
|
||||
}
|
||||
|
||||
pub async fn serialize_tx(tx: impl SerializableTransaction) -> String {
|
||||
let tx = bincode::serialize(&tx).unwrap();
|
||||
bs58::encode(tx).into_string()
|
||||
}
|
||||
|
||||
pub async fn raw_get_block(&mut self, slot: impl Into<u64>) {
|
||||
self.send(RpcRequest::GetBlock, json! {[slot.into()]}).await
|
||||
}
|
||||
|
||||
pub async fn raw_get_multiple_accounts(&mut self, accounts: Vec<Pubkey>) {
|
||||
let accounts: Vec<String> = accounts
|
||||
.into_iter()
|
||||
.map(|pubkey| pubkey.to_string())
|
||||
.collect();
|
||||
|
||||
self.send(RpcRequest::GetMultipleAccounts, json!([accounts]))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn raw_send_transaction(&mut self, tx: impl SerializableTransaction) {
|
||||
let tx = Self::serialize_tx(tx).await;
|
||||
|
||||
self.send(RpcRequest::SendTransaction, json! {[tx]}).await
|
||||
}
|
||||
|
||||
pub async fn raw_simulate_transaction(&mut self, tx: impl SerializableTransaction) {
|
||||
let tx = Self::serialize_tx(tx).await;
|
||||
|
||||
self.send(RpcRequest::SimulateTransaction, json! {[tx]})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn send(&mut self, request: RpcRequest, params: Value) {
|
||||
let id = self.id.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
let req_raw_body = request
|
||||
.build_request_json(id, params)
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let bytes_sent = req_raw_body.len();
|
||||
self.metric.bytes_sent += bytes_sent as u64;
|
||||
|
||||
let err = match self.send_raw(req_raw_body).await {
|
||||
Ok(res_bytes) => {
|
||||
self.metric.bytes_received += res_bytes.len() as u64;
|
||||
|
||||
let res: Value =
|
||||
serde_json::from_slice(&res_bytes).expect("Server invalid response json");
|
||||
|
||||
if res.get("result").is_some() {
|
||||
self.metric.requests_completed += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
res["error"].to_string()
|
||||
}
|
||||
Err(err) => err.to_string(),
|
||||
};
|
||||
|
||||
self.metric.errors.push(err);
|
||||
self.metric.requests_failed += 1;
|
||||
}
|
||||
|
||||
pub async fn send_raw(&self, req_raw_body: Vec<u8>) -> anyhow::Result<Bytes> {
|
||||
Ok(self
|
||||
.client
|
||||
.post(&self.url)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(req_raw_body)
|
||||
.send()
|
||||
.await?
|
||||
.bytes()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
use async_trait::async_trait;
|
||||
use const_env::from_env;
|
||||
use rand::{seq::IteratorRandom, SeedableRng};
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer};
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
use std::str::FromStr;
|
||||
use tokio::time::Instant;
|
||||
|
||||
use crate::{
|
||||
bencher::{Bencher, Benchmark, Run, Stats},
|
||||
bencher::{Bencher, Benchmark, Stats},
|
||||
config::Config,
|
||||
rpc_client::CustomRpcClient,
|
||||
test_registry::TestingTask,
|
||||
};
|
||||
|
||||
|
@ -56,15 +56,15 @@ pub struct GetAccountsBench {
|
|||
impl Benchmark for GetAccountsBench {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: std::time::Duration,
|
||||
random_number: u64,
|
||||
) -> anyhow::Result<crate::bencher::Run> {
|
||||
let mut result = Run::default();
|
||||
) -> anyhow::Result<()> {
|
||||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(random_number);
|
||||
let number_of_fetched_accounts =
|
||||
NB_OF_ACCOUNTS_FETCHED_PER_TASK.min(self.accounts_list.len());
|
||||
let start = Instant::now();
|
||||
|
||||
while start.elapsed() < duration {
|
||||
let accounts = self
|
||||
.accounts_list
|
||||
|
@ -72,18 +72,9 @@ impl Benchmark for GetAccountsBench {
|
|||
.copied()
|
||||
.choose_multiple(&mut rng, number_of_fetched_accounts);
|
||||
|
||||
match rpc_client.get_multiple_accounts(accounts.as_slice()).await {
|
||||
Ok(_) => {
|
||||
result.requests_completed += 1;
|
||||
result.bytes_received += 0;
|
||||
}
|
||||
Err(e) => {
|
||||
result.requests_failed += 1;
|
||||
result.errors.push(format!("{:?}", e.kind()));
|
||||
}
|
||||
}
|
||||
result.bytes_sent += 0;
|
||||
rpc_client.raw_get_multiple_accounts(accounts).await
|
||||
}
|
||||
Ok(result)
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use log::info;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::slot_history::Slot;
|
||||
|
||||
use crate::{
|
||||
bencher::{Bencher, Benchmark, Run, Stats},
|
||||
bencher::{Bencher, Benchmark, Stats},
|
||||
cli::Args,
|
||||
config::Config,
|
||||
rpc_client::CustomRpcClient,
|
||||
test_registry::TestingTask,
|
||||
};
|
||||
|
||||
|
@ -19,7 +16,7 @@ pub struct GetBlockTest;
|
|||
#[async_trait::async_trait]
|
||||
impl TestingTask for GetBlockTest {
|
||||
async fn test(&self, args: Args, _: Config) -> anyhow::Result<Stats> {
|
||||
let slot = { args.get_rpc_client().get_slot().await.unwrap() };
|
||||
let slot = args.get_rpc_client().get_slot().await.unwrap();
|
||||
let instant = GetBlockBench { slot };
|
||||
let metric = Bencher::bench::<GetBlockBench>(instant, args).await?;
|
||||
info!("{} {}", self.get_name(), serde_json::to_string(&metric)?);
|
||||
|
@ -40,27 +37,16 @@ pub struct GetBlockBench {
|
|||
impl Benchmark for GetBlockBench {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: Duration,
|
||||
_: u64,
|
||||
) -> anyhow::Result<Run> {
|
||||
let mut result = Run::default();
|
||||
|
||||
) -> anyhow::Result<()> {
|
||||
let start = Instant::now();
|
||||
|
||||
while start.elapsed() < duration {
|
||||
match rpc_client.get_block(self.slot).await {
|
||||
Ok(_) => {
|
||||
result.requests_completed += 1;
|
||||
result.bytes_received += 0;
|
||||
}
|
||||
Err(e) => {
|
||||
result.requests_failed += 1;
|
||||
result.errors.push(format!("{:?}", e.kind()));
|
||||
}
|
||||
}
|
||||
result.bytes_sent += 0;
|
||||
rpc_client.raw_get_block(self.slot).await;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use log::info;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
|
||||
use crate::bencher::{Bencher, Benchmark, Run, Stats};
|
||||
use crate::{cli::Args, config::Config, test_registry::TestingTask};
|
||||
use crate::{
|
||||
bencher::{Bencher, Benchmark, Stats},
|
||||
cli::Args,
|
||||
config::Config,
|
||||
rpc_client::CustomRpcClient,
|
||||
test_registry::TestingTask,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GetSlotTest;
|
||||
|
@ -28,27 +31,16 @@ impl TestingTask for GetSlotTest {
|
|||
impl Benchmark for GetSlotTest {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: Duration,
|
||||
_: u64,
|
||||
) -> anyhow::Result<Run> {
|
||||
let mut result = Run::default();
|
||||
|
||||
) -> anyhow::Result<()> {
|
||||
let start = Instant::now();
|
||||
|
||||
while start.elapsed() < duration {
|
||||
match rpc_client.get_slot().await {
|
||||
Ok(_) => {
|
||||
result.requests_completed += 1;
|
||||
result.bytes_received += 0;
|
||||
}
|
||||
Err(e) => {
|
||||
result.requests_failed += 1;
|
||||
result.errors.push(format!("{:?}", e.kind()));
|
||||
}
|
||||
}
|
||||
result.bytes_sent += 0;
|
||||
rpc_client.raw_get_slot().await;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::{
|
||||
bencher::{Bencher, Benchmark, Run, Stats},
|
||||
bencher::{Bencher, Benchmark, Stats},
|
||||
rpc_client::CustomRpcClient,
|
||||
test_registry::TestingTask,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use rand::{distributions::Alphanumeric, prelude::Distribution, seq::SliceRandom, SeedableRng};
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::{
|
||||
hash::Hash, instruction::Instruction, message::Message, pubkey::Pubkey, signature::Keypair,
|
||||
signer::Signer, transaction::Transaction,
|
||||
|
@ -61,12 +61,10 @@ struct SendMemoTransactionsBench {
|
|||
impl Benchmark for SendMemoTransactionsBench {
|
||||
async fn run(
|
||||
self,
|
||||
rpc_client: Arc<RpcClient>,
|
||||
rpc_client: &mut CustomRpcClient,
|
||||
duration: std::time::Duration,
|
||||
random_number: u64,
|
||||
) -> anyhow::Result<crate::bencher::Run> {
|
||||
let mut result = Run::default();
|
||||
|
||||
) -> anyhow::Result<()> {
|
||||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(random_number);
|
||||
let start = Instant::now();
|
||||
while start.elapsed() < duration {
|
||||
|
@ -74,19 +72,10 @@ impl Benchmark for SendMemoTransactionsBench {
|
|||
let payer = self.payers.choose(&mut rng).unwrap();
|
||||
|
||||
let blockhash = { *self.block_hash.read().await };
|
||||
let tx = create_memo_tx(&msg, &payer, blockhash);
|
||||
match rpc_client.send_transaction(&tx).await {
|
||||
Ok(_) => {
|
||||
result.requests_completed += 1;
|
||||
result.bytes_received += 0;
|
||||
}
|
||||
Err(e) => {
|
||||
result.requests_failed += 1;
|
||||
result.errors.push(format!("{:?}", e.kind()));
|
||||
}
|
||||
}
|
||||
result.bytes_sent += 0;
|
||||
let tx = create_memo_tx(&msg, payer, blockhash);
|
||||
let _ = rpc_client.raw_send_transaction(tx).await;
|
||||
}
|
||||
Ok(result)
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue