Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expose genesis config and records via RPC #2109

Merged
merged 6 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ impl ChainGenesis {
}
}

impl From<GenesisConfig> for ChainGenesis {
fn from(genesis_config: GenesisConfig) -> Self {
impl<T> From<T> for ChainGenesis
where
T: AsRef<GenesisConfig>,
{
fn from(genesis_config: T) -> Self {
let genesis_config = genesis_config.as_ref();
ChainGenesis::new(
genesis_config.genesis_time,
genesis_config.gas_limit,
Expand Down
26 changes: 14 additions & 12 deletions chain/client/tests/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use std::sync::Arc;
use borsh::BorshSerialize;
use reed_solomon_erasure::galois_8::ReedSolomon;

use near::config::{GenesisConfigExt, FISHERMEN_THRESHOLD};
use near::config::{GenesisExt, FISHERMEN_THRESHOLD};
use near::NightshadeRuntime;
use near_chain::chain::BlockEconomicsConfig;
use near_chain::validate::validate_challenge;
use near_chain::{
Block, ChainGenesis, ChainStoreAccess, DoomslugThresholdMode, Error, ErrorKind, Provenance,
RuntimeAdapter,
};
use near_chain_configs::GenesisConfig;
use near_chain_configs::Genesis;
use near_client::test_utils::{MockNetworkAdapter, TestEnv};
use near_client::Client;
use near_crypto::{InMemorySigner, KeyType, Signer};
Expand Down Expand Up @@ -417,11 +417,11 @@ fn challenge(
#[test]
fn test_verify_chunk_invalid_state_challenge() {
let store1 = create_test_store();
let genesis_config = GenesisConfig::test(vec!["test0", "test1"], 1);
let genesis = Genesis::test(vec!["test0", "test1"], 1);
let runtimes: Vec<Arc<dyn RuntimeAdapter>> = vec![Arc::new(near::NightshadeRuntime::new(
Path::new("."),
store1,
genesis_config,
Arc::new(genesis),
vec![],
vec![],
))];
Expand Down Expand Up @@ -683,13 +683,14 @@ fn test_block_challenge() {
#[test]
fn test_fishermen_challenge() {
init_test_logger();
let mut genesis_config = GenesisConfig::test(vec!["test0", "test1", "test2"], 1);
genesis_config.epoch_length = 5;
let mut genesis = Genesis::test(vec!["test0", "test1", "test2"], 1);
genesis.config.epoch_length = 5;
let genesis = Arc::new(genesis);
let create_runtime = || -> Arc<NightshadeRuntime> {
Arc::new(near::NightshadeRuntime::new(
Path::new("."),
create_test_store(),
genesis_config.clone(),
Arc::clone(&genesis),
vec![],
vec![],
))
Expand Down Expand Up @@ -742,21 +743,22 @@ fn test_fishermen_challenge() {
#[test]
fn test_challenge_in_different_epoch() {
init_test_logger();
let mut genesis_config = GenesisConfig::test(vec!["test0", "test1"], 2);
genesis_config.epoch_length = 2;
// genesis_config.validator_kickout_threshold = 10;
let mut genesis = Genesis::test(vec!["test0", "test1"], 2);
genesis.config.epoch_length = 2;
let genesis = Arc::new(genesis);
// genesis.config.validator_kickout_threshold = 10;
let network_adapter = Arc::new(MockNetworkAdapter::default());
let runtime1 = Arc::new(near::NightshadeRuntime::new(
Path::new("."),
create_test_store(),
genesis_config.clone(),
Arc::clone(&genesis),
vec![],
vec![],
));
let runtime2 = Arc::new(near::NightshadeRuntime::new(
Path::new("."),
create_test_store(),
genesis_config,
genesis,
vec![],
vec![],
));
Expand Down
5 changes: 3 additions & 2 deletions chain/jsonrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ chrono = { version = "0.4.4", features = ["serde"] }
lazy_static = "1.4"
log = "0.4"
prometheus = "^0.7"
serde_derive = "1.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
validator = "0.10"
uuid = { version = "~0.8", features = ["v4"] }
borsh = "0.2.10"

near-chain-configs = { path = "../../core/chain-configs" }
near-crypto = { path = "../../core/crypto" }
near-primitives = { path = "../../core/primitives" }
near-store = { path = "../../core/store" }
Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2018"
[dependencies]
actix-web = "2.0.0"
futures = "0.3"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde = "1.0"
uuid = { version = "~0.8", features = ["v4"] }

near-chain-configs = { path = "../../../core/chain-configs" }
near-primitives = { path = "../../../core/primitives" }
14 changes: 12 additions & 2 deletions chain/jsonrpc/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use serde::Deserialize;
use serde::Serialize;

use near_primitives::hash::CryptoHash;
use near_primitives::rpc::{BlockQueryInfo, RpcQueryRequest};
use near_primitives::rpc::{BlockQueryInfo, RpcGenesisRecordsRequest, RpcQueryRequest};
use near_primitives::types::{BlockId, MaybeBlockId, ShardId};
use near_primitives::views::{
BlockView, ChunkView, EpochValidatorInfo, FinalExecutionOutcomeView, GasPriceView,
QueryResponse, StateChangesView, StatusResponse,
GenesisRecordsView, QueryResponse, StateChangesView, StatusResponse,
};

use crate::message::{from_slice, Message, RpcError};
Expand Down Expand Up @@ -180,6 +180,8 @@ jsonrpc_client!(pub struct JsonRpcClient {
pub fn broadcast_tx_async(&mut self, tx: String) -> RpcRequest<String>;
pub fn broadcast_tx_commit(&mut self, tx: String) -> RpcRequest<FinalExecutionOutcomeView>;
pub fn status(&mut self) -> RpcRequest<StatusResponse>;
#[allow(non_snake_case)]
pub fn EXPERIMENTAL_genesis_config(&mut self) -> RpcRequest<serde_json::Value>;
frol marked this conversation as resolved.
Show resolved Hide resolved
pub fn health(&mut self) -> RpcRequest<()>;
pub fn tx(&mut self, hash: String, account_id: String) -> RpcRequest<FinalExecutionOutcomeView>;
pub fn chunk(&mut self, id: ChunkId) -> RpcRequest<ChunkView>;
Expand All @@ -189,6 +191,14 @@ jsonrpc_client!(pub struct JsonRpcClient {
});

impl JsonRpcClient {
#[allow(non_snake_case)]
pub fn EXPERIMENTAL_genesis_records(
&mut self,
request: RpcGenesisRecordsRequest,
) -> RpcRequest<GenesisRecordsView> {
call_method(&self.client, &self.server_addr, "EXPERIMENTAL_genesis_records", request)
}

/// This is a soft-deprecated method to do query RPC request with a path and data positional
/// parameters.
pub fn query_by_path(&mut self, path: String, data: String) -> RpcRequest<QueryResponse> {
Expand Down
Loading