Skip to content

Qbft create message spec tests #270

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

Draft
wants to merge 18 commits into
base: unstable
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "anchor/spec_tests/src/ssv-spec"]
path = anchor/spec_tests/src/ssv-spec
url = https://github.com/ssvlabs/ssv-spec.git
81 changes: 79 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"anchor/processor",
"anchor/qbft_manager",
"anchor/signature_collector",
"anchor/spec_tests",
"anchor/subnet_tracker",
"anchor/validator_store",
]
Expand Down
34 changes: 31 additions & 3 deletions anchor/common/qbft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,14 +871,21 @@ where
data_hash: D::Hash,
round_change_justification: Vec<SignedSSVMessage>,
prepare_justification: Vec<SignedSSVMessage>,
round: Option<Round>,
) -> UnsignedWrappedQbftMessage {
let data = self.get_message_data(&msg_type, data_hash);

let round = if let Some(round) = round {
round
} else {
data.round.into()
};

// Create the QBFT message
let qbft_message = QbftMessage {
qbft_message_type: msg_type,
height: *self.instance_height as u64,
round: data.round,
round: round.into(),
identifier: (&self.identifier).into(),
root: data.root,
data_round: data.data_round,
Expand Down Expand Up @@ -1030,6 +1037,7 @@ where
value_to_propose,
round_change_justifications,
prepare_justifications,
None,
);

(self.send_message)(unsigned_msg);
Expand All @@ -1045,7 +1053,7 @@ where

// Construct unsigned prepare
let unsigned_msg =
self.new_unsigned_message(QbftMessageType::Prepare, data_hash, vec![], vec![]);
self.new_unsigned_message(QbftMessageType::Prepare, data_hash, vec![], vec![], None);

(self.send_message)(unsigned_msg);
}
Expand All @@ -1054,7 +1062,7 @@ where
fn send_commit(&mut self, data_hash: D::Hash) {
// Construct unsigned commit
let unsigned_msg =
self.new_unsigned_message(QbftMessageType::Commit, data_hash, vec![], vec![]);
self.new_unsigned_message(QbftMessageType::Commit, data_hash, vec![], vec![], None);

(self.send_message)(unsigned_msg);
}
Expand All @@ -1072,6 +1080,7 @@ where
data_hash,
round_change_justifications,
vec![],
None,
);

// forget that we accpeted a proposal
Expand Down Expand Up @@ -1102,4 +1111,23 @@ where
}
})
}

// Expose the ability to create new unsigned messages for spec testing
//#[cfg(test)]
pub fn new_unsigned_message_spec(
&self,
msg_type: QbftMessageType,
data_hash: D::Hash,
round_change_justification: Vec<SignedSSVMessage>,
prepare_justification: Vec<SignedSSVMessage>,
round: Option<Round>,
) -> UnsignedWrappedQbftMessage {
self.new_unsigned_message(
msg_type,
data_hash,
round_change_justification,
prepare_justification,
round,
)
}
}
3 changes: 3 additions & 0 deletions anchor/common/ssv_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ hex = { workspace = true }
indexmap = { workspace = true }
openssl = { workspace = true }
rusqlite = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
tree_hash = { workspace = true }
tree_hash_derive = { workspace = true }
types = { workspace = true }
zerocopy = "0.8.24"
Loading
Loading