Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nearprotocol/nearcore into fix/20…
Browse files Browse the repository at this point in the history
…48-query-account-changes
  • Loading branch information
frol committed Mar 5, 2020
2 parents 33e85f9 + f605a11 commit 37d7113
Show file tree
Hide file tree
Showing 28 changed files with 357 additions and 256 deletions.
106 changes: 0 additions & 106 deletions .gitlab-ci.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM gitpod/workspace-full

RUN git clone https://github.com/nearprotocol/nearcore.git --depth 1 /home/gitpod/nearcore
RUN bash -cl "cd /home/gitpod/nearcore && cargo build && cargo test"
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tasks:
- init: cp -R /home/gitpod/nearcore/target ./target && cargo build && cargo test
image:
file: .gitpod.Dockerfile
github:
prebuilds:
addCheck: true
addComment: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## NEAR Protocol - scalable and usable blockchain

![Build status](https://gitlab.com/near-protocol/nearcore/badges/master/pipeline.svg)
[![Build status](https://badge.buildkite.com/a81147cb62c585cc434459eedd1d25e521453120ead9ee6c64.svg)](https://buildkite.com/nearprotocol/nearcore)
[![codecov](https://codecov.io/gh/nearprotocol/nearcore/branch/master/graph/badge.svg)](https://codecov.io/gh/nearprotocol/nearcore)
[![dependency status](https://deps.rs/repo/github/nearprotocol/nearcore/status.svg)](https://deps.rs/repo/github/nearprotocol/nearcore)
[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/near)
Expand Down
8 changes: 4 additions & 4 deletions chain/client/tests/catching_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ mod tests {
);
*connectors.write().unwrap() = conn;

near_network::test_utils::wait_or_panic(30000);
near_network::test_utils::wait_or_panic(60000);
})
.unwrap();
}
Expand Down Expand Up @@ -703,7 +703,7 @@ mod tests {
key_pairs.clone(),
validator_groups,
true,
400,
600,
false,
false,
5,
Expand Down Expand Up @@ -740,7 +740,7 @@ mod tests {
);
*connectors.write().unwrap() = conn;

near_network::test_utils::wait_or_panic(30000);
near_network::test_utils::wait_or_panic(60000);
})
.unwrap();
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ mod tests {
})),
);
*connectors.write().unwrap() = conn;
let max_wait_ms = block_prod_time * last_height / 10 * 13 + 10000;
let max_wait_ms = block_prod_time * last_height / 10 * 18 + 20000;

near_network::test_utils::wait_or_panic(max_wait_ms);
})
Expand Down
26 changes: 16 additions & 10 deletions chain/client/tests/cross_shard_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ mod tests {
rotate_validators: bool,
drop_chunks: bool,
test_doomslug: bool,
block_production_time: u64,
) {
if !cfg!(feature = "expensive_tests") {
return;
Expand Down Expand Up @@ -412,7 +413,7 @@ mod tests {
key_pairs.clone(),
validator_groups,
true,
if drop_chunks || rotate_validators { 150 } else { 100 },
block_production_time,
drop_chunks,
!test_doomslug,
20,
Expand Down Expand Up @@ -474,41 +475,46 @@ mod tests {
}

near_network::test_utils::wait_or_panic(if rotate_validators {
1000 * 60 * 15 * 4
1000 * 60 * 80
} else {
1000 * 60 * 15 * 2
1000 * 60 * 30
});
})
.unwrap();
}

#[test]
fn test_cross_shard_tx() {
test_cross_shard_tx_common(64, false, false, false);
test_cross_shard_tx_common(64, false, false, false, 100);
}

#[test]
fn test_cross_shard_tx_doomslug() {
test_cross_shard_tx_common(64, false, false, true);
test_cross_shard_tx_common(64, false, false, true, 100);
}

#[test]
fn test_cross_shard_tx_drop_chunks() {
test_cross_shard_tx_common(64, false, true, false);
test_cross_shard_tx_common(64, false, true, false, 150);
}

#[test]
fn test_cross_shard_tx_8_iterations() {
test_cross_shard_tx_common(8, false, false, false);
test_cross_shard_tx_common(8, false, false, false, 100);
}

#[test]
fn test_cross_shard_tx_8_iterations_drop_chunks() {
test_cross_shard_tx_common(8, false, true, false);
test_cross_shard_tx_common(8, false, true, false, 150);
}

#[test]
fn test_cross_shard_tx_with_validator_rotation() {
test_cross_shard_tx_common(64, true, false, false);
fn test_cross_shard_tx_with_validator_rotation_1() {
test_cross_shard_tx_common(8, true, false, false, 200);
}

#[test]
fn test_cross_shard_tx_with_validator_rotation_2() {
test_cross_shard_tx_common(24, true, false, false, 400);
}
}
41 changes: 40 additions & 1 deletion chain/epoch_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ impl EpochManager {
last_block_hash: &CryptoHash,
rng_seed: RngSeed,
) -> Result<EpochId, EpochError> {
println!("finalize epoch");
let EpochSummary {
prev_epoch_last_block_hash,
all_proposals,
Expand Down Expand Up @@ -2438,6 +2437,46 @@ mod tests {
assert_eq!(em.get_epoch_info(&EpochId(CryptoHash::default())).unwrap(), &epoch_info)
}

#[test]
fn test_fishermen_unstake() {
let stake_amount = 1_000;
let fishermen_threshold = 100;
let validators = vec![
("test1", stake_amount),
("test2", fishermen_threshold),
("test3", fishermen_threshold),
];
let mut em = setup_epoch_manager(
validators,
2,
1,
1,
0,
90,
70,
fishermen_threshold,
default_reward_calculator(),
);
let h = hash_range(5);
record_block(&mut em, CryptoHash::default(), h[0], 0, vec![]);
// fishermen unstake
record_block(&mut em, h[0], h[1], 1, vec![stake("test2", 0)]);
record_block(&mut em, h[1], h[2], 2, vec![stake("test3", 1)]);
assert_eq!(
em.get_epoch_info(&EpochId(h[2])).unwrap(),
&epoch_info(
vec![("test1", stake_amount)],
vec![0],
vec![vec![0]],
vec![],
vec![],
change_stake(vec![("test1", stake_amount), ("test2", 0), ("test3", 0)]),
reward(vec![("test1", 0), ("near", 0)]),
0
)
);
}

#[test]
fn test_validator_consistency() {
let stake_amount = 1_000;
Expand Down
70 changes: 67 additions & 3 deletions chain/epoch_manager/src/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ pub fn proposals_to_epoch_info(
}

for r in epoch_info.fishermen.iter() {
if !ordered_proposals.contains_key(&r.account_id) {
if !ordered_proposals.contains_key(&r.account_id)
&& !validator_kickout.contains(&r.account_id)
{
// safe to do this here because fishermen from previous epoch is guaranteed to have no
// duplicates.
fishermen_to_index.insert(r.account_id.clone(), fishermen.len() as ValidatorId);
Expand Down Expand Up @@ -113,7 +115,9 @@ pub fn proposals_to_epoch_info(
}
})
.or_insert((0, p.stake));
if epoch_info.validator_to_index.contains_key(&account_id) {
if epoch_info.validator_to_index.contains_key(&account_id)
|| epoch_info.fishermen_to_index.contains_key(&account_id)
{
validator_kickout.insert(account_id);
}
}
Expand Down Expand Up @@ -166,7 +170,9 @@ pub fn proposals_to_epoch_info(
fishermen.push(p);
} else {
stake_change.insert(p.account_id.clone(), (0, p.stake));
if epoch_info.validator_to_index.contains_key(&p.account_id) {
if epoch_info.validator_to_index.contains_key(&p.account_id)
|| epoch_info.fishermen_to_index.contains_key(&p.account_id)
{
validator_kickout.insert(p.account_id);
}
}
Expand Down Expand Up @@ -298,4 +304,62 @@ mod tests {
)
);
}

#[test]
fn test_fishermen_allocation() {
// 4 proposals of stake 10, fishermen threshold 10 --> 1 validator and 3 fishermen
assert_eq!(
proposals_to_epoch_info(
&epoch_config(2, 2, 1, 0, 90, 60, 10),
[0; 32],
&EpochInfo::default(),
vec![
stake("test1", 10),
stake("test2", 10),
stake("test3", 10),
stake("test4", 10)
],
HashSet::default(),
HashMap::default(),
0
)
.unwrap(),
epoch_info(
vec![("test1", 10)],
vec![0],
vec![vec![0], vec![0]],
vec![],
vec![("test2", 10), ("test3", 10), ("test4", 10)],
change_stake(vec![("test1", 10), ("test2", 10), ("test3", 10), ("test4", 10)]),
HashMap::default(),
0
)
);

// 4 proposals of stake 9, fishermen threshold 10 --> 1 validator and 0 fishermen
let mut epoch_info = epoch_info(
vec![("test1", 9)],
vec![0],
vec![vec![0], vec![0]],
vec![],
vec![],
change_stake(vec![("test1", 9), ("test2", 0), ("test3", 0), ("test4", 0)]),
HashMap::default(),
0,
);
epoch_info.validator_kickout = HashSet::default();
assert_eq!(
proposals_to_epoch_info(
&epoch_config(2, 2, 1, 0, 90, 60, 10),
[0; 32],
&EpochInfo::default(),
vec![stake("test1", 9), stake("test2", 9), stake("test3", 9), stake("test4", 9)],
HashSet::default(),
HashMap::default(),
0
)
.unwrap(),
epoch_info
);
}
}
Loading

0 comments on commit 37d7113

Please sign in to comment.