From 11bc1d2d09402b6ce15322249313f868d8eb6c4f Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 6 Jul 2024 13:30:02 +0400 Subject: [PATCH 1/3] chore: Prepare crates for publishing (#147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ - Changes git dependency on `pairing` to the published one. - Same for `vise` and `vise-exporter` - Uses `workspace.version` for all the crates. ## Why ❔ --- node/Cargo.lock | 14 +++++++++----- node/Cargo.toml | 7 ++++--- node/actors/bft/Cargo.toml | 2 +- node/actors/executor/Cargo.toml | 2 +- node/actors/network/Cargo.toml | 2 +- node/libs/concurrency/Cargo.toml | 2 +- node/libs/crypto/Cargo.toml | 2 +- node/libs/protobuf/Cargo.toml | 2 +- node/libs/protobuf_build/Cargo.toml | 4 ++-- node/libs/roles/Cargo.toml | 2 +- node/libs/storage/Cargo.toml | 2 +- node/libs/utils/Cargo.toml | 2 +- node/tests/Cargo.toml | 2 +- node/tools/Cargo.toml | 2 +- 14 files changed, 26 insertions(+), 21 deletions(-) diff --git a/node/Cargo.lock b/node/Cargo.lock index f85572f2..3a6cfade 100644 --- a/node/Cargo.lock +++ b/node/Cargo.lock @@ -2124,8 +2124,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pairing_ce" -version = "0.28.5" -source = "git+https://github.com/matter-labs/pairing.git?rev=d24f2c5871089c4cd4f54c0ca266bb9fef6115eb#d24f2c5871089c4cd4f54c0ca266bb9fef6115eb" +version = "0.28.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843b5b6fb63f00460f611dbc87a50bbbb745f0dfe5cbf67ca89299c79098640e" dependencies = [ "byteorder", "cfg-if", @@ -3635,7 +3636,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vise" version = "0.1.0" -source = "git+https://github.com/matter-labs/vise.git?rev=a5bb80c9ce7168663114ee30e794d6dc32159ee4#a5bb80c9ce7168663114ee30e794d6dc32159ee4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229baafe01d5177b63c6ee1def80d8e39a2365e64caf69ddb05a57594b15647c" dependencies = [ "compile-fmt", "elsa", @@ -3648,7 +3650,8 @@ dependencies = [ [[package]] name = "vise-exporter" version = "0.1.0" -source = "git+https://github.com/matter-labs/vise.git?rev=a5bb80c9ce7168663114ee30e794d6dc32159ee4#a5bb80c9ce7168663114ee30e794d6dc32159ee4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23981b18d697026f5430249ab01ba739ef2edc463e400042394331cb2bb63494" dependencies = [ "hyper 0.14.29", "once_cell", @@ -3660,7 +3663,8 @@ dependencies = [ [[package]] name = "vise-macros" version = "0.1.0" -source = "git+https://github.com/matter-labs/vise.git?rev=a5bb80c9ce7168663114ee30e794d6dc32159ee4#a5bb80c9ce7168663114ee30e794d6dc32159ee4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bb19c33cd5f04dcf4e767635e058a998edbc2b7fca32ade0a4a1cea0f8e9b34" dependencies = [ "proc-macro2", "quote", diff --git a/node/Cargo.toml b/node/Cargo.toml index ccfaf133..85e26017 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -20,6 +20,7 @@ edition = "2021" authors = ["The Matter Labs Team "] homepage = "https://matter-labs.io/" license = "MIT" +version = "0.1.0" [workspace.dependencies] # Crates from this repo. @@ -38,9 +39,9 @@ zksync_protobuf = { path = "libs/protobuf" } zksync_protobuf_build = { path = "libs/protobuf_build" } # Crates from Matter Labs. -pairing = { package = "pairing_ce", git = "https://github.com/matter-labs/pairing.git", rev = "d24f2c5871089c4cd4f54c0ca266bb9fef6115eb" } -vise = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "a5bb80c9ce7168663114ee30e794d6dc32159ee4" } -vise-exporter = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "a5bb80c9ce7168663114ee30e794d6dc32159ee4" } +pairing = { package = "pairing_ce", version = "=0.28.6" } +vise = "0.1.0" +vise-exporter = "0.1.0" # Crates from third-parties. anyhow = "1" diff --git a/node/actors/bft/Cargo.toml b/node/actors/bft/Cargo.toml index 99932bfa..8cbe0a65 100644 --- a/node/actors/bft/Cargo.toml +++ b/node/actors/bft/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_bft" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/actors/executor/Cargo.toml b/node/actors/executor/Cargo.toml index be95dcb3..03e0c9f2 100644 --- a/node/actors/executor/Cargo.toml +++ b/node/actors/executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_executor" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/actors/network/Cargo.toml b/node/actors/network/Cargo.toml index 56657a68..ab7f7dbb 100644 --- a/node/actors/network/Cargo.toml +++ b/node/actors/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_network" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/concurrency/Cargo.toml b/node/libs/concurrency/Cargo.toml index e305f684..96a72f3d 100644 --- a/node/libs/concurrency/Cargo.toml +++ b/node/libs/concurrency/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_concurrency" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/crypto/Cargo.toml b/node/libs/crypto/Cargo.toml index 72fb18ed..44f7fd83 100644 --- a/node/libs/crypto/Cargo.toml +++ b/node/libs/crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_crypto" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/protobuf/Cargo.toml b/node/libs/protobuf/Cargo.toml index 889b531c..1be22904 100644 --- a/node/libs/protobuf/Cargo.toml +++ b/node/libs/protobuf/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_protobuf" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/protobuf_build/Cargo.toml b/node/libs/protobuf_build/Cargo.toml index 93e4b831..58055e7a 100644 --- a/node/libs/protobuf_build/Cargo.toml +++ b/node/libs/protobuf_build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_protobuf_build" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true @@ -18,4 +18,4 @@ quote.workspace = true syn.workspace = true [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/node/libs/roles/Cargo.toml b/node/libs/roles/Cargo.toml index c3e2426b..d4666689 100644 --- a/node/libs/roles/Cargo.toml +++ b/node/libs/roles/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_roles" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/storage/Cargo.toml b/node/libs/storage/Cargo.toml index e1cca9e2..e44a5cd4 100644 --- a/node/libs/storage/Cargo.toml +++ b/node/libs/storage/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_storage" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/libs/utils/Cargo.toml b/node/libs/utils/Cargo.toml index 9dedc6b8..ffb3f5b1 100644 --- a/node/libs/utils/Cargo.toml +++ b/node/libs/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_utils" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/tests/Cargo.toml b/node/tests/Cargo.toml index acf9ac25..d46a0925 100644 --- a/node/tests/Cargo.toml +++ b/node/tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tester" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true diff --git a/node/tools/Cargo.toml b/node/tools/Cargo.toml index b6df9de7..70ba698f 100644 --- a/node/tools/Cargo.toml +++ b/node/tools/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zksync_consensus_tools" -version = "0.1.0" +version.workspace = true edition.workspace = true authors.workspace = true homepage.workspace = true From cd077557f1a08d545649210bb5758f6ed59d8653 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 8 Jul 2024 16:09:54 +0400 Subject: [PATCH 2/3] chore: Misc preparations for publishing (#149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ - Changes version to `0.1.0-rc.1` since the codebase is under heavy changes and is not in production yet; will prevent us from premature version bumps until consensus is on mainnet. - Sets other required fields for publishing. - Marks tests as `publish=false`. ## Why ❔ Preparations for publishing on crates.io. --- node/Cargo.lock | 24 ++++++++++++------------ node/Cargo.toml | 28 +++++++++++++++------------- node/actors/bft/Cargo.toml | 2 ++ node/actors/executor/Cargo.toml | 2 ++ node/actors/network/Cargo.toml | 2 ++ node/libs/concurrency/Cargo.toml | 2 ++ node/libs/crypto/Cargo.toml | 2 ++ node/libs/protobuf/Cargo.toml | 2 ++ node/libs/protobuf_build/Cargo.toml | 2 ++ node/libs/roles/Cargo.toml | 2 ++ node/libs/storage/Cargo.toml | 2 ++ node/libs/utils/Cargo.toml | 2 ++ node/tests/Cargo.toml | 3 +++ node/tools/Cargo.toml | 2 ++ 14 files changed, 52 insertions(+), 25 deletions(-) diff --git a/node/Cargo.lock b/node/Cargo.lock index 3a6cfade..98cf249b 100644 --- a/node/Cargo.lock +++ b/node/Cargo.lock @@ -3234,7 +3234,7 @@ dependencies = [ [[package]] name = "tester" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "clap", @@ -3987,7 +3987,7 @@ dependencies = [ [[package]] name = "zksync_concurrency" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "assert_matches", @@ -4005,7 +4005,7 @@ dependencies = [ [[package]] name = "zksync_consensus_bft" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "assert_matches", @@ -4029,7 +4029,7 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "blst", @@ -4052,7 +4052,7 @@ dependencies = [ [[package]] name = "zksync_consensus_executor" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "rand 0.8.5", @@ -4072,7 +4072,7 @@ dependencies = [ [[package]] name = "zksync_consensus_network" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "assert_matches", @@ -4108,7 +4108,7 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "assert_matches", @@ -4129,7 +4129,7 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "assert_matches", @@ -4150,7 +4150,7 @@ dependencies = [ [[package]] name = "zksync_consensus_tools" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "async-trait", @@ -4185,7 +4185,7 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "rand 0.8.5", @@ -4195,7 +4195,7 @@ dependencies = [ [[package]] name = "zksync_protobuf" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "bit-vec", @@ -4217,7 +4217,7 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" -version = "0.1.0" +version = "0.1.0-rc.1" dependencies = [ "anyhow", "heck", diff --git a/node/Cargo.toml b/node/Cargo.toml index 85e26017..30f332af 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -19,24 +19,26 @@ resolver = "2" edition = "2021" authors = ["The Matter Labs Team "] homepage = "https://matter-labs.io/" -license = "MIT" -version = "0.1.0" +repository = "https://github.com/matter-labs/era-consensus" +license = "MIT OR Apache-2.0" +keywords = ["blockchain", "zksync"] +version = "0.1.0-rc.1" [workspace.dependencies] # Crates from this repo. -zksync_consensus_bft = { path = "actors/bft" } -zksync_consensus_crypto = { path = "libs/crypto" } -zksync_consensus_executor = { path = "actors/executor" } -zksync_consensus_network = { path = "actors/network" } -zksync_consensus_roles = { path = "libs/roles" } -zksync_consensus_storage = { path = "libs/storage" } -zksync_consensus_tools = { path = "tools" } -zksync_consensus_utils = { path = "libs/utils" } +zksync_consensus_bft = { version = "=0.1.0-rc.1", path = "actors/bft" } +zksync_consensus_crypto = { version = "=0.1.0-rc.1", path = "libs/crypto" } +zksync_consensus_executor = { version = "=0.1.0-rc.1", path = "actors/executor" } +zksync_consensus_network = { version = "=0.1.0-rc.1", path = "actors/network" } +zksync_consensus_roles = { version = "=0.1.0-rc.1", path = "libs/roles" } +zksync_consensus_storage = { version = "=0.1.0-rc.1", path = "libs/storage" } +zksync_consensus_tools = { version = "=0.1.0-rc.1", path = "tools" } +zksync_consensus_utils = { version = "=0.1.0-rc.1", path = "libs/utils" } # Crates from this repo that might become independent in the future. -zksync_concurrency = { path = "libs/concurrency" } -zksync_protobuf = { path = "libs/protobuf" } -zksync_protobuf_build = { path = "libs/protobuf_build" } +zksync_concurrency = { version = "=0.1.0-rc.1", path = "libs/concurrency" } +zksync_protobuf = { version = "=0.1.0-rc.1", path = "libs/protobuf" } +zksync_protobuf_build = { version = "=0.1.0-rc.1", path = "libs/protobuf_build" } # Crates from Matter Labs. pairing = { package = "pairing_ce", version = "=0.28.6" } diff --git a/node/actors/bft/Cargo.toml b/node/actors/bft/Cargo.toml index 8cbe0a65..863c2a30 100644 --- a/node/actors/bft/Cargo.toml +++ b/node/actors/bft/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] zksync_concurrency.workspace = true diff --git a/node/actors/executor/Cargo.toml b/node/actors/executor/Cargo.toml index 03e0c9f2..eee74d39 100644 --- a/node/actors/executor/Cargo.toml +++ b/node/actors/executor/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] zksync_concurrency.workspace = true diff --git a/node/actors/network/Cargo.toml b/node/actors/network/Cargo.toml index ab7f7dbb..8d7fc4da 100644 --- a/node/actors/network/Cargo.toml +++ b/node/actors/network/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] zksync_concurrency.workspace = true diff --git a/node/libs/concurrency/Cargo.toml b/node/libs/concurrency/Cargo.toml index 96a72f3d..f5611cd9 100644 --- a/node/libs/concurrency/Cargo.toml +++ b/node/libs/concurrency/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] anyhow.workspace = true diff --git a/node/libs/crypto/Cargo.toml b/node/libs/crypto/Cargo.toml index 44f7fd83..d28374cd 100644 --- a/node/libs/crypto/Cargo.toml +++ b/node/libs/crypto/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] anyhow.workspace = true diff --git a/node/libs/protobuf/Cargo.toml b/node/libs/protobuf/Cargo.toml index 1be22904..118418fd 100644 --- a/node/libs/protobuf/Cargo.toml +++ b/node/libs/protobuf/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true links = "zksync_protobuf_proto" [dependencies] diff --git a/node/libs/protobuf_build/Cargo.toml b/node/libs/protobuf_build/Cargo.toml index 58055e7a..1d9be8fc 100644 --- a/node/libs/protobuf_build/Cargo.toml +++ b/node/libs/protobuf_build/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] anyhow.workspace = true diff --git a/node/libs/roles/Cargo.toml b/node/libs/roles/Cargo.toml index d4666689..b4278ed1 100644 --- a/node/libs/roles/Cargo.toml +++ b/node/libs/roles/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true links = "zksync_consensus_roles_proto" [dependencies] diff --git a/node/libs/storage/Cargo.toml b/node/libs/storage/Cargo.toml index e44a5cd4..a85a42d7 100644 --- a/node/libs/storage/Cargo.toml +++ b/node/libs/storage/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] zksync_concurrency.workspace = true diff --git a/node/libs/utils/Cargo.toml b/node/libs/utils/Cargo.toml index ffb3f5b1..5f3f7dfc 100644 --- a/node/libs/utils/Cargo.toml +++ b/node/libs/utils/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true [dependencies] zksync_concurrency.workspace = true diff --git a/node/tests/Cargo.toml b/node/tests/Cargo.toml index d46a0925..7f1e33ce 100644 --- a/node/tests/Cargo.toml +++ b/node/tests/Cargo.toml @@ -5,6 +5,9 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true +publish = false [dependencies] zksync_consensus_tools.workspace = true diff --git a/node/tools/Cargo.toml b/node/tools/Cargo.toml index 70ba698f..f1696853 100644 --- a/node/tools/Cargo.toml +++ b/node/tools/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true authors.workspace = true homepage.workspace = true license.workspace = true +repository.workspace = true +keywords.workspace = true default-run = "executor" [dependencies] From 92fe49cec6f982ed3f1d92cb17912a8e6b4fc629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Fran=C3=A7a?= Date: Mon, 8 Jul 2024 16:29:15 +0100 Subject: [PATCH 3/3] Refactored TimeoutQC to contain just one CommitQC (#144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Refactored (in the informal spec) `TimeoutQC`, `SignedTimeoutVote` and `TimeoutVote` so that `TimeoutQC` contains only one `CommitQC` (the high QC). ## Why ❔ It reduces the state space which should help with model checking. --------- Co-authored-by: Igor Konnov --- spec/informal-spec/replica.rs | 8 ++--- spec/informal-spec/types.rs | 59 +++++++++++++++++------------------ 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/spec/informal-spec/replica.rs b/spec/informal-spec/replica.rs index 02d6ec14..901c5dc2 100644 --- a/spec/informal-spec/replica.rs +++ b/spec/informal-spec/replica.rs @@ -165,7 +165,7 @@ fn on_proposal(self, proposal: Proposal) { match proposal.justification { Commit(qc) => self.process_commit_qc(Some(qc)), Timeout(qc) => { - self.process_commit_qc(qc.high_qc()); + self.process_commit_qc(qc.high_commit_qc); self.high_timeout_qc = max(Some(qc), self.high_timeout_qc); } }; @@ -177,7 +177,7 @@ fn on_proposal(self, proposal: Proposal) { // Processed an (already verified) commit_qc received from the network // as part of some message. It bumps the local high_commit_qc and if // we have the proposal corresponding to this qc, we append it to the committed_blocks. -fn process_commit_qc(self, qc_opt: Option[CommitQC]) { +fn process_commit_qc(self, qc_opt: Option) { if let Some(qc) = qc_opt { self.high_commit_qc = max(Some(qc), self.high_commit_qc); let Some(block) = self.cached_proposals.get((qc.vote.block_number,qc.vote.block_hash)) else { return }; @@ -218,7 +218,7 @@ fn on_timeout(self, sig_vote: SignedTimeoutVote) { // Check if we now have a timeout QC for this view. if let Some(qc) = self.get_timeout_qc(sig_vote.view()) { - self.process_commit_qc(qc.high_qc()); + self.process_commit_qc(qc.high_commit_qc); self.high_timeout_qc = max(Some(qc), self.high_timeout_qc); self.start_new_view(sig_vote.view() + 1); } @@ -235,7 +235,7 @@ fn on_new_view(self, new_view: NewView) { match new_view.justification { Commit(qc) => self.process_commit_qc(Some(qc)), Timeout(qc) => { - self.process_commit_qc(qc.high_qc()); + self.process_commit_qc(qc.high_commit_qc); self.high_timeout_qc = max(Some(qc), self.high_timeout_qc); } }; diff --git a/spec/informal-spec/types.rs b/spec/informal-spec/types.rs index 16d955ea..7dd9885e 100644 --- a/spec/informal-spec/types.rs +++ b/spec/informal-spec/types.rs @@ -77,7 +77,7 @@ impl Justification { // Get the high commit QC of the timeout QC. We compare the high QC field of // all timeout votes in the QC, and get the highest one, if it exists. - let high_qc: Option = qc.high_qc(); + let high_qc: Option = qc.high_commit_qc; if high_vote.is_some() && (high_qc.is_none() || high_vote.block_number > high_qc.block_number) @@ -154,16 +154,19 @@ struct TimeoutVote { view: ViewNumber, // The commit vote with the highest view that this replica has signed, if any. high_vote: Option, - // The commit quorum certificate with the highest view that this replica + // The view number of the highest commit quorum certificate that this replica // has observed, if any. - high_commit_qc: Option, + high_commit_qc_view: Option, } struct SignedTimeoutVote { // The timeout. vote: TimeoutVote, - // Signature of the sender. + // Signature of the sender. This signature is ONLY over the vote field. sig: Signature, + // The commit quorum certificate with the highest view that this replica + // has observed, if any. It MUST match `high_commit_qc_view` in `vote`. + high_commit_qc: Option, } impl SignedTimeoutVote { @@ -172,9 +175,10 @@ impl SignedTimeoutVote { } fn verify(self) -> bool { - // Technically, only the signature needs to be verified. But if we wish, there are two invariants that are easy to check: - // self.view() >= self.high_vote.view() && self.high_vote.view() >= self.high_commit_qc.view() - self.verify_sig() + // If we wish, there are two invariants that are easy to check but aren't required for correctness: + // self.view() >= self.high_vote.view() && self.high_vote.view() >= self.high_commit_qc_view + self.vote.high_commit_qc_view == self.high_commit_qc.map(|x| x.view()) && self.verify_sig() + && self.high_commit_qc.map(|qc| qc.verify()) } } @@ -189,6 +193,9 @@ struct TimeoutQC { // The aggregate signature of the replicas. We ignore the details here. // Can be something as simple as a vector of signatures. agg_sig: AggregateSignature, + // The commit quorum certificate with the highest view that all replicas in this + // QC have observed, if any. It MUST match the highest `high_commit_qc_view` in `votes`. + high_commit_qc: Option, } impl TimeoutQC { @@ -197,27 +204,27 @@ impl TimeoutQC { } fn verify(self) -> bool { - // Check that all votes have the same view. - for (_, vote) in votes { - if vote.view != self.view() { - return false; - } - } + // Check that all votes have the same view and get the highest commit QC view of the timeout QC. + let high_qc_view = None; - // Get the high commit QC of the timeout QC. We compare the high QC field of all - // timeout votes in the QC, and get the highest one, if it exists. - // We then need to verify that it is valid. We don't need to verify the commit QCs - // of the other timeout votes, since they don't have any influence in the result. - if let Some(high_qc) = self.high_qc() { - if !high_qc.verify() { + for (_, vote) in self.votes { + if vote.view != self.view() { return false; } + high_qc_view = max(high_qc_view, vote.high_commit_qc_view); } - // In here we need to not only check the signature, but also that // it has enough weight beyond it. - self.verify_agg_sig(QUORUM_WEIGHT) + if !self.verify_agg_sig(QUORUM_WEIGHT) { + return false; + } + + // We check that the high commit QC view matches the high commit QC that we have, and we verify the QC. + match self.high_commit_qc { + Some(high_qc) => high_qc_view == Some(high_qc.view()) && high_qc.verify(); + None => high_qc_view.is_none(); + } } fn high_vote(self) -> Option { @@ -245,16 +252,6 @@ impl TimeoutQC { None } } - - fn high_qc(self) -> Option { - let high_qc = None; - - for (_, vote) in votes { - high_qc = max(high_qc, vote.high_commit_qc); - } - - high_qc - } } struct NewView {