Compare commits

...

78 Commits

Author SHA1 Message Date
31f7b3782e Fix Blocktree Config (#7399) (#7468)
automerge
2019-12-13 00:16:19 -08:00
d6169f92c1 Add vote-update-validator subcommand
(cherry picked from commit f7a87d5e52)
2019-12-13 00:19:10 -07:00
7df72d36c4 Publish solana-docker releases (#7460) (#7462)
automerge
2019-12-12 16:50:23 -08:00
5318cdac8f Add solana-watchtower program 2019-12-12 16:21:39 -07:00
00434d5e6e Clarify show-vote-account/uptime output: "node id" really means "validator identity" (#7458)
automerge
2019-12-12 14:50:44 -08:00
ebf644ddef Add uptime column to show-validators (#7441) (#7445)
automerge
2019-12-12 08:27:50 -08:00
5e4fe9c67b Bump version to 0.21.4 2019-12-11 21:35:45 -07:00
1b65f9189e Add special handling for snapshot root slot in get_confirmed_block (bp #7430) (#7434)
automerge
2019-12-11 14:44:42 -08:00
57d91c9da0 Fix sigverify metrics (#7393) (#7405)
automerge
2019-12-10 12:10:23 -08:00
a6e6ec63f1 Better space out show-stake-history columns (#7403)
automerge
2019-12-10 08:56:31 -08:00
b8b1e57df4 Fix offline stakes payer (#7385) (#7394)
automerge
2019-12-09 23:44:51 -08:00
969afe54c2 Improve get-epoch-info output for longer epoch durations (#7392)
automerge
2019-12-09 23:17:18 -08:00
5a8d4dcbd7 Fix stable metrics graph: "Bank Height / Slot Distance ($hostid)" 2019-12-09 22:57:48 -07:00
685ef72288 Continue processing the ledger on InvalidTickCount errors (#7387)
automerge
2019-12-09 16:24:26 -08:00
521fd755ac Fix Erasure Index (#7319) (#7371)
automerge
2019-12-09 14:22:26 -08:00
74fe6163c6 Support local cluster edge case testing (#7135) (#7382)
automerge
2019-12-09 13:42:16 -08:00
6e592dba17 Remove redundant check (#7369) (#7375)
automerge
2019-12-09 01:58:53 -08:00
625a9fd932 Properly set parallelism (#7370) (#7372)
automerge
2019-12-09 01:03:35 -08:00
5d37a0d108 Bump version to 0.21.3 2019-12-08 22:55:06 -07:00
68cb6aa1af no lockups for community (bp #7366) (#7367)
automerge
2019-12-08 20:57:00 -08:00
9d0cb47367 500M SOL (bp #7361) (#7365)
automerge
2019-12-08 15:37:25 -08:00
569d0ccb4d Add argument to configure the authorized pubkey for the bootstrap leader's stake (#7362) (#7363)
automerge
2019-12-08 13:40:12 -08:00
ffe17566f1 Adjust show-validators column alignment (#7359) (#7360)
automerge
2019-12-08 09:39:39 -08:00
293ad196f3 Account for all tokens at genesis (bp #7350) (#7358)
automerge
2019-12-08 09:07:39 -08:00
729e1159aa Add Forbole ValidatorInfo (#7355) (#7357)
automerge
2019-12-07 23:19:25 -08:00
f9d354f711 Add Stake Capital ValidatorInfo (#7346) (#7347)
automerge
2019-12-07 01:39:30 -08:00
f9849b515b getVoteAccounts RPC API no longer returns "idle" vote accounts, take II (bp #7344) (#7345)
automerge
2019-12-07 00:52:12 -08:00
fdc0276ed1 Update cargo version to 0.21.2 (#7342) 2019-12-06 21:32:39 -05:00
08569c81e9 getVoteAccounts RPC API no longer returns "idle" vote accounts (#7339) (#7341)
automerge
2019-12-06 18:13:46 -08:00
3ba89f8363 Add more pool tokens (#7338) (#7340)
automerge

(cherry picked from commit 8a908a6864)
2019-12-06 18:04:26 -07:00
9161dbc08e Fix typo (#7336) (#7337)
(cherry picked from commit 2d6ed7142f)
2019-12-06 16:50:33 -07:00
a1b2fa295a cli: Confirm recovered pubkeys (#7316) (#7321)
automerge
2019-12-06 13:34:32 -08:00
4f33eaa9dd Increase signature confirmation timeout to fix wallet sanity (#7283) (#7332)
automerge
2019-12-06 13:29:33 -08:00
3718bab078 Add spare validator accounts (#7330)
automerge
2019-12-06 11:55:24 -08:00
dfc48705a4 more genesis (#7291) 2019-12-06 10:50:26 -07:00
f59115b503 bs58 (#7252) 2019-12-06 10:49:14 -07:00
cac467118e Update name 2019-12-06 10:15:51 -07:00
d0718075a7 Add pools (#7324) 2019-12-06 09:27:00 -07:00
ad55cc79b3 Add verify of keypair (#7301) (#7322)
automerge
2019-12-06 08:26:33 -08:00
5111cc10ca Add ChainFlow ValidatorInfo 2019-12-06 09:23:20 -07:00
a1736606dc Fail fast if account paths cannot be canonicalized (#7300) (#7315)
automerge
2019-12-05 19:45:39 -08:00
bae659b9c7 Add docs for using a paper wallet with solana cli (#7311) (#7317)
automerge
2019-12-05 19:38:18 -08:00
c480c2225d Add RockX ValidatorInfo (#7310) (#7312)
automerge
2019-12-05 18:55:29 -08:00
52771c472e Add ChorusOne ValidatorInfo (#7306) (#7308)
automerge
2019-12-05 15:31:12 -08:00
5ce21827c8 Only serialize rooted append vecs (#7281) (#7307)
automerge
2019-12-05 15:02:55 -08:00
a2c4a70fbf Canonicalize paths before symlink-ing when generating snapshots (#7294) (#7299)
automerge
2019-12-05 12:34:42 -08:00
d6e5f78834 custodian signs withdraw (#7286) (#7290)
automerge
2019-12-04 21:57:47 -08:00
74eb408460 vote update node_id (#7253) (#7285)
automerge
2019-12-04 18:24:00 -08:00
a4c6576ba4 Import validators (#7282) (#7284)
automerge
2019-12-04 18:02:00 -08:00
1fcc391a8d Fix typo, grammar, and formatting in Paper Wallet documentation (#7268) (#7271)
automerge
2019-12-04 13:19:16 -08:00
2970f960a4 Sanitize whitespace in seed phrase input (#7260) (#7267)
automerge
2019-12-04 12:32:28 -08:00
d06bea7fb2 genesis validators (#7235) (#7256)
* genesis validators (#7235)

* genesis validators

* slp1 nodes get 500SOL

* no commission

* clippy
2019-12-04 11:34:21 -08:00
45a57e8513 Use wrappable code snippet for paper wallet installation (#7261) (#7262)
automerge
2019-12-04 09:33:49 -08:00
3622e513aa make tx fee's burn percent in proper range (#7226) (#7228)
automerge
2019-12-04 03:11:25 -08:00
c4e1faa853 genesis config hashmaps (#7107) (#7255)
automerge
2019-12-03 23:44:24 -08:00
905428bee6 Allow generation of longer seed phrases with keygen (#7210) (#7249)
automerge
2019-12-03 21:56:06 -08:00
9596e7772c commission as percent (#7239) (#7251)
automerge
2019-12-03 21:42:01 -08:00
5294fe6292 Remove extra installation options for paper wallet (#7245) (#7247)
automerge
2019-12-03 20:12:57 -08:00
571cf53827 Add Paper Wallet Installation page to sidebar (#7242) (#7243) 2019-12-03 22:13:20 -05:00
35ae76532a Use procedural macro to generate static public keys (bp #7219) (#7241)
automerge
2019-12-03 19:07:19 -08:00
57dce86d5e Update paper wallet documentation (#7223) (#7237)
automerge
2019-12-03 17:32:55 -08:00
797cb01bb8 enforce proper range for rent burn_percent (#7217) (#7224)
automerge
2019-12-03 11:59:16 -08:00
9eded7a227 Prevent passphrase mistakes with confirmation prompt (#7207) (#7211)
(cherry picked from commit b874441a47)
2019-12-03 11:48:13 -07:00
a8d32103d1 Ensure IpEchoServerMessage is not fragmented (#7214) (#7215)
automerge
2019-12-02 23:00:56 -08:00
49d4925856 Fix typo (#7202) (#7205)
automerge
2019-12-02 19:26:42 -08:00
f5fad5b43d Correctly parse ip echo server response and fix broken test (#7196) (#7200)
automerge
2019-12-02 18:11:10 -08:00
4c40f9dbc9 Drop default signature fee by 10x (#7192) (#7193)
automerge
2019-12-02 14:17:37 -08:00
17db734783 Improve error handling when the user mixes up gossip (8001) and RPC (8899) ports (#7158) (#7184)
automerge
2019-12-02 11:52:57 -08:00
6ce9f97254 More conservative purge_zero_lamport_accounts purge logic (#7157) (#7190)
automerge
2019-12-02 11:46:46 -08:00
1688dd6b5c Add Paper Wallet documentation to the book (#7147) (#7161)
automerge
2019-11-26 21:11:18 -08:00
07ffcab857 Update cargo.toml file versions to 0.21.1 (#7156) 2019-11-26 19:11:07 -05:00
de6cf6b7e3 solana-keygen: Support pubkey recovery directly from seed phrase (#7149) (#7150)
automerge
2019-11-26 13:16:48 -08:00
32cf04c77d Ensure beta/stable testnets use public IPs 2019-11-26 11:23:44 -07:00
96df4c772f Add getBlockTime rpc api (#7130) (#7140)
automerge
2019-11-26 00:10:59 -08:00
640c2f88bd mut 2019-11-25 22:49:39 -07:00
82f78a5610 keygen: Support not writing keypairs to disk (#7136) (#7138)
* keygen: Add flag to prevent new from writing keypair to disk

* check_for_overwrite bails, do it before prompts

(cherry picked from commit 506ff5809e)
2019-11-25 22:46:46 -07:00
cf8f8afbc6 Add offline signing support to CLI (#7104) (#7137)
automerge
2019-11-25 21:45:37 -08:00
e6bc92f6c9 Stop open measurement before logging it 2019-11-25 22:20:54 -07:00
171 changed files with 6380 additions and 2633 deletions

853
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -44,12 +44,14 @@ members = [
"runtime",
"sdk",
"sdk-c",
"scripts",
"upload-perf",
"net-utils",
"fixed-buf",
"vote-signer",
"cli",
"rayon-threadlimit",
"watchtower",
]
exclude = [

View File

@ -2,7 +2,7 @@
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-archiver"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -10,10 +10,10 @@ homepage = "https://solana.com/"
[dependencies]
clap = "2.33.0"
console = "0.9.1"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }

View File

@ -2,7 +2,7 @@
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-banking-bench"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -10,11 +10,11 @@ homepage = "https://solana.com/"
[dependencies]
log = "0.4.6"
rayon = "1.2.0"
solana-core = { path = "../core", version = "0.21.0" }
solana-ledger = { path = "../ledger", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-measure = { path = "../measure", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.4" }
solana-ledger = { path = "../ledger", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-measure = { path = "../measure", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
rand = "0.6.5"
crossbeam-channel = "0.3"

View File

@ -2,7 +2,7 @@
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-bench-exchange"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -23,19 +23,19 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-genesis = { path = "../genesis", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-genesis = { path = "../genesis", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-drone = { path = "../drone", version = "0.21.4" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
untrusted = "0.7.0"
ws = "0.9.1"
[dev-dependencies]
solana-local-cluster = { path = "../local-cluster", version = "0.21.0" }
solana-local-cluster = { path = "../local-cluster", version = "0.21.4" }

View File

@ -2,14 +2,14 @@
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-bench-streamer"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
[dependencies]
clap = "2.33.0"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }

View File

@ -2,7 +2,7 @@
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-bench-tps"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -16,24 +16,24 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-genesis = { path = "../genesis", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
solana-librapay-api = { path = "../programs/librapay_api", version = "0.21.0", optional = true }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-measure = { path = "../measure", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-move-loader-program = { path = "../programs/move_loader", version = "0.21.0", optional = true }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-genesis = { path = "../genesis", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-drone = { path = "../drone", version = "0.21.4" }
solana-librapay-api = { path = "../programs/librapay_api", version = "0.21.4", optional = true }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-measure = { path = "../measure", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-move-loader-program = { path = "../programs/move_loader", version = "0.21.4", optional = true }
[dev-dependencies]
serial_test = "0.2.0"
serial_test_derive = "0.2.0"
solana-local-cluster = { path = "../local-cluster", version = "0.21.0" }
solana-local-cluster = { path = "../local-cluster", version = "0.21.4" }
[features]
move = ["solana-librapay-api", "solana-move-loader-program"]

View File

@ -36,6 +36,10 @@
* [Troubleshooting](running-validator/validator-troubleshoot.md)
* [FAQ](running-validator/validator-faq.md)
* [Running an Archiver](running-archiver.md)
* [Paper Wallet](paper-wallet/README.md)
* [Installation](paper-wallet/installation.md)
* [Creating and Using a Seed Phrase](paper-wallet/keypair.md)
* [Paper Wallet Usage](paper-wallet/usage.md)
* [API Reference](api-reference/README.md)
* [Transaction](api-reference/transaction-api.md)
* [Instruction](api-reference/instruction-api.md)

View File

@ -177,7 +177,7 @@ $ solana send-timestamp <PUBKEY> <PROCESS_ID> --date 2018-12-24T23:59:00
## Usage
### solana-cli
```text
solana-cli 0.21.0
solana-cli 0.21.4
Blockchain, Rebuilt for Scale
USAGE:
@ -467,7 +467,7 @@ FLAGS:
OPTIONS:
--authorized-voter <PUBKEY> Public key of the authorized voter (defaults to vote account)
--authorized-withdrawer <PUBKEY> Public key of the authorized withdrawer (defaults to cli config pubkey)
--commission <NUM> The commission taken on reward redemption (0-255), default: 0
--commission <NUM> The commission taken on reward redemption (0-100), default: 0
-C, --config <PATH> Configuration file to use [default:
~/.config/solana/cli/config.yml]
-u, --url <URL> JSON RPC URL for the solana cluster

View File

@ -18,6 +18,7 @@ To interact with a Solana node inside a JavaScript application, use the [solana-
* [getAccountInfo](jsonrpc-api.md#getaccountinfo)
* [getBalance](jsonrpc-api.md#getbalance)
* [getBlockCommitment](jsonrpc-api.md#getblockcommitment)
* [getBlockTime](jsonrpc-api.md#getblocktime)
* [getClusterNodes](jsonrpc-api.md#getclusternodes)
* [getConfirmedBlock](jsonrpc-api.md#getconfirmedblock)
* [getEpochInfo](jsonrpc-api.md#getepochinfo)
@ -155,7 +156,7 @@ The result value will be an RpcResponse JSON object containing an AccountInfo JS
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getAccountInfo", "params":["2gVkYWexTHR5Hb2aLeQN3tnngvWzisFKXDUPrgMHpdST"]}' http://localhost:8899
// Result
{"jsonrpc":"2.0","result":{"context":{"slot":1},"value":{"executable":false,"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"lamports":1,"data":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0.21.0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]}},"id":1}
{"jsonrpc":"2.0","result":{"context":{"slot":1},"value":{"executable":false,"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"lamports":1,"data":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0.21.4,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]}},"id":1}
```
### getBalance
@ -209,6 +210,31 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "m
{"jsonrpc":"2.0","result":[{"commitment":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,32]},42],"id":1}
```
### getBlockTime
Returns the estimated production time of a block. Validators report their UTC
time to the ledger on a regular interval. A block's time is calculated as an
offset from the median value of the most recent validator time report.
#### Parameters:
* `u64` - block, identified by Slot
#### Results:
* `null` - block has not yet been produced
* `i64` - estimated production time, as Unix timestamp (seconds since the Unix epoch)
#### Example:
```bash
// Request
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockTime","params":[5]}' http://localhost:8899
// Result
{"jsonrpc":"2.0","result":1574721591,"id":1}
```
### getClusterNodes
Returns information about all the nodes participating in the cluster
@ -687,7 +713,7 @@ The result field will be a JSON object of `current` and `delinquent` accounts, e
* `nodePubkey` - Node public key, as base-58 encoded string
* `activatedStake` - the stake, in lamports, delegated to this vote account and active in this epoch
* `epochVoteAccount` - bool, whether the vote account is staked for this epoch
* `commission`, an 8-bit integer used as a fraction \(commission/MAX\_U8\) for rewards payout
* `commission`, percentage (0-100) of rewards payout owed to the vote account
* `lastVote` - Most recent slot voted on by this vote account
#### Example:
@ -798,7 +824,7 @@ Subscribe to an account to receive notifications when the lamports or data for a
#### Notification Format:
```bash
{"jsonrpc": "2.0","method": "accountNotification", "params": {"result": {"executable":false,"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"lamports":1,"data":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0.21.0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"subscription":0}}
{"jsonrpc": "2.0","method": "accountNotification", "params": {"result": {"executable":false,"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"lamports":1,"data":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0.21.4,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"subscription":0}}
```
### accountUnsubscribe
@ -856,7 +882,7 @@ Subscribe to a program to receive notifications when the lamports or data for a
* `object` - account info JSON object \(see [getAccountInfo](jsonrpc-api.md#getaccountinfo) for field details\)
```bash
{"jsonrpc":"2.0","method":"programNotification","params":{{"result":["8Rshv2oMkPu5E4opXTRyuyBeZBqQ4S477VG26wUTFxUM",{"executable":false,"lamports":1,"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"data":[1,1,1,0,0,0,0,0,0,0.21.0,0,0,0,0,0,0,50,48,49,56,45,49,50,45,50,52,84,50,51,58,53,57,58,48,48,90,235,233,39,152,15,44,117,176,41,89,100,86,45,61,2,44,251,46,212,37,35,118,163,189,247,84,27,235,178,62,55,89,0,0,0,0,50,0,0,0,0,0,0,0,235,233,39,152,15,44,117,176,41,89,100,86,45,61,2,44,251,46,212,37,35,118,163,189,247,84,27,235,178,62,45,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}],"subscription":0}}
{"jsonrpc":"2.0","method":"programNotification","params":{{"result":["8Rshv2oMkPu5E4opXTRyuyBeZBqQ4S477VG26wUTFxUM",{"executable":false,"lamports":1,"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"data":[1,1,1,0,0,0,0,0,0,0.21.4,0,0,0,0,0,0,50,48,49,56,45,49,50,45,50,52,84,50,51,58,53,57,58,48,48,90,235,233,39,152,15,44,117,176,41,89,100,86,45,61,2,44,251,46,212,37,35,118,163,189,247,84,27,235,178,62,55,89,0,0,0,0,50,0,0,0,0,0,0,0,235,233,39,152,15,44,117,176,41,89,100,86,45,61,2,44,251,46,212,37,35,118,163,189,247,84,27,235,178,62,45,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}],"subscription":0}}
```
### programUnsubscribe

View File

@ -16,7 +16,7 @@ The total stake allocated to a Vote account can be calculated by the sum of all
## Vote and Stake accounts
The rewards process is split into two on-chain programs. The Vote program solves the problem of making stakes slashable. The Stake account acts as custodian of the rewards pool, and provides passive delegation. The Stake program is responsible for paying out each staker once the staker proves to the Stake program that its delegate has participated in validating the ledger.
The rewards process is split into two on-chain programs. The Vote program solves the problem of making stakes slashable. The Stake program acts as custodian of the rewards pool and provides for passive delegation. The Stake program is responsible for paying rewards to staker and voter when shown that a staker's delegate has participated in validating the ledger.
### VoteState
@ -228,4 +228,4 @@ Only lamports in excess of effective+activating stake may be withdrawn at any ti
### Lock-up
Stake accounts support the notion of lock-up, wherein the stake account balance is unavailable for withdrawal until a specified time. Lock-up is specified as a slot height, i.e. the minimum slot height that must be reached by the network before the stake account balance is available for withdrawal, except to a specified custodian. This information is gathered when the stake account is created.
Stake accounts support the notion of lock-up, wherein the stake account balance is unavailable for withdrawal until a specified time. Lock-up is specified as an epoch height, i.e. the minimum epoch height that must be reached by the network before the stake account balance is available for withdrawal, unless the transaction is also signed by a specified custodian. This information is gathered when the stake account is created, and stored in the Lockup field of the stake account's state.

View File

@ -81,8 +81,8 @@ With a FEC rate: `16:4`
With FEC rate of `16:16`
* `G = 12800`
* `S = SUM of i=0 -> 32 for binomial(prob_failure = 0.2775, trials = 64, failures = i) = 0.002132`
* `B = (1 - 0.002132) ^ (12800 / 32) = 0.42583`
* `S = SUM of i=0 -> 32 for binomial(prob_failure = 0.2775, trials = 64, failures = i) = 0.0.21.4`
* `B = (1 - 0.0.21.4) ^ (12800 / 32) = 0.42583`
With FEC rate of `32:32`
* `G = 12800`

View File

@ -0,0 +1,24 @@
# Paper Wallet
This document describes how to create and use a paper wallet with the Solana CLI
tools.
{% hint style="info" %}
We do not intend to advise on how to *securely* create or manage paper wallets.
Please research the security concerns carefully.
{% endhint %}
## Overview
Solana provides a key generation tool to derive keys from BIP39 compliant seed
phrases. Solana CLI commands for running a validator and staking tokens all
support keypair input via seed phrases.
To learn more about the BIP39 standard, visit the Bitcoin BIPs Github repository
[here](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
{% page-ref page="installation.md" %}
{% page-ref page="keypair.md" %}
{% page-ref page="usage.md" %}

View File

@ -0,0 +1,51 @@
# Installation Guide
Follow this guide to setup Solana's key generation tool called `solana-keygen`
{% hint style="warn" %}
After installation, ensure your version is `0.21.4` or higher by running `solana-keygen -V`
{% endhint %}
## Download
First, download the latest release tarball from GitHub.
1. Setup download url
```bash
solana_downloads=https://github.com/solana-labs/solana/releases/latest/download
```
2. Specify the download file based on your machine
**MacOS**
```bash
solana_release=solana-release-x86_64-apple-darwin.tar.bz2
```
**Linux**
```bash
solana_release=solana-release-x86_64-unknown-linux-gnu.tar.bz2
```
3. Download
```bash
curl -L -sSf -o solana-release.tar.bz2 $solana_downloads/$solana_release
```
## Extract
Next, extract the tarball
```bash
tar xf solana-release.tar.bz2
```
## Add to "PATH"
Now add the tool to your PATH environment variable with the following command
```bash
export PATH="$(pwd)/solana-release/bin:${PATH}"
```
## Check
Finally, check that `solana-keygen` can be run by running
```bash
solana-keygen -V
```

View File

@ -0,0 +1,70 @@
# Creating a Paper Wallet
Using the `solana-keygen` tool, it is possible to generate new seed phrases as
well as derive a keypair from an existing seed phrase and (optional) passphrase.
The seed phrase and passphrase can be used together as a paper wallet. As long
as you keep your seed phrase and passphrase stored safely, you can use them to
access your account.
{% hint style="info" %}
For more information about how seed phrases work, review this
[Bitcoin Wiki page](https://en.bitcoin.it/wiki/Seed_phrase).
{% endhint %}
## Seed Phrase Generation
Generating a new keypair can be done using the `solana-keygen new` command. The
command will generate a random seed phrase, ask you to enter an optional
passphrase, and then will display the derived public key and the generated seed
phrase for your paper wallet.
```bash
solana-keygen new --no-outfile
```
{% hint style="warning" %}
If the `--no-outfile` flag is **omitted**, the default behavior is to write the
keypair to `~/.config/solana/id.json`
{% endhint %}
{% hint style="info" %}
For added security, increase the seed phrase word count using the `--word-count`
argument
{% endhint %}
For full usage details run:
```bash
solana-keygen new --help
```
## Public Key Derivation
Public keys can be derived from a seed phrase and a passphrase if you choose to
use one. This is useful for using using an offline-generated seed phrase to
derive a valid public key. The `solana-keygen pubkey` command will walk you
through entering your seed phrase and a passphrase if you chose to use one.
```bash
solana-keygen pubkey ASK
```
{% hint style="info" %}
Note that you could potentially use different passphrases for the same seed
phrase. Each unique passphrase will yield a different keypair.
{% endhint %}
The `solana-keygen` tool assumes the use of the BIP39 standard English word
list. If you chose to deviate from the word list or used a different language
for your seed phrase, you can still derive a valid public key but will need to
explicitly skip seed phrase validation.
```bash
solana-keygen pubkey ASK --skip-seed-phrase-validation
```
For full usage details run:
```bash
solana-keygen pubkey --help
```

View File

@ -0,0 +1,73 @@
# Paper Wallet Usage
Solana commands can be run without ever saving a keypair to disk on a machine.
If avoiding writing a private key to disk is a security concern of yours, you've
come to the right place.
{% hint style="warning" %}
Even using this secure input method, it's still possible that a private key gets
written to disk by unencrypted memory swaps. It is the user's responsibility to
protect against this scenario.
{% endhint %}
## Running a Validator
In order to run a validator, you will need to specify an "identity keypair"
which will be used to fund all of the vote transactions signed by your validator.
Rather than specifying a path with `--identity-keypair <PATH>` you can use the
`--ask-seed-phrase` option.
```bash
solana-validator --ask-seed-phrase identity-keypair --ledger ...
[identity-keypair] seed phrase: 🔒
[identity-keypair] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
```
The `--ask-seed-phrase` option accepts multiple keypairs. If you wish to use this
input method for your voting keypair as well you can do the following:
```bash
solana-validator --ask-seed-phrase identity-keypair voting-keypair --ledger ...
[identity-keypair] seed phrase: 🔒
[identity-keypair] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
[voting-keypair] seed phrase: 🔒
[voting-keypair] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
```
Refer to the following page for a comprehensive guide on running a validator:
{% page-ref page="../running-validator/README.md" %}
## Delegating Stake
Solana CLI tooling supports secure keypair input for stake delegation. To do so,
first create a stake account with some SOL. Use the special `ASK` keyword to
trigger a seed phrase input prompt for the stake account and use
`--ask-seed-phrase keypair` to securely input the funding keypair.
```bash
solana create-stake-account ASK 1 SOL --ask-seed-phrase keypair
[stake_account] seed phrase: 🔒
[stake_account] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
[keypair] seed phrase: 🔒
[keypair] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
```
Then, to delegate that stake to a validator, use `--ask-seed-phrase keypair` to
securely input the funding keypair.
```bash
solana delegate-stake --ask-seed-phrase keypair <STAKE_ACCOUNT_PUBKEY> <VOTE_ACCOUNT_PUBKEY>
[keypair] seed phrase: 🔒
[keypair] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue:
```
Refer to the following page for a comprehensive guide on delegating stake:
{% page-ref page="../running-validator/validator-stake.md" %}
---
{% page-ref page="../api-reference/cli.md" %}

View File

@ -1,6 +1,6 @@
[package]
name = "solana-chacha-sys"
version = "0.21.0"
version = "0.21.4"
description = "Solana chacha-sys"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"

View File

@ -86,17 +86,19 @@ nodes=(
--rpc-port 18899"
)
for i in $(seq 1 $extraNodes); do
portStart=$((8100 + i * 50))
portEnd=$((portStart + 49))
nodes+=(
"multinode-demo/validator.sh \
--no-restart \
--dynamic-port-range $portStart-$portEnd
--label dyn$i \
--init-complete-file init-complete-node$((2 + i)).log"
)
done
if [[ extraNodes -gt 0 ]]; then
for i in $(seq 1 $extraNodes); do
portStart=$((8100 + i * 50))
portEnd=$((portStart + 49))
nodes+=(
"multinode-demo/validator.sh \
--no-restart \
--dynamic-port-range $portStart-$portEnd
--label dyn$i \
--init-complete-file init-complete-node$((2 + i)).log"
)
done
fi
numNodes=$((2 + extraNodes))
pids=()
@ -313,7 +315,7 @@ flag_error() {
if ! $skipSetup; then
clear_config_dir "$SOLANA_CONFIG_DIR"
multinode-demo/setup.sh
multinode-demo/setup.sh --hashes-per-tick sleep
else
verifyLedger
fi
@ -365,7 +367,7 @@ while [[ $iteration -le $iterations ]]; do
echo "--- Wallet sanity ($iteration)"
(
set -x
timeout 90s scripts/wallet-sanity.sh --url http://127.0.0.1"$walletRpcPort"
timeout 60s scripts/wallet-sanity.sh --url http://127.0.0.1"$walletRpcPort"
) || flag_error
iteration=$((iteration + 1))

View File

@ -33,7 +33,7 @@ else
fi
if [[ -z $CHANNEL_OR_TAG ]]; then
echo +++ Unable to determine channel to publish into, exiting.
echo +++ Unable to determine channel or tag to publish into, exiting.
exit 0
fi

View File

@ -246,7 +246,7 @@ sanity() {
(
set -x
NO_INSTALL_CHECK=1 \
ci/testnet-sanity.sh beta-testnet-solana-com gce us-west1-b
ci/testnet-sanity.sh beta-testnet-solana-com gce -P us-west1-b
maybe_deploy_software --deploy-if-newer
)
;;
@ -260,7 +260,7 @@ sanity() {
testnet)
(
set -x
ci/testnet-sanity.sh testnet-solana-com gce us-west1-b
ci/testnet-sanity.sh testnet-solana-com gce -P us-west1-b
)
;;
testnet-perf)

View File

@ -1,6 +1,6 @@
[package]
name = "solana-clap-utils"
version = "0.21.0"
version = "0.21.4"
description = "Solana utilities for the clap"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,7 +12,7 @@ edition = "2018"
clap = "2.33.0"
rpassword = "4.0"
semver = "0.9.0"
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
tiny-bip39 = "0.6.2"
url = "2.1.0"

View File

@ -3,8 +3,9 @@ use clap::ArgMatches;
use solana_sdk::{
native_token::sol_to_lamports,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, KeypairUtil},
signature::{read_keypair_file, Keypair, KeypairUtil, Signature},
};
use std::str::FromStr;
// Return parsed values from matches at `name`
pub fn values_of<T>(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<T>>
@ -35,7 +36,7 @@ pub fn keypair_of(matches: &ArgMatches<'_>, name: &str) -> Option<Keypair> {
if let Some(value) = matches.value_of(name) {
if value == ASK_KEYWORD {
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
keypair_from_seed_phrase(name, skip_validation).ok()
keypair_from_seed_phrase(name, skip_validation, true).ok()
} else {
read_keypair_file(value).ok()
}
@ -50,6 +51,20 @@ pub fn pubkey_of(matches: &ArgMatches<'_>, name: &str) -> Option<Pubkey> {
value_of(matches, name).or_else(|| keypair_of(matches, name).map(|keypair| keypair.pubkey()))
}
// Return pubkey/signature pairs for a string of the form pubkey=signature
pub fn pubkeys_sigs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<(Pubkey, Signature)>> {
matches.values_of(name).map(|values| {
values
.map(|pubkey_signer_string| {
let mut signer = pubkey_signer_string.split('=');
let key = Pubkey::from_str(signer.next().unwrap()).unwrap();
let sig = Signature::from_str(signer.next().unwrap()).unwrap();
(key, sig)
})
.collect()
})
}
pub fn amount_of(matches: &ArgMatches<'_>, name: &str, unit: &str) -> Option<u64> {
if matches.value_of(unit) == Some("lamports") {
value_of(matches, name)
@ -172,4 +187,25 @@ mod tests {
fs::remove_file(&outfile).unwrap();
}
#[test]
fn test_pubkeys_sigs_of() {
let key1 = Pubkey::new_rand();
let key2 = Pubkey::new_rand();
let sig1 = Keypair::new().sign_message(&[0u8]);
let sig2 = Keypair::new().sign_message(&[1u8]);
let signer1 = format!("{}={}", key1, sig1);
let signer2 = format!("{}={}", key2, sig2);
let matches = app().clone().get_matches_from(vec![
"test",
"--multiple",
&signer1,
"--multiple",
&signer2,
]);
assert_eq!(
pubkeys_sigs_of(&matches, "multiple"),
Some(vec![(key1, sig1), (key2, sig2)])
);
}
}

View File

@ -1,6 +1,8 @@
use crate::keypair::ASK_KEYWORD;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::read_keypair_file;
use solana_sdk::signature::{read_keypair_file, Signature};
use std::str::FromStr;
// Return an error if a pubkey cannot be parsed.
pub fn is_pubkey(string: String) -> Result<(), String> {
@ -10,6 +12,14 @@ pub fn is_pubkey(string: String) -> Result<(), String> {
}
}
// Return an error if a hash cannot be parsed.
pub fn is_hash(string: String) -> Result<(), String> {
match string.parse::<Hash>() {
Ok(_) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
}
}
// Return an error if a keypair file cannot be parsed.
pub fn is_keypair(string: String) -> Result<(), String> {
read_keypair_file(&string)
@ -32,6 +42,28 @@ pub fn is_pubkey_or_keypair(string: String) -> Result<(), String> {
is_pubkey(string.clone()).or_else(|_| is_keypair(string))
}
// Return an error if string cannot be parsed as pubkey=signature string
pub fn is_pubkey_sig(string: String) -> Result<(), String> {
let mut signer = string.split('=');
match Pubkey::from_str(
signer
.next()
.ok_or_else(|| "Malformed signer string".to_string())?,
) {
Ok(_) => {
match Signature::from_str(
signer
.next()
.ok_or_else(|| "Malformed signer string".to_string())?,
) {
Ok(_) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
}
}
Err(err) => Err(format!("{:?}", err)),
}
}
// Return an error if a url cannot be parsed.
pub fn is_url(string: String) -> Result<(), String> {
match url::Url::parse(&string) {
@ -65,3 +97,24 @@ pub fn is_port(port: String) -> Result<(), String> {
.map(|_| ())
.map_err(|e| format!("{:?}", e))
}
pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
percentage
.parse::<u8>()
.map_err(|e| {
format!(
"Unable to parse input percentage, provided: {}, err: {:?}",
percentage, e
)
})
.and_then(|v| {
if v > 100 {
Err(format!(
"Percentage must be in range of 0 to 100, provided: {}",
v
))
} else {
Ok(())
}
})
}

View File

@ -2,11 +2,18 @@ use crate::ArgConstant;
use bip39::{Language, Mnemonic, Seed};
use clap::values_t;
use rpassword::prompt_password_stderr;
use solana_sdk::signature::{
keypair_from_seed, keypair_from_seed_phrase_and_passphrase, read_keypair_file, Keypair,
KeypairUtil,
use solana_sdk::{
pubkey::Pubkey,
signature::{
keypair_from_seed, keypair_from_seed_phrase_and_passphrase, read_keypair_file, Keypair,
KeypairUtil,
},
};
use std::{
error,
io::{stdin, stdout, Write},
process::exit,
};
use std::error;
// Keyword used to indicate that the user should be asked for a keypair seed phrase
pub const ASK_KEYWORD: &str = "ASK";
@ -41,10 +48,25 @@ impl KeypairWithSource {
}
}
/// Prompts user for a passphrase and then asks for confirmirmation to check for mistakes
pub fn prompt_passphrase(prompt: &str) -> Result<String, Box<dyn error::Error>> {
let passphrase = prompt_password_stderr(&prompt)?;
if !passphrase.is_empty() {
let confirmed = rpassword::prompt_password_stderr("Enter same passphrase again: ")?;
if confirmed != passphrase {
return Err("Passphrases did not match".into());
}
}
Ok(passphrase)
}
/// Reads user input from stdin to retrieve a seed phrase and passphrase for keypair derivation
/// Optionally skips validation of seed phrase
/// Optionally confirms recovered public key
pub fn keypair_from_seed_phrase(
keypair_name: &str,
skip_validation: bool,
confirm_pubkey: bool,
) -> Result<Keypair, Box<dyn error::Error>> {
let seed_phrase = prompt_password_stderr(&format!("[{}] seed phrase: ", keypair_name))?;
let seed_phrase = seed_phrase.trim();
@ -53,15 +75,30 @@ pub fn keypair_from_seed_phrase(
keypair_name,
);
if skip_validation {
let passphrase = prompt_password_stderr(&passphrase_prompt)?;
keypair_from_seed_phrase_and_passphrase(&seed_phrase, &passphrase)
let keypair = if skip_validation {
let passphrase = prompt_passphrase(&passphrase_prompt)?;
keypair_from_seed_phrase_and_passphrase(&seed_phrase, &passphrase)?
} else {
let mnemonic = Mnemonic::from_phrase(seed_phrase, Language::English)?;
let passphrase = prompt_password_stderr(&passphrase_prompt)?;
let sanitized = sanitize_seed_phrase(seed_phrase);
let mnemonic = Mnemonic::from_phrase(sanitized, Language::English)?;
let passphrase = prompt_passphrase(&passphrase_prompt)?;
let seed = Seed::new(&mnemonic, &passphrase);
keypair_from_seed(seed.as_bytes())
keypair_from_seed(seed.as_bytes())?
};
if confirm_pubkey {
let pubkey = Pubkey::new(keypair.public.as_ref());
print!("Recovered pubkey `{:?}`. Continue? (y/n): ", pubkey);
let _ignored = stdout().flush();
let mut input = String::new();
stdin().read_line(&mut input).expect("Unexpected input");
if input.to_lowercase().trim() != "y" {
println!("Exiting");
exit(1);
}
}
Ok(keypair)
}
/// Checks CLI arguments to determine whether a keypair should be:
@ -91,7 +128,7 @@ pub fn keypair_input(
}
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
keypair_from_seed_phrase(keypair_name, skip_validation)
keypair_from_seed_phrase(keypair_name, skip_validation, true)
.map(|keypair| KeypairWithSource::new(keypair, Source::SeedPhrase))
} else if let Some(keypair_file) = matches.value_of(keypair_match_name) {
read_keypair_file(keypair_file).map(|keypair| KeypairWithSource::new(keypair, Source::File))
@ -100,6 +137,13 @@ pub fn keypair_input(
}
}
fn sanitize_seed_phrase(seed_phrase: &str) -> String {
seed_phrase
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
}
#[cfg(test)]
mod tests {
use super::*;
@ -111,4 +155,13 @@ mod tests {
let KeypairWithSource { source, .. } = keypair_input(&arg_matches, "").unwrap();
assert_eq!(source, Source::Generated);
}
#[test]
fn test_sanitize_seed_phrase() {
let seed_phrase = " Mary had\ta\u{2009}little \n\t lamb";
assert_eq!(
"Mary had a little lamb".to_owned(),
sanitize_seed_phrase(seed_phrase)
);
}
}

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-cli"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -20,6 +20,7 @@ dirs = "2.0.2"
lazy_static = "1.4.0"
log = "0.4.8"
indicatif = "0.13.0"
humantime = "1.3.0"
num-traits = "0.2"
pretty-hex = "0.1.1"
reqwest = { version = "0.9.22", default-features = false, features = ["rustls-tls"] }
@ -27,24 +28,24 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-config-program = { path = "../programs/config", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-storage-program = { path = "../programs/storage", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-vote-signer = { path = "../vote-signer", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-config-program = { path = "../programs/config", version = "0.21.4" }
solana-drone = { path = "../drone", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-storage-program = { path = "../programs/storage", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
solana-vote-signer = { path = "../vote-signer", version = "0.21.4" }
url = "2.1.0"
[dev-dependencies]
solana-core = { path = "../core", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.4" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
tempfile = "3.1.0"
[[bin]]

View File

@ -1,5 +1,10 @@
use crate::{
cluster_query::*, display::println_name_value, stake::*, storage::*, validator_info::*, vote::*,
cluster_query::*,
display::{println_name_value, println_signers},
stake::*,
storage::*,
validator_info::*,
vote::*,
};
use chrono::prelude::*;
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
@ -15,6 +20,7 @@ use solana_drone::drone::request_airdrop_transaction;
use solana_drone::drone_mock::request_airdrop_transaction;
use solana_sdk::{
bpf_loader,
clock::Slot,
commitment_config::CommitmentConfig,
fee_calculator::FeeCalculator,
hash::Hash,
@ -74,6 +80,9 @@ pub enum CliCommand {
},
ClusterVersion,
Fees,
GetBlockTime {
slot: Slot,
},
GetEpochInfo {
commitment_config: CommitmentConfig,
},
@ -105,8 +114,20 @@ pub enum CliCommand {
lockup: Lockup,
lamports: u64,
},
DeactivateStake(Pubkey),
DelegateStake(Pubkey, Pubkey, bool),
DeactivateStake {
stake_account_pubkey: Pubkey,
sign_only: bool,
signers: Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
},
DelegateStake {
stake_account_pubkey: Pubkey,
vote_account_pubkey: Pubkey,
force: bool,
sign_only: bool,
signers: Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
},
RedeemVoteCredits(Pubkey, Pubkey),
ShowStakeHistory {
use_lamports_unit: bool,
@ -152,7 +173,16 @@ pub enum CliCommand {
aggregate: bool,
span: Option<u64>,
},
VoteAuthorize(Pubkey, Pubkey, VoteAuthorize),
VoteAuthorize {
vote_account_pubkey: Pubkey,
new_authorized_pubkey: Pubkey,
vote_authorize: VoteAuthorize,
},
VoteUpdateValidator {
vote_account_pubkey: Pubkey,
new_identity_pubkey: Pubkey,
authorized_voter: KeypairEq,
},
// Wallet Commands
Address,
Airdrop {
@ -174,6 +204,9 @@ pub enum CliCommand {
timestamp_pubkey: Option<Pubkey>,
witnesses: Option<Vec<Pubkey>>,
cancelable: bool,
sign_only: bool,
signers: Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
},
ShowAccount {
pubkey: Pubkey,
@ -266,6 +299,7 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
command: CliCommand::Fees,
require_keypair: false,
}),
("get-block-time", Some(matches)) => parse_get_block_time(matches),
("get-epoch-info", Some(matches)) => parse_get_epoch_info(matches),
("get-genesis-hash", Some(_matches)) => Ok(CliCommandInfo {
command: CliCommand::GetGenesisHash,
@ -321,6 +355,7 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
},
// Vote Commands
("create-vote-account", Some(matches)) => parse_vote_create_account(matches),
("vote-update-validator", Some(matches)) => parse_vote_update_validator(matches),
("vote-authorize-voter", Some(matches)) => {
parse_vote_authorize(matches, VoteAuthorize::Voter)
}
@ -413,6 +448,9 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
let timestamp_pubkey = value_of(&matches, "timestamp_pubkey");
let witnesses = values_of(&matches, "witness");
let cancelable = matches.is_present("cancelable");
let sign_only = matches.is_present("sign_only");
let signers = pubkeys_sigs_of(&matches, "signer");
let blockhash = value_of(&matches, "blockhash");
Ok(CliCommandInfo {
command: CliCommand::Pay {
@ -422,8 +460,11 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
timestamp_pubkey,
witnesses,
cancelable,
sign_only,
signers,
blockhash,
},
require_keypair: true,
require_keypair: !sign_only,
})
}
("show-account", Some(matches)) => {
@ -481,20 +522,20 @@ pub type ProcessResult = Result<String, Box<dyn std::error::Error>>;
pub fn check_account_for_fee(
rpc_client: &RpcClient,
config: &CliConfig,
account_pubkey: &Pubkey,
fee_calculator: &FeeCalculator,
message: &Message,
) -> Result<(), Box<dyn error::Error>> {
check_account_for_multiple_fees(rpc_client, config, fee_calculator, &[message])
check_account_for_multiple_fees(rpc_client, account_pubkey, fee_calculator, &[message])
}
fn check_account_for_multiple_fees(
rpc_client: &RpcClient,
config: &CliConfig,
account_pubkey: &Pubkey,
fee_calculator: &FeeCalculator,
messages: &[&Message],
) -> Result<(), Box<dyn error::Error>> {
let balance = rpc_client.retry_get_balance(&config.keypair.pubkey(), 5)?;
let balance = rpc_client.retry_get_balance(account_pubkey, 5)?;
if let Some(lamports) = balance {
if lamports
>= messages
@ -522,6 +563,48 @@ pub fn check_unique_pubkeys(
}
}
pub fn get_blockhash_fee_calculator(
rpc_client: &RpcClient,
sign_only: bool,
blockhash: Option<Hash>,
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
Ok(if let Some(blockhash) = blockhash {
if sign_only {
(blockhash, FeeCalculator::default())
} else {
(blockhash, rpc_client.get_recent_blockhash()?.1)
}
} else {
rpc_client.get_recent_blockhash()?
})
}
pub fn return_signers(tx: &Transaction) -> ProcessResult {
println_signers(tx);
let signers: Vec<_> = tx
.signatures
.iter()
.zip(tx.message.account_keys.clone())
.map(|(signature, pubkey)| format!("{}={}", pubkey, signature))
.collect();
Ok(json!({
"blockhash": tx.message.recent_blockhash.to_string(),
"signers": &signers,
})
.to_string())
}
pub fn replace_signatures(tx: &mut Transaction, signers: &[(Pubkey, Signature)]) -> ProcessResult {
tx.replace_signatures(signers).map_err(|_| {
CliError::BadParameter(
"Transaction construction failed, incorrect signature or public key provided"
.to_string(),
)
})?;
Ok("".to_string())
}
fn process_airdrop(
rpc_client: &RpcClient,
config: &CliConfig,
@ -671,7 +754,12 @@ fn process_deploy(
let mut finalize_tx = Transaction::new(&signers, message, blockhash);
messages.push(&finalize_tx.message);
check_account_for_multiple_fees(rpc_client, config, &fee_calculator, &messages)?;
check_account_for_multiple_fees(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&messages,
)?;
trace!("Creating program account");
let result = rpc_client.send_and_confirm_transaction(&mut create_account_tx, &signers);
@ -694,6 +782,7 @@ fn process_deploy(
.to_string())
}
#[allow(clippy::too_many_arguments)]
fn process_pay(
rpc_client: &RpcClient,
config: &CliConfig,
@ -703,12 +792,17 @@ fn process_pay(
timestamp_pubkey: Option<Pubkey>,
witnesses: &Option<Vec<Pubkey>>,
cancelable: bool,
sign_only: bool,
signers: &Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
) -> ProcessResult {
check_unique_pubkeys(
(&config.keypair.pubkey(), "cli keypair".to_string()),
(to, "to".to_string()),
)?;
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let (blockhash, fee_calculator) =
get_blockhash_fee_calculator(rpc_client, sign_only, blockhash)?;
let cancelable = if cancelable {
Some(config.keypair.pubkey())
@ -718,9 +812,22 @@ fn process_pay(
if timestamp == None && *witnesses == None {
let mut tx = system_transaction::transfer(&config.keypair, to, lamports, blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<SystemError>(result)
if let Some(signers) = signers {
replace_signatures(&mut tx, &signers)?;
}
if sign_only {
return_signers(&tx)
} else {
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<SystemError>(result)
}
} else if *witnesses == None {
let dt = timestamp.unwrap();
let dt_pubkey = match timestamp_pubkey {
@ -745,19 +852,29 @@ fn process_pay(
ixs,
blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
if let Some(signers) = signers {
replace_signatures(&mut tx, &signers)?;
}
if sign_only {
return_signers(&tx)
} else {
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client
.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
Ok(json!({
"signature": signature_str,
"processId": format!("{}", contract_state.pubkey()),
})
.to_string())
Ok(json!({
"signature": signature_str,
"processId": format!("{}", contract_state.pubkey()),
})
.to_string())
}
} else if timestamp == None {
let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
let witness = if let Some(ref witness_vec) = *witnesses {
witness_vec[0]
} else {
@ -783,16 +900,28 @@ fn process_pay(
ixs,
blockhash,
);
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
if let Some(signers) = signers {
replace_signatures(&mut tx, &signers)?;
}
if sign_only {
return_signers(&tx)
} else {
let result = rpc_client
.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
Ok(json!({
"signature": signature_str,
"processId": format!("{}", contract_state.pubkey()),
})
.to_string())
Ok(json!({
"signature": signature_str,
"processId": format!("{}", contract_state.pubkey()),
})
.to_string())
}
} else {
Ok("Combo transactions not yet handled".to_string())
}
@ -806,7 +935,12 @@ fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -
&config.keypair.pubkey(),
);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<BudgetError>(result)
}
@ -822,7 +956,12 @@ fn process_time_elapsed(
let ix = budget_instruction::apply_timestamp(&config.keypair.pubkey(), pubkey, to, dt);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<BudgetError>(result)
}
@ -837,7 +976,12 @@ fn process_witness(
let ix = budget_instruction::apply_signature(&config.keypair.pubkey(), pubkey, to);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<BudgetError>(result)
}
@ -870,6 +1014,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::Catchup { node_pubkey } => process_catchup(&rpc_client, node_pubkey),
CliCommand::ClusterVersion => process_cluster_version(&rpc_client),
CliCommand::Fees => process_fees(&rpc_client),
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, *slot),
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
CliCommand::GetEpochInfo { commitment_config } => {
process_get_epoch_info(&rpc_client, commitment_config)
@ -926,18 +1071,36 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*lamports,
),
// Deactivate stake account
CliCommand::DeactivateStake(stake_account_pubkey) => {
process_deactivate_stake_account(&rpc_client, config, &stake_account_pubkey)
}
CliCommand::DelegateStake(stake_account_pubkey, vote_account_pubkey, force) => {
process_delegate_stake(
&rpc_client,
config,
&stake_account_pubkey,
&vote_account_pubkey,
*force,
)
}
CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only,
ref signers,
blockhash,
} => process_deactivate_stake_account(
&rpc_client,
config,
&stake_account_pubkey,
*sign_only,
signers,
*blockhash,
),
CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force,
sign_only,
ref signers,
blockhash,
} => process_delegate_stake(
&rpc_client,
config,
&stake_account_pubkey,
&vote_account_pubkey,
*force,
*sign_only,
signers,
*blockhash,
),
CliCommand::RedeemVoteCredits(stake_account_pubkey, vote_account_pubkey) => {
process_redeem_vote_credits(
&rpc_client,
@ -1053,15 +1216,28 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
&vote_account_pubkey,
*use_lamports_unit,
),
CliCommand::VoteAuthorize(vote_account_pubkey, new_authorized_pubkey, vote_authorize) => {
process_vote_authorize(
&rpc_client,
config,
&vote_account_pubkey,
&new_authorized_pubkey,
*vote_authorize,
)
}
CliCommand::VoteAuthorize {
vote_account_pubkey,
new_authorized_pubkey,
vote_authorize,
} => process_vote_authorize(
&rpc_client,
config,
&vote_account_pubkey,
&new_authorized_pubkey,
*vote_authorize,
),
CliCommand::VoteUpdateValidator {
vote_account_pubkey,
new_identity_pubkey,
authorized_voter,
} => process_vote_update_validator(
&rpc_client,
config,
&vote_account_pubkey,
&new_identity_pubkey,
authorized_voter,
),
CliCommand::Uptime {
pubkey: vote_account_pubkey,
aggregate,
@ -1118,6 +1294,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
timestamp_pubkey,
ref witnesses,
cancelable,
sign_only,
ref signers,
blockhash,
} => process_pay(
&rpc_client,
config,
@ -1127,6 +1306,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*timestamp_pubkey,
witnesses,
*cancelable,
*sign_only,
signers,
*blockhash,
),
CliCommand::ShowAccount {
pubkey,
@ -1410,6 +1592,29 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
Arg::with_name("cancelable")
.long("cancelable")
.takes_value(false),
)
.arg(
Arg::with_name("sign_only")
.long("sign-only")
.takes_value(false)
.help("Sign the transaction offline"),
)
.arg(
Arg::with_name("signer")
.long("signer")
.value_name("PUBKEY=BASE58_SIG")
.takes_value(true)
.validator(is_pubkey_sig)
.multiple(true)
.help("Provide a public-key/signature pair for the transaction"),
)
.arg(
Arg::with_name("blockhash")
.long("blockhash")
.value_name("BLOCKHASH")
.takes_value(true)
.validator(is_hash)
.help("Use the supplied blockhash"),
),
)
.subcommand(
@ -1667,6 +1872,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
},
require_keypair: true
}
@ -1694,6 +1902,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: Some(vec![witness0, witness1]),
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
},
require_keypair: true
}
@ -1717,6 +1928,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: Some(vec![witness0]),
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
},
require_keypair: true
}
@ -1744,6 +1958,130 @@ mod tests {
timestamp_pubkey: Some(witness0),
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
},
require_keypair: true
}
);
// Test Pay Subcommand w/ sign-only
let test_pay = test_commands.clone().get_matches_from(vec![
"test",
"pay",
&pubkey_string,
"50",
"lamports",
"--sign-only",
]);
assert_eq!(
parse_command(&test_pay).unwrap(),
CliCommandInfo {
command: CliCommand::Pay {
lamports: 50,
to: pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: true,
signers: None,
blockhash: None,
},
require_keypair: false
}
);
// Test Pay Subcommand w/ signer
let key1 = Pubkey::new_rand();
let sig1 = Keypair::new().sign_message(&[0u8]);
let signer1 = format!("{}={}", key1, sig1);
let test_pay = test_commands.clone().get_matches_from(vec![
"test",
"pay",
&pubkey_string,
"50",
"lamports",
"--signer",
&signer1,
]);
assert_eq!(
parse_command(&test_pay).unwrap(),
CliCommandInfo {
command: CliCommand::Pay {
lamports: 50,
to: pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: Some(vec![(key1, sig1)]),
blockhash: None,
},
require_keypair: true
}
);
// Test Pay Subcommand w/ signers
let key2 = Pubkey::new_rand();
let sig2 = Keypair::new().sign_message(&[1u8]);
let signer2 = format!("{}={}", key2, sig2);
let test_pay = test_commands.clone().get_matches_from(vec![
"test",
"pay",
&pubkey_string,
"50",
"lamports",
"--signer",
&signer1,
"--signer",
&signer2,
]);
assert_eq!(
parse_command(&test_pay).unwrap(),
CliCommandInfo {
command: CliCommand::Pay {
lamports: 50,
to: pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: Some(vec![(key1, sig1), (key2, sig2)]),
blockhash: None,
},
require_keypair: true
}
);
// Test Pay Subcommand w/ Blockhash
let blockhash = Hash::default();
let blockhash_string = format!("{}", blockhash);
let test_pay = test_commands.clone().get_matches_from(vec![
"test",
"pay",
&pubkey_string,
"50",
"lamports",
"--blockhash",
&blockhash_string,
]);
assert_eq!(
parse_command(&test_pay).unwrap(),
CliCommandInfo {
command: CliCommand::Pay {
lamports: 50,
to: pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: Some(blockhash),
},
require_keypair: true
}
@ -1788,6 +2126,9 @@ mod tests {
timestamp_pubkey: Some(witness0),
witnesses: Some(vec![witness0, witness1]),
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
},
require_keypair: true
}
@ -1866,8 +2207,20 @@ mod tests {
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
let new_authorized_pubkey = Pubkey::new_rand();
config.command =
CliCommand::VoteAuthorize(bob_pubkey, new_authorized_pubkey, VoteAuthorize::Voter);
config.command = CliCommand::VoteAuthorize {
vote_account_pubkey: bob_pubkey,
new_authorized_pubkey,
vote_authorize: VoteAuthorize::Voter,
};
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
let new_identity_pubkey = Pubkey::new_rand();
config.command = CliCommand::VoteUpdateValidator {
vote_account_pubkey: bob_pubkey,
new_identity_pubkey,
authorized_voter: Keypair::new().into(),
};
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
@ -1894,7 +2247,12 @@ mod tests {
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
let stake_pubkey = Pubkey::new_rand();
config.command = CliCommand::DeactivateStake(stake_pubkey);
config.command = CliCommand::DeactivateStake {
stake_account_pubkey: stake_pubkey,
sign_only: false,
signers: None,
blockhash: None,
};
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
@ -1915,6 +2273,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
@ -1928,6 +2289,9 @@ mod tests {
timestamp_pubkey: Some(config.keypair.pubkey()),
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
let result = process_command(&config);
let json: Value = serde_json::from_str(&result.unwrap()).unwrap();
@ -1949,6 +2313,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: Some(vec![witness]),
cancelable: true,
sign_only: false,
signers: None,
blockhash: None,
};
let result = process_command(&config);
let json: Value = serde_json::from_str(&result.unwrap()).unwrap();
@ -2036,7 +2403,18 @@ mod tests {
};
assert!(process_command(&config).is_err());
config.command = CliCommand::VoteAuthorize(bob_pubkey, bob_pubkey, VoteAuthorize::Voter);
config.command = CliCommand::VoteAuthorize {
vote_account_pubkey: bob_pubkey,
new_authorized_pubkey: bob_pubkey,
vote_authorize: VoteAuthorize::Voter,
};
assert!(process_command(&config).is_err());
config.command = CliCommand::VoteUpdateValidator {
vote_account_pubkey: bob_pubkey,
new_identity_pubkey: bob_pubkey,
authorized_voter: Keypair::new().into(),
};
assert!(process_command(&config).is_err());
config.command = CliCommand::GetSlot {
@ -2056,6 +2434,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
assert!(process_command(&config).is_err());
@ -2066,6 +2447,9 @@ mod tests {
timestamp_pubkey: Some(config.keypair.pubkey()),
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
assert!(process_command(&config).is_err());
@ -2076,6 +2460,9 @@ mod tests {
timestamp_pubkey: None,
witnesses: Some(vec![witness]),
cancelable: true,
sign_only: false,
signers: None,
blockhash: None,
};
assert!(process_command(&config).is_err());

View File

@ -11,8 +11,9 @@ use indicatif::{ProgressBar, ProgressStyle};
use solana_clap_utils::{input_parsers::*, input_validators::*};
use solana_client::{rpc_client::RpcClient, rpc_request::RpcVoteAccountInfo};
use solana_sdk::{
clock,
clock::{self, Slot},
commitment_config::CommitmentConfig,
epoch_schedule::{Epoch, EpochSchedule},
hash::Hash,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
@ -53,6 +54,17 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.about("Get the version of the cluster entrypoint"),
)
.subcommand(SubCommand::with_name("fees").about("Display current cluster fees"))
.subcommand(SubCommand::with_name("get-block-time")
.about("Get estimated production time of a block")
.arg(
Arg::with_name("slot")
.index(1)
.takes_value(true)
.value_name("SLOT")
.required(true)
.help("Slot number of the block to query")
)
)
.subcommand(
SubCommand::with_name("get-epoch-info")
.about("Get information about the current epoch")
@ -187,6 +199,14 @@ pub fn parse_cluster_ping(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Cl
})
}
pub fn parse_get_block_time(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let slot = value_t_or_exit!(matches, "slot", u64);
Ok(CliCommandInfo {
command: CliCommand::GetBlockTime { slot },
require_keypair: false,
})
}
pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let commitment_config = if matches.is_present("confirmed") {
CommitmentConfig::default()
@ -241,6 +261,20 @@ fn new_spinner_progress_bar() -> ProgressBar {
progress_bar
}
/// Aggregate epoch credit stats and return (total credits, total slots, total epochs)
pub fn aggregate_epoch_credits(
epoch_credits: &[(Epoch, u64, u64)],
epoch_schedule: &EpochSchedule,
) -> (u64, u64, u64) {
epoch_credits
.iter()
.fold((0, 0, 0), |acc, (epoch, credits, prev_credits)| {
let credits_earned = credits - prev_credits;
let slots_in_epoch = epoch_schedule.get_slots_in_epoch(*epoch);
(acc.0 + credits_earned, acc.1 + slots_in_epoch, acc.2 + 1)
})
}
pub fn process_catchup(rpc_client: &RpcClient, node_pubkey: &Pubkey) -> ProcessResult {
let cluster_nodes = rpc_client.get_cluster_nodes()?;
@ -313,6 +347,11 @@ pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
))
}
pub fn process_get_block_time(rpc_client: &RpcClient, slot: Slot) -> ProcessResult {
let timestamp = rpc_client.get_block_time(slot)?;
Ok(timestamp.to_string())
}
pub fn process_get_epoch_info(
rpc_client: &RpcClient,
commitment_config: &CommitmentConfig,
@ -336,11 +375,7 @@ pub fn process_get_epoch_info(
);
println_name_value(
"Time remaining in current epoch:",
&format!(
"{} minutes, {} seconds",
remaining_time_in_epoch.as_secs() / 60,
remaining_time_in_epoch.as_secs() % 60
),
&humantime::format_duration(remaining_time_in_epoch).to_string(),
);
Ok("".to_string())
}
@ -399,7 +434,12 @@ pub fn process_ping(
let transaction =
system_transaction::transfer(&config.keypair, &to, lamports, recent_blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &transaction.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&transaction.message,
)?;
match rpc_client.send_transaction(&transaction) {
Ok(signature) => {
@ -442,8 +482,7 @@ pub fn process_ping(
// Sleep for half a slot
if signal_receiver
.recv_timeout(Duration::from_millis(
500 * solana_sdk::clock::DEFAULT_TICKS_PER_SLOT
/ solana_sdk::clock::DEFAULT_TICKS_PER_SECOND,
500 * clock::DEFAULT_TICKS_PER_SLOT / clock::DEFAULT_TICKS_PER_SECOND,
))
.is_ok()
{
@ -526,6 +565,7 @@ pub fn process_show_gossip(rpc_client: &RpcClient) -> ProcessResult {
}
pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool) -> ProcessResult {
let epoch_schedule = rpc_client.get_epoch_schedule()?;
let vote_accounts = rpc_client.get_vote_accounts()?;
let total_active_stake = vote_accounts
.current
@ -568,19 +608,21 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
println!(
"{}",
style(format!(
" {:<44} {:<44} {:<11} {:>10} {:>11} {}",
" {:<44} {:<44} {} {} {} {:>7} {}",
"Identity Pubkey",
"Vote Account Pubkey",
"Commission",
"Last Vote",
"Root Block",
"Uptime",
"Active Stake",
))
.bold()
);
fn print_vote_account(
vote_account: &RpcVoteAccountInfo,
vote_account: RpcVoteAccountInfo,
epoch_schedule: &EpochSchedule,
total_active_stake: f64,
use_lamports_unit: bool,
delinquent: bool,
@ -592,8 +634,20 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
format!("{}", v)
}
}
fn uptime(epoch_credits: Vec<(Epoch, u64, u64)>, epoch_schedule: &EpochSchedule) -> String {
let (total_credits, total_slots, _) =
aggregate_epoch_credits(&epoch_credits, &epoch_schedule);
if total_slots > 0 {
let total_uptime = 100_f64 * total_credits as f64 / total_slots as f64;
format!("{:.2}%", total_uptime)
} else {
"-".into()
}
}
println!(
"{} {:<44} {:<44} {:>3} ({:>4.1}%) {:>10} {:>11} {:>11}",
"{} {:<44} {:<44} {:>9}% {:>8} {:>10} {:>7} {}",
if delinquent {
WARNING.to_string()
} else {
@ -602,9 +656,9 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
vote_account.node_pubkey,
vote_account.vote_pubkey,
vote_account.commission,
f64::from(vote_account.commission) * 100.0 / f64::from(std::u8::MAX),
non_zero_or_dash(vote_account.last_vote),
non_zero_or_dash(vote_account.root_slot),
uptime(vote_account.epoch_credits, epoch_schedule),
if vote_account.activated_stake > 0 {
format!(
"{} ({:.2}%)",
@ -617,11 +671,23 @@ pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool)
);
}
for vote_account in vote_accounts.current.iter() {
print_vote_account(vote_account, total_active_stake, use_lamports_unit, false);
for vote_account in vote_accounts.current.into_iter() {
print_vote_account(
vote_account,
&epoch_schedule,
total_active_stake,
use_lamports_unit,
false,
);
}
for vote_account in vote_accounts.delinquent.iter() {
print_vote_account(vote_account, total_active_stake, use_lamports_unit, true);
for vote_account in vote_accounts.delinquent.into_iter() {
print_vote_account(
vote_account,
&epoch_schedule,
total_active_stake,
use_lamports_unit,
true,
);
}
Ok("".to_string())
@ -656,6 +722,20 @@ mod tests {
}
);
let slot = 100;
let test_get_block_time = test_commands.clone().get_matches_from(vec![
"test",
"get-block-time",
&slot.to_string(),
]);
assert_eq!(
parse_command(&test_get_block_time).unwrap(),
CliCommandInfo {
command: CliCommand::GetBlockTime { slot },
require_keypair: false
}
);
let test_get_epoch_info = test_commands
.clone()
.get_matches_from(vec!["test", "get-epoch-info"]);

View File

@ -1,4 +1,5 @@
use console::style;
use solana_sdk::transaction::Transaction;
// Pretty print a "name value"
pub fn println_name_value(name: &str, value: &str) {
@ -22,3 +23,14 @@ pub fn println_name_value_or(name: &str, value: &str, default_value: &str) {
println!("{} {}", style(name).bold(), style(value));
};
}
pub fn println_signers(tx: &Transaction) {
println!();
println!("Blockhash: {}", tx.message.recent_blockhash);
println!("Signers (Pubkey=Signature):");
tx.signatures
.iter()
.zip(tx.message.account_keys.clone())
.for_each(|(signature, pubkey)| println!(" {:?}={:?}", pubkey, signature));
println!();
}

View File

@ -1,14 +1,16 @@
use crate::cli::{
build_balance_message, check_account_for_fee, check_unique_pubkeys,
log_instruction_custom_error, CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult,
get_blockhash_fee_calculator, log_instruction_custom_error, replace_signatures, return_signers,
CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult,
};
use clap::{App, Arg, ArgMatches, SubCommand};
use console::style;
use solana_clap_utils::{input_parsers::*, input_validators::*};
use solana_client::rpc_client::RpcClient;
use solana_sdk::signature::Keypair;
use solana_sdk::signature::{Keypair, Signature};
use solana_sdk::{
account_utils::State,
hash::Hash,
pubkey::Pubkey,
signature::KeypairUtil,
system_instruction::SystemError,
@ -120,6 +122,29 @@ impl StakeSubCommands for App<'_, '_> {
.validator(is_pubkey_or_keypair)
.help("The vote account to which the stake will be delegated")
)
.arg(
Arg::with_name("sign_only")
.long("sign-only")
.takes_value(false)
.help("Sign the transaction offline"),
)
.arg(
Arg::with_name("signer")
.long("signer")
.value_name("PUBKEY=BASE58_SIG")
.takes_value(true)
.validator(is_pubkey_sig)
.multiple(true)
.help("Provide a public-key/signature pair for the transaction"),
)
.arg(
Arg::with_name("blockhash")
.long("blockhash")
.value_name("BLOCKHASH")
.takes_value(true)
.validator(is_hash)
.help("Use the supplied blockhash"),
),
)
.subcommand(
SubCommand::with_name("stake-authorize-staker")
@ -176,6 +201,29 @@ impl StakeSubCommands for App<'_, '_> {
.required(true)
.help("Stake account to be deactivated.")
)
.arg(
Arg::with_name("sign_only")
.long("sign-only")
.takes_value(false)
.help("Sign the transaction offline"),
)
.arg(
Arg::with_name("signer")
.long("signer")
.value_name("PUBKEY=BASE58_SIG")
.takes_value(true)
.validator(is_pubkey_sig)
.multiple(true)
.help("Provide a public-key/signature pair for the transaction"),
)
.arg(
Arg::with_name("blockhash")
.long("blockhash")
.value_name("BLOCKHASH")
.takes_value(true)
.validator(is_hash)
.help("Use the supplied blockhash"),
),
)
.subcommand(
SubCommand::with_name("withdraw-stake")
@ -293,10 +341,21 @@ pub fn parse_stake_delegate_stake(matches: &ArgMatches<'_>) -> Result<CliCommand
let stake_account_pubkey = pubkey_of(matches, "stake_account_pubkey").unwrap();
let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap();
let force = matches.is_present("force");
let sign_only = matches.is_present("sign_only");
let signers = pubkeys_sigs_of(&matches, "signer");
let blockhash = value_of(matches, "blockhash");
let require_keypair = signers.is_none();
Ok(CliCommandInfo {
command: CliCommand::DelegateStake(stake_account_pubkey, vote_account_pubkey, force),
require_keypair: true,
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force,
sign_only,
signers,
blockhash,
},
require_keypair,
})
}
@ -320,6 +379,7 @@ pub fn parse_stake_authorize(
pub fn parse_redeem_vote_credits(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let stake_account_pubkey = pubkey_of(matches, "stake_account_pubkey").unwrap();
let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap();
Ok(CliCommandInfo {
command: CliCommand::RedeemVoteCredits(stake_account_pubkey, vote_account_pubkey),
require_keypair: true,
@ -328,9 +388,19 @@ pub fn parse_redeem_vote_credits(matches: &ArgMatches<'_>) -> Result<CliCommandI
pub fn parse_stake_deactivate_stake(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let stake_account_pubkey = pubkey_of(matches, "stake_account_pubkey").unwrap();
let sign_only = matches.is_present("sign_only");
let signers = pubkeys_sigs_of(&matches, "signer");
let blockhash = value_of(matches, "blockhash");
let require_keypair = signers.is_none();
Ok(CliCommandInfo {
command: CliCommand::DeactivateStake(stake_account_pubkey),
require_keypair: true,
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only,
signers,
blockhash,
},
require_keypair,
})
}
@ -423,7 +493,12 @@ pub fn process_create_stake_account(
&[&config.keypair, stake_account],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, stake_account]);
log_instruction_custom_error::<SystemError>(result)
@ -454,7 +529,12 @@ pub fn process_stake_authorize(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
}
@ -463,8 +543,12 @@ pub fn process_deactivate_stake_account(
rpc_client: &RpcClient,
config: &CliConfig,
stake_account_pubkey: &Pubkey,
sign_only: bool,
signers: &Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
) -> ProcessResult {
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let (recent_blockhash, fee_calculator) =
get_blockhash_fee_calculator(rpc_client, sign_only, blockhash)?;
let ixs = vec![stake_instruction::deactivate_stake(
stake_account_pubkey,
&config.keypair.pubkey(),
@ -475,9 +559,21 @@ pub fn process_deactivate_stake_account(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
if let Some(signers) = signers {
replace_signatures(&mut tx, &signers)?;
}
if sign_only {
return_signers(&tx)
} else {
check_account_for_fee(
rpc_client,
&tx.message.account_keys[0],
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
}
}
pub fn process_withdraw_stake(
@ -502,7 +598,12 @@ pub fn process_withdraw_stake(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
}
@ -524,7 +625,12 @@ pub fn process_redeem_vote_credits(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
}
@ -619,7 +725,7 @@ pub fn process_show_stake_history(
println!(
"{}",
style(format!(
" {:<5} {:>15} {:>16} {:>18}",
" {:<5} {:>20} {:>20} {:>20}",
"Epoch", "Effective Stake", "Activating Stake", "Deactivating Stake",
))
.bold()
@ -627,7 +733,7 @@ pub fn process_show_stake_history(
for (epoch, entry) in stake_history.deref() {
println!(
" {:>5} {:>15} {:>16} {:>18} {}",
" {:>5} {:>20} {:>20} {:>20} {}",
epoch,
build_balance_message(entry.effective, use_lamports_unit, false),
build_balance_message(entry.activating, use_lamports_unit, false),
@ -644,6 +750,9 @@ pub fn process_delegate_stake(
stake_account_pubkey: &Pubkey,
vote_account_pubkey: &Pubkey,
force: bool,
sign_only: bool,
signers: &Option<Vec<(Pubkey, Signature)>>,
blockhash: Option<Hash>,
) -> ProcessResult {
check_unique_pubkeys(
(&config.keypair.pubkey(), "cli keypair".to_string()),
@ -690,7 +799,8 @@ pub fn process_delegate_stake(
}
}
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let (recent_blockhash, fee_calculator) =
get_blockhash_fee_calculator(rpc_client, sign_only, blockhash)?;
let ixs = vec![stake_instruction::delegate_stake(
stake_account_pubkey,
@ -704,9 +814,21 @@ pub fn process_delegate_stake(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
if let Some(signers) = signers {
replace_signatures(&mut tx, &signers)?;
}
if sign_only {
return_signers(&tx)
} else {
check_account_for_fee(
rpc_client,
&tx.message.account_keys[0],
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<StakeError>(result)
}
}
#[cfg(test)]
@ -831,18 +953,25 @@ mod tests {
);
// Test DelegateStake Subcommand
let stake_pubkey = Pubkey::new_rand();
let stake_pubkey_string = stake_pubkey.to_string();
let vote_account_pubkey = Pubkey::new_rand();
let vote_account_string = vote_account_pubkey.to_string();
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"delegate-stake",
&stake_pubkey_string,
&stake_account_string,
&vote_account_string,
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake(stake_pubkey, stake_account_pubkey, false),
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: false,
sign_only: false,
signers: None,
blockhash: None
},
require_keypair: true
}
);
@ -851,22 +980,133 @@ mod tests {
"test",
"delegate-stake",
"--force",
&stake_pubkey_string,
&stake_account_string,
&vote_account_string,
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake(stake_pubkey, stake_account_pubkey, true),
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: true,
sign_only: false,
signers: None,
blockhash: None
},
require_keypair: true
}
);
// Test Delegate Subcommand w/ Blockhash
let blockhash = Hash::default();
let blockhash_string = format!("{}", blockhash);
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"delegate-stake",
&stake_account_string,
&vote_account_string,
"--blockhash",
&blockhash_string,
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: false,
sign_only: false,
signers: None,
blockhash: Some(blockhash)
},
require_keypair: true
}
);
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"delegate-stake",
&stake_account_string,
&vote_account_string,
"--sign-only",
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: false,
sign_only: true,
signers: None,
blockhash: None
},
require_keypair: true
}
);
// Test Delegate Subcommand w/ signer
let key1 = Pubkey::new_rand();
let sig1 = Keypair::new().sign_message(&[0u8]);
let signer1 = format!("{}={}", key1, sig1);
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"delegate-stake",
&stake_account_string,
&vote_account_string,
"--signer",
&signer1,
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: false,
sign_only: false,
signers: Some(vec![(key1, sig1)]),
blockhash: None
},
require_keypair: false
}
);
// Test Delegate Subcommand w/ signers
let key2 = Pubkey::new_rand();
let sig2 = Keypair::new().sign_message(&[0u8]);
let signer2 = format!("{}={}", key2, sig2);
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"delegate-stake",
&stake_account_string,
&vote_account_string,
"--signer",
&signer1,
"--signer",
&signer2,
]);
assert_eq!(
parse_command(&test_delegate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
force: false,
sign_only: false,
signers: Some(vec![(key1, sig1), (key2, sig2)]),
blockhash: None
},
require_keypair: false
}
);
// Test WithdrawStake Subcommand
let test_withdraw_stake = test_commands.clone().get_matches_from(vec![
"test",
"withdraw-stake",
&stake_pubkey_string,
&stake_account_string,
&stake_account_string,
"42",
"lamports",
@ -875,7 +1115,7 @@ mod tests {
assert_eq!(
parse_command(&test_withdraw_stake).unwrap(),
CliCommandInfo {
command: CliCommand::WithdrawStake(stake_pubkey, stake_account_pubkey, 42),
command: CliCommand::WithdrawStake(stake_account_pubkey, stake_account_pubkey, 42),
require_keypair: true
}
);
@ -884,14 +1124,111 @@ mod tests {
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
"test",
"deactivate-stake",
&stake_pubkey_string,
&stake_account_string,
]);
assert_eq!(
parse_command(&test_deactivate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DeactivateStake(stake_pubkey),
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only: false,
signers: None,
blockhash: None
},
require_keypair: true
}
);
// Test Deactivate Subcommand w/ Blockhash
let blockhash = Hash::default();
let blockhash_string = format!("{}", blockhash);
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
"test",
"deactivate-stake",
&stake_account_string,
"--blockhash",
&blockhash_string,
]);
assert_eq!(
parse_command(&test_deactivate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only: false,
signers: None,
blockhash: Some(blockhash)
},
require_keypair: true
}
);
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
"test",
"deactivate-stake",
&stake_account_string,
"--sign-only",
]);
assert_eq!(
parse_command(&test_deactivate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only: true,
signers: None,
blockhash: None
},
require_keypair: true
}
);
// Test Deactivate Subcommand w/ signers
let key1 = Pubkey::new_rand();
let sig1 = Keypair::new().sign_message(&[0u8]);
let signer1 = format!("{}={}", key1, sig1);
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
"test",
"deactivate-stake",
&stake_account_string,
"--signer",
&signer1,
]);
assert_eq!(
parse_command(&test_deactivate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only: false,
signers: Some(vec![(key1, sig1)]),
blockhash: None
},
require_keypair: false
}
);
// Test Deactivate Subcommand w/ signers
let key2 = Pubkey::new_rand();
let sig2 = Keypair::new().sign_message(&[0u8]);
let signer2 = format!("{}={}", key2, sig2);
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
"test",
"deactivate-stake",
&stake_account_string,
"--signer",
&signer1,
"--signer",
&signer2,
]);
assert_eq!(
parse_command(&test_deactivate_stake).unwrap(),
CliCommandInfo {
command: CliCommand::DeactivateStake {
stake_account_pubkey,
sign_only: false,
signers: Some(vec![(key1, sig1), (key2, sig2)]),
blockhash: None
},
require_keypair: false
}
);
}
}

View File

@ -176,7 +176,12 @@ pub fn process_create_storage_account(
ixs,
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &storage_account]);
log_instruction_custom_error::<SystemError>(result)
@ -196,7 +201,12 @@ pub fn process_claim_storage_reward(
let message = Message::new_with_payer(vec![instruction], Some(&signers[0].pubkey()));
let mut tx = Transaction::new(&signers, message, recent_blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &signers)?;
Ok(signature_str.to_string())
}

View File

@ -347,7 +347,12 @@ pub fn process_set_validator_info(
// Submit transaction
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new(&signers, message, recent_blockhash);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &signers)?;
println!("Success! Validator info published at: {:?}", info_pubkey);

View File

@ -1,6 +1,10 @@
use crate::cli::{
build_balance_message, check_account_for_fee, check_unique_pubkeys,
log_instruction_custom_error, CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult,
use crate::{
cli::{
build_balance_message, check_account_for_fee, check_unique_pubkeys,
log_instruction_custom_error, CliCommand, CliCommandInfo, CliConfig, CliError,
ProcessResult,
},
cluster_query::aggregate_epoch_credits,
};
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
use solana_clap_utils::{input_parsers::*, input_validators::*};
@ -34,9 +38,9 @@ impl VoteSubCommands for App<'_, '_> {
.help("Vote account keypair to fund"),
)
.arg(
Arg::with_name("node_pubkey")
Arg::with_name("identity_pubkey")
.index(2)
.value_name("VALIDATOR PUBKEY")
.value_name("VALIDATOR IDENTITY PUBKEY")
.takes_value(true)
.required(true)
.validator(is_pubkey_or_keypair)
@ -47,7 +51,7 @@ impl VoteSubCommands for App<'_, '_> {
.long("commission")
.value_name("NUM")
.takes_value(true)
.help("The commission taken on reward redemption (0-255), default: 0"),
.help("The commission taken on reward redemption (0-100), default: 0"),
)
.arg(
Arg::with_name("authorized_voter")
@ -66,6 +70,37 @@ impl VoteSubCommands for App<'_, '_> {
.help("Public key of the authorized withdrawer (defaults to cli config pubkey)"),
),
)
.subcommand(
SubCommand::with_name("vote-update-validator")
.about("Update the vote account's validator identity")
.arg(
Arg::with_name("vote_account_pubkey")
.index(1)
.value_name("VOTE ACCOUNT PUBKEY")
.takes_value(true)
.required(true)
.validator(is_pubkey_or_keypair)
.help("Vote account to update"),
)
.arg(
Arg::with_name("new_identity_pubkey")
.index(2)
.value_name("NEW VALIDATOR IDENTITY PUBKEY")
.takes_value(true)
.required(true)
.validator(is_pubkey_or_keypair)
.help("New validator that will vote with this account"),
)
.arg(
Arg::with_name("authorized_voter")
.index(3)
.value_name("AUTHORIZED VOTER KEYPAIR")
.takes_value(true)
.required(true)
.validator(is_keypair)
.help("Authorized voter keypair"),
)
)
.subcommand(
SubCommand::with_name("vote-authorize-voter")
.about("Authorize a new vote signing keypair for the given vote account")
@ -159,7 +194,7 @@ impl VoteSubCommands for App<'_, '_> {
pub fn parse_vote_create_account(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let vote_account = keypair_of(matches, "vote_account").unwrap();
let node_pubkey = pubkey_of(matches, "node_pubkey").unwrap();
let identity_pubkey = pubkey_of(matches, "identity_pubkey").unwrap();
let commission = value_of(&matches, "commission").unwrap_or(0);
let authorized_voter = pubkey_of(matches, "authorized_voter");
let authorized_withdrawer = pubkey_of(matches, "authorized_withdrawer");
@ -167,7 +202,7 @@ pub fn parse_vote_create_account(matches: &ArgMatches<'_>) -> Result<CliCommandI
Ok(CliCommandInfo {
command: CliCommand::CreateVoteAccount {
vote_account: vote_account.into(),
node_pubkey,
node_pubkey: identity_pubkey,
authorized_voter,
authorized_withdrawer,
commission,
@ -184,11 +219,26 @@ pub fn parse_vote_authorize(
let new_authorized_pubkey = pubkey_of(matches, "new_authorized_pubkey").unwrap();
Ok(CliCommandInfo {
command: CliCommand::VoteAuthorize(
command: CliCommand::VoteAuthorize {
vote_account_pubkey,
new_authorized_pubkey,
vote_authorize,
),
},
require_keypair: true,
})
}
pub fn parse_vote_update_validator(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap();
let new_identity_pubkey = pubkey_of(matches, "new_identity_pubkey").unwrap();
let authorized_voter = keypair_of(matches, "authorized_voter").unwrap();
Ok(CliCommandInfo {
command: CliCommand::VoteUpdateValidator {
vote_account_pubkey,
new_identity_pubkey,
authorized_voter: authorized_voter.into(),
},
require_keypair: true,
})
}
@ -229,7 +279,7 @@ pub fn process_create_vote_account(
rpc_client: &RpcClient,
config: &CliConfig,
vote_account: &Keypair,
node_pubkey: &Pubkey,
identity_pubkey: &Pubkey,
authorized_voter: &Option<Pubkey>,
authorized_withdrawer: &Option<Pubkey>,
commission: u8,
@ -237,7 +287,7 @@ pub fn process_create_vote_account(
let vote_account_pubkey = vote_account.pubkey();
check_unique_pubkeys(
(&vote_account_pubkey, "vote_account_pubkey".to_string()),
(&node_pubkey, "node_pubkey".to_string()),
(&identity_pubkey, "identity_pubkey".to_string()),
)?;
check_unique_pubkeys(
(&config.keypair.pubkey(), "cli keypair".to_string()),
@ -251,7 +301,7 @@ pub fn process_create_vote_account(
1
};
let vote_init = VoteInit {
node_pubkey: *node_pubkey,
node_pubkey: *identity_pubkey,
authorized_voter: authorized_voter.unwrap_or(vote_account_pubkey),
authorized_withdrawer: authorized_withdrawer.unwrap_or(config.keypair.pubkey()),
commission,
@ -268,7 +318,12 @@ pub fn process_create_vote_account(
ixs,
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, vote_account]);
log_instruction_custom_error::<SystemError>(result)
}
@ -298,7 +353,46 @@ pub fn process_vote_authorize(
&[&config.keypair],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<VoteError>(result)
}
pub fn process_vote_update_validator(
rpc_client: &RpcClient,
config: &CliConfig,
vote_account_pubkey: &Pubkey,
new_identity_pubkey: &Pubkey,
authorized_voter: &Keypair,
) -> ProcessResult {
check_unique_pubkeys(
(vote_account_pubkey, "vote_account_pubkey".to_string()),
(new_identity_pubkey, "new_identity_pubkey".to_string()),
)?;
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let ixs = vec![vote_instruction::update_node(
vote_account_pubkey,
&authorized_voter.pubkey(),
new_identity_pubkey,
)];
let mut tx = Transaction::new_signed_with_payer(
ixs,
Some(&config.keypair.pubkey()),
&[&config.keypair, authorized_voter],
recent_blockhash,
);
check_account_for_fee(
rpc_client,
&config.keypair.pubkey(),
&fee_calculator,
&tx.message,
)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
log_instruction_custom_error::<VoteError>(result)
}
@ -338,17 +432,14 @@ pub fn process_show_vote_account(
"account balance: {}",
build_balance_message(vote_account.lamports, use_lamports_unit, true)
);
println!("node id: {}", vote_state.node_pubkey);
println!("validator identity: {}", vote_state.node_pubkey);
println!("authorized voter: {}", vote_state.authorized_voter);
println!(
"authorized withdrawer: {}",
vote_state.authorized_withdrawer
);
println!("credits: {}", vote_state.credits());
println!(
"commission: {}%",
f64::from(vote_state.commission) / f64::from(std::u32::MAX)
);
println!("commission: {}%", vote_state.commission);
println!(
"root slot: {}",
match vote_state.root_slot {
@ -389,38 +480,42 @@ pub fn process_uptime(
let epoch_schedule = rpc_client.get_epoch_schedule()?;
println!("Node id: {}", vote_state.node_pubkey);
println!("Authorized voter: {}", vote_state.authorized_voter);
println!("validator identity: {}", vote_state.node_pubkey);
println!("authorized voter: {}", vote_state.authorized_voter);
if !vote_state.votes.is_empty() {
println!("Uptime:");
println!("uptime:");
let epoch_credits_vec: Vec<(u64, u64, u64)> = vote_state.epoch_credits().copied().collect();
let epoch_credits = if let Some(x) = span {
epoch_credits_vec.iter().rev().take(x as usize)
let epoch_credits: Vec<(u64, u64, u64)> = if let Some(x) = span {
vote_state
.epoch_credits()
.iter()
.rev()
.take(x as usize)
.cloned()
.collect()
} else {
epoch_credits_vec.iter().rev().take(epoch_credits_vec.len())
vote_state.epoch_credits().iter().rev().cloned().collect()
};
if aggregate {
let (credits_earned, slots_in_epoch, epochs): (u64, u64, u64) =
epoch_credits.fold((0, 0, 0), |acc, (epoch, credits, prev_credits)| {
let credits_earned = credits - prev_credits;
let slots_in_epoch = epoch_schedule.get_slots_in_epoch(*epoch);
(acc.0 + credits_earned, acc.1 + slots_in_epoch, acc.2 + 1)
});
let total_uptime = credits_earned as f64 / slots_in_epoch as f64;
println!("{:.2}% over {} epochs", total_uptime * 100_f64, epochs,);
let (total_credits, total_slots, epochs) =
aggregate_epoch_credits(&epoch_credits, &epoch_schedule);
if total_slots > 0 {
let total_uptime = 100_f64 * total_credits as f64 / total_slots as f64;
println!("{:.2}% over {} epochs", total_uptime, epochs);
} else {
println!("Insufficient voting history available");
}
} else {
for (epoch, credits, prev_credits) in epoch_credits {
let credits_earned = credits - prev_credits;
let slots_in_epoch = epoch_schedule.get_slots_in_epoch(*epoch);
let slots_in_epoch = epoch_schedule.get_slots_in_epoch(epoch);
let uptime = credits_earned as f64 / slots_in_epoch as f64;
println!("- epoch: {} {:.2}% uptime", epoch, uptime * 100_f64,);
}
}
if let Some(x) = span {
if x > epoch_credits_vec.len() as u64 {
if x > vote_state.epoch_credits().len() as u64 {
println!("(span longer than available epochs)");
}
}
@ -446,17 +541,24 @@ mod tests {
let keypair = Keypair::new();
let pubkey = keypair.pubkey();
let pubkey_string = pubkey.to_string();
let keypair2 = Keypair::new();
let pubkey2 = keypair2.pubkey();
let pubkey2_string = pubkey2.to_string();
let test_authorize_voter = test_commands.clone().get_matches_from(vec![
"test",
"vote-authorize-voter",
&pubkey_string,
&pubkey_string,
&pubkey2_string,
]);
assert_eq!(
parse_command(&test_authorize_voter).unwrap(),
CliCommandInfo {
command: CliCommand::VoteAuthorize(pubkey, pubkey, VoteAuthorize::Voter),
command: CliCommand::VoteAuthorize {
vote_account_pubkey: pubkey,
new_authorized_pubkey: pubkey2,
vote_authorize: VoteAuthorize::Voter
},
require_keypair: true
}
);
@ -567,6 +669,27 @@ mod tests {
}
);
let test_update_validator = test_commands.clone().get_matches_from(vec![
"test",
"vote-update-validator",
&pubkey_string,
&pubkey2_string,
&keypair_file,
]);
assert_eq!(
parse_command(&test_update_validator).unwrap(),
CliCommandInfo {
command: CliCommand::VoteUpdateValidator {
vote_account_pubkey: pubkey,
new_identity_pubkey: pubkey2,
authorized_voter: solana_sdk::signature::read_keypair_file(&keypair_file)
.unwrap()
.into(),
},
require_keypair: true
}
);
// Test Uptime Subcommand
let pubkey = Pubkey::new_rand();
let matches = test_commands.clone().get_matches_from(vec![

View File

@ -3,9 +3,9 @@ use serde_json::Value;
use solana_cli::cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig};
use solana_client::rpc_client::RpcClient;
use solana_drone::drone::run_local_drone;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::KeypairUtil;
use solana_sdk::{hash::Hash, pubkey::Pubkey, signature::KeypairUtil, signature::Signature};
use std::fs::remove_dir_all;
use std::str::FromStr;
use std::sync::mpsc::channel;
#[cfg(test)]
@ -71,6 +71,9 @@ fn test_cli_timestamp_tx() {
timestamp_pubkey: Some(config_witness.keypair.pubkey()),
witnesses: None,
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_payer);
@ -138,6 +141,9 @@ fn test_cli_witness_tx() {
timestamp_pubkey: None,
witnesses: Some(vec![config_witness.keypair.pubkey()]),
cancelable: false,
sign_only: false,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_payer);
@ -198,6 +204,9 @@ fn test_cli_cancel_tx() {
timestamp_pubkey: None,
witnesses: Some(vec![config_witness.keypair.pubkey()]),
cancelable: true,
sign_only: false,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_payer).unwrap();
@ -223,3 +232,94 @@ fn test_cli_cancel_tx() {
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}
#[test]
fn test_offline_pay_tx() {
let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
let bob_pubkey = Pubkey::new_rand();
let (sender, receiver) = channel();
run_local_drone(alice, sender, None);
let drone_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new_socket(leader_data.rpc);
let mut config_offline = CliConfig::default();
config_offline.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let mut config_online = CliConfig::default();
config_online.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
assert_ne!(
config_offline.keypair.pubkey(),
config_online.keypair.pubkey()
);
request_and_confirm_airdrop(
&rpc_client,
&drone_addr,
&config_offline.keypair.pubkey(),
50,
)
.unwrap();
request_and_confirm_airdrop(
&rpc_client,
&drone_addr,
&config_online.keypair.pubkey(),
50,
)
.unwrap();
check_balance(50, &rpc_client, &config_offline.keypair.pubkey());
check_balance(50, &rpc_client, &config_online.keypair.pubkey());
config_offline.command = CliCommand::Pay {
lamports: 10,
to: bob_pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: true,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_offline).unwrap();
check_balance(50, &rpc_client, &config_offline.keypair.pubkey());
check_balance(50, &rpc_client, &config_online.keypair.pubkey());
check_balance(0, &rpc_client, &bob_pubkey);
let object: Value = serde_json::from_str(&sig_response).unwrap();
let blockhash_str = object.get("blockhash").unwrap().as_str().unwrap();
let signer_strings = object.get("signers").unwrap().as_array().unwrap();
let signers: Vec<_> = signer_strings
.iter()
.map(|signer_string| {
let mut signer = signer_string.as_str().unwrap().split('=');
let key = Pubkey::from_str(signer.next().unwrap()).unwrap();
let sig = Signature::from_str(signer.next().unwrap()).unwrap();
(key, sig)
})
.collect();
config_online.command = CliCommand::Pay {
lamports: 10,
to: bob_pubkey,
timestamp: None,
timestamp_pubkey: None,
witnesses: None,
cancelable: false,
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash_str.parse::<Hash>().unwrap()),
};
process_command(&config_online).unwrap();
check_balance(40, &rpc_client, &config_offline.keypair.pubkey());
check_balance(50, &rpc_client, &config_online.keypair.pubkey());
check_balance(10, &rpc_client, &bob_pubkey);
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}

252
cli/tests/stake.rs Normal file
View File

@ -0,0 +1,252 @@
use serde_json::Value;
use solana_cli::cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig};
use solana_client::rpc_client::RpcClient;
use solana_drone::drone::run_local_drone;
use solana_sdk::{
hash::Hash,
pubkey::Pubkey,
signature::{read_keypair_file, write_keypair, KeypairUtil, Signature},
};
use solana_stake_program::stake_state::Lockup;
use std::fs::remove_dir_all;
use std::str::FromStr;
use std::sync::mpsc::channel;
#[cfg(test)]
use solana_core::validator::new_validator_for_tests;
use std::thread::sleep;
use std::time::Duration;
use tempfile::NamedTempFile;
fn make_tmp_file() -> (String, NamedTempFile) {
let tmp_file = NamedTempFile::new().unwrap();
(String::from(tmp_file.path().to_str().unwrap()), tmp_file)
}
fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
(0..5).for_each(|tries| {
let balance = client.retry_get_balance(pubkey, 1).unwrap().unwrap();
if balance == expected_balance {
return;
}
if tries == 4 {
assert_eq!(balance, expected_balance);
}
sleep(Duration::from_millis(500));
});
}
#[test]
fn test_stake_delegation_and_deactivation() {
solana_logger::setup();
let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
let (sender, receiver) = channel();
run_local_drone(alice, sender, None);
let drone_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new_socket(leader_data.rpc);
let mut config_validator = CliConfig::default();
config_validator.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let mut config_vote = CliConfig::default();
config_vote.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let (vote_keypair_file, mut tmp_file) = make_tmp_file();
write_keypair(&config_vote.keypair, tmp_file.as_file_mut()).unwrap();
let mut config_stake = CliConfig::default();
config_stake.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let (stake_keypair_file, mut tmp_file) = make_tmp_file();
write_keypair(&config_stake.keypair, tmp_file.as_file_mut()).unwrap();
request_and_confirm_airdrop(
&rpc_client,
&drone_addr,
&config_validator.keypair.pubkey(),
100_000,
)
.unwrap();
check_balance(100_000, &rpc_client, &config_validator.keypair.pubkey());
// Create vote account
config_validator.command = CliCommand::CreateVoteAccount {
vote_account: read_keypair_file(&vote_keypair_file).unwrap().into(),
node_pubkey: config_validator.keypair.pubkey(),
authorized_voter: None,
authorized_withdrawer: None,
commission: 0,
};
process_command(&config_validator).unwrap();
// Create stake account
config_validator.command = CliCommand::CreateStakeAccount {
stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(),
staker: None,
withdrawer: None,
lockup: Lockup {
custodian: Pubkey::default(),
epoch: 0,
},
lamports: 50_000,
};
process_command(&config_validator).unwrap();
// Delegate stake
config_validator.command = CliCommand::DelegateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
vote_account_pubkey: config_vote.keypair.pubkey(),
force: true,
sign_only: false,
signers: None,
blockhash: None,
};
process_command(&config_validator).unwrap();
// Deactivate stake
config_validator.command = CliCommand::DeactivateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
sign_only: false,
signers: None,
blockhash: None,
};
process_command(&config_validator).unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}
#[test]
fn test_stake_delegation_and_deactivation_offline() {
solana_logger::setup();
let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
let (sender, receiver) = channel();
run_local_drone(alice, sender, None);
let drone_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new_socket(leader_data.rpc);
let mut config_validator = CliConfig::default();
config_validator.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let mut config_payer = CliConfig::default();
config_payer.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let mut config_vote = CliConfig::default();
config_vote.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let (vote_keypair_file, mut tmp_file) = make_tmp_file();
write_keypair(&config_vote.keypair, tmp_file.as_file_mut()).unwrap();
let mut config_stake = CliConfig::default();
config_stake.json_rpc_url =
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
let (stake_keypair_file, mut tmp_file) = make_tmp_file();
write_keypair(&config_stake.keypair, tmp_file.as_file_mut()).unwrap();
request_and_confirm_airdrop(
&rpc_client,
&drone_addr,
&config_validator.keypair.pubkey(),
100_000,
)
.unwrap();
check_balance(100_000, &rpc_client, &config_validator.keypair.pubkey());
// Create vote account
config_validator.command = CliCommand::CreateVoteAccount {
vote_account: read_keypair_file(&vote_keypair_file).unwrap().into(),
node_pubkey: config_validator.keypair.pubkey(),
authorized_voter: None,
authorized_withdrawer: None,
commission: 0,
};
process_command(&config_validator).unwrap();
// Create stake account
config_validator.command = CliCommand::CreateStakeAccount {
stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(),
staker: None,
withdrawer: None,
lockup: Lockup {
custodian: Pubkey::default(),
epoch: 0,
},
lamports: 50_000,
};
process_command(&config_validator).unwrap();
// Delegate stake offline
config_validator.command = CliCommand::DelegateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
vote_account_pubkey: config_vote.keypair.pubkey(),
force: true,
sign_only: true,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_validator).unwrap();
let object: Value = serde_json::from_str(&sig_response).unwrap();
let blockhash_str = object.get("blockhash").unwrap().as_str().unwrap();
let signer_strings = object.get("signers").unwrap().as_array().unwrap();
let signers: Vec<_> = signer_strings
.iter()
.map(|signer_string| {
let mut signer = signer_string.as_str().unwrap().split('=');
let key = Pubkey::from_str(signer.next().unwrap()).unwrap();
let sig = Signature::from_str(signer.next().unwrap()).unwrap();
(key, sig)
})
.collect();
// Delegate stake online
config_payer.command = CliCommand::DelegateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
vote_account_pubkey: config_vote.keypair.pubkey(),
force: true,
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash_str.parse::<Hash>().unwrap()),
};
process_command(&config_payer).unwrap();
// Deactivate stake offline
config_validator.command = CliCommand::DeactivateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
sign_only: true,
signers: None,
blockhash: None,
};
let sig_response = process_command(&config_validator).unwrap();
let object: Value = serde_json::from_str(&sig_response).unwrap();
let blockhash_str = object.get("blockhash").unwrap().as_str().unwrap();
let signer_strings = object.get("signers").unwrap().as_array().unwrap();
let signers: Vec<_> = signer_strings
.iter()
.map(|signer_string| {
let mut signer = signer_string.as_str().unwrap().split('=');
let key = Pubkey::from_str(signer.next().unwrap()).unwrap();
let sig = Signature::from_str(signer.next().unwrap()).unwrap();
(key, sig)
})
.collect();
// Deactivate stake online
config_payer.command = CliCommand::DeactivateStake {
stake_account_pubkey: config_stake.keypair.pubkey(),
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash_str.parse::<Hash>().unwrap()),
};
process_command(&config_payer).unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}

View File

@ -1,6 +1,6 @@
[package]
name = "solana-client"
version = "0.21.0"
version = "0.21.4"
description = "Solana Client"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -19,10 +19,10 @@ reqwest = { version = "0.9.22", default-features = false, features = ["rustls-tl
serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
[dev-dependencies]
jsonrpc-core = "14.0.3"
jsonrpc-http-server = "14.0.3"
solana-logger = { path = "../logger", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.4" }

View File

@ -11,7 +11,7 @@ use log::*;
use serde_json::{json, Value};
use solana_sdk::{
account::Account,
clock::{Slot, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT},
clock::{Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT},
commitment_config::CommitmentConfig,
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
@ -196,6 +196,32 @@ impl RpcClient {
})
}
pub fn get_block_time(&self, slot: Slot) -> io::Result<UnixTimestamp> {
let params = json!(slot);
let response = self
.client
.send(&RpcRequest::GetBlockTime, Some(params), 0, None);
response
.map(|result_json| {
if result_json.is_null() {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Block Not Found: slot={}", slot),
));
}
let result = serde_json::from_value(result_json)?;
trace!("Response block timestamp {:?} {:?}", slot, result);
Ok(result)
})
.map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("GetBlockTime request failure: {:?}", err),
)
})?
}
pub fn get_epoch_info(&self) -> io::Result<RpcEpochInfo> {
self.get_epoch_info_with_commitment(CommitmentConfig::default())
}

View File

@ -56,6 +56,10 @@ impl GenericRpcClientRequest for RpcClientRequest {
.send()
{
Ok(mut response) => {
if !response.status().is_success() {
return Err(response.error_for_status().unwrap_err().into());
}
let json: serde_json::Value = serde_json::from_str(&response.text()?)?;
if json["error"].is_object() {
return Err(RpcError::RpcRequestError(format!(

View File

@ -31,7 +31,7 @@ pub struct RpcConfirmedBlock {
pub transactions: Vec<(Transaction, Option<RpcTransactionStatus>)>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct RpcTransactionStatus {
pub status: Result<()>,
pub fee: u64,
@ -97,6 +97,10 @@ pub struct RpcVoteAccountInfo {
/// Whether this account is staked for the current epoch
pub epoch_vote_account: bool,
/// History of how many credits earned by the end of each epoch
/// each tuple is (Epoch, credits, prev_credits)
pub epoch_credits: Vec<(Epoch, u64, u64)>,
/// Most recent slot voted on by this vote account (0 if no votes exist)
pub last_vote: u64,
@ -111,6 +115,7 @@ pub enum RpcRequest {
ValidatorExit,
GetAccountInfo,
GetBalance,
GetBlockTime,
GetClusterNodes,
GetEpochInfo,
GetEpochSchedule,
@ -150,6 +155,7 @@ impl RpcRequest {
RpcRequest::ValidatorExit => "validatorExit",
RpcRequest::GetAccountInfo => "getAccountInfo",
RpcRequest::GetBalance => "getBalance",
RpcRequest::GetBlockTime => "getBlockTime",
RpcRequest::GetClusterNodes => "getClusterNodes",
RpcRequest::GetEpochInfo => "getEpochInfo",
RpcRequest::GetEpochSchedule => "getEpochSchedule",

View File

@ -1,7 +1,7 @@
[package]
name = "solana-core"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
documentation = "https://docs.rs/solana"
homepage = "https://solana.com/"
readme = "../README.md"
@ -41,25 +41,25 @@ rayon = "1.2.0"
serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-chacha-sys = { path = "../chacha-sys", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-chacha-sys = { path = "../chacha-sys", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-drone = { path = "../drone", version = "0.21.4" }
ed25519-dalek = "1.0.0-pre.1"
solana-ledger = { path = "../ledger", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-merkle-tree = { path = "../merkle-tree", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-measure = { path = "../measure", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-perf = { path = "../perf", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-storage-program = { path = "../programs/storage", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-vote-signer = { path = "../vote-signer", version = "0.21.0" }
solana-ledger = { path = "../ledger", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-merkle-tree = { path = "../merkle-tree", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-measure = { path = "../measure", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-perf = { path = "../perf", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-storage-program = { path = "../programs/storage", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
solana-vote-signer = { path = "../vote-signer", version = "0.21.4" }
symlink = "0.1.0"
sys-info = "0.5.8"
tempfile = "3.1.0"
@ -68,7 +68,7 @@ tokio-codec = "0.1"
tokio-fs = "0.1"
tokio-io = "0.1"
untrusted = "0.7.0"
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.0" }
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.4" }
reed-solomon-erasure = { package = "solana-reed-solomon-erasure", version = "4.0.1-3", features = ["simd-accel"] }
[target."cfg(unix)".dependencies]

View File

@ -1025,7 +1025,7 @@ impl ReplayStage {
);
datapoint_error!(
"replay-stage-entry_verification_failure",
"replay-stage-block-error",
("slot", bank.slot(), i64),
("last_entry", last_entry.to_string(), String),
);

View File

@ -295,7 +295,7 @@ mod tests {
..ProcessOptions::default()
};
let (bank_forks, _, cached_leader_schedule) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
let leader_schedule_cache = Arc::new(cached_leader_schedule);
let bank_forks = Arc::new(RwLock::new(bank_forks));

View File

@ -20,7 +20,7 @@ use solana_ledger::{bank_forks::BankForks, blocktree::Blocktree};
use solana_runtime::bank::Bank;
use solana_sdk::{
account::Account,
clock::Slot,
clock::{Slot, UnixTimestamp},
commitment_config::{CommitmentConfig, CommitmentLevel},
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
@ -28,6 +28,7 @@ use solana_sdk::{
inflation::Inflation,
pubkey::Pubkey,
signature::Signature,
timing::slot_duration_from_slots_per_year,
transaction::{self, Transaction},
};
use solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
@ -250,10 +251,15 @@ impl JsonRpcRequestProcessor {
activated_stake: *activated_stake,
commission: vote_state.commission,
root_slot: vote_state.root_slot.unwrap_or(0),
epoch_credits: vote_state.epoch_credits().clone(),
epoch_vote_account,
last_vote,
}
})
.filter(|vote_account_info| {
// Remove vote accounts with no delegated stake that have never voted
vote_account_info.last_vote != 0 || vote_account_info.activated_stake != 0
})
.partition(|vote_account_info| {
if bank.slot() >= MAX_LOCKOUT_HISTORY as u64 {
vote_account_info.last_vote > bank.slot() - MAX_LOCKOUT_HISTORY as u64
@ -304,6 +310,21 @@ impl JsonRpcRequestProcessor {
pub fn get_confirmed_block(&self, slot: Slot) -> Result<Option<RpcConfirmedBlock>> {
Ok(self.blocktree.get_confirmed_block(slot).ok())
}
// The `get_block_time` method is not fully implemented. It currently returns `slot` *
// DEFAULT_MS_PER_SLOT offset from 0 for all requests, and null for any values that would
// overflow.
pub fn get_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
// This calculation currently assumes that bank.ticks_per_slot and bank.slots_per_year will
// remain unchanged after genesis. If these values will be variable in the future, those
// timing parameters will need to be stored persistently, and this calculation will likely
// need to be moved upstream into blocktree. Also, an explicit commitment level will need
// to be set.
let bank = self.bank(None);
let slot_duration = slot_duration_from_slots_per_year(bank.slots_per_year());
Ok(self.blocktree.get_block_time(slot, slot_duration))
}
}
fn get_tpu_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
@ -513,6 +534,9 @@ pub trait RpcSol {
meta: Self::Metadata,
slot: Slot,
) -> Result<Option<RpcConfirmedBlock>>;
#[rpc(meta, name = "getBlockTime")]
fn get_block_time(&self, meta: Self::Metadata, slot: Slot) -> Result<Option<UnixTimestamp>>;
}
pub struct RpcSolImpl;
@ -967,6 +991,10 @@ impl RpcSol for RpcSolImpl {
.unwrap()
.get_confirmed_block(slot)
}
fn get_block_time(&self, meta: Self::Metadata, slot: Slot) -> Result<Option<UnixTimestamp>> {
meta.request_processor.read().unwrap().get_block_time(slot)
}
}
#[cfg(test)]
@ -987,27 +1015,34 @@ pub mod tests {
system_transaction,
transaction::TransactionError,
};
use solana_vote_program::{
vote_instruction,
vote_state::{Vote, VoteInit, MAX_LOCKOUT_HISTORY},
};
use std::{
collections::HashMap,
sync::atomic::{AtomicBool, Ordering},
thread,
};
const TEST_MINT_LAMPORTS: u64 = 10_000;
const TEST_MINT_LAMPORTS: u64 = 1_000_000;
const TEST_SLOTS_PER_EPOCH: u64 = 50;
struct RpcHandler {
io: MetaIoHandler<Meta>,
meta: Meta,
bank: Arc<Bank>,
bank_forks: Arc<RwLock<BankForks>>,
blockhash: Hash,
alice: Keypair,
leader_pubkey: Pubkey,
leader_vote_keypair: Keypair,
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
confirmed_block_signatures: Vec<Signature>,
}
fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> RpcHandler {
let (bank_forks, alice) = new_bank_forks();
let (bank_forks, alice, leader_vote_keypair) = new_bank_forks();
let bank = bank_forks.read().unwrap().working_bank();
let commitment_slot0 = BlockCommitment::new([8; MAX_LOCKOUT_HISTORY]);
@ -1049,7 +1084,7 @@ pub mod tests {
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
JsonRpcConfig::default(),
bank_forks,
bank_forks.clone(),
block_commitment_cache.clone(),
blocktree,
StorageState::default(),
@ -1079,9 +1114,11 @@ pub mod tests {
io,
meta,
bank,
bank_forks,
blockhash,
alice,
leader_pubkey,
leader_vote_keypair,
block_commitment_cache,
confirmed_block_signatures,
}
@ -1092,7 +1129,7 @@ pub mod tests {
let bob_pubkey = Pubkey::new_rand();
let exit = Arc::new(AtomicBool::new(false));
let validator_exit = create_validator_exit(&exit);
let (bank_forks, alice) = new_bank_forks();
let (bank_forks, alice, _) = new_bank_forks();
let bank = bank_forks.read().unwrap().working_bank();
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
let ledger_path = get_tmp_ledger_path!();
@ -1602,20 +1639,23 @@ pub mod tests {
);
}
fn new_bank_forks() -> (Arc<RwLock<BankForks>>, Keypair) {
fn new_bank_forks() -> (Arc<RwLock<BankForks>>, Keypair, Keypair) {
let GenesisConfigInfo {
mut genesis_config,
mint_keypair,
..
voting_keypair,
} = create_genesis_config(TEST_MINT_LAMPORTS);
genesis_config.rent.lamports_per_byte_year = 50;
genesis_config.rent.exemption_threshold = 2.0;
genesis_config.epoch_schedule =
EpochSchedule::custom(TEST_SLOTS_PER_EPOCH, TEST_SLOTS_PER_EPOCH, false);
let bank = Bank::new(&genesis_config);
(
Arc::new(RwLock::new(BankForks::new(bank.slot(), bank))),
mint_keypair,
voting_keypair,
)
}
@ -1818,4 +1858,153 @@ pub mod tests {
}
}
}
#[test]
fn test_get_block_time() {
let bob_pubkey = Pubkey::new_rand();
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&bob_pubkey);
let slot_duration = slot_duration_from_slots_per_year(bank.slots_per_year());
let slot = 100;
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockTime","params":[{}]}}"#,
slot
);
let res = io.handle_request_sync(&req, meta.clone());
let expected = format!(
r#"{{"jsonrpc":"2.0","result":{},"id":1}}"#,
(slot * slot_duration).as_secs()
);
let expected: Response =
serde_json::from_str(&expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
let slot = 12345;
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockTime","params":[{}]}}"#,
slot
);
let res = io.handle_request_sync(&req, meta.clone());
let expected = format!(
r#"{{"jsonrpc":"2.0","result":{},"id":1}}"#,
(slot * slot_duration).as_secs()
);
let expected: Response =
serde_json::from_str(&expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
let slot = 123450000000000000u64;
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockTime","params":[{}]}}"#,
slot
);
let res = io.handle_request_sync(&req, meta);
let expected = format!(r#"{{"jsonrpc":"2.0","result":null,"id":1}}"#);
let expected: Response =
serde_json::from_str(&expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
}
#[test]
fn test_get_vote_accounts() {
let RpcHandler {
io,
meta,
mut bank,
bank_forks,
alice,
leader_vote_keypair,
..
} = start_rpc_handler_with_tx(&Pubkey::new_rand());
assert_eq!(bank.vote_accounts().len(), 1);
// Create a second vote account that has no stake. It should not be included in the
// getVoteAccounts response
let vote_keypair = Keypair::new();
let instructions = vote_instruction::create_account(
&alice.pubkey(),
&vote_keypair.pubkey(),
&VoteInit {
node_pubkey: alice.pubkey(),
authorized_voter: vote_keypair.pubkey(),
authorized_withdrawer: vote_keypair.pubkey(),
commission: 0,
},
bank.get_minimum_balance_for_rent_exemption(VoteState::size_of()),
);
let transaction = Transaction::new_signed_instructions(
&[&alice, &vote_keypair],
instructions,
bank.last_blockhash(),
);
bank.process_transaction(&transaction)
.expect("process transaction");
assert_eq!(bank.vote_accounts().len(), 2);
// Advance bank to the next epoch
for _ in 0..TEST_SLOTS_PER_EPOCH {
bank.freeze();
let instruction = vote_instruction::vote(
&leader_vote_keypair.pubkey(),
&leader_vote_keypair.pubkey(),
Vote {
slots: vec![bank.slot()],
hash: bank.hash(),
},
);
bank = bank_forks.write().unwrap().insert(Bank::new_from_parent(
&bank,
&Pubkey::default(),
bank.slot() + 1,
));
let transaction = Transaction::new_signed_with_payer(
vec![instruction],
Some(&alice.pubkey()),
&[&alice, &leader_vote_keypair],
bank.last_blockhash(),
);
bank.process_transaction(&transaction)
.expect("process transaction");
}
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getVoteAccounts","params":{}}}"#,
json!([CommitmentConfig::recent()])
);
let res = io.handle_request_sync(&req, meta.clone());
let result: Value = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
let vote_account_status: RpcVoteAccountStatus =
serde_json::from_value(result["result"].clone()).unwrap();
// The vote account with no stake should not be present.
assert!(vote_account_status.delinquent.is_empty());
// The leader vote account should be active and have voting history.
assert_eq!(vote_account_status.current.len(), 1);
let leader_info = &vote_account_status.current[0];
assert_eq!(
leader_info.vote_pubkey,
leader_vote_keypair.pubkey().to_string()
);
assert_ne!(leader_info.activated_stake, 0);
// Subtract one because the last vote always carries over to the next epoch
let expected_credits = TEST_SLOTS_PER_EPOCH - MAX_LOCKOUT_HISTORY as u64 - 1;
assert_eq!(leader_info.epoch_credits, vec![(0, expected_credits, 0)]);
}
}

View File

@ -11,7 +11,7 @@ use crate::sigverify;
use crate::streamer::{self, PacketReceiver};
use crossbeam_channel::Sender as CrossbeamSender;
use solana_measure::measure::Measure;
use solana_metrics::{datapoint_debug, inc_new_counter_info};
use solana_metrics::datapoint_debug;
use solana_perf::perf_libs;
use solana_sdk::timing;
use std::sync::mpsc::{Receiver, RecvTimeoutError};
@ -65,7 +65,6 @@ impl SigVerifyStage {
RECV_BATCH_MAX_CPU
},
)?;
inc_new_counter_info!("sigverify_stage-packets_received", len);
let mut verify_batch_time = Measure::start("sigverify_batch_time");
let batch_len = batch.len();
@ -77,7 +76,6 @@ impl SigVerifyStage {
);
let verified_batch = verifier.verify_batch(batch);
inc_new_counter_info!("sigverify_stage-verified_packets_send", len);
for v in verified_batch {
if sendr.send(vec![v]).is_err() {
@ -87,10 +85,6 @@ impl SigVerifyStage {
verify_batch_time.stop();
inc_new_counter_info!(
"sigverify_stage-time_ms",
(verify_batch_time.as_ms() + recv_time) as usize
);
debug!(
"@{:?} verifier: done. batches: {} total verify time: {:?} id: {} verified: {} v/s {}",
timing::timestamp(),
@ -103,9 +97,10 @@ impl SigVerifyStage {
datapoint_debug!(
"sigverify_stage-total_verify_time",
("batch_len", batch_len, i64),
("len", len, i64),
("total_time_ms", verify_batch_time.as_ms(), i64)
("num_batches", batch_len, i64),
("num_packets", len, i64),
("verify_time_ms", verify_batch_time.as_ms(), i64),
("recv_time", recv_time, i64),
);
Ok(())

View File

@ -87,7 +87,14 @@ impl SnapshotPackagerService {
// `storage_path` - The file path where the AppendVec itself is located
// `output_path` - The directory where the AppendVec will be placed in the staging directory.
symlink::symlink_dir(storage_path, output_path)?;
let storage_path =
fs::canonicalize(storage_path).expect("Could not get absolute path for accounts");
symlink::symlink_dir(storage_path, &output_path)?;
if !output_path.is_file() {
return Err(Self::get_io_error(
"Error trying to generate snapshot archive: storage path symlink is invalid",
));
}
}
// Tar the staging directory into the archive at `archive_path`
@ -185,17 +192,42 @@ mod tests {
use super::*;
use solana_ledger::snapshot_utils;
use solana_runtime::accounts_db::AccountStorageEntry;
use std::fs::OpenOptions;
use std::io::Write;
use std::{
fs::{remove_dir_all, OpenOptions},
io::Write,
path::{Path, PathBuf},
};
use tempfile::TempDir;
// Create temporary placeholder directory for all test files
fn make_tmp_dir_path() -> PathBuf {
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
let path = PathBuf::from(format!("{}/tmp/test_package_snapshots", out_dir));
// whack any possible collision
let _ignored = std::fs::remove_dir_all(&path);
// whack any possible collision
let _ignored = std::fs::remove_file(&path);
path
}
#[test]
fn test_package_snapshots_relative_ledger_path() {
let temp_dir = make_tmp_dir_path();
create_and_verify_snapshot(&temp_dir);
remove_dir_all(temp_dir).expect("should remove tmp dir");
}
#[test]
fn test_package_snapshots() {
// Create temporary placeholder directory for all test files
let temp_dir = TempDir::new().unwrap();
let accounts_dir = temp_dir.path().join("accounts");
let snapshots_dir = temp_dir.path().join("snapshots");
let snapshot_package_output_path = temp_dir.path().join("snapshots_output");
create_and_verify_snapshot(TempDir::new().unwrap().path())
}
fn create_and_verify_snapshot(temp_dir: &Path) {
let accounts_dir = temp_dir.join("accounts");
let snapshots_dir = temp_dir.join("snapshots");
let snapshot_package_output_path = temp_dir.join("snapshots_output");
fs::create_dir_all(&snapshot_package_output_path).unwrap();
// Create some storage entries
@ -221,7 +253,7 @@ mod tests {
.collect();
// Create directory of hard links for snapshots
let link_snapshots_dir = tempfile::tempdir_in(temp_dir.path()).unwrap();
let link_snapshots_dir = tempfile::tempdir_in(&temp_dir).unwrap();
for snapshots_path in snapshots_paths {
let snapshot_file_name = snapshots_path.file_name().unwrap();
let link_path = link_snapshots_dir.path().join(snapshot_file_name);

View File

@ -41,7 +41,9 @@ fn recv_loop(
}
recv_count += len;
call_count += 1;
channel.send(msgs)?;
if len > 0 {
channel.send(msgs)?;
}
break;
}
}
@ -55,9 +57,9 @@ fn recv_loop(
);
recv_count = 0;
call_count = 0;
now = Instant::now();
num_max_received = 0;
}
now = Instant::now();
}
}
@ -100,7 +102,6 @@ pub fn recv_batch(recvr: &PacketReceiver, max_batch: usize) -> Result<(Vec<Packe
trace!("got more msgs");
len += more.packets.len();
batch.push(more);
if len > max_batch {
break;
}

View File

@ -26,6 +26,7 @@ use solana_ledger::{
blocktree::{Blocktree, CompletedSlotsReceiver},
blocktree_processor::{self, BankForksInfo},
create_new_tmp_ledger,
leader_schedule::FixedSchedule,
leader_schedule_cache::LeaderScheduleCache,
};
use solana_metrics::datapoint_info;
@ -59,12 +60,13 @@ pub struct ValidatorConfig {
pub transaction_status_service_disabled: bool,
pub blockstream_unix_socket: Option<PathBuf>,
pub storage_slots_per_turn: u64,
pub account_paths: Option<String>,
pub account_paths: Vec<PathBuf>,
pub rpc_config: JsonRpcConfig,
pub snapshot_config: Option<SnapshotConfig>,
pub max_ledger_slots: Option<u64>,
pub broadcast_stage_type: BroadcastStageType,
pub partition_cfg: Option<PartitionCfg>,
pub fixed_leader_schedule: Option<FixedSchedule>,
}
impl Default for ValidatorConfig {
@ -78,11 +80,12 @@ impl Default for ValidatorConfig {
blockstream_unix_socket: None,
storage_slots_per_turn: DEFAULT_SLOTS_PER_TURN,
max_ledger_slots: None,
account_paths: None,
account_paths: Vec::new(),
rpc_config: JsonRpcConfig::default(),
snapshot_config: None,
broadcast_stage_type: BroadcastStageType::Standard,
partition_cfg: None,
fixed_leader_schedule: None,
}
}
}
@ -182,6 +185,7 @@ impl Validator {
config.snapshot_config.clone(),
poh_verify,
config.dev_halt_at_slot,
config.fixed_leader_schedule.clone(),
);
let leader_schedule_cache = Arc::new(leader_schedule_cache);
@ -465,10 +469,11 @@ impl Validator {
pub fn new_banks_from_blocktree(
expected_genesis_hash: Option<Hash>,
blocktree_path: &Path,
account_paths: Option<String>,
account_paths: Vec<PathBuf>,
snapshot_config: Option<SnapshotConfig>,
poh_verify: bool,
dev_halt_at_slot: Option<Slot>,
fixed_leader_schedule: Option<FixedSchedule>,
) -> (
Hash,
BankForks,
@ -506,7 +511,7 @@ pub fn new_banks_from_blocktree(
..blocktree_processor::ProcessOptions::default()
};
let (mut bank_forks, bank_forks_info, leader_schedule_cache) = bank_forks_utils::load(
let (mut bank_forks, bank_forks_info, mut leader_schedule_cache) = bank_forks_utils::load(
&genesis_config,
&blocktree,
account_paths,
@ -518,6 +523,8 @@ pub fn new_banks_from_blocktree(
std::process::exit(1);
});
leader_schedule_cache.set_fixed_leader_schedule(fixed_leader_schedule);
bank_forks.set_snapshot_config(snapshot_config);
(

View File

@ -52,7 +52,7 @@ mod tests {
let genesis_config_info = create_genesis_config(10_000);
let bank0 = Bank::new_with_paths(
&genesis_config_info.genesis_config,
Some(accounts_dir.path().to_str().unwrap().to_string()),
vec![accounts_dir.path().to_path_buf()],
);
bank0.freeze();
let mut bank_forks = BankForks::new(0, bank0);
@ -73,7 +73,7 @@ mod tests {
}
}
fn restore_from_snapshot(old_bank_forks: &BankForks, account_paths: String) {
fn restore_from_snapshot(old_bank_forks: &BankForks, account_paths: Vec<PathBuf>) {
let (snapshot_path, snapshot_package_output_path) = old_bank_forks
.snapshot_config
.as_ref()
@ -81,7 +81,7 @@ mod tests {
.unwrap();
let deserialized_bank = snapshot_utils::bank_from_archive(
account_paths,
&account_paths,
&old_bank_forks
.snapshot_config
.as_ref()
@ -151,10 +151,7 @@ mod tests {
.unwrap();
SnapshotPackagerService::package_snapshots(&snapshot_package).unwrap();
restore_from_snapshot(
bank_forks,
accounts_dir.path().to_str().unwrap().to_string(),
);
restore_from_snapshot(bank_forks, vec![accounts_dir.path().to_path_buf()]);
}
#[test]
@ -237,7 +234,7 @@ mod tests {
let key1 = Keypair::new().pubkey();
let tx = system_transaction::transfer(&mint_keypair, &key1, 1, genesis_config.hash());
assert_eq!(bank.process_transaction(&tx), Ok(()));
bank.freeze();
bank.squash();
bank_forks.insert(bank);
let package_sender = {

View File

@ -1,6 +1,6 @@
[package]
name = "solana-crate-features"
version = "0.21.0"
version = "0.21.4"
description = "Solana Crate Features"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-drone"
version = "0.21.0"
version = "0.21.4"
description = "Solana Drone"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -19,10 +19,10 @@ clap = "2.33"
log = "0.4.8"
serde = "1.0.102"
serde_derive = "1.0.102"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
tokio = "0.1"
tokio-codec = "0.1"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-fixed-buf"
version = "0.21.0"
version = "0.21.4"
description = "A fixed-size byte array that supports bincode serde"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-genesis-programs"
version = "0.21.0"
version = "0.21.4"
description = "Solana genesis programs"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -10,16 +10,16 @@ edition = "2018"
[dependencies]
log = { version = "0.4.8" }
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-config-program = { path = "../programs/config", version = "0.21.0" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-storage-program = { path = "../programs/storage", version = "0.21.0" }
solana-vest-program = { path = "../programs/vest", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "0.21.4" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
solana-config-program = { path = "../programs/config", version = "0.21.4" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-storage-program = { path = "../programs/storage", version = "0.21.4" }
solana-vest-program = { path = "../programs/vest", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
[lib]
crate-type = ["lib"]

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-genesis"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -16,11 +16,11 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.0" }
solana-ledger = { path = "../ledger", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-storage-program = { path = "../programs/storage", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.4" }
solana-ledger = { path = "../ledger", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-storage-program = { path = "../programs/storage", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
tempfile = "3.1.0"

View File

@ -24,6 +24,7 @@ impl AddressGenerator {
.as_ref(),
)
}
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Pubkey {
let nth = self.nth;
self.nth += 1;

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,9 @@
pub mod address_generator;
pub mod genesis_accounts;
pub mod stakes;
pub mod unlocks;
pub mod validators;
use serde::{Deserialize, Serialize};
/// An account where the data is encoded as a Base64 string.

View File

@ -1,14 +1,9 @@
//! A command-line executable for generating the chain's genesis config.
mod address_generator;
mod genesis_accounts;
mod stakes;
mod unlocks;
use crate::genesis_accounts::add_genesis_accounts;
use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches};
use solana_clap_utils::input_parsers::pubkey_of;
use solana_genesis::Base64Account;
use solana_clap_utils::input_validators::is_valid_percentage;
use solana_genesis::{genesis_accounts::add_genesis_accounts, Base64Account};
use solana_ledger::{blocktree::create_new_ledger, poh::compute_hashes_per_tick};
use solana_sdk::{
account::Account,
@ -27,7 +22,15 @@ use solana_sdk::{
use solana_stake_program::stake_state;
use solana_storage_program::storage_contract;
use solana_vote_program::vote_state;
use std::{collections::HashMap, error, fs::File, io, path::PathBuf, str::FromStr, time::Duration};
use std::{
collections::{BTreeMap, HashMap},
error,
fs::File,
io,
path::PathBuf,
str::FromStr,
time::Duration,
};
pub enum AccountFileFormat {
Pubkey,
@ -116,7 +119,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
};
let default_target_tick_duration =
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).to_string();
timing::duration_as_us(&PohConfig::default().target_tick_duration);
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
let default_operating_mode = "softlaunch";
@ -161,7 +164,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.arg(
Arg::with_name("bootstrap_vote_pubkey_file")
.short("s")
.long("bootstrap-vote-pubkey")
.value_name("BOOTSTRAP VOTE PUBKEY")
.takes_value(true)
@ -170,13 +172,19 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.arg(
Arg::with_name("bootstrap_stake_pubkey_file")
.short("k")
.long("bootstrap-stake-pubkey")
.value_name("BOOTSTRAP STAKE PUBKEY")
.takes_value(true)
.required(true)
.help("Path to file containing the bootstrap leader's staking pubkey"),
)
.arg(
Arg::with_name("bootstrap_stake_authorized_pubkey_file")
.long("bootstrap-stake-authorized-pubkey")
.value_name("BOOTSTRAP STAKE AUTHORIZED PUBKEY")
.takes_value(true)
.help("Path to file containing the pubkey authorized to manage the bootstrap leader's stake [default: --bootstrap-leader-pubkey]"),
)
.arg(
Arg::with_name("bootstrap_storage_pubkey_file")
.long("bootstrap-storage-pubkey")
@ -241,7 +249,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.value_name("NUMBER")
.takes_value(true)
.default_value(default_rent_burn_percentage)
.help("amount of rent to burn, as a fraction of std::u8::MAX."),
.help("percentage of collected rent to burn")
.validator(is_valid_percentage),
)
.arg(
Arg::with_name("target_signatures_per_slot")
@ -261,7 +270,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("target-tick-duration")
.value_name("MILLIS")
.takes_value(true)
.default_value(default_target_tick_duration)
.help("The target tick rate of the cluster in milliseconds"),
)
.arg(
@ -314,7 +322,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.get_matches();
let faucet_lamports = value_t!(matches, "faucet_lamports", u64);
let faucet_lamports = value_t!(matches, "faucet_lamports", u64).unwrap_or(0);
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
let bootstrap_leader_lamports = value_t_or_exit!(matches, "bootstrap_leader_lamports", u64);
let bootstrap_leader_stake_lamports =
@ -323,6 +331,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_leader_pubkey = required_pubkey(&matches, "bootstrap_leader_pubkey_file")?;
let bootstrap_vote_pubkey = required_pubkey(&matches, "bootstrap_vote_pubkey_file")?;
let bootstrap_stake_pubkey = required_pubkey(&matches, "bootstrap_stake_pubkey_file")?;
let bootstrap_stake_authorized_pubkey =
pubkey_of(&matches, "bootstrap_stake_authorized_pubkey_file");
let bootstrap_storage_pubkey = pubkey_of(&matches, "bootstrap_storage_pubkey_file");
let faucet_pubkey = pubkey_of(&matches, "faucet_pubkey_file");
@ -336,14 +346,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
let bootstrap_leader_stake_account = stake_state::create_account(
&bootstrap_leader_pubkey,
bootstrap_stake_authorized_pubkey
.as_ref()
.unwrap_or(&bootstrap_leader_pubkey),
&bootstrap_vote_pubkey,
&bootstrap_leader_vote_account,
&rent,
bootstrap_leader_stake_lamports,
);
let mut accounts = vec![
let mut accounts: BTreeMap<Pubkey, Account> = [
// node needs an account to issue votes from
(
bootstrap_leader_pubkey,
@ -353,13 +365,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
(bootstrap_vote_pubkey, bootstrap_leader_vote_account),
// bootstrap leader stake
(bootstrap_stake_pubkey, bootstrap_leader_stake_account),
];
]
.iter()
.cloned()
.collect();
if let Some(bootstrap_storage_pubkey) = bootstrap_storage_pubkey {
accounts.push((
accounts.insert(
bootstrap_storage_pubkey,
storage_contract::create_validator_storage_account(bootstrap_leader_pubkey, 1),
));
);
}
let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64);
@ -370,8 +385,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
);
let mut poh_config = PohConfig::default();
poh_config.target_tick_duration =
Duration::from_millis(value_t_or_exit!(matches, "target_tick_duration", u64));
poh_config.target_tick_duration = if matches.is_present("target_tick_duration") {
Duration::from_micros(value_t_or_exit!(matches, "target_tick_duration", u64))
} else {
Duration::from_micros(default_target_tick_duration)
};
let operating_mode = if matches.value_of("operating_mode").unwrap() == "development" {
OperatingMode::Development
@ -429,7 +447,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
if let Some(faucet_pubkey) = faucet_pubkey {
genesis_config.add_account(
faucet_pubkey,
Account::new(faucet_lamports.unwrap(), 0, &system_program::id()),
Account::new(faucet_lamports, 0, &system_program::id()),
);
}
@ -443,12 +461,19 @@ fn main() -> Result<(), Box<dyn error::Error>> {
}
}
add_genesis_accounts(&mut genesis_config);
let issued_lamports = genesis_config
.accounts
.iter()
.map(|(_key, account)| account.lamports)
.sum::<u64>();
add_genesis_accounts(&mut genesis_config, issued_lamports - faucet_lamports);
create_new_ledger(&ledger_path, &genesis_config)?;
println!(
"Genesis mode: {:?} hashes per tick: {:?} slots_per_epoch: {} capitalization: {}SOL in {} accounts",
"Genesis hash: {}\nOperating mode: {:?}\nHashes per tick: {:?}\nSlots per epoch: {}\nCapitalization: {} SOL in {} accounts",
genesis_config.hash(),
operating_mode,
genesis_config.poh_config.hashes_per_tick,
slots_per_epoch,
@ -535,27 +560,28 @@ mod tests {
assert_eq!(genesis_config.accounts.len(), genesis_accounts.len());
// Test account data matches
(0..genesis_accounts.len()).for_each(|i| {
for (pubkey_str, b64_account) in genesis_accounts.iter() {
let pubkey = pubkey_str.parse().unwrap();
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].owner,
genesis_config.accounts[i].1.owner.to_string()
b64_account.owner,
genesis_config.accounts[&pubkey].owner.to_string()
);
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].balance,
genesis_config.accounts[i].1.lamports
b64_account.balance,
genesis_config.accounts[&pubkey].lamports
);
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].executable,
genesis_config.accounts[i].1.executable
b64_account.executable,
genesis_config.accounts[&pubkey].executable
);
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].data,
base64::encode(&genesis_config.accounts[i].1.data)
b64_account.data,
base64::encode(&genesis_config.accounts[&pubkey].data)
);
});
}
}
// Test more accounts can be appended
@ -608,54 +634,37 @@ mod tests {
);
// Test old accounts are still there
(0..genesis_accounts.len()).for_each(|i| {
for (pubkey_str, b64_account) in genesis_accounts.iter() {
let pubkey = &pubkey_str.parse().unwrap();
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].balance,
genesis_config.accounts[i].1.lamports,
b64_account.balance,
genesis_config.accounts[&pubkey].lamports,
);
});
}
// Test new account data matches
(0..genesis_accounts1.len()).for_each(|i| {
for (pubkey_str, b64_account) in genesis_accounts1.iter() {
let pubkey = pubkey_str.parse().unwrap();
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.owner,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.owner
.to_string(),
b64_account.owner,
genesis_config.accounts[&pubkey].owner.to_string()
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.balance,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.lamports,
b64_account.balance,
genesis_config.accounts[&pubkey].lamports,
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.executable,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.executable,
b64_account.executable,
genesis_config.accounts[&pubkey].executable,
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.data,
base64::encode(&genesis_config.accounts[genesis_accounts.len() + i].1.data),
b64_account.data,
base64::encode(&genesis_config.accounts[&pubkey].data),
);
});
}
// Test accounts from keypairs can be appended
let account_keypairs: Vec<_> = (0..3).map(|_| Keypair::new()).collect();
@ -710,89 +719,60 @@ mod tests {
);
// Test old accounts are still there
(0..genesis_accounts.len()).for_each(|i| {
for (pubkey_str, b64_account) in genesis_accounts {
let pubkey = pubkey_str.parse().unwrap();
assert_eq!(
genesis_accounts[&genesis_config.accounts[i].0.to_string()].balance,
genesis_config.accounts[i].1.lamports,
b64_account.balance,
genesis_config.accounts[&pubkey].lamports,
);
});
}
// Test new account data matches
(0..genesis_accounts1.len()).for_each(|i| {
for (pubkey_str, b64_account) in genesis_accounts1 {
let pubkey = pubkey_str.parse().unwrap();
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.owner,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.owner
.to_string(),
b64_account.owner,
genesis_config.accounts[&pubkey].owner.to_string(),
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.balance,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.lamports,
b64_account.balance,
genesis_config.accounts[&pubkey].lamports,
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.executable,
genesis_config.accounts[genesis_accounts.len() + i]
.1
.executable,
b64_account.executable,
genesis_config.accounts[&pubkey].executable,
);
assert_eq!(
genesis_accounts1[&genesis_config.accounts[genesis_accounts.len() + i]
.0
.to_string()]
.data,
base64::encode(&genesis_config.accounts[genesis_accounts.len() + i].1.data),
b64_account.data,
base64::encode(&genesis_config.accounts[&pubkey].data),
);
});
}
let offset = genesis_accounts.len() + genesis_accounts1.len();
// Test account data for keypairs matches
account_keypairs.iter().for_each(|keypair| {
let mut i = 0;
(offset..(offset + account_keypairs.len())).for_each(|n| {
if keypair.pubkey() == genesis_config.accounts[n].0 {
i = n;
}
});
assert_ne!(i, 0);
let keypair_str = serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap();
let pubkey = keypair.pubkey();
assert_eq!(
genesis_accounts2[&serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap()]
.owner,
genesis_config.accounts[i].1.owner.to_string(),
genesis_accounts2[&keypair_str].owner,
genesis_config.accounts[&pubkey].owner.to_string(),
);
assert_eq!(
genesis_accounts2[&serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap()]
.balance,
genesis_config.accounts[i].1.lamports,
genesis_accounts2[&keypair_str].balance,
genesis_config.accounts[&pubkey].lamports,
);
assert_eq!(
genesis_accounts2[&serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap()]
.executable,
genesis_config.accounts[i].1.executable,
genesis_accounts2[&keypair_str].executable,
genesis_config.accounts[&pubkey].executable,
);
assert_eq!(
genesis_accounts2[&serde_json::to_string(&keypair.to_bytes().to_vec()).unwrap()]
.data,
base64::encode(&genesis_config.accounts[i].1.data),
genesis_accounts2[&keypair_str].data,
base64::encode(&genesis_config.accounts[&pubkey].data),
);
});
}

View File

@ -8,30 +8,27 @@ use solana_sdk::{
pubkey::Pubkey, system_program, timing::years_as_slots,
};
use solana_stake_program::stake_state::{
create_lockup_stake_account, get_stake_rent_exempt_reserve, Authorized, Lockup,
create_lockup_stake_account, Authorized, Lockup, StakeState,
};
#[derive(Debug)]
pub struct StakerInfo {
pub name: &'static str,
pub staker: &'static str,
pub withdrawer: &'static str,
pub sol: f64,
pub custodian: &'static str,
}
// lamports required to run staking operations for one year
// the staker account needs to be rent exempt *and* carry enough
// the staker account needs carry enough
// lamports to cover TX fees (delegation) for one year,
// and we support one delegation per epoch
fn calculate_staker_lamports(genesis_config: &GenesisConfig) -> u64 {
genesis_config.rent.minimum_balance(0).max(1)
+ genesis_config.fee_calculator.max_lamports_per_signature
* genesis_config.epoch_schedule.get_epoch(years_as_slots(
1.0,
&genesis_config.poh_config.target_tick_duration,
genesis_config.ticks_per_slot,
) as Slot)
fn calculate_staker_fees(genesis_config: &GenesisConfig, years: f64) -> u64 {
genesis_config.fee_calculator.max_lamports_per_signature
* genesis_config.epoch_schedule.get_epoch(years_as_slots(
years,
&genesis_config.poh_config.target_tick_duration,
genesis_config.ticks_per_slot,
) as Slot)
}
/// create stake accounts for lamports with at most stake_granularity in each
@ -45,27 +42,38 @@ pub fn create_and_add_stakes(
// the largest each stake account should be, in lamports
granularity: u64,
) -> u64 {
let authorized = Authorized {
staker: Pubkey::new(&hex::decode(staker_info.staker).expect("hex")),
withdrawer: Pubkey::new(&hex::decode(staker_info.withdrawer).expect("hex")),
};
let custodian = Pubkey::new(&hex::decode(staker_info.custodian).expect("hex"));
let authorized = Authorized::auto(
&staker_info
.staker
.parse::<Pubkey>()
.expect("invalid staker"),
);
let custodian = unlock_info
.custodian
.parse::<Pubkey>()
.expect("invalid custodian");
let total_lamports = sol_to_lamports(staker_info.sol);
let staker_lamports = calculate_staker_lamports(genesis_config);
let staker_account = (
authorized.staker,
Account::new(staker_lamports, 0, &system_program::id()),
);
// staker is a system account
let staker_rent_reserve = genesis_config.rent.minimum_balance(0).max(1);
let staker_fees = calculate_staker_fees(genesis_config, 1.0);
let stakes_lamports = if !genesis_config.accounts.contains(&staker_account) {
genesis_config.accounts.push(staker_account);
let mut stakes_lamports = total_lamports - staker_fees;
total_lamports - staker_lamports
} else {
total_lamports
};
// lamports required to run staking operations for one year
// the staker account needs to be rent exempt *and* carry enough
// lamports to cover TX fees (delegation) for one year,
// and we support one delegation per epoch
// a single staker may administer any number of accounts
genesis_config
.accounts
.entry(authorized.staker)
.or_insert_with(|| {
stakes_lamports -= staker_rent_reserve;
Account::new(staker_rent_reserve, 0, &system_program::id())
})
.lamports += staker_fees;
// the staker account needs to be rent exempt *and* carry enough
// lamports to cover TX fees (delegation) for one year
@ -82,7 +90,7 @@ pub fn create_and_add_stakes(
let mut address_generator = AddressGenerator::new(&authorized.staker, staker_info.name);
let stake_rent_exempt_reserve = get_stake_rent_exempt_reserve(&genesis_config.rent);
let stake_rent_reserve = StakeState::get_rent_exempt_reserve(&genesis_config.rent);
for unlock in unlocks {
let lamports = unlock.amount(stakes_lamports);
@ -108,7 +116,7 @@ pub fn create_and_add_stakes(
),
);
}
if remainder <= stake_rent_exempt_reserve {
if remainder <= stake_rent_reserve {
genesis_config.add_account(
address_generator.next(),
create_lockup_stake_account(
@ -150,11 +158,10 @@ mod tests {
granularity: u64,
len: usize,
) {
assert!(
total_lamports
== create_and_add_stakes(genesis_config, staker_info, unlock_info, granularity)
assert_eq!(
total_lamports,
create_and_add_stakes(genesis_config, staker_info, unlock_info, granularity)
);
assert_eq!(genesis_config.accounts.len(), len);
assert_eq!(
genesis_config
@ -169,9 +176,41 @@ mod tests {
.iter()
.all(|(_pubkey, account)| account.lamports <= granularity
|| account.lamports - granularity
< get_stake_rent_exempt_reserve(&genesis_config.rent)));
<= StakeState::get_rent_exempt_reserve(&genesis_config.rent)));
}
// #[ignore]
// #[test]
// fn hex_test_keys_to_bs58() {
// vec![
// "ab22196afde08a090a3721eb20e3e1ea84d36e14d1a3f0815b236b300d9d33ef", // CX2sgoat51bnDgCN2YeesrTcscgVhnhWnwxtWEEEqBs4
// "a2a7ae9098f862f4b3ba7d102d174de5e84a560444c39c035f3eeecce442eadc", // BwwM47pLHwUgjJXKQKVNiRfGhtPNWfNLH27na2HJQHhd
// "6a56514c29f6b1de4d46164621d6bd25b337a711f569f9283c1143c7e8fb546e", // 8A6ZEEW2odkqXNjTWHNG6tUk7uj6zCzHueTyEr9pM1tH
// "b420af728f58d9f269d6e07fbbaecf6ed6535e5348538e3f39f2710351f2b940", // D89HyaBmr2WmrTehsfkQrY23wCXcDfsFnN9gMfUXHaDd
// "ddf2e4c81eafae2d68ac99171b066c87bddb168d6b7c07333cd951f36640163d", // FwPvDpvUmnco1CSfwXQDTbUbuhG5eP7h2vgCKYKVL7at
// "312fa06ccf1b671b26404a34136161ed2aba9e66f248441b4fddb5c592fde560", // 4K16iBoC9kAQRT8pUEKeD2h9WEx1zsRgEmJFssXcXmqq
// "0cbf98cd35ceff84ca72b752c32cc3eeee4f765ca1bef1140927ebf5c6e74339", // rmLpENW4V6QNeEhdJJVxo9Xt99oKgNUFZS4Y4375amW
// "467e06fa25a9e06824eedc926ce431947ed99c728bed36be54561354c1330959", // 5kAztE3XtrpeyGZZxckSUt3ZWojNTmph1QSC9S2682z4
// "ef1562bf9edfd0f5e62530cce4244e8de544a3a30075a2cd5c9074edfbcbe78a", // H6HMVuDR8XCw3EuhLvFG4EciVvGo76Agq1kSBL2ozoDs
// "2ab26abb9d8131a30a4a63446125cf961ece4b926c31cce0eb84da4eac3f836e", // 3sfv8tk5ZSDBWbTkFkvFxCvJUyW5yDJUu6VMJcUARQWq
// ]
// .iter()
// .for_each(|_hex| {
// print(
// "\n\"{}\", // {:?}",
// hex,
// Pubkey::new(&hex::decode(hex).unwrap())
// );
// });
// println();
// println(
// "{:?}",
// "P1aceHo1derPubkey11111111111111111111111111"
// .parse::<Pubkey>()
// .unwrap()
// );
//}
#[test]
fn test_create_stakes() {
// 2 unlocks
@ -182,11 +221,12 @@ mod tests {
..Rent::default()
};
let reserve = get_stake_rent_exempt_reserve(&rent);
let reserve = StakeState::get_rent_exempt_reserve(&rent);
let staker_reserve = rent.minimum_balance(0);
// verify that a small remainder ends up in the last stake
let granularity = reserve;
let total_lamports = reserve + reserve * 2 + 1;
let total_lamports = staker_reserve + reserve * 2 + 1;
create_and_check_stakes(
&mut GenesisConfig {
rent,
@ -194,16 +234,15 @@ mod tests {
},
&StakerInfo {
name: "fun",
staker: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
withdrawer: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
custodian: "0000000000000000000000000000000000000000000000000000000000000000",
},
&UnlockInfo {
cliff_fraction: 0.5,
cliff_years: 0.5,
unlocks: 1,
unlock_years: 0.5,
custodian: "11111111111111111111111111111111",
},
total_lamports,
granularity,
@ -212,7 +251,7 @@ mod tests {
// huge granularity doesn't blow up
let granularity = std::u64::MAX;
let total_lamports = reserve + reserve * 2 + 1;
let total_lamports = staker_reserve + reserve * 2 + 1;
create_and_check_stakes(
&mut GenesisConfig {
rent,
@ -220,25 +259,24 @@ mod tests {
},
&StakerInfo {
name: "fun",
staker: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
withdrawer: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
custodian: "0000000000000000000000000000000000000000000000000000000000000000",
},
&UnlockInfo {
cliff_fraction: 0.5,
cliff_years: 0.5,
unlocks: 1,
unlock_years: 0.5,
custodian: "11111111111111111111111111111111",
},
total_lamports,
granularity,
2 + 1,
);
// exactly reserve as a remainder
// exactly reserve as a remainder, reserve gets folded in
let granularity = reserve * 3;
let total_lamports = reserve + (granularity + reserve) * 2;
let total_lamports = staker_reserve + (granularity + reserve) * 2;
create_and_check_stakes(
&mut GenesisConfig {
rent,
@ -246,16 +284,39 @@ mod tests {
},
&StakerInfo {
name: "fun",
staker: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
withdrawer: "cafebabedeadbeef000000000000000000000000000000000000000000000000",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
custodian: "0000000000000000000000000000000000000000000000000000000000000000",
},
&UnlockInfo {
cliff_fraction: 0.5,
cliff_years: 0.5,
unlocks: 1,
unlock_years: 0.5,
custodian: "11111111111111111111111111111111",
},
total_lamports,
granularity,
2 + 1,
);
// exactly reserve + 1 as a remainder, reserve + 1 gets its own stake
let granularity = reserve * 3;
let total_lamports = staker_reserve + (granularity + reserve + 1) * 2;
create_and_check_stakes(
&mut GenesisConfig {
rent,
..GenesisConfig::default()
},
&StakerInfo {
name: "fun",
staker: "P1aceHo1derPubkey11111111111111111111111111",
sol: lamports_to_sol(total_lamports),
},
&UnlockInfo {
cliff_fraction: 0.5,
cliff_years: 0.5,
unlocks: 1,
unlock_years: 0.5,
custodian: "11111111111111111111111111111111",
},
total_lamports,
granularity,

View File

@ -8,6 +8,7 @@ pub struct UnlockInfo {
pub cliff_years: f64,
pub unlocks: usize,
pub unlock_years: f64,
pub custodian: &'static str,
}
#[derive(Debug, Default, Clone)]

209
genesis/src/validators.rs Normal file
View File

@ -0,0 +1,209 @@
//! validators generator
use solana_sdk::{
account::Account, genesis_config::GenesisConfig, native_token::sol_to_lamports, pubkey::Pubkey,
system_program, timing::years_as_slots,
};
use solana_vote_program::vote_state::{self, VoteState};
#[derive(Debug)]
pub struct ValidatorInfo {
pub name: &'static str,
pub node: &'static str,
pub node_sol: f64,
pub vote: &'static str,
pub commission: u8,
}
// the node's account needs carry enough
// lamports to cover TX fees for voting for one year,
// validators can vote once per slot
fn calculate_voting_fees(genesis_config: &GenesisConfig, years: f64) -> u64 {
genesis_config.fee_calculator.max_lamports_per_signature
* years_as_slots(
years,
&genesis_config.poh_config.target_tick_duration,
genesis_config.ticks_per_slot,
) as u64
}
/// create and add vote and node id accounts for a validator
pub fn create_and_add_validator(
genesis_config: &mut GenesisConfig,
// information about this validator
validator_info: &ValidatorInfo,
) -> u64 {
let node: Pubkey = validator_info.node.parse().expect("invalid node");
let vote: Pubkey = validator_info.vote.parse().expect("invalid vote");
let node_lamports = sol_to_lamports(validator_info.node_sol);
// node is the system account from which votes will be issued
let node_rent_reserve = genesis_config.rent.minimum_balance(0).max(1);
let node_voting_fees = calculate_voting_fees(genesis_config, 1.0);
let vote_rent_reserve = VoteState::get_rent_exempt_reserve(&genesis_config.rent).max(1);
let mut total_lamports = node_voting_fees + vote_rent_reserve + node_lamports;
genesis_config
.accounts
.entry(node)
.or_insert_with(|| {
total_lamports += node_rent_reserve;
Account::new(node_rent_reserve, 0, &system_program::id())
})
.lamports += node_voting_fees + node_lamports;
assert!(
genesis_config.accounts.get(&vote).is_none(),
"{} is already in genesis",
vote
);
genesis_config.add_account(
vote,
vote_state::create_account(&vote, &node, validator_info.commission, vote_rent_reserve),
);
total_lamports
}
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::rent::Rent;
fn create_and_check_validators(
genesis_config: &mut GenesisConfig,
validator_infos: &[ValidatorInfo],
total_lamports: u64,
len: usize,
) {
assert_eq!(
validator_infos
.iter()
.map(|validator_info| create_and_add_validator(genesis_config, validator_info))
.sum::<u64>(),
total_lamports
);
assert_eq!(genesis_config.accounts.len(), len);
assert_eq!(
genesis_config
.accounts
.iter()
.map(|(_pubkey, account)| account.lamports)
.sum::<u64>(),
total_lamports,
);
assert!(genesis_config
.accounts
.iter()
.all(|(_pubkey, account)| account.lamports
>= genesis_config.rent.minimum_balance(0).max(1)));
}
#[test]
fn test_create_one_validator() {
let rent = Rent {
lamports_per_byte_year: 1,
exemption_threshold: 1.0,
..Rent::default()
};
let mut genesis_config = GenesisConfig {
rent,
..GenesisConfig::default()
};
let total_lamports = VoteState::get_rent_exempt_reserve(&rent)
+ calculate_voting_fees(&genesis_config, 1.0)
+ rent.minimum_balance(0);
create_and_check_validators(
&mut genesis_config,
&[ValidatorInfo {
name: "fun",
node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkeys
node_sol: 0.0,
vote: "77TQYZTHodhnxJcSuVjUvx8GYRCkykPyHtmFTFLjj1Rc",
commission: 50,
}],
total_lamports,
2,
);
}
#[test]
fn test_create_one_validator_two_votes() {
let rent = Rent {
lamports_per_byte_year: 1,
exemption_threshold: 1.0,
..Rent::default()
};
let mut genesis_config = GenesisConfig {
rent,
..GenesisConfig::default()
};
let total_lamports = VoteState::get_rent_exempt_reserve(&rent) * 2
+ calculate_voting_fees(&genesis_config, 1.0) * 2 // two vote accounts
+ rent.minimum_balance(0) // one node account
+ sol_to_lamports(1.0); // 2nd vote account ask has SOL
// weird case, just wanted to verify that the duplicated node account gets double fees
create_and_check_validators(
&mut genesis_config,
&[
ValidatorInfo {
name: "fun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys
node_sol: 0.0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW",
commission: 50,
},
ValidatorInfo {
name: "unfun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node
node_sol: 1.0,
vote: "8XrFPRULg98kSm535kFaLV4GMnK5JQSuAymyrCHXsUcy",
commission: 50,
},
],
total_lamports,
3,
);
}
#[test]
#[should_panic]
fn test_vote_collision() {
let rent = Rent {
lamports_per_byte_year: 1,
exemption_threshold: 1.0,
..Rent::default()
};
let mut genesis_config = GenesisConfig {
rent,
..GenesisConfig::default()
};
create_and_check_validators(
&mut genesis_config,
&[
ValidatorInfo {
name: "fun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys
node_sol: 0.0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW",
commission: 50,
},
ValidatorInfo {
name: "unfun",
node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node
node_sol: 0.0,
vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW", // duplicate vote, bad juju
commission: 50,
},
],
0,
0,
);
}
}

View File

@ -3,19 +3,19 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-gossip"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
[dependencies]
clap = "2.33.0"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-net-utils = { path = "../net-utils", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-install"
description = "The solana cluster software installer"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -26,11 +26,11 @@ reqwest = { version = "0.9.22", default-features = false, features = ["rustls-tl
serde = "1.0.102"
serde_derive = "1.0.102"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-config-program = { path = "../programs/config", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-config-program = { path = "../programs/config", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
tar = "0.4.26"
tempdir = "0.3.7"
url = "2.1.0"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-keygen"
version = "0.21.0"
version = "0.21.4"
description = "Solana key generation utility"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -14,8 +14,8 @@ clap = "2.33"
dirs = "2.0.2"
num_cpus = "1.11.1"
rpassword = "4.0"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
tiny-bip39 = "0.6.2"
[[bin]]

View File

@ -1,15 +1,18 @@
use bip39::{Language, Mnemonic, MnemonicType, Seed};
use bs58;
use clap::{
crate_description, crate_name, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
crate_description, crate_name, value_t, values_t_or_exit, App, AppSettings, Arg, ArgMatches,
SubCommand,
};
use num_cpus;
use solana_clap_utils::keypair::{keypair_from_seed_phrase, SKIP_SEED_PHRASE_VALIDATION_ARG};
use solana_clap_utils::keypair::{
keypair_from_seed_phrase, prompt_passphrase, ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG,
};
use solana_sdk::{
pubkey::write_pubkey_file,
signature::{
keypair_from_seed, read_keypair, read_keypair_file, write_keypair, write_keypair_file,
Keypair, KeypairUtil,
Keypair, KeypairUtil, Signature,
},
};
use std::{
@ -35,6 +38,26 @@ fn check_for_overwrite(outfile: &str, matches: &ArgMatches) {
}
}
fn get_keypair_from_matches(matches: &ArgMatches) -> Result<Keypair, Box<dyn error::Error>> {
let mut path = dirs::home_dir().expect("home directory");
let infile = if matches.is_present("infile") {
matches.value_of("infile").unwrap()
} else {
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
};
if infile == "-" {
let mut stdin = std::io::stdin();
read_keypair(&mut stdin)
} else if infile == ASK_KEYWORD {
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
keypair_from_seed_phrase("pubkey recovery", skip_validation, false)
} else {
read_keypair_file(infile)
}
}
fn output_keypair(
keypair: &Keypair,
outfile: &str,
@ -55,6 +78,24 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.about(crate_description!())
.version(solana_clap_utils::version!())
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("verify")
.about("Verify a keypair can sign and verify a message.")
.arg(
Arg::with_name("infile")
.index(1)
.value_name("PATH")
.takes_value(true)
.help("Path to keypair file"),
)
.arg(
Arg::with_name("pubkey")
.index(2)
.value_name("BASE58_PUBKEY")
.takes_value(true)
.help("Public key"),
)
)
.subcommand(
SubCommand::with_name("new")
.about("Generate new keypair file from a passphrase and random seed phrase")
@ -73,11 +114,26 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("force")
.help("Overwrite the output file if it exists"),
)
.arg(
Arg::with_name("word_count")
.long("word-count")
.possible_values(&["12", "15", "18", "21", "24"])
.default_value("12")
.value_name("NUM")
.takes_value(true)
.help("Specify the number of words that will be present in the generated seed phrase"),
)
.arg(
Arg::with_name("no_passphrase")
.long("no-passphrase")
.help("Do not prompt for a passphrase"),
)
.arg(
Arg::with_name("no_outfile")
.long("no-outfile")
.conflicts_with_all(&["outfile", "silent"])
.help("Only print a seed phrase and pubkey. Do not output a keypair file"),
)
.arg(
Arg::with_name("silent")
.short("s")
@ -132,6 +188,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.takes_value(true)
.help("Path to keypair file"),
)
.arg(
Arg::with_name(SKIP_SEED_PHRASE_VALIDATION_ARG.name)
.long(SKIP_SEED_PHRASE_VALIDATION_ARG.long)
.help(SKIP_SEED_PHRASE_VALIDATION_ARG.help),
)
.arg(
Arg::with_name("outfile")
.short("o")
@ -176,19 +237,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
match matches.subcommand() {
("pubkey", Some(matches)) => {
let mut path = dirs::home_dir().expect("home directory");
let infile = if matches.is_present("infile") {
matches.value_of("infile").unwrap()
} else {
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
};
let keypair = if infile == "-" {
let mut stdin = std::io::stdin();
read_keypair(&mut stdin)?
} else {
read_keypair_file(infile)?
};
let keypair = get_keypair_from_matches(matches)?;
if matches.is_present("outfile") {
let outfile = matches.value_of("outfile").unwrap();
@ -201,29 +250,37 @@ fn main() -> Result<(), Box<dyn error::Error>> {
("new", Some(matches)) => {
let mut path = dirs::home_dir().expect("home directory");
let outfile = if matches.is_present("outfile") {
matches.value_of("outfile").unwrap()
matches.value_of("outfile")
} else if matches.is_present("no_outfile") {
None
} else {
path.extend(&[".config", "solana", "id.json"]);
path.to_str().unwrap()
Some(path.to_str().unwrap())
};
if outfile != "-" {
check_for_overwrite(&outfile, &matches);
match outfile {
Some("-") => (),
Some(outfile) => check_for_overwrite(&outfile, &matches),
None => (),
}
let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English);
let word_count = value_t!(matches.value_of("word_count"), usize).unwrap();
let mnemonic_type = MnemonicType::for_word_count(word_count)?;
let mnemonic = Mnemonic::new(mnemonic_type, Language::English);
let passphrase = if matches.is_present("no_passphrase") {
NO_PASSPHRASE.to_string()
} else {
eprintln!("Generating a new keypair");
rpassword::prompt_password_stderr(
"For added security, enter a passphrase (empty for no passphrase):",
prompt_passphrase(
"For added security, enter a passphrase (empty for no passphrase): ",
)?
};
let seed = Seed::new(&mnemonic, &passphrase);
let keypair = keypair_from_seed(seed.as_bytes())?;
output_keypair(&keypair, &outfile, "new")?;
if let Some(outfile) = outfile {
output_keypair(&keypair, &outfile, "new")?;
}
let silent = matches.is_present("silent");
if !silent {
@ -249,7 +306,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
}
let skip_validation = matches.is_present(SKIP_SEED_PHRASE_VALIDATION_ARG.name);
let keypair = keypair_from_seed_phrase("recover", skip_validation)?;
let keypair = keypair_from_seed_phrase("recover", skip_validation, true)?;
output_keypair(&keypair, &outfile, "recovered")?;
}
("grind", Some(matches)) => {
@ -331,6 +388,19 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.collect::<Vec<_>>();
thread::park();
}
("verify", Some(matches)) => {
let keypair = get_keypair_from_matches(matches)?;
let test_data = b"test";
let signature = Signature::new(&keypair.sign(test_data).to_bytes());
let pubkey_bs58 = matches.value_of("pubkey").unwrap();
let pubkey = bs58::decode(pubkey_bs58).into_vec().unwrap();
if signature.verify(&pubkey, test_data) {
println!("Verification for public key: {}: Success", pubkey_bs58);
} else {
println!("Verification for public key: {}: Failed", pubkey_bs58);
exit(1);
}
}
_ => unreachable!(),
}

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-ledger-tool"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -15,12 +15,12 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-ledger = { path = "../ledger", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-ledger = { path = "../ledger", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
[dev-dependencies]
assert_cmd = "0.11"

View File

@ -581,9 +581,9 @@ fn main() {
})
};
let account_paths = if let Some(account_paths) = matches.value_of("account_paths") {
Some(account_paths.to_string())
account_paths.split(',').map(PathBuf::from).collect()
} else {
Some(ledger_path.join("accounts").to_str().unwrap().to_string())
vec![ledger_path.join("accounts")]
};
let process_options = blocktree_processor::ProcessOptions {

View File

@ -1,6 +1,6 @@
[package]
name = "solana-ledger"
version = "0.21.0"
version = "0.21.4"
description = "Solana ledger"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -29,19 +29,19 @@ rayon = "1.2.0"
reed-solomon-erasure = { package = "solana-reed-solomon-erasure", version = "4.0.1-3", features = ["simd-accel"] }
serde = "1.0.102"
serde_derive = "1.0.102"
solana-client = { path = "../client", version = "0.21.0" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-measure = { path = "../measure", version = "0.21.0" }
solana-merkle-tree = { path = "../merkle-tree", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-perf = { path = "../perf", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.4" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-measure = { path = "../measure", version = "0.21.4" }
solana-merkle-tree = { path = "../merkle-tree", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
solana-perf = { path = "../perf", version = "0.21.4" }
ed25519-dalek = "1.0.0-pre.1"
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
sys-info = "0.5.8"
tar = "0.4.26"
tempfile = "3.1.0"
@ -54,8 +54,9 @@ default-features = false
features = ["lz4"]
[dev-dependencies]
assert_matches = "1.3.0"
matches = "0.1.6"
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
[lib]
crate-type = ["lib"]

View File

@ -7,12 +7,12 @@ use crate::{
};
use log::*;
use solana_sdk::genesis_config::GenesisConfig;
use std::{fs, sync::Arc};
use std::{fs, path::PathBuf, sync::Arc};
pub fn load(
genesis_config: &GenesisConfig,
blocktree: &Blocktree,
account_paths: Option<String>,
account_paths: Vec<PathBuf>,
snapshot_config: Option<&SnapshotConfig>,
process_options: ProcessOptions,
) -> Result<(BankForks, Vec<BankForksInfo>, LeaderScheduleCache), BlocktreeProcessorError> {
@ -30,10 +30,13 @@ pub fn load(
if tar.exists() {
info!("Loading snapshot package: {:?}", tar);
// Fail hard here if snapshot fails to load, don't silently continue
if account_paths.is_empty() {
panic!("Account paths not present when booting from snapshot")
}
let deserialized_bank = snapshot_utils::bank_from_archive(
account_paths
.clone()
.expect("Account paths not present when booting from snapshot"),
&account_paths,
&snapshot_config.snapshot_path,
&tar,
)

View File

@ -16,6 +16,7 @@ pub use crate::{
blocktree_meta::SlotMeta,
};
use bincode::deserialize;
use chrono::{offset::TimeZone, Duration as ChronoDuration, Utc};
use log::*;
use rayon::{
iter::{IntoParallelRefIterator, ParallelIterator},
@ -27,17 +28,18 @@ use solana_measure::measure::Measure;
use solana_metrics::{datapoint_debug, datapoint_error};
use solana_rayon_threadlimit::get_thread_count;
use solana_sdk::{
clock::{Slot, DEFAULT_TICKS_PER_SECOND},
clock::{Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND},
genesis_config::GenesisConfig,
hash::Hash,
signature::{Keypair, KeypairUtil, Signature},
timing::timestamp,
timing::{duration_as_ms, timestamp},
transaction::Transaction,
};
use std::{
cell::RefCell,
cmp,
collections::HashMap,
convert::TryFrom,
fs,
path::{Path, PathBuf},
rc::Rc,
@ -45,6 +47,7 @@ use std::{
mpsc::{sync_channel, Receiver, SyncSender, TrySendError},
Arc, Mutex, RwLock,
},
time::Duration,
};
pub const BLOCKTREE_DIRECTORY: &str = "rocksdb";
@ -154,7 +157,7 @@ impl Blocktree {
adjust_ulimit_nofile();
// Open the database
let measure = Measure::start("open");
let mut measure = Measure::start("open");
let db = Database::open(&blocktree_path)?;
// Create the metadata column family
@ -185,6 +188,7 @@ impl Blocktree {
.unwrap_or(0);
let last_root = Arc::new(RwLock::new(max_root));
measure.stop();
info!("{:?} {}", blocktree_path, measure);
Ok(Blocktree {
db,
@ -353,10 +357,20 @@ impl Blocktree {
Ok(slot_iterator.take_while(move |((shred_slot, _), _)| *shred_slot == slot))
}
pub fn slot_coding_iterator<'a>(
&'a self,
slot: Slot,
) -> Result<impl Iterator<Item = ((u64, u64), Box<[u8]>)> + 'a> {
let slot_iterator = self
.db
.iter::<cf::ShredCode>(IteratorMode::From((slot, 0), IteratorDirection::Forward))?;
Ok(slot_iterator.take_while(move |((shred_slot, _), _)| *shred_slot == slot))
}
fn try_shred_recovery(
db: &Database,
erasure_metas: &HashMap<(u64, u64), ErasureMeta>,
index_working_set: &HashMap<u64, IndexMetaWorkingSetEntry>,
index_working_set: &mut HashMap<u64, IndexMetaWorkingSetEntry>,
prev_inserted_datas: &mut HashMap<(u64, u64), Shred>,
prev_inserted_codes: &mut HashMap<(u64, u64), Shred>,
) -> Vec<Shred> {
@ -381,8 +395,8 @@ impl Blocktree {
);
};
let index_meta_entry = index_working_set.get(&slot).expect("Index");
let index = &index_meta_entry.index;
let index_meta_entry = index_working_set.get_mut(&slot).expect("Index");
let index = &mut index_meta_entry.index;
match erasure_meta.status(&index) {
ErasureMetaStatus::CanRecover => {
// Find shreds for this erasure set and try recovery
@ -409,8 +423,17 @@ impl Blocktree {
});
(set_index..set_index + erasure_meta.config.num_coding() as u64).for_each(
|i| {
if let Some(shred) =
prev_inserted_codes.remove(&(slot, i)).or_else(|| {
if let Some(shred) = prev_inserted_codes
.remove(&(slot, i))
.map(|s| {
// Remove from the index so it doesn't get committed. We know
// this is safe to do because everything in
// `prev_inserted_codes` does not yet exist in blocktree
// (guaranteed by `check_cache_coding_shred`)
index.coding_mut().set_present(i, false);
s
})
.or_else(|| {
if index.coding().is_present(i) {
let some_code = code_cf
.get_bytes((slot, i))
@ -446,8 +469,14 @@ impl Blocktree {
ErasureMetaStatus::DataFull => {
(set_index..set_index + erasure_meta.config.num_coding() as u64).for_each(
|i| {
// Remove saved coding shreds. We don't need these for future recovery
let _ = prev_inserted_codes.remove(&(slot, i));
// Remove saved coding shreds. We don't need these for future recovery.
if prev_inserted_codes.remove(&(slot, i)).is_some() {
// Remove from the index so it doesn't get committed. We know
// this is safe to do because everything in
// `prev_inserted_codes` does not yet exist in blocktree
// (guaranteed by `check_cache_coding_shred`)
index.coding_mut().set_present(i, false);
}
},
);
submit_metrics(false, "complete".into(), 0);
@ -520,7 +549,7 @@ impl Blocktree {
let recovered_data = Self::try_shred_recovery(
&db,
&erasure_metas,
&index_working_set,
&mut index_working_set,
&mut just_inserted_data_shreds,
&mut just_inserted_coding_shreds,
);
@ -677,6 +706,13 @@ impl Blocktree {
);
}
// Should be safe to modify index_meta here. Two cases
// 1) Recovery happens: Then all inserted erasure metas are removed
// from just_received_coding_shreds, and nothing wll be committed by
// `check_insert_coding_shred`, so the coding index meta will not be
// committed
index_meta.coding_mut().set_present(shred_index, true);
just_received_coding_shreds
.entry((slot, shred_index))
.or_insert_with(|| shred);
@ -858,19 +894,10 @@ impl Blocktree {
// Parent for slot meta should have been set by this point
assert!(!is_orphan(slot_meta));
let data_cf = self.db.column::<cf::ShredData>();
let check_data_cf = |slot, index| {
data_cf
.get_bytes((slot, index))
.map(|opt| opt.is_some())
.unwrap_or(false)
};
let new_consumed = if slot_meta.consumed == index {
let mut current_index = index + 1;
while data_index.is_present(current_index) || check_data_cf(slot, current_index) {
while data_index.is_present(current_index) {
current_index += 1;
}
current_index
@ -1129,6 +1156,25 @@ impl Blocktree {
}
}
// The `get_block_time` method is not fully implemented (depends on validator timestamp
// transactions). It currently returns Some(`slot` * DEFAULT_MS_PER_SLOT) offset from 0 for all
// transactions, and None for any values that would overflow any step.
pub fn get_block_time(&self, slot: Slot, slot_duration: Duration) -> Option<UnixTimestamp> {
let ms_per_slot = duration_as_ms(&slot_duration);
let (offset_millis, overflow) = slot.overflowing_mul(ms_per_slot);
if !overflow {
i64::try_from(offset_millis)
.ok()
.and_then(|millis| {
let median_datetime = Utc.timestamp(0, 0);
median_datetime.checked_add_signed(ChronoDuration::milliseconds(millis))
})
.map(|dt| dt.timestamp())
} else {
None
}
}
pub fn get_confirmed_block(&self, slot: Slot) -> Result<RpcConfirmedBlock> {
if self.is_root(slot) {
let slot_meta_cf = self.db.column::<cf::SlotMeta>();
@ -1137,24 +1183,30 @@ impl Blocktree {
.expect("Rooted slot must exist in SlotMeta");
let slot_entries = self.get_slot_entries(slot, 0, None)?;
let slot_transaction_iterator = slot_entries
.iter()
.cloned()
.flat_map(|entry| entry.transactions);
let parent_slot_entries = self.get_slot_entries(slot_meta.parent_slot, 0, None)?;
if !slot_entries.is_empty() {
let slot_transaction_iterator = slot_entries
.iter()
.cloned()
.flat_map(|entry| entry.transactions);
let parent_slot_entries = self.get_slot_entries(slot_meta.parent_slot, 0, None)?;
let previous_blockhash = if !parent_slot_entries.is_empty() {
get_last_hash(parent_slot_entries.iter()).unwrap()
} else {
Hash::default()
};
let block = RpcConfirmedBlock {
previous_blockhash: get_last_hash(parent_slot_entries.iter())
.expect("Rooted parent slot must have blockhash"),
blockhash: get_last_hash(slot_entries.iter())
.expect("Rooted slot must have blockhash"),
parent_slot: slot_meta.parent_slot,
transactions: self.map_transactions_to_statuses(slot, slot_transaction_iterator),
};
Ok(block)
} else {
Err(BlocktreeError::SlotNotRooted)
let block = RpcConfirmedBlock {
previous_blockhash,
blockhash: get_last_hash(slot_entries.iter())
.unwrap_or_else(|| panic!("Rooted slot {:?} must have blockhash", slot)),
parent_slot: slot_meta.parent_slot,
transactions: self
.map_transactions_to_statuses(slot, slot_transaction_iterator),
};
return Ok(block);
}
}
Err(BlocktreeError::SlotNotRooted)
}
fn map_transactions_to_statuses<'a>(
@ -2069,12 +2121,16 @@ pub mod tests {
use crate::{
entry::{next_entry, next_entry_mut},
genesis_utils::{create_genesis_config, GenesisConfigInfo},
leader_schedule::{FixedSchedule, LeaderSchedule},
shred::{max_ticks_per_n_shreds, DataShredHeader},
};
use assert_matches::assert_matches;
use bincode::serialize;
use itertools::Itertools;
use rand::{seq::SliceRandom, thread_rng};
use solana_runtime::bank::Bank;
use solana_sdk::{
hash::{self, Hash},
hash::{self, hash, Hash},
instruction::CompiledInstruction,
packet::PACKET_DATA_SIZE,
pubkey::Pubkey,
@ -2084,13 +2140,9 @@ pub mod tests {
use std::{iter::FromIterator, time::Duration};
// used for tests only
fn make_slot_entries_with_transactions(
slot: Slot,
parent_slot: Slot,
num_entries: u64,
) -> (Vec<Shred>, Vec<Entry>) {
fn make_slot_entries_with_transactions(num_entries: u64) -> Vec<Entry> {
let mut entries: Vec<Entry> = Vec::new();
for _ in 0..num_entries {
for x in 0..num_entries {
let transaction = Transaction::new_with_compiled_instructions(
&[&Keypair::new()],
&[Pubkey::new_rand()],
@ -2099,11 +2151,10 @@ pub mod tests {
vec![CompiledInstruction::new(1, &(), vec![0])],
);
entries.push(next_entry_mut(&mut Hash::default(), 0, vec![transaction]));
let mut tick = create_ticks(1, 0, Hash::default());
let mut tick = create_ticks(1, 0, hash(&serialize(&x).unwrap()));
entries.append(&mut tick);
}
let shreds = entries_to_test_shreds(entries.clone(), slot, parent_slot, true, 0);
(shreds, entries)
entries
}
#[test]
@ -4146,13 +4197,22 @@ pub mod tests {
#[test]
fn test_get_confirmed_block() {
let slot = 0;
let (shreds, entries) = make_slot_entries_with_transactions(slot, 0, 100);
let slot = 10;
let entries = make_slot_entries_with_transactions(100);
let blockhash = get_last_hash(entries.iter()).unwrap();
let shreds = entries_to_test_shreds(entries.clone(), slot, slot - 1, true, 0);
let more_shreds = entries_to_test_shreds(entries.clone(), slot + 1, slot, true, 0);
let ledger_path = get_tmp_ledger_path!();
let ledger = Blocktree::open(&ledger_path).unwrap();
ledger.insert_shreds(shreds, None, false).unwrap();
ledger.set_roots(&[0]).unwrap();
ledger.insert_shreds(more_shreds, None, false).unwrap();
ledger.set_roots(&[slot - 1, slot, slot + 1]).unwrap();
let mut parent_meta = SlotMeta::default();
parent_meta.parent_slot = std::u64::MAX;
ledger
.put_meta_bytes(slot - 1, &serialize(&parent_meta).unwrap())
.unwrap();
let expected_transactions: Vec<(Transaction, Option<RpcTransactionStatus>)> = entries
.iter()
@ -4171,6 +4231,16 @@ pub mod tests {
},
)
.unwrap();
ledger
.transaction_status_cf
.put(
(slot + 1, signature),
&RpcTransactionStatus {
status: Ok(()),
fee: 42,
},
)
.unwrap();
(
transaction,
Some(RpcTransactionStatus {
@ -4181,17 +4251,33 @@ pub mod tests {
})
.collect();
let confirmed_block = ledger.get_confirmed_block(0).unwrap();
// Even if marked as root, a slot that is empty of entries should return an error
let confirmed_block_err = ledger.get_confirmed_block(slot - 1).unwrap_err();
assert_matches!(confirmed_block_err, BlocktreeError::SlotNotRooted);
let confirmed_block = ledger.get_confirmed_block(slot).unwrap();
assert_eq!(confirmed_block.transactions.len(), 100);
let mut expected_block = RpcConfirmedBlock::default();
expected_block.transactions = expected_transactions.clone();
expected_block.parent_slot = slot - 1;
expected_block.blockhash = blockhash;
// The previous_blockhash of `expected_block` is default because its parent slot is a
// root, but empty of entries. This is special handling for snapshot root slots.
assert_eq!(confirmed_block, expected_block);
let confirmed_block = ledger.get_confirmed_block(slot + 1).unwrap();
assert_eq!(confirmed_block.transactions.len(), 100);
let mut expected_block = RpcConfirmedBlock::default();
expected_block.transactions = expected_transactions;
// The blockhash and previous_blockhash of `expected_block` are default only because
// `make_slot_entries_with_transactions` sets all entry hashes to default
expected_block.parent_slot = slot;
expected_block.previous_blockhash = blockhash;
expected_block.blockhash = blockhash;
assert_eq!(confirmed_block, expected_block);
let not_root = ledger.get_confirmed_block(1);
assert!(not_root.is_err());
let not_root = ledger.get_confirmed_block(slot + 2).unwrap_err();
assert_matches!(not_root, BlocktreeError::SlotNotRooted);
drop(ledger);
Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
@ -4319,4 +4405,236 @@ pub mod tests {
}
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
}
#[test]
fn test_recovery() {
let slot = 1;
let (data_shreds, coding_shreds, leader_schedule_cache) =
setup_erasure_shreds(slot, 0, 100, 1.0);
let blocktree_path = get_tmp_ledger_path!();
{
let blocktree = Blocktree::open(&blocktree_path).unwrap();
blocktree
.insert_shreds(coding_shreds, Some(&leader_schedule_cache), false)
.unwrap();
let shred_bufs: Vec<_> = data_shreds
.iter()
.map(|shred| shred.payload.clone())
.collect();
// Check all the data shreds were recovered
for (s, buf) in data_shreds.iter().zip(shred_bufs) {
assert_eq!(
blocktree
.get_data_shred(s.slot(), s.index() as u64)
.unwrap()
.unwrap(),
buf
);
}
verify_index_integrity(&blocktree, slot);
}
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
}
#[test]
fn test_index_integrity() {
let slot = 1;
let num_entries = 100;
let (data_shreds, coding_shreds, leader_schedule_cache) =
setup_erasure_shreds(slot, 0, num_entries, 1.0);
assert!(data_shreds.len() > 3);
assert!(coding_shreds.len() > 3);
let blocktree_path = get_tmp_ledger_path!();
{
let blocktree = Blocktree::open(&blocktree_path).unwrap();
// Test inserting all the shreds
let all_shreds: Vec<_> = data_shreds
.iter()
.cloned()
.chain(coding_shreds.iter().cloned())
.collect();
blocktree
.insert_shreds(all_shreds, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test inserting just the codes, enough for recovery
blocktree
.insert_shreds(coding_shreds.clone(), Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test inserting some codes, but not enough for recovery
blocktree
.insert_shreds(
coding_shreds[..coding_shreds.len() - 1].to_vec(),
Some(&leader_schedule_cache),
false,
)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test inserting just the codes, and some data, enough for recovery
let shreds: Vec<_> = data_shreds[..data_shreds.len() - 1]
.iter()
.cloned()
.chain(coding_shreds[..coding_shreds.len() - 1].iter().cloned())
.collect();
blocktree
.insert_shreds(shreds, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test inserting some codes, and some data, but enough for recovery
let shreds: Vec<_> = data_shreds[..data_shreds.len() / 2 - 1]
.iter()
.cloned()
.chain(coding_shreds[..coding_shreds.len() / 2 - 1].iter().cloned())
.collect();
blocktree
.insert_shreds(shreds, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test inserting all shreds in 2 rounds, make sure nothing is lost
let shreds1: Vec<_> = data_shreds[..data_shreds.len() / 2 - 1]
.iter()
.cloned()
.chain(coding_shreds[..coding_shreds.len() / 2 - 1].iter().cloned())
.collect();
let shreds2: Vec<_> = data_shreds[data_shreds.len() / 2 - 1..]
.iter()
.cloned()
.chain(coding_shreds[coding_shreds.len() / 2 - 1..].iter().cloned())
.collect();
blocktree
.insert_shreds(shreds1, Some(&leader_schedule_cache), false)
.unwrap();
blocktree
.insert_shreds(shreds2, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test not all, but enough data and coding shreds in 2 rounds to trigger recovery,
// make sure nothing is lost
let shreds1: Vec<_> = data_shreds[..data_shreds.len() / 2 - 1]
.iter()
.cloned()
.chain(coding_shreds[..coding_shreds.len() / 2 - 1].iter().cloned())
.collect();
let shreds2: Vec<_> = data_shreds[data_shreds.len() / 2 - 1..data_shreds.len() / 2]
.iter()
.cloned()
.chain(
coding_shreds[coding_shreds.len() / 2 - 1..data_shreds.len() / 2]
.iter()
.cloned(),
)
.collect();
blocktree
.insert_shreds(shreds1, Some(&leader_schedule_cache), false)
.unwrap();
blocktree
.insert_shreds(shreds2, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
// Test insert shreds in 2 rounds, but not enough to trigger
// recovery, make sure nothing is lost
let shreds1: Vec<_> = data_shreds[..data_shreds.len() / 2 - 2]
.iter()
.cloned()
.chain(coding_shreds[..coding_shreds.len() / 2 - 2].iter().cloned())
.collect();
let shreds2: Vec<_> = data_shreds[data_shreds.len() / 2 - 2..data_shreds.len() / 2 - 1]
.iter()
.cloned()
.chain(
coding_shreds[coding_shreds.len() / 2 - 2..coding_shreds.len() / 2 - 1]
.iter()
.cloned(),
)
.collect();
blocktree
.insert_shreds(shreds1, Some(&leader_schedule_cache), false)
.unwrap();
blocktree
.insert_shreds(shreds2, Some(&leader_schedule_cache), false)
.unwrap();
verify_index_integrity(&blocktree, slot);
blocktree.purge_slots(0, Some(slot));
}
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
}
fn setup_erasure_shreds(
slot: u64,
parent_slot: u64,
num_entries: u64,
erasure_rate: f32,
) -> (Vec<Shred>, Vec<Shred>, Arc<LeaderScheduleCache>) {
let entries = make_slot_entries_with_transactions(num_entries);
let leader_keypair = Arc::new(Keypair::new());
let shredder = Shredder::new(
slot,
parent_slot,
erasure_rate,
leader_keypair.clone(),
0,
0,
)
.expect("Failed in creating shredder");
let (data_shreds, coding_shreds, _) = shredder.entries_to_shreds(&entries, true, 0);
let genesis_config = create_genesis_config(2).genesis_config;
let bank = Arc::new(Bank::new(&genesis_config));
let mut leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank);
let fixed_schedule = FixedSchedule {
leader_schedule: Arc::new(LeaderSchedule::new_from_schedule(vec![
leader_keypair.pubkey()
])),
start_epoch: 0,
};
leader_schedule_cache.set_fixed_leader_schedule(Some(fixed_schedule));
(data_shreds, coding_shreds, Arc::new(leader_schedule_cache))
}
fn verify_index_integrity(blocktree: &Blocktree, slot: u64) {
let index = blocktree.get_index(slot).unwrap().unwrap();
// Test the set of data shreds in the index and in the data column
// family are the same
let data_iter = blocktree.slot_data_iterator(slot).unwrap();
let mut num_data = 0;
for ((slot, index), _) in data_iter {
num_data += 1;
assert!(blocktree.get_data_shred(slot, index).unwrap().is_some());
}
// Test the data index doesn't have anything extra
let num_data_in_index = index.data().num_data();
assert_eq!(num_data_in_index, num_data);
// Test the set of coding shreds in the index and in the coding column
// family are the same
let coding_iter = blocktree.slot_coding_iterator(slot).unwrap();
let mut num_coding = 0;
for ((slot, index), _) in coding_iter {
num_coding += 1;
assert!(blocktree.get_coding_shred(slot, index).unwrap().is_some());
}
// Test the data index doesn't have anything extra
let num_coding_in_index = index.coding().num_coding();
assert_eq!(num_coding_in_index, num_coding);
}
}

View File

@ -13,8 +13,6 @@ use solana_client::rpc_request::RpcTransactionStatus;
use solana_sdk::{clock::Slot, signature::Signature};
use std::{collections::HashMap, fs, marker::PhantomData, path::Path, sync::Arc};
// A good value for this is the number of cores on the machine
const TOTAL_THREADS: i32 = 8;
const MAX_WRITE_BUFFER_SIZE: u64 = 256 * 1024 * 1024; // 256MB
// Column family for metadata about a leader slot
@ -718,8 +716,15 @@ fn get_cf_options() -> Options {
// 256 * 8 = 2GB. 6 of these columns should take at most 12GB of RAM
options.set_max_write_buffer_number(8);
options.set_write_buffer_size(MAX_WRITE_BUFFER_SIZE as usize);
options.set_target_file_size_base(MAX_WRITE_BUFFER_SIZE / 10);
options.set_max_bytes_for_level_base(MAX_WRITE_BUFFER_SIZE);
let file_num_compaction_trigger = 4;
// Recommend that this be around the size of level 0. Level 0 estimated size in stable state is
// write_buffer_size * min_write_buffer_number_to_merge * level0_file_num_compaction_trigger
// Source: https://docs.rs/rocksdb/0.6.0/rocksdb/struct.Options.html#method.set_level_zero_file_num_compaction_trigger
let total_size_base = MAX_WRITE_BUFFER_SIZE * file_num_compaction_trigger;
let file_size_base = total_size_base / 10;
options.set_level_zero_file_num_compaction_trigger(file_num_compaction_trigger as i32);
options.set_max_bytes_for_level_base(total_size_base);
options.set_target_file_size_base(file_size_base);
options
}
@ -727,8 +732,7 @@ fn get_db_options() -> Options {
let mut options = Options::default();
options.create_if_missing(true);
options.create_missing_column_families(true);
options.increase_parallelism(TOTAL_THREADS);
options.set_max_background_flushes(4);
options.set_max_background_compactions(4);
// A good value for this is the number of cores on the machine
options.increase_parallelism(sys_info::cpu_num().unwrap() as i32);
options
}

View File

@ -97,6 +97,10 @@ impl Index {
}
impl CodingIndex {
pub fn num_coding(&self) -> usize {
self.index.len()
}
pub fn present_in_bounds(&self, bounds: impl RangeBounds<u64>) -> usize {
self.index.range(bounds).count()
}
@ -121,6 +125,10 @@ impl CodingIndex {
}
impl DataIndex {
pub fn num_data(&self) -> usize {
self.index.len()
}
pub fn present_in_bounds(&self, bounds: impl RangeBounds<u64>) -> usize {
self.index.range(bounds).count()
}

View File

@ -27,6 +27,7 @@ use solana_sdk::{
};
use std::{
cell::RefCell,
path::PathBuf,
result,
sync::Arc,
time::{Duration, Instant},
@ -230,6 +231,7 @@ pub enum BlocktreeProcessorError {
FailedToLoadMeta,
InvalidBlock(BlockError),
InvalidTransaction,
NoValidForksFound,
}
impl From<BlockError> for BlocktreeProcessorError {
@ -253,7 +255,7 @@ pub struct ProcessOptions {
pub fn process_blocktree(
genesis_config: &GenesisConfig,
blocktree: &Blocktree,
account_paths: Option<String>,
account_paths: Vec<PathBuf>,
opts: ProcessOptions,
) -> result::Result<(BankForks, Vec<BankForksInfo>, LeaderScheduleCache), BlocktreeProcessorError> {
if let Some(num_threads) = opts.override_num_threads {
@ -313,6 +315,9 @@ pub fn process_blocktree_from_root(
opts,
)?;
let (banks, bank_forks_info): (Vec<_>, Vec<_>) = fork_info.into_iter().unzip();
if banks.is_empty() {
return Err(BlocktreeProcessorError::NoValidForksFound);
}
let bank_forks = BankForks::new_from_banks(&banks, rooted_path);
(bank_forks, bank_forks_info, leader_schedule_cache)
} else {
@ -510,7 +515,10 @@ fn process_pending_slots(
BlocktreeProcessorError::FailedToLoadEntries
})?;
verify_and_process_slot_entries(&bank, &entries, last_entry_hash, opts)?;
if let Err(err) = verify_and_process_slot_entries(&bank, &entries, last_entry_hash, opts) {
warn!("slot {} failed to verify: {:?}", slot, err);
continue;
}
bank.freeze(); // all banks handled by this routine are created from complete slots
@ -643,8 +651,8 @@ pub mod tests {
let parent_slot = 0;
let slot = 1;
let entries = create_ticks(ticks_per_slot, hashes_per_tick - 1, blockhash);
blocktree
.write_entries(
assert_matches!(
blocktree.write_entries(
slot,
0,
0,
@ -654,18 +662,22 @@ pub mod tests {
&Arc::new(Keypair::new()),
entries,
0,
)
.expect("Expected to write shredded entries to blocktree");
),
Ok(_)
);
let opts = ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
};
assert_eq!(
process_blocktree(&genesis_config, &blocktree, None, opts).err(),
Some(BlocktreeProcessorError::InvalidBlock(
BlockError::InvalidTickHashCount
)),
process_blocktree(
&genesis_config,
&blocktree,
Vec::new(),
ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
}
)
.err(),
Some(BlocktreeProcessorError::NoValidForksFound)
);
}
@ -684,8 +696,8 @@ pub mod tests {
let parent_slot = 0;
let slot = 1;
let entries = create_ticks(ticks_per_slot - 1, 0, blockhash);
blocktree
.write_entries(
assert_matches!(
blocktree.write_entries(
slot,
0,
0,
@ -695,19 +707,42 @@ pub mod tests {
&Arc::new(Keypair::new()),
entries,
0,
)
.expect("Expected to write shredded entries to blocktree");
let opts = ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
};
assert_eq!(
process_blocktree(&genesis_config, &blocktree, None, opts).err(),
Some(BlocktreeProcessorError::InvalidBlock(
BlockError::InvalidTickCount
)),
),
Ok(_)
);
// No valid forks in blocktree, expect a failure
assert_eq!(
process_blocktree(
&genesis_config,
&blocktree,
Vec::new(),
ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
}
)
.err(),
Some(BlocktreeProcessorError::NoValidForksFound)
);
// Write slot 2 fully
let _last_slot2_entry_hash =
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 0, blockhash);
let (_bank_forks, bank_forks_info, _) = process_blocktree(
&genesis_config,
&blocktree,
Vec::new(),
ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
},
)
.unwrap();
// One valid fork, one bad fork. process_blocktree() should only return the valid fork
assert_eq!(bank_forks_info, vec![BankForksInfo { bank_slot: 2 }]);
}
#[test]
@ -736,8 +771,8 @@ pub mod tests {
// per slot.
let parent_slot = 0;
let slot = 1;
blocktree
.write_entries(
assert_matches!(
blocktree.write_entries(
slot,
0,
0,
@ -747,18 +782,17 @@ pub mod tests {
&Arc::new(Keypair::new()),
entries,
0,
)
.expect("Expected to write shredded entries to blocktree");
),
Ok(_)
);
let opts = ProcessOptions {
poh_verify: true,
..ProcessOptions::default()
};
assert_eq!(
process_blocktree(&genesis_config, &blocktree, None, opts).err(),
Some(BlocktreeProcessorError::InvalidBlock(
BlockError::TrailingEntry
)),
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).err(),
Some(BlocktreeProcessorError::NoValidForksFound)
);
}
@ -799,8 +833,8 @@ pub mod tests {
// throw away last one
entries.pop();
blocktree
.write_entries(
assert_matches!(
blocktree.write_entries(
slot,
0,
0,
@ -810,8 +844,9 @@ pub mod tests {
&Arc::new(Keypair::new()),
entries,
0,
)
.expect("Expected to write shredded entries to blocktree");
),
Ok(_)
);
}
// slot 2, points at slot 1
@ -822,7 +857,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (mut _bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 1);
assert_eq!(
@ -884,7 +919,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 1); // One fork, other one is ignored b/c not a descendant of the root
@ -958,7 +993,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 2); // There are two forks
assert_eq!(
@ -1022,9 +1057,13 @@ pub mod tests {
blocktree.set_dead_slot(2).unwrap();
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 3, 1, slot1_blockhash);
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, ProcessOptions::default())
.unwrap();
let (bank_forks, bank_forks_info, _) = process_blocktree(
&genesis_config,
&blocktree,
Vec::new(),
ProcessOptions::default(),
)
.unwrap();
assert_eq!(bank_forks_info.len(), 1);
assert_eq!(bank_forks_info[0], BankForksInfo { bank_slot: 3 });
@ -1054,7 +1093,7 @@ pub mod tests {
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
// Let last_slot be the number of slots in the first two epochs
let epoch_schedule = get_epoch_schedule(&genesis_config, None);
let epoch_schedule = get_epoch_schedule(&genesis_config, Vec::new());
let last_slot = epoch_schedule.get_last_slot_in_epoch(1);
// Create a single chain of slots with all indexes in the range [0, last_slot + 1]
@ -1081,7 +1120,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 1); // There is one fork
assert_eq!(
@ -1229,7 +1268,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 1);
assert_eq!(bank_forks.root(), 0);
@ -1258,7 +1297,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (bank_forks, bank_forks_info, _) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(bank_forks_info.len(), 1);
assert_eq!(bank_forks_info[0], BankForksInfo { bank_slot: 0 });
@ -1276,7 +1315,7 @@ pub mod tests {
override_num_threads: Some(1),
..ProcessOptions::default()
};
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
PAR_THREAD_POOL.with(|pool| {
assert_eq!(pool.borrow().current_num_threads(), 1);
});
@ -1293,7 +1332,7 @@ pub mod tests {
..ProcessOptions::default()
};
let (_bank_forks, _bank_forks_info, cached_leader_schedule) =
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(cached_leader_schedule.max_schedules(), std::usize::MAX);
}
@ -1353,7 +1392,7 @@ pub mod tests {
entry_callback: Some(entry_callback),
..ProcessOptions::default()
};
process_blocktree(&genesis_config, &blocktree, None, opts).unwrap();
process_blocktree(&genesis_config, &blocktree, Vec::new(), opts).unwrap();
assert_eq!(*callback_counter.write().unwrap(), 2);
}
@ -2188,7 +2227,7 @@ pub mod tests {
fn get_epoch_schedule(
genesis_config: &GenesisConfig,
account_paths: Option<String>,
account_paths: Vec<PathBuf>,
) -> EpochSchedule {
let bank = Bank::new_with_paths(&genesis_config, account_paths);
bank.epoch_schedule().clone()

View File

@ -3,6 +3,14 @@ use rand::SeedableRng;
use rand_chacha::ChaChaRng;
use solana_sdk::pubkey::Pubkey;
use std::ops::Index;
use std::sync::Arc;
// Used for testing
#[derive(Clone, Debug)]
pub struct FixedSchedule {
pub leader_schedule: Arc<LeaderSchedule>,
pub start_epoch: u64,
}
/// Stake-weighted leader schedule for one epoch.
#[derive(Debug, Default, PartialEq)]
@ -30,9 +38,17 @@ impl LeaderSchedule {
Self { slot_leaders }
}
pub fn new_from_schedule(slot_leaders: Vec<Pubkey>) -> Self {
Self { slot_leaders }
}
pub fn get_slot_leaders(&self) -> &[Pubkey] {
&self.slot_leaders
}
pub fn num_slots(&self) -> usize {
self.slot_leaders.len()
}
}
impl Index<u64> for LeaderSchedule {

View File

@ -1,4 +1,8 @@
use crate::{blocktree::Blocktree, leader_schedule::LeaderSchedule, leader_schedule_utils};
use crate::{
blocktree::Blocktree,
leader_schedule::{FixedSchedule, LeaderSchedule},
leader_schedule_utils,
};
use log::*;
use solana_runtime::bank::Bank;
use solana_sdk::{
@ -28,6 +32,7 @@ pub struct LeaderScheduleCache {
epoch_schedule: EpochSchedule,
max_epoch: RwLock<Epoch>,
max_schedules: CacheCapacity,
fixed_schedule: Option<Arc<FixedSchedule>>,
}
impl LeaderScheduleCache {
@ -41,6 +46,7 @@ impl LeaderScheduleCache {
epoch_schedule,
max_epoch: RwLock::new(0),
max_schedules: CacheCapacity::default(),
fixed_schedule: None,
};
// This sets the root and calculates the schedule at leader_schedule_epoch(root)
@ -153,8 +159,17 @@ impl LeaderScheduleCache {
first_slot.map(|slot| (slot, last_slot))
}
pub fn set_fixed_leader_schedule(&mut self, fixed_schedule: Option<FixedSchedule>) {
self.fixed_schedule = fixed_schedule.map(Arc::new);
}
fn slot_leader_at_no_compute(&self, slot: Slot) -> Option<Pubkey> {
let (epoch, slot_index) = self.epoch_schedule.get_epoch_and_slot_index(slot);
if let Some(ref fixed_schedule) = self.fixed_schedule {
if epoch >= fixed_schedule.start_epoch {
return Some(fixed_schedule.leader_schedule[slot_index]);
}
}
self.cached_schedules
.read()
.unwrap()
@ -191,6 +206,11 @@ impl LeaderScheduleCache {
epoch: Epoch,
bank: &Bank,
) -> Option<Arc<LeaderSchedule>> {
if let Some(ref fixed_schedule) = self.fixed_schedule {
if epoch >= fixed_schedule.start_epoch {
return Some(fixed_schedule.leader_schedule.clone());
}
}
let epoch_schedule = self.cached_schedules.read().unwrap().0.get(&epoch).cloned();
if epoch_schedule.is_some() {

View File

@ -86,7 +86,7 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
// Get a reference to all the relevant AccountStorageEntries
let account_storage_entries: Vec<_> = bank
.rc
.get_storage_entries()
.get_rooted_storage_entries()
.into_iter()
.filter(|x| x.slot_id() <= bank.slot())
.collect();
@ -207,7 +207,7 @@ pub fn bank_slot_from_archive<P: AsRef<Path>>(snapshot_tar: P) -> Result<u64> {
}
pub fn bank_from_archive<P: AsRef<Path>>(
account_paths: String,
account_paths: &[PathBuf],
snapshot_path: &PathBuf,
snapshot_tar: P,
) -> Result<Bank> {
@ -266,7 +266,7 @@ pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(
}
fn rebuild_bank_from_snapshots<P>(
local_account_paths: String,
local_account_paths: &[PathBuf],
unpacked_snapshots_dir: &PathBuf,
append_vecs_path: P,
) -> Result<Bank>

View File

@ -3,31 +3,32 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-local-cluster"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
[dependencies]
itertools = "0.8.1"
log = "0.4.8"
rand = "0.6.5"
solana-config-program = { path = "../programs/config", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.0" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.0" }
solana-ledger = { path = "../ledger", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-runtime = { path = "../runtime", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-stake-program = { path = "../programs/stake", version = "0.21.0" }
solana-storage-program = { path = "../programs/storage", version = "0.21.0" }
solana-vest-program = { path = "../programs/vest", version = "0.21.0" }
solana-vote-program = { path = "../programs/vote", version = "0.21.0" }
solana-config-program = { path = "../programs/config", version = "0.21.4" }
solana-core = { path = "../core", version = "0.21.4" }
solana-client = { path = "../client", version = "0.21.4" }
solana-drone = { path = "../drone", version = "0.21.4" }
solana-exchange-program = { path = "../programs/exchange", version = "0.21.4" }
solana-genesis-programs = { path = "../genesis-programs", version = "0.21.4" }
solana-ledger = { path = "../ledger", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-runtime = { path = "../runtime", version = "0.21.4" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-stake-program = { path = "../programs/stake", version = "0.21.4" }
solana-storage-program = { path = "../programs/storage", version = "0.21.4" }
solana-vest-program = { path = "../programs/vest", version = "0.21.4" }
solana-vote-program = { path = "../programs/vote", version = "0.21.4" }
symlink = "0.1.0"
tempfile = "3.1.0"
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.0" }
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.4" }
[dev-dependencies]
serial_test = "0.2.0"

View File

@ -1,5 +1,6 @@
use solana_client::thin_client::ThinClient;
use solana_core::contact_info::ContactInfo;
use solana_core::validator::Validator;
use solana_core::validator::ValidatorConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
@ -17,13 +18,19 @@ pub struct ValidatorInfo {
pub struct ClusterValidatorInfo {
pub info: ValidatorInfo,
pub config: ValidatorConfig,
pub validator: Option<Validator>,
}
impl ClusterValidatorInfo {
pub fn new(validator_info: ValidatorInfo, config: ValidatorConfig) -> Self {
pub fn new(
validator_info: ValidatorInfo,
config: ValidatorConfig,
validator: Validator,
) -> Self {
Self {
info: validator_info,
config,
validator: Some(validator),
}
}
}

View File

@ -15,9 +15,12 @@ use solana_ledger::{
};
use solana_sdk::{
client::SyncClient,
clock::{Slot, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
clock::{
Slot, DEFAULT_MS_PER_SLOT, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
NUM_CONSECUTIVE_LEADER_SLOTS,
},
commitment_config::CommitmentConfig,
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
hash::Hash,
poh_config::PohConfig,
pubkey::Pubkey,
@ -169,6 +172,11 @@ pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
}
}
pub fn time_until_nth_epoch(epoch: u64, slots_per_epoch: u64, stakers_slot_offset: u64) -> u64 {
let epoch_schedule = EpochSchedule::custom(slots_per_epoch, stakers_slot_offset, true);
epoch_schedule.get_last_slot_in_epoch(epoch) * DEFAULT_MS_PER_SLOT
}
pub fn sleep_n_epochs(
num_epochs: f64,
config: &PohConfig,

View File

@ -1,4 +1,5 @@
use crate::cluster::{Cluster, ClusterValidatorInfo, ValidatorInfo};
use itertools::izip;
use log::*;
use solana_client::thin_client::{create_client, ThinClient};
use solana_core::{
@ -39,6 +40,7 @@ use std::{
collections::HashMap,
fs::remove_dir_all,
io::{Error, ErrorKind, Result},
iter,
path::PathBuf,
sync::Arc,
};
@ -66,6 +68,8 @@ pub struct ClusterConfig {
pub num_archivers: usize,
/// Number of nodes that are unstaked and not voting (a.k.a listening)
pub num_listeners: u64,
/// The specific pubkeys of each node if specified
pub validator_keys: Option<Vec<Arc<Keypair>>>,
/// The stakes of each node
pub node_stakes: Vec<u64>,
/// The total lamports available to the cluster
@ -85,6 +89,7 @@ impl Default for ClusterConfig {
validator_configs: vec![],
num_archivers: 0,
num_listeners: 0,
validator_keys: None,
node_stakes: vec![],
cluster_lamports: 0,
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
@ -103,9 +108,7 @@ pub struct LocalCluster {
pub funding_keypair: Keypair,
/// Entry point from which the rest of the network can be discovered
pub entry_point_info: ContactInfo,
pub validator_infos: HashMap<Pubkey, ClusterValidatorInfo>,
pub listener_infos: HashMap<Pubkey, ClusterValidatorInfo>,
validators: HashMap<Pubkey, Validator>,
pub validators: HashMap<Pubkey, ClusterValidatorInfo>,
pub genesis_config: GenesisConfig,
archivers: Vec<Archiver>,
pub archiver_infos: HashMap<Pubkey, ArchiverInfo>,
@ -129,9 +132,20 @@ impl LocalCluster {
pub fn new(config: &ClusterConfig) -> Self {
assert_eq!(config.validator_configs.len(), config.node_stakes.len());
let leader_keypair = Arc::new(Keypair::new());
let validator_keys = {
if let Some(ref keys) = config.validator_keys {
assert_eq!(config.validator_configs.len(), keys.len());
keys.clone()
} else {
iter::repeat_with(|| Arc::new(Keypair::new()))
.take(config.validator_configs.len())
.collect()
}
};
let leader_keypair = &validator_keys[0];
let leader_pubkey = leader_keypair.pubkey();
let leader_node = Node::new_localhost_with_pubkey(&leader_keypair.pubkey());
let leader_node = Node::new_localhost_with_pubkey(&leader_pubkey);
let GenesisConfigInfo {
mut genesis_config,
mint_keypair,
@ -151,7 +165,10 @@ impl LocalCluster {
match genesis_config.operating_mode {
OperatingMode::SoftLaunch => {
genesis_config.native_instruction_processors =
solana_genesis_programs::get_programs(genesis_config.operating_mode, 0).unwrap()
solana_genesis_programs::get_programs(genesis_config.operating_mode, 0)
.unwrap()
.into_iter()
.collect()
}
// create_genesis_config_with_leader() assumes OperatingMode::Development so do
// nothing...
@ -169,18 +186,13 @@ impl LocalCluster {
.push(solana_storage_program!());
let storage_keypair = Keypair::new();
genesis_config.accounts.push((
genesis_config.add_account(
storage_keypair.pubkey(),
storage_contract::create_validator_storage_account(leader_pubkey, 1),
));
);
// Replace staking config
genesis_config.accounts = genesis_config
.accounts
.into_iter()
.filter(|(pubkey, _)| *pubkey != stake_config::id())
.collect();
genesis_config.accounts.push((
genesis_config.add_account(
stake_config::id(),
stake_config::create_account(
1,
@ -189,7 +201,7 @@ impl LocalCluster {
slash_penalty: std::u8::MAX,
},
),
));
);
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
let leader_contact_info = leader_node.info.clone();
@ -210,20 +222,22 @@ impl LocalCluster {
);
let mut validators = HashMap::new();
let mut validator_infos = HashMap::new();
validators.insert(leader_pubkey, leader_server);
error!("leader_pubkey: {}", leader_pubkey);
let leader_info = ValidatorInfo {
keypair: leader_keypair,
keypair: leader_keypair.clone(),
voting_keypair: leader_voting_keypair,
storage_keypair: leader_storage_keypair,
ledger_path: leader_ledger_path,
contact_info: leader_contact_info.clone(),
};
let cluster_leader =
ClusterValidatorInfo::new(leader_info, config.validator_configs[0].clone());
let cluster_leader = ClusterValidatorInfo::new(
leader_info,
config.validator_configs[0].clone(),
leader_server,
);
validator_infos.insert(leader_pubkey, cluster_leader);
validators.insert(leader_pubkey, cluster_leader);
let mut cluster = Self {
funding_keypair: mint_keypair,
@ -231,23 +245,24 @@ impl LocalCluster {
validators,
archivers: vec![],
genesis_config,
validator_infos,
archiver_infos: HashMap::new(),
listener_infos: HashMap::new(),
};
for (stake, validator_config) in (&config.node_stakes[1..])
.iter()
.zip((&config.validator_configs[1..]).iter())
{
cluster.add_validator(validator_config, *stake);
for (stake, validator_config, key) in izip!(
(&config.node_stakes[1..]).iter(),
config.validator_configs[1..].iter(),
validator_keys[1..].iter(),
) {
cluster.add_validator(validator_config, *stake, key.clone());
}
let listener_config = ValidatorConfig {
voting_disabled: true,
..config.validator_configs[0].clone()
};
(0..config.num_listeners).for_each(|_| cluster.add_validator(&listener_config, 0));
(0..config.num_listeners).for_each(|_| {
cluster.add_validator(&listener_config, 0, Arc::new(Keypair::new()));
});
discover_cluster(
&cluster.entry_point_info.gossip,
@ -270,14 +285,18 @@ impl LocalCluster {
pub fn exit(&mut self) {
for node in self.validators.values_mut() {
node.exit();
if let Some(ref mut v) = node.validator {
v.exit();
}
}
}
pub fn close_preserve_ledgers(&mut self) {
self.exit();
for (_, node) in self.validators.drain() {
node.join().unwrap();
for (_, node) in self.validators.iter_mut() {
if let Some(v) = node.validator.take() {
v.join().unwrap();
}
}
while let Some(archiver) = self.archivers.pop() {
@ -285,14 +304,18 @@ impl LocalCluster {
}
}
pub fn add_validator(&mut self, validator_config: &ValidatorConfig, stake: u64) {
pub fn add_validator(
&mut self,
validator_config: &ValidatorConfig,
stake: u64,
validator_keypair: Arc<Keypair>,
) -> Pubkey {
let client = create_client(
self.entry_point_info.client_facing_addr(),
VALIDATOR_PORT_RANGE,
);
// Must have enough tokens to fund vote account and set delegate
let validator_keypair = Arc::new(Keypair::new());
let voting_keypair = Keypair::new();
let storage_keypair = Arc::new(Keypair::new());
let validator_pubkey = validator_keypair.pubkey();
@ -343,8 +366,6 @@ impl LocalCluster {
&config,
);
self.validators
.insert(validator_keypair.pubkey(), validator_server);
let validator_pubkey = validator_keypair.pubkey();
let validator_info = ClusterValidatorInfo::new(
ValidatorInfo {
@ -355,14 +376,11 @@ impl LocalCluster {
contact_info,
},
validator_config.clone(),
validator_server,
);
if validator_config.voting_disabled {
self.listener_infos.insert(validator_pubkey, validator_info);
} else {
self.validator_infos
.insert(validator_pubkey, validator_info);
}
self.validators.insert(validator_pubkey, validator_info);
validator_pubkey
}
fn add_archiver(&mut self) {
@ -407,7 +425,7 @@ impl LocalCluster {
fn close(&mut self) {
self.close_preserve_ledgers();
for ledger_path in self
.validator_infos
.validators
.values()
.map(|f| &f.info.ledger_path)
.chain(self.archiver_infos.values().map(|info| &info.ledger_path))
@ -618,7 +636,7 @@ impl Cluster for LocalCluster {
}
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient> {
self.validator_infos.get(pubkey).map(|f| {
self.validators.get(pubkey).map(|f| {
create_client(
f.info.contact_info.client_facing_addr(),
VALIDATOR_PORT_RANGE,
@ -630,10 +648,10 @@ impl Cluster for LocalCluster {
let mut node = self.validators.remove(&pubkey).unwrap();
// Shut down the validator
node.exit();
node.join().unwrap();
self.validator_infos.remove(&pubkey).unwrap()
let mut validator = node.validator.take().expect("Validator must be running");
validator.exit();
validator.join().unwrap();
node
}
fn restart_node(&mut self, pubkey: &Pubkey, mut cluster_validator_info: ClusterValidatorInfo) {
@ -668,8 +686,8 @@ impl Cluster for LocalCluster {
&cluster_validator_info.config,
);
self.validators.insert(*pubkey, restarted_node);
self.validator_infos.insert(*pubkey, cluster_validator_info);
cluster_validator_info.validator = Some(restarted_node);
self.validators.insert(*pubkey, cluster_validator_info);
}
fn exit_restart_node(&mut self, pubkey: &Pubkey, validator_config: ValidatorConfig) {

View File

@ -8,13 +8,15 @@ use solana_core::{
partition_cfg::{Partition, PartitionCfg},
validator::ValidatorConfig,
};
use solana_ledger::{bank_forks::SnapshotConfig, blocktree::Blocktree, snapshot_utils};
use solana_ledger::{
bank_forks::SnapshotConfig, blocktree::Blocktree, leader_schedule::FixedSchedule,
leader_schedule::LeaderSchedule, snapshot_utils,
};
use solana_local_cluster::{
cluster::Cluster,
cluster_tests,
local_cluster::{ClusterConfig, LocalCluster},
};
use solana_runtime::accounts_db::AccountsDB;
use solana_sdk::timing::timestamp;
use solana_sdk::{
client::SyncClient,
@ -23,13 +25,15 @@ use solana_sdk::{
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
genesis_config::OperatingMode,
poh_config::PohConfig,
signature::{Keypair, KeypairUtil},
};
use std::{
collections::{HashMap, HashSet},
fs,
fs, iter,
path::{Path, PathBuf},
sync::Arc,
thread::sleep,
time::Duration,
time::{Duration, Instant},
};
use tempfile::TempDir;
@ -60,7 +64,7 @@ fn test_ledger_cleanup_service() {
);
cluster.close_preserve_ledgers();
//check everyone's ledgers and make sure only ~100 slots are stored
for (_, info) in &cluster.validator_infos {
for (_, info) in &cluster.validators {
let mut slots = 0;
let blocktree = Blocktree::open(&info.info.ledger_path).unwrap();
blocktree
@ -188,71 +192,166 @@ fn test_leader_failure_4() {
);
}
fn run_network_partition(partitions: &[usize]) {
/// This function runs a network, initiates a partition based on a
/// configuration, resolve the partition, then checks that the network
/// continues to achieve consensus
/// # Arguments
/// * `partitions` - A slice of partition configurations, where each partition
/// configuration is a slice of (usize, bool), representing a node's stake and
/// whether or not it should be killed during the partition
/// * `leader_schedule` - An option that specifies whether the cluster should
/// run with a fixed, predetermined leader schedule
fn run_cluster_partition(
partitions: &[&[(usize, bool)]],
leader_schedule: Option<(LeaderSchedule, Vec<Arc<Keypair>>)>,
) {
solana_logger::setup();
info!("PARTITION_TEST!");
let num_nodes = partitions.iter().sum();
let validator_config = ValidatorConfig::default();
let num_nodes = partitions.len();
let node_stakes: Vec<_> = partitions
.iter()
.flat_map(|p| p.iter().map(|(stake_weight, _)| 100 * *stake_weight as u64))
.collect();
assert_eq!(node_stakes.len(), num_nodes);
let cluster_lamports = node_stakes.iter().sum::<u64>() * 2;
let partition_start_epoch = 2;
let mut validator_config = ValidatorConfig::default();
// Returns:
// 1) The keys for the validiators
// 2) The amount of time it would take to iterate through one full iteration of the given
// leader schedule
let (validator_keys, leader_schedule_time): (Vec<_>, u64) = {
if let Some((leader_schedule, validator_keys)) = leader_schedule {
assert_eq!(validator_keys.len(), num_nodes);
let num_slots_per_rotation = leader_schedule.num_slots() as u64;
let fixed_schedule = FixedSchedule {
start_epoch: partition_start_epoch,
leader_schedule: Arc::new(leader_schedule),
};
validator_config.fixed_leader_schedule = Some(fixed_schedule);
(
validator_keys,
num_slots_per_rotation * clock::DEFAULT_MS_PER_SLOT,
)
} else {
(
iter::repeat_with(|| Arc::new(Keypair::new()))
.take(partitions.len())
.collect(),
10_000,
)
}
};
let validator_pubkeys: Vec<_> = validator_keys.iter().map(|v| v.pubkey()).collect();
let mut config = ClusterConfig {
cluster_lamports: 10_000,
node_stakes: vec![100; num_nodes],
cluster_lamports,
node_stakes,
validator_configs: vec![validator_config.clone(); num_nodes],
validator_keys: Some(validator_keys),
..ClusterConfig::default()
};
let now = timestamp();
let partition_start = now + 60_000;
let partition_end = partition_start + 10_000;
let mut total = 0;
for (j, pn) in partitions.iter().enumerate() {
info!(
"PARTITION_TEST configuring partition {} for nodes {} - {}",
j,
total,
total + *pn
);
for i in total..(total + *pn) {
// Partition needs to start after the first few shorter warmup epochs, otherwise
// no root will be set before the partition is resolved, the leader schedule will
// not be computable, and the cluster wll halt.
let partition_epoch_start_offset = cluster_tests::time_until_nth_epoch(
partition_start_epoch,
config.slots_per_epoch,
config.stakers_slot_offset,
);
// Assume it takes <= 10 seconds for `LocalCluster::new` to boot up.
let local_cluster_boot_time = 10_000;
let partition_start = now + partition_epoch_start_offset + local_cluster_boot_time;
let partition_end = partition_start + leader_schedule_time as u64;
let mut validator_index = 0;
for (i, partition) in partitions.iter().enumerate() {
for _ in partition.iter() {
let mut p1 = Partition::default();
p1.num_partitions = partitions.len();
p1.my_partition = j;
p1.my_partition = i;
p1.start_ts = partition_start;
p1.end_ts = partition_end;
config.validator_configs[i].partition_cfg = Some(PartitionCfg::new(vec![p1]));
config.validator_configs[validator_index].partition_cfg =
Some(PartitionCfg::new(vec![p1]));
validator_index += 1;
}
total += *pn;
}
info!(
"PARTITION_TEST starting cluster with {:?} partitions",
partitions
);
let cluster = LocalCluster::new(&config);
let now = Instant::now();
let mut cluster = LocalCluster::new(&config);
let elapsed = now.elapsed();
assert!(elapsed.as_millis() < local_cluster_boot_time as u128);
let now = timestamp();
let timeout = partition_start as i64 - now as i64;
let timeout = partition_start as u64 - now as u64;
info!(
"PARTITION_TEST sleeping until partition start timeout {}",
timeout
);
let mut dead_nodes = HashSet::new();
if timeout > 0 {
sleep(Duration::from_millis(timeout as u64));
}
info!("PARTITION_TEST done sleeping until partition start timeout");
let now = timestamp();
let timeout = partition_end as i64 - now as i64;
let timeout = partition_end as u64 - now as u64;
info!(
"PARTITION_TEST sleeping until partition end timeout {}",
timeout
);
let mut alive_node_contact_infos = vec![];
let should_exits: Vec<_> = partitions
.iter()
.flat_map(|p| p.iter().map(|(_, should_exit)| should_exit))
.collect();
assert_eq!(should_exits.len(), validator_pubkeys.len());
if timeout > 0 {
sleep(Duration::from_millis(timeout as u64));
// Give partitions time to propagate their blocks from durinig the partition
// after the partition resolves
let propagation_time = leader_schedule_time;
info!("PARTITION_TEST resolving partition");
sleep(Duration::from_millis(timeout));
info!("PARTITION_TEST waiting for blocks to propagate after partition");
sleep(Duration::from_millis(propagation_time));
info!("PARTITION_TEST resuming normal operation");
for (pubkey, should_exit) in validator_pubkeys.iter().zip(should_exits) {
if *should_exit {
info!("Killing validator with id: {}", pubkey);
cluster.exit_node(pubkey);
dead_nodes.insert(*pubkey);
} else {
alive_node_contact_infos.push(
cluster
.validators
.get(pubkey)
.unwrap()
.info
.contact_info
.clone(),
);
}
}
}
info!("PARTITION_TEST done sleeping until partition end timeout");
assert!(alive_node_contact_infos.len() > 0);
info!("PARTITION_TEST discovering nodes");
let (cluster_nodes, _) = discover_cluster(&cluster.entry_point_info.gossip, num_nodes).unwrap();
let (cluster_nodes, _) = discover_cluster(
&alive_node_contact_infos[0].gossip,
alive_node_contact_infos.len(),
)
.unwrap();
info!("PARTITION_TEST discovered {} nodes", cluster_nodes.len());
info!("PARTITION_TEST looking for new roots on all nodes");
let mut roots = vec![HashSet::new(); cluster_nodes.len()];
let mut roots = vec![HashSet::new(); alive_node_contact_infos.len()];
let mut done = false;
while !done {
for (i, ingress_node) in cluster_nodes.iter().enumerate() {
for (i, ingress_node) in alive_node_contact_infos.iter().enumerate() {
let client = create_client(
ingress_node.client_facing_addr(),
solana_core::cluster_info::VALIDATOR_PORT_RANGE,
@ -272,22 +371,64 @@ fn run_network_partition(partitions: &[usize]) {
#[ignore]
#[test]
#[serial]
fn test_network_partition_1_2() {
run_network_partition(&[1, 2])
fn test_cluster_partition_1_2() {
run_cluster_partition(&[&[(1, false)], &[(1, false), (1, false)]], None)
}
#[allow(unused_attributes)]
#[ignore]
#[test]
#[serial]
fn test_network_partition_1_1() {
run_network_partition(&[1, 1])
fn test_cluster_partition_1_1() {
run_cluster_partition(&[&[(1, false)], &[(1, false)]], None)
}
#[test]
#[serial]
fn test_network_partition_1_1_1() {
run_network_partition(&[1, 1, 1])
fn test_cluster_partition_1_1_1() {
run_cluster_partition(&[&[(1, false)], &[(1, false)], &[(1, false)]], None)
}
#[test]
#[serial]
fn test_kill_partition() {
// This test:
// 1) Spins up three partitions
// 2) Forces more slots in the leader schedule for the first partition so
// that this partition will be the heaviiest
// 3) Schedules the other validators for sufficient slots in the schedule
// so that they will still be locked out of voting for the major partitoin
// when the partition resolves
// 4) Kills the major partition. Validators are locked out, but should be
// able to reset to the major partition
// 5) Check for recovery
let mut leader_schedule = vec![];
let num_slots_per_validator = 8;
let partitions: [&[(usize, bool)]; 3] = [&[(9, true)], &[(10, false)], &[(10, false)]];
let validator_keys: Vec<_> = iter::repeat_with(|| Arc::new(Keypair::new()))
.take(partitions.len())
.collect();
for (i, k) in validator_keys.iter().enumerate() {
let num_slots = {
if i == 0 {
// Set up the leader to have 50% of the slots
num_slots_per_validator * (partitions.len() - 1)
} else {
num_slots_per_validator
}
};
for _ in 0..num_slots {
leader_schedule.push(k.pubkey())
}
}
run_cluster_partition(
&partitions,
Some((
LeaderSchedule::new_from_schedule(leader_schedule),
validator_keys,
)),
)
}
#[test]
@ -319,10 +460,7 @@ fn test_two_unbalanced_stakes() {
);
cluster.close_preserve_ledgers();
let leader_pubkey = cluster.entry_point_info.id;
let leader_ledger = cluster.validator_infos[&leader_pubkey]
.info
.ledger_path
.clone();
let leader_ledger = cluster.validators[&leader_pubkey].info.ledger_path.clone();
cluster_tests::verify_ledger_ticks(&leader_ledger, num_ticks_per_slot as usize);
}
@ -560,6 +698,7 @@ fn test_snapshots_blocktree_floor() {
cluster.add_validator(
&validator_snapshot_test_config.validator_config,
validator_stake,
Arc::new(Keypair::new()),
);
let all_pubkeys = cluster.get_node_pubkeys();
let validator_id = all_pubkeys
@ -583,7 +722,7 @@ fn test_snapshots_blocktree_floor() {
// Check the validator ledger doesn't contain any slots < slot_floor
cluster.close_preserve_ledgers();
let validator_ledger_path = &cluster.validator_infos[&validator_id];
let validator_ledger_path = &cluster.validators[&validator_id];
let blocktree = Blocktree::open(&validator_ledger_path.info.ledger_path).unwrap();
// Skip the zeroth slot in blocktree that the ledger is initialized with
@ -648,7 +787,7 @@ fn test_snapshots_restart_validity() {
let (new_account_storage_dirs, new_account_storage_paths) =
generate_account_paths(num_account_paths);
all_account_storage_dirs.push(new_account_storage_dirs);
snapshot_test_config.validator_config.account_paths = Some(new_account_storage_paths);
snapshot_test_config.validator_config.account_paths = new_account_storage_paths;
// Restart node
trace!("Restarting cluster from snapshot");
@ -721,7 +860,7 @@ fn test_faulty_node(faulty_node_type: BroadcastStageType) {
);
let corrupt_node = cluster
.validator_infos
.validators
.iter()
.find(|(_, v)| v.config.broadcast_stage_type == faulty_node_type)
.unwrap()
@ -768,10 +907,7 @@ fn test_no_voting() {
cluster.close_preserve_ledgers();
let leader_pubkey = cluster.entry_point_info.id;
let ledger_path = cluster.validator_infos[&leader_pubkey]
.info
.ledger_path
.clone();
let ledger_path = cluster.validators[&leader_pubkey].info.ledger_path.clone();
let ledger = Blocktree::open(&ledger_path).unwrap();
for i in 0..2 * VOTE_THRESHOLD_DEPTH {
let meta = ledger.meta(i as u64).unwrap().unwrap();
@ -850,7 +986,7 @@ fn run_repairman_catchup(num_repairmen: u64) {
// Start up a new node, wait for catchup. Backwards repair won't be sufficient because the
// leader is sending shreds past this validator's first two confirmed epochs. Thus, the repairman
// protocol will have to kick in for this validator to repair.
cluster.add_validator(&validator_config, repairee_stake);
cluster.add_validator(&validator_config, repairee_stake, Arc::new(Keypair::new()));
let all_pubkeys = cluster.get_node_pubkeys();
let repairee_id = all_pubkeys
@ -903,15 +1039,14 @@ fn wait_for_next_snapshot<P: AsRef<Path>>(cluster: &LocalCluster, tar: P) {
}
}
fn generate_account_paths(num_account_paths: usize) -> (Vec<TempDir>, String) {
fn generate_account_paths(num_account_paths: usize) -> (Vec<TempDir>, Vec<PathBuf>) {
let account_storage_dirs: Vec<TempDir> = (0..num_account_paths)
.map(|_| TempDir::new().unwrap())
.collect();
let account_storage_paths: Vec<_> = account_storage_dirs
.iter()
.map(|a| a.path().to_str().unwrap().to_string())
.map(|a| a.path().to_path_buf())
.collect();
let account_storage_paths = AccountsDB::format_paths(account_storage_paths);
(account_storage_dirs, account_storage_paths)
}
@ -942,7 +1077,7 @@ fn setup_snapshot_validator_config(
let mut validator_config = ValidatorConfig::default();
validator_config.rpc_config.enable_validator_exit = true;
validator_config.snapshot_config = Some(snapshot_config);
validator_config.account_paths = Some(account_storage_paths);
validator_config.account_paths = account_storage_paths;
SnapshotValidatorConfig {
_snapshot_dir: snapshot_dir,

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-log-analyzer"
description = "The solana cluster network analysis tool"
version = "0.1.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -17,8 +17,8 @@ semver = "0.9.0"
serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
[[bin]]
name = "solana-log-analyzer"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-logger"
version = "0.21.0"
version = "0.21.4"
description = "Solana Logger"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"

View File

@ -1,7 +1,7 @@
[package]
name = "solana-measure"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
documentation = "https://docs.rs/solana"
homepage = "https://solana.com/"
readme = "../README.md"
@ -11,4 +11,4 @@ license = "Apache-2.0"
edition = "2018"
[dependencies]
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.4" }

View File

@ -1,6 +1,6 @@
[package]
name = "solana-merkle-tree"
version = "0.21.0"
version = "0.21.4"
description = "Solana Merkle Tree"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -9,7 +9,7 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
[dev-dependencies]
hex = "0.4.0"

View File

@ -1,6 +1,6 @@
[package]
name = "solana-metrics"
version = "0.21.0"
version = "0.21.4"
description = "Solana Metrics"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -13,7 +13,7 @@ env_logger = "0.7.1"
lazy_static = "1.4.0"
log = "0.4.8"
reqwest = { version = "0.9.22", default-features = false, features = ["rustls-tls"] }
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
sys-info = "0.5.8"
[dev-dependencies]

View File

@ -95,7 +95,24 @@ elif channel == 'stable':
'text': 'testnet-perf',
'value': 'testnet-perf'}],
'query': 'testnet,testnet-perf',
'type': 'custom'}]
'type': 'custom'},
{'allValue': ".*",
'datasource': '$datasource',
'hide': 0,
'includeAll': True,
'label': 'HostID',
'multi': False,
'name': 'hostid',
'options': [],
'query': 'SELECT DISTINCT(\"id\") FROM \"$testnet\".\"autogen\".\"validator-new\" ',
'refresh': 2,
'regex': '',
'sort': 1,
'tagValuesQuery': '',
'tags': [],
'tagsQuery': '',
'type': 'query',
'useTags': False}]
else:
# Non-stable dashboard only allows the user to select between all testnet
# databases

View File

@ -4538,7 +4538,7 @@
"x": 0,
"y": 50
},
"id": 68,
"id": 38,
"links": [],
"pageSize": null,
"scroll": true,
@ -4621,7 +4621,7 @@
"x": 0,
"y": 55
},
"id": 38,
"id": 39,
"panels": [],
"title": "Bench Exchange",
"type": "row"
@ -4639,7 +4639,7 @@
"x": 0,
"y": 56
},
"id": 39,
"id": 40,
"legend": {
"avg": false,
"current": false,
@ -4790,7 +4790,7 @@
"x": 12,
"y": 56
},
"id": 40,
"id": 41,
"legend": {
"avg": false,
"current": false,
@ -4973,7 +4973,7 @@
"x": 0,
"y": 61
},
"id": 41,
"id": 42,
"panels": [],
"title": "Validator Streamer",
"type": "row"
@ -4991,7 +4991,7 @@
"x": 0,
"y": 62
},
"id": 42,
"id": 43,
"legend": {
"alignAsTable": false,
"avg": false,
@ -5093,45 +5093,6 @@
],
"tags": []
},
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"hide": false,
"measurement": "cluster_info-vote-count",
"orderByTime": "ASC",
"policy": "autogen",
"query": "SELECT mean(\"clone_and_seed\") AS \"clone_and_seed\" FROM \"$testnet\".\"autogen\".\"broadcast-bank-stats\" WHERE host_id::tag =~ /$hostid/ AND $timeFilter GROUP BY time($__interval)",
"rawQuery": true,
"refId": "C",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"count"
],
"type": "field"
},
{
"params": [],
"type": "sum"
}
]
],
"tags": []
},
{
"groupBy": [
{
@ -5248,6 +5209,45 @@
]
],
"tags": []
},
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"hide": false,
"measurement": "cluster_info-vote-count",
"orderByTime": "ASC",
"policy": "autogen",
"query": "SELECT mean(\"insertion_time\") AS \"insertion_time\" FROM \"$testnet\".\"autogen\".\"broadcast-bank-stats\" WHERE host_id::tag =~ /$hostid/ AND $timeFilter GROUP BY time($__interval)",
"rawQuery": true,
"refId": "D",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"count"
],
"type": "field"
},
{
"params": [],
"type": "sum"
}
]
],
"tags": []
}
],
"thresholds": [],
@ -5310,7 +5310,7 @@
"x": 8,
"y": 62
},
"id": 43,
"id": 44,
"legend": {
"alignAsTable": false,
"avg": false,
@ -5668,7 +5668,7 @@
"x": 16,
"y": 62
},
"id": 44,
"id": 45,
"legend": {
"alignAsTable": false,
"avg": false,
@ -5980,7 +5980,7 @@
"x": 0,
"y": 68
},
"id": 45,
"id": 46,
"legend": {
"alignAsTable": false,
"avg": false,
@ -6636,7 +6636,7 @@
"x": 16,
"y": 68
},
"id": 47,
"id": 48,
"legend": {
"alignAsTable": false,
"avg": false,
@ -6757,7 +6757,7 @@
"x": 16,
"y": 73
},
"id": 48,
"id": 49,
"legend": {
"alignAsTable": false,
"avg": false,
@ -6913,7 +6913,7 @@
"x": 0,
"y": 74
},
"id": 49,
"id": 50,
"legend": {
"alignAsTable": false,
"avg": false,
@ -7069,7 +7069,7 @@
"x": 8,
"y": 74
},
"id": 50,
"id": 51,
"legend": {
"alignAsTable": false,
"avg": false,
@ -7184,7 +7184,7 @@
"x": 16,
"y": 78
},
"id": 51,
"id": 52,
"legend": {
"alignAsTable": false,
"avg": false,
@ -7388,7 +7388,7 @@
"x": 0,
"y": 79
},
"id": 52,
"id": 53,
"legend": {
"alignAsTable": false,
"avg": false,
@ -7690,7 +7690,7 @@
"x": 8,
"y": 79
},
"id": 53,
"id": 54,
"legend": {
"alignAsTable": false,
"avg": false,
@ -7838,7 +7838,7 @@
"x": 0,
"y": 84
},
"id": 54,
"id": 55,
"panels": [],
"title": "Tower Consensus",
"type": "row"
@ -7861,7 +7861,7 @@
"x": 0,
"y": 85
},
"id": 55,
"id": 56,
"legend": {
"alignAsTable": false,
"avg": false,
@ -8021,7 +8021,7 @@
"x": 8,
"y": 85
},
"id": 56,
"id": 57,
"legend": {
"alignAsTable": false,
"avg": false,
@ -8181,7 +8181,7 @@
"x": 16,
"y": 85
},
"id": 57,
"id": 58,
"legend": {
"alignAsTable": false,
"avg": false,
@ -8366,7 +8366,7 @@
"x": 0,
"y": 90
},
"id": 58,
"id": 59,
"panels": [],
"repeat": null,
"title": "IP Network",
@ -8385,7 +8385,7 @@
"x": 0,
"y": 91
},
"id": 59,
"id": 60,
"legend": {
"alignAsTable": false,
"avg": false,
@ -8618,7 +8618,7 @@
"x": 12,
"y": 91
},
"id": 60,
"id": 61,
"legend": {
"alignAsTable": false,
"avg": false,
@ -8771,7 +8771,7 @@
"x": 0,
"y": 96
},
"id": 61,
"id": 62,
"panels": [],
"title": "Signature Verification",
"type": "row"
@ -8789,7 +8789,7 @@
"x": 0,
"y": 97
},
"id": 62,
"id": 63,
"legend": {
"avg": false,
"current": false,
@ -8830,7 +8830,83 @@
"measurement": "cluster_info-vote-count",
"orderByTime": "ASC",
"policy": "autogen",
"query": "SELECT max(\"total_time_ms\") AS \"max\" FROM \"$testnet\".\"autogen\".\"sigverify_stage-total_verify_time\" WHERE $timeFilter GROUP BY time($__interval) FILL(0)\n\n",
"query": "SELECT mean(\"num_packets\") AS \"num_packets\" FROM \"$testnet\".\"autogen\".\"sigverify_stage-total_verify_time\" WHERE $timeFilter GROUP BY time(500ms) FILL(0)\n\n",
"rawQuery": true,
"refId": "B",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"count"
],
"type": "field"
},
{
"params": [],
"type": "sum"
}
]
],
"tags": []
},
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "cluster_info-vote-count",
"orderByTime": "ASC",
"policy": "autogen",
"query": "SELECT mean(\"verify_time_ms\") AS \"verify_time\" FROM \"$testnet\".\"autogen\".\"sigverify_stage-total_verify_time\" WHERE $timeFilter GROUP BY time(500ms) FILL(0)\n\n",
"rawQuery": true,
"refId": "C",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"count"
],
"type": "field"
},
{
"params": [],
"type": "sum"
}
]
],
"tags": []
},
{
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "cluster_info-vote-count",
"orderByTime": "ASC",
"policy": "autogen",
"query": "SELECT mean(\"recv_time\") AS \"recv_time\" FROM \"$testnet\".\"autogen\".\"sigverify_stage-total_verify_time\" WHERE $timeFilter GROUP BY time(500ms) FILL(0)\n\n",
"rawQuery": true,
"refId": "A",
"resultFormat": "time_series",
@ -8910,7 +8986,7 @@
"x": 12,
"y": 97
},
"id": 63,
"id": 64,
"legend": {
"alignAsTable": false,
"avg": false,
@ -9059,7 +9135,7 @@
"x": 0,
"y": 102
},
"id": 64,
"id": 65,
"panels": [],
"title": "Snapshots",
"type": "row"
@ -9077,7 +9153,7 @@
"x": 0,
"y": 103
},
"id": 65,
"id": 66,
"legend": {
"avg": false,
"current": false,
@ -9269,7 +9345,7 @@
"x": 8,
"y": 103
},
"id": 66,
"id": 67,
"legend": {
"avg": false,
"current": false,
@ -9461,7 +9537,7 @@
"x": 16,
"y": 103
},
"id": 67,
"id": 68,
"legend": {
"avg": false,
"current": false,
@ -9650,7 +9726,7 @@
"x": 0,
"y": 109
},
"id": 74,
"id": 69,
"panels": [],
"title": "Resources",
"type": "row"
@ -9905,6 +9981,7 @@
{
"allValue": ".*",
"current": {
"selected": false,
"text": "testnet",
"value": "testnet"
},

View File

@ -262,7 +262,7 @@ setup_validator_accounts() {
fi
echo "Creating validator vote account"
wallet create-vote-account "$voting_keypair_path" "$identity_keypair_path" --commission 127 || return $?
wallet create-vote-account "$voting_keypair_path" "$identity_keypair_path" --commission 50 || return $?
fi
echo "Validator vote account configured"

View File

@ -3,7 +3,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-net-shaper"
description = "The solana cluster network shaping tool"
version = "0.1.0"
version = "0.21.4"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
@ -16,8 +16,8 @@ semver = "0.9.0"
serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
rand = "0.6.5"
[[bin]]

View File

@ -1,6 +1,6 @@
[package]
name = "solana-net-utils"
version = "0.21.0"
version = "0.21.4"
description = "Solana Network Utilities"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -18,8 +18,8 @@ rand = "0.6.1"
serde = "1.0.102"
serde_derive = "1.0.102"
socket2 = "0.3.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
tokio = "0.1"
tokio-codec = "0.1"

View File

@ -42,83 +42,145 @@ pub fn ip_echo_server(tcp: std::net::TcpListener) -> IpEchoServer {
.incoming()
.map_err(|err| warn!("accept failed: {:?}", err))
.for_each(move |socket| {
let ip = socket.peer_addr().expect("Expect peer_addr()").ip();
info!("connection from {:?}", ip);
let peer_addr = socket.peer_addr().expect("Expect peer_addr()");
info!("connection from {:?}", peer_addr);
let framed = BytesCodec::new().framed(socket);
let (writer, reader) = framed.split();
let processor = reader
.and_then(move |bytes| {
bincode::deserialize::<IpEchoServerMessage>(&bytes).or_else(|err| {
Err(io::Error::new(
.and_then(move |data| {
if data.len() < 4 {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to deserialize IpEchoServerMessage: {:?}", err),
))
})
format!("Request too short, received {} bytes", data.len()),
));
}
let request_header: String = data[0..4].iter().map(|b| *b as char).collect();
if request_header != "\0\0\0\0" {
// Explicitly check for HTTP GET/POST requests to more gracefully handle
// the case where a user accidentally tried to use a gossip entrypoint in
// place of a JSON RPC URL:
if request_header == "GET " || request_header == "POST" {
return Ok(None); // None -> Send HTTP error response
}
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Bad request header: {}", request_header),
));
}
let expected_len =
bincode::serialized_size(&IpEchoServerMessage::default()).unwrap() as usize;
let actual_len = data[4..].len();
if actual_len < expected_len {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Request too short, actual {} < expected {}",
actual_len, expected_len
),
));
}
bincode::deserialize::<IpEchoServerMessage>(&data[4..])
.map(Some)
.or_else(|err| {
Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to deserialize IpEchoServerMessage: {:?}", err),
))
})
})
.and_then(move |msg| {
// Fire a datagram at each non-zero UDP port
if !msg.udp_ports.is_empty() {
match std::net::UdpSocket::bind("0.0.0.0:0") {
Ok(udp_socket) => {
for udp_port in &msg.udp_ports {
if *udp_port != 0 {
match udp_socket
.send_to(&[0], SocketAddr::from((ip, *udp_port)))
{
Ok(_) => debug!("Successful send_to udp/{}", udp_port),
Err(err) => {
info!("Failed to send_to udp/{}: {}", udp_port, err)
.and_then(move |maybe_msg| {
match maybe_msg {
None => None, // Send HTTP error response
Some(msg) => {
// Fire a datagram at each non-zero UDP port
if !msg.udp_ports.is_empty() {
match std::net::UdpSocket::bind("0.0.0.0:0") {
Ok(udp_socket) => {
for udp_port in &msg.udp_ports {
if *udp_port != 0 {
match udp_socket.send_to(
&[0],
SocketAddr::from((peer_addr.ip(), *udp_port)),
) {
Ok(_) => debug!(
"Successful send_to udp/{}",
udp_port
),
Err(err) => info!(
"Failed to send_to udp/{}: {}",
udp_port, err
),
}
}
}
}
Err(err) => {
warn!("Failed to bind local udp socket: {}", err);
}
}
}
Err(err) => {
warn!("Failed to bind local udp socket: {}", err);
}
// Try to connect to each non-zero TCP port
let tcp_futures: Vec<_> =
msg.tcp_ports
.iter()
.filter_map(|tcp_port| {
let tcp_port = *tcp_port;
if tcp_port == 0 {
None
} else {
Some(
tokio::net::TcpStream::connect(&SocketAddr::new(
peer_addr.ip(),
tcp_port,
))
.and_then(move |tcp_stream| {
debug!(
"Connection established to tcp/{}",
tcp_port
);
let _ = tcp_stream
.shutdown(std::net::Shutdown::Both);
Ok(())
})
.timeout(Duration::from_secs(5))
.or_else(move |err| {
Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Connection timeout to {}: {:?}",
tcp_port, err
),
))
}),
)
}
})
.collect();
Some(future::join_all(tcp_futures))
}
}
// Try to connect to each non-zero TCP port
let tcp_futures: Vec<_> = msg
.tcp_ports
.iter()
.filter_map(|tcp_port| {
let tcp_port = *tcp_port;
if tcp_port == 0 {
None
} else {
Some(
tokio::net::TcpStream::connect(&SocketAddr::new(ip, tcp_port))
.and_then(move |tcp_stream| {
debug!("Connection established to tcp/{}", tcp_port);
let _ = tcp_stream.shutdown(std::net::Shutdown::Both);
Ok(())
})
.timeout(Duration::from_secs(5))
.or_else(move |err| {
Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Connection timeout to {}: {:?}",
tcp_port, err
),
))
}),
)
}
})
.collect();
future::join_all(tcp_futures)
})
.and_then(move |_| {
let ip = bincode::serialize(&ip).unwrap_or_else(|err| {
warn!("Failed to serialize: {:?}", err);
vec![]
});
Ok(Bytes::from(ip))
.and_then(move |valid_request| {
if valid_request.is_none() {
Ok(Bytes::from(
"HTTP/1.1 400 Bad Request\nContent-length: 0\n\n",
))
} else {
// "\0\0\0\0" header is added to ensure a valid response will never
// conflict with the first four bytes of a valid HTTP response.
let mut bytes = vec![
0;
4 + bincode::serialized_size(&peer_addr.ip()).unwrap()
as usize
];
bincode::serialize_into(&mut bytes[4..], &peer_addr.ip()).unwrap();
Ok(Bytes::from(bytes))
}
});
let connection = writer

View File

@ -29,8 +29,15 @@ fn ip_echo_server_request(
let timeout = Duration::new(5, 0);
TcpStream::connect_timeout(ip_echo_server_addr, timeout)
.and_then(|mut stream| {
let msg = bincode::serialize(&msg).expect("serialize IpEchoServerMessage");
stream.write_all(&msg)?;
let mut bytes = vec![0; 4]; // Start with 4 null bytes to avoid looking like an HTTP GET/POST request
bytes.append(&mut bincode::serialize(&msg).expect("serialize IpEchoServerMessage"));
// End with '\n' to make this request look HTTP-ish and tickle an error response back
// from an HTTP server
bytes.push(b'\n');
stream.write_all(&bytes)?;
stream.shutdown(std::net::Shutdown::Write)?;
stream
.set_read_timeout(Some(Duration::new(10, 0)))
@ -38,7 +45,38 @@ fn ip_echo_server_request(
stream.read_to_end(&mut data)
})
.and_then(|_| {
bincode::deserialize(&data).map_err(|err| {
// It's common for users to accidentally confuse the validator's gossip port and JSON
// RPC port. Attempt to detect when this occurs by looking for the standard HTTP
// response header and provide the user with a helpful error message
if data.len() < 4 {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Response too short, received {} bytes", data.len()),
));
}
let response_header: String = data[0..4].iter().map(|b| *b as char).collect();
if response_header != "\0\0\0\0" {
if response_header == "HTTP" {
let http_response = data.iter().map(|b| *b as char).collect::<String>();
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Invalid gossip entrypoint. {} looks to be an HTTP port: {}",
ip_echo_server_addr, http_response
),
));
}
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Invalid gossip entrypoint. {} provided an invalid response header: '{}'",
ip_echo_server_addr, response_header
),
));
}
bincode::deserialize(&data[4..]).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed to deserialize: {:?}", err),
@ -102,7 +140,7 @@ pub fn verify_reachable_ports(
);
std::process::exit(1);
});
info!("tdp/{} is reachable", port);
info!("tcp/{} is reachable", port);
}
// Wait for a datagram to arrive at each UDP port
@ -435,6 +473,7 @@ mod tests {
#[test]
fn test_get_public_ip_addr() {
solana_logger::setup();
let (_server_port, (server_udp_socket, server_tcp_listener)) =
bind_common_in_range((3200, 3250)).unwrap();
let (client_port, (client_udp_socket, client_tcp_listener)) =
@ -443,7 +482,10 @@ mod tests {
let _runtime = ip_echo_server(server_tcp_listener);
let ip_echo_server_addr = server_udp_socket.local_addr().unwrap();
get_public_ip_addr(&ip_echo_server_addr).unwrap();
assert_eq!(
get_public_ip_addr(&ip_echo_server_addr),
parse_host("127.0.0.1"),
);
verify_reachable_ports(
&ip_echo_server_addr,

View File

@ -1,6 +1,6 @@
[package]
name = "solana-perf"
version = "0.21.0"
version = "0.21.4"
description = "Solana Performance APIs"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -18,11 +18,11 @@ serde_derive = "1.0.102"
dlopen_derive = "0.1.4"
lazy_static = "1.4.0"
log = "0.4.8"
solana-sdk = { path = "../sdk", version = "0.21.0" }
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-metrics = { path = "../metrics", version = "0.21.0" }
solana-sdk = { path = "../sdk", version = "0.21.4" }
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.4" }
solana-budget-program = { path = "../programs/budget", version = "0.21.4" }
solana-logger = { path = "../logger", version = "0.21.4" }
solana-metrics = { path = "../metrics", version = "0.21.4" }
[lib]
name = "solana_perf"

203
programs/bpf/Cargo.lock generated
View File

@ -245,12 +245,12 @@ dependencies = [
[[package]]
name = "chrono"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -822,7 +822,7 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1117,7 +1117,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1585,156 +1585,157 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "solana-bpf-loader-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
"solana_rbpf 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-bpf-programs"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"elf 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-bpf-loader-program 0.21.0",
"solana-logger 0.21.0",
"solana-runtime 0.21.0",
"solana-sdk 0.21.0",
"solana-bpf-loader-program 0.21.1",
"solana-logger 0.21.1",
"solana-runtime 0.21.1",
"solana-sdk 0.21.1",
"solana_rbpf 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-bpf-rust-128bit"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-128bit-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-128bit-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-128bit-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-alloc"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-dep-crate"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-external-spend"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-iter"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-many-args"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-many-args-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-many-args-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-many-args-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-noop"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-panic"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-param-passing"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-param-passing-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-param-passing-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-param-passing-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-sysval"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-config-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-crate-features"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1757,7 +1758,7 @@ dependencies = [
[[package]]
name = "solana-logger"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1766,26 +1767,26 @@ dependencies = [
[[package]]
name = "solana-measure"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-metrics"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk 0.21.0",
"solana-sdk 0.21.1",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-rayon-threadlimit"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1793,14 +1794,14 @@ dependencies = [
[[package]]
name = "solana-runtime"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bv 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1811,22 +1812,22 @@ dependencies = [
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-bpf-loader-program 0.21.0",
"solana-logger 0.21.0",
"solana-measure 0.21.0",
"solana-metrics 0.21.0",
"solana-rayon-threadlimit 0.21.0",
"solana-sdk 0.21.0",
"solana-stake-program 0.21.0",
"solana-storage-program 0.21.0",
"solana-vote-program 0.21.0",
"solana-bpf-loader-program 0.21.1",
"solana-logger 0.21.1",
"solana-measure 0.21.1",
"solana-metrics 0.21.1",
"solana-rayon-threadlimit 0.21.1",
"solana-sdk 0.21.1",
"solana-stake-program 0.21.1",
"solana-storage-program 0.21.1",
"solana-vote-program 0.21.1",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-sdk"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1836,8 +1837,7 @@ dependencies = [
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1850,17 +1850,28 @@ dependencies = [
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.0",
"solana-logger 0.21.0",
"solana-crate-features 0.21.1",
"solana-logger 0.21.1",
"solana-sdk-macro 0.21.1",
]
[[package]]
name = "solana-sdk-bpf-test"
version = "0.21.0"
version = "0.21.1"
[[package]]
name = "solana-sdk-macro"
version = "0.21.1"
dependencies = [
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-stake-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1869,16 +1880,16 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-config-program 0.21.0",
"solana-logger 0.21.0",
"solana-metrics 0.21.0",
"solana-sdk 0.21.0",
"solana-vote-program 0.21.0",
"solana-config-program 0.21.1",
"solana-logger 0.21.1",
"solana-metrics 0.21.1",
"solana-sdk 0.21.1",
"solana-vote-program 0.21.1",
]
[[package]]
name = "solana-storage-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1887,13 +1898,13 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-vote-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1901,9 +1912,9 @@ dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-metrics 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-metrics 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
@ -2601,7 +2612,7 @@ dependencies = [
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
@ -2662,7 +2673,7 @@ dependencies = [
"checksum indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a61202fbe46c4a951e9404a720a0180bcf3212c750d735cb5c4ba4dc551299f3"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
"checksum itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "87fa75c9dea7b07be3138c49abbb83fd4bea199b5cdc76f9804458edc5da0d6e"
"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160"
"checksum js-sys 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "1efc4f2a556c58e79c5500912e221dd826bec64ff4aabd8ce71ccef6da02d7d4"

View File

@ -1,7 +1,7 @@
[package]
name = "solana-bpf-programs"
description = "Blockchain, Rebuilt for Scale"
version = "0.21.0"
version = "0.21.4"
documentation = "https://docs.rs/solana"
homepage = "https://solana.com/"
readme = "README.md"
@ -22,10 +22,10 @@ walkdir = "2"
bincode = "1.1.4"
byteorder = "1.3.2"
elf = "0.0.10"
solana-bpf-loader-program = { path = "../bpf_loader", version = "0.21.0" }
solana-logger = { path = "../../logger", version = "0.21.0" }
solana-runtime = { path = "../../runtime", version = "0.21.0" }
solana-sdk = { path = "../../sdk", version = "0.21.0" }
solana-bpf-loader-program = { path = "../bpf_loader", version = "0.21.4" }
solana-logger = { path = "../../logger", version = "0.21.4" }
solana-runtime = { path = "../../runtime", version = "0.21.4" }
solana-sdk = { path = "../../sdk", version = "0.21.4" }
solana_rbpf = "=0.1.19"
[[bench]]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-128bit"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,11 +12,11 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-bpf-rust-128bit-dep = { path = "../128bit_dep", version = "0.21.0" }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
solana-bpf-rust-128bit-dep = { path = "../128bit_dep", version = "0.21.4" }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-128bit-dep"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,10 +12,10 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-alloc"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,10 +12,10 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-dep-crate"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -13,10 +13,10 @@ edition = "2018"
[dependencies]
byteorder = { version = "1", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-external-spend"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,10 +12,10 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

View File

@ -3,7 +3,7 @@
[package]
name = "solana-bpf-rust-iter"
version = "0.21.0"
version = "0.21.4"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
@ -12,10 +12,10 @@ homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.21.0", default-features = false }
solana-sdk = { path = "../../../../sdk/", version = "0.21.4", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.0" }
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.21.4" }
[features]
program = ["solana-sdk/program"]

Some files were not shown because too many files have changed in this diff Show More