8000 Fix `Propose` invalidation logic [ECR-4223] by slowli · Pull Request #1782 · exonum/exonum · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Propose invalidation logic [ECR-4223] #1782

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

Merged
merged 8 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
- cargo test --all --lib --tests --benches
- cargo test --all --doc

# Run examples.
# Run examples and soak tests.
- name: examples
script:
- cargo run -p exonum-merkledb --example manual_migration
Expand All @@ -146,6 +146,7 @@ jobs:
- cargo run -p exonum-testkit --example timestamping
- cargo run -p exonum-supervisor --example configuration_change
- cargo run -p exonum-time --example simple_service
- cargo run -p exonum-soak-tests --bin toggle -- -H 10
- cargo run -p exonum-keys --example key-generator -- -p passphrase -s a7839ea524f38d0e91a5ec96a723092719dc8a5b8a75f9131d9eb38f45e76344

# Integration tests.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
- Testkit now does not include incorrect transactions into blocks or memory pool,
similar to real Exonum nodes. (#1785)

### Bug Fixes

#### exonum-node

- Fixed incorrect invalidation of block proposals. (#1782)

## 1.0.0-rc.1 - 2020-02-07

### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"test-suite/testkit",
"test-suite/testkit/server",
"test-suite/rust-runtime-proto",
"test-suite/soak-tests",

"runtimes/rust",

Expand Down
45 changes: 45 additions & 0 deletions exonum-node/src/sandbox/tests/round_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,51 @@ fn not_sending_precommit_for_proposal_with_incorrect_tx() {
sandbox.add_time(Duration::from_millis(0));
}

#[test]
fn invalid_tx_does_not_invalidate_unrelated_proposes() {
let sandbox = timestamping_sandbox();
let invalid_tx = gen_incorrect_tx();

let propose = ProposeBuilder::new(&sandbox).with_tx_hashes(&[]).build();
sandbox.recv(&propose);
let our_prevote = sandbox.create_prevote(
ValidatorId(0),
Height(1),
Round(1),
propose.object_hash(),
NOT_LOCKED,
sandbox.secret_key(ValidatorId(0)),
);
sandbox.broadcast(&our_prevote);

sandbox.recv(&invalid_tx);
{
let inner = sandbox.inner.borrow();
let propose_state = inner.handler.state.propose(&propose.object_hash()).unwrap();
assert!(!propose_state.has_invalid_txs());
}

let block = sandbox.create_block(&[]);
let precommits = (1..4).map(|i| {
let validator_id = ValidatorId(i);
sandbox.create_precommit(
validator_id,
Height(1),
Round(1),
propose.object_hash(),
block.object_hash(),
sandbox.time().into(),
sandbox.secret_key(validator_id),
)
});

for precommit in precommits {
sandbox.recv(&precommit);
}
sandbox.assert_state(Height(2), Round(1));
sandbox.check_broadcast_status(Height(2), block.object_hash());
}

/// scenario: // HANDLE PRECOMMIT positive scenario with commit
#[test]
fn handle_precommit_positive_scenario_commit() {
Expand Down
5 changes: 2 additions & 3 deletions exonum-node/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,8 @@ impl State {
pub(super) fn check_incomplete_proposes(&mut self, tx_hash: Hash) -> Vec<(Hash, Round)> {
let mut full_proposes = Vec::new();
for (propose_hash, propose_state) in &mut self.proposes {
propose_state.unknown_txs.remove(&tx_hash);

if self.invalid_txs.contains(& ED48 tx_hash) {
let contained_tx = propose_state.unknown_txs.remove(&tx_hash);
if contained_tx && self.invalid_txs.contains(&tx_hash) {
// Mark prevote with newly received invalid transaction as invalid.
propose_state.is_valid = false;
}
Expand Down
25 changes: 25 additions & 0 deletions test-suite/soak-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "exonum-soak-tests"
version = "0.0.0"
edition = "2018"
authors = ["The Exonum Team <exonum@bitfury.com>"]
homepage = "https://exonum.com/"
repository = "https://github.com/exonum/exonum"
readme = "README.md"
description = "The crate for soak testing of Exonum node."
publish = false

[[bin]]
name = "toggle"
path = "src/toggle.rs"

[dependencies]
exonum = { version = "1.0.0-rc.1", path = "../../exonum" }
exonum-derive = { version = "1.0.0-rc.1", path = "../../components/derive" }
exonum-merkledb = { version = "1.0.0-rc.1", path = "../../components/merkledb" }
exonum-node = { version = "1.0.0-rc.1", path = "../../exonum-node" }
exonum-rust-runtime = { version = "1.0.0-rc.1", path = "../../runtimes/rust" }

futures = "0.1.29"
log = "0.4.6"
structopt = "0.3.9"
25 changes: 25 additions & 0 deletions test-suite/soak-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Soak Tests for Exonum Nodes

This is an internal crate for subjecting Exonum networks to [soak tests].

## Contents

The crate exposes the following binaries:

- [`toggle`](src/toggle.rs). Tests repeatedly switching a service on and off.
The service generates transactions in the `after_commit` hook.

## Usage

Run the selected binary like this:

```sh
cargo run -p exonum-soak-tests --bin $binary
```

Use `--help` option to find out command-line options specific to the binary.

You may want to set up `RUST_LOG` env variable to check events in the nodes
and/or the core library, for example, `RUST_LOG=exonum_node=info,warn`.

[soak tests]: https://en.wikipedia.org/wiki/Soak_testing
99 changes: 99 additions & 0 deletions test-suite/soak-tests/src/services.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2020 The Exonum Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use exonum::runtime::SUPERVISOR_INSTANCE_ID;
use exonum::{
helpers::Height,
merkledb::access::AccessExt,
runtime::{ExecutionContext, ExecutionError, InstanceId},
};
use exonum_derive::*;
use exonum_rust_runtime::{AfterCommitContext, DefaultInstance, Service};

#[exonum_interface(auto_ids)]
pub trait MainServiceInterface<Ctx> {
type Output;

fn timestamp(&self, context: Ctx, height: Height) -> Self::Output;
}

#[derive(Debug, Clone, Copy, ServiceDispatcher, ServiceFactory)]
#[service_dispatcher(implements("MainServiceInterface"))]
#[service_factory(artifact_name = "main", artifact_version = "1.0.0")]
pub struct MainService;

impl MainServiceInterface<ExecutionContext<'_>> for MainService {
type Output = Result<(), ExecutionError>;

fn timestamp(&self, _context: ExecutionContext<'_>, _height: Height) -> Self::Output {
Ok(())
}
}

impl Service for MainService {
fn after_transactions(&self, context: ExecutionContext<'_>) -> Result<(), ExecutionError> {
let height = context.data().for_core().next_height();
let height_str = height.0.to_string();

let mut map = context
.service_data()
.get_proof_map::<_, u64, String>("some");
map.put(&0, height_str.clone());
map.put(&(height.0 / 2), height_str.clone());
map.put(&height.0, height_str.clone());
map.put(&(height.0 + 1), height_str);

Ok(())
}

fn after_commit(&self, context: AfterCommitContext<'_>) {
if let Some(broadcaster) = context.broadcaster() {
if let Err(e) = broadcaster.timestamp((), context.height()) {
log::error!(
"[{}] Failed to broadcast transaction at height {}: {}",
context.service_key(),
context.height(),
e
);
}
}
}
}

impl DefaultInstance for MainService {
const INSTANCE_ID: InstanceId = 100;
const INSTANCE_NAME: &'static str = "main";
}

#[derive(Debug, Clone, Copy, ServiceDispatcher, ServiceFactory)]
#[service_factory(artifact_name = "supervisor", artifact_version = "1.0.0")]
pub struct TogglingSupervisor;

impl Service for TogglingSupervisor {
fn after_transactions(&self, mut context: ExecutionContext<'_>) -> Result<(), ExecutionError> {
let height = context.data().for_core().next_height();
let mut extensions = context.supervisor_extensions();

match height.0 % 5 {
1 => extensions.initiate_stopping_service(MainService::INSTANCE_ID),
4 => extensions.initiate_resuming_service(MainService::INSTANCE_ID, ()),
_ => Ok(()),
}
}
}

impl DefaultInstance for TogglingSupervisor {
const INSTANCE_ID: InstanceId = SUPERVISOR_INSTANCE_ID;
const INSTANCE_NAME: &'static str = "supervisor";
}
Loading
0