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

Merge stable into master #2199

Merged
merged 11 commits into from
Feb 27, 2020
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Cargo.lock linguist-generated=true -diff
**/package-lock.json linguist-generated=true -diff
near/res/testnet.json linguist-generated=true -diff
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ tmp/
# Vim tmp files
*.swp
rusty-tags.vi

# target dir for building adversarial node for pytests
pytest/.adversary

# a file indicating that the person understands the risks of running adversarial tests
pytest/.consent

# testnet genesis
/near/res/testnet.json
/near/res/testnet_genesis_records*.json
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Develop and deploy contracts without any setup required using [NEAR Studio](http

## Status

This project is currently under heavy development. Please see Issues and Milestones to checkout the current progress and working items.
This project is currently under heavy development. Please see [Issues](https://github.com/nearprotocol/nearcore/issues) and [Milestones](https://github.com/nearprotocol/nearcore/milestones) to checkout the current progress and working items.

High level milestones:

Expand Down
5 changes: 4 additions & 1 deletion chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,10 @@ impl RuntimeAdapter for KeyValueRuntime {
block_hash: *block_hash,
}),
QueryRequest::ViewState { .. } => Ok(QueryResponse {
kind: QueryResponseKind::ViewState(ViewStateResult { values: Default::default() }),
kind: QueryResponseKind::ViewState(ViewStateResult {
values: Default::default(),
proof: vec![],
}),
block_height,
block_hash: *block_hash,
}),
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn setup(
runtime.clone(),
network_adapter.clone(),
config.clone(),
None,
)
.unwrap();

Expand Down
12 changes: 11 additions & 1 deletion chain/client/src/view_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,24 @@ impl ViewClientActor {
runtime_adapter: Arc<dyn RuntimeAdapter>,
network_adapter: Arc<dyn NetworkAdapter>,
config: ClientConfig,
expected_genesis_hash: Option<String>,
) -> Result<Self, Error> {
// TODO: should we create shared ChainStore that is passed to both Client and ViewClient?
let chain = Chain::new(
let mut chain = Chain::new(
store,
runtime_adapter.clone(),
chain_genesis,
DoomslugThresholdMode::HalfStake,
)?;
if let Some(expected_genesis_hash) = expected_genesis_hash {
let genesis_hash = chain.get_block_by_height(0).unwrap().hash().to_string();
if genesis_hash != expected_genesis_hash {
panic!(
"Expected genesis hash to be {}, actual {}",
expected_genesis_hash, genesis_hash,
);
}
}
Ok(ViewClientActor {
#[cfg(feature = "adversarial")]
adv_disable_header_sync: false,
Expand Down
1 change: 1 addition & 0 deletions chain/network/tests/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn setup_network_node(
runtime.clone(),
network_adapter.clone(),
client_config,
None,
)
.unwrap()
.start();
Expand Down
52 changes: 44 additions & 8 deletions core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use near_primitives::types::{
use near_runtime_configs::RuntimeConfig;

use crate::PROTOCOL_VERSION;
use std::mem::swap;

pub const CONFIG_VERSION: u32 = 1;

Expand Down Expand Up @@ -88,26 +89,56 @@ impl GenesisConfig {
}

/// Reads GenesisConfig from a file.
pub fn from_file(path: &PathBuf) -> Self {
pub fn from_file(path: &PathBuf, records_path: Option<PathBuf>) -> Self {
let mut file = File::open(path).expect("Could not open genesis config file.");
let mut content = String::new();
file.read_to_string(&mut content).expect("Could not read from genesis config file.");
GenesisConfig::from(content.as_str())
let records_str = records_path.map(|path| {
let mut content = String::new();
let mut file = File::open(&path).expect("Could not open genesis records file.");
file.read_to_string(&mut content).expect("Could not read from genesis records file.");
content
});
GenesisConfig::from(content.as_str(), records_str)
}

/// Writes GenesisConfig to the file.
pub fn write_to_file(&self, path: &Path) {
let mut file = File::create(path).expect("Failed to create / write a genesis config file.");
let str =
serde_json::to_string_pretty(self).expect("Error serializing the genesis config.");
if let Err(err) = file.write_all(str.as_bytes()) {
let mut buf =
serde_json::to_vec_pretty(self).expect("Error serializing the genesis config.");
if let Err(err) = file.write_all(&mut buf) {
panic!("Failed to write a genesis config file {}", err);
}
}

/// Writes GenesisConfig to the 2 files.
/// All fields but records into `config_path` file and records into a `records_path` file.
/// Requires `&mut self` to avoid cloning records.
pub fn write_to_config_and_records_files(&mut self, config_path: &Path, records_path: &Path) {
// Writing records
let mut file =
File::create(records_path).expect("Failed to create / write a genesis records file.");
let mut buf = serde_json::to_vec_pretty(&self.records)
.expect("Error serializing the genesis records.");
if let Err(err) = file.write_all(&mut buf) {
panic!("Failed to write a genesis records file {}", err);
}

// Writing config
let mut file =
File::create(config_path).expect("Failed to create / write a genesis config file.");
let mut tmp_records = vec![];
swap(&mut tmp_records, &mut self.records);
let mut buf =
serde_json::to_vec_pretty(self).expect("Error serializing the genesis config.");
swap(&mut tmp_records, &mut self.records);
if let Err(err) = file.write_all(&mut buf) {
panic!("Failed to write a genesis config file {}", err);
}
}
}

impl From<&str> for GenesisConfig {
fn from(config: &str) -> Self {
pub fn from(config: &str, records_str: Option<String>) -> Self {
let mut config: GenesisConfig =
serde_json::from_str(config).expect("Failed to deserialize the genesis config.");
if config.protocol_version != PROTOCOL_VERSION {
Expand All @@ -116,6 +147,11 @@ impl From<&str> for GenesisConfig {
config.protocol_version, PROTOCOL_VERSION
));
}
if let Some(records_str) = records_str {
let mut records: Vec<StateRecord> = serde_json::from_str(&records_str)
.expect("Failed to deserialize the genesis config.");
config.records.append(&mut records);
}
config.init();
config
}
Expand Down
15 changes: 13 additions & 2 deletions core/primitives/src/views.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt;

Expand Down Expand Up @@ -122,9 +121,21 @@ impl From<AccessKeyView> for AccessKey {
}
}

/// Set of serialized TrieNodes that are encoded in base64. Represent proof of inclusion of some TrieNode in the MerkleTrie.
pub type TrieProofPath = Vec<String>;

/// Item of the state, key and value are serialized in base64 and proof for inclusion of given state item.
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct StateItem {
pub key: String,
pub value: String,
pub proof: TrieProofPath,
}

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct ViewStateResult {
pub values: HashMap<Vec<u8>, Vec<u8>>,
pub values: Vec<StateItem>,
pub proof: TrieProofPath,
}

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
Expand Down
Loading