mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
round-localized signatures on GRANDPA messages
This commit is contained in:
@@ -298,9 +298,15 @@ impl<I, N: Network> Drop for ClearOnDrop<I, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn round_localized_payload<E: Encode>(round: u64, message: &E) -> Vec<u8> {
|
||||||
|
let mut v = message.encode();
|
||||||
|
round.using_encoded(|s| v.extend(s));
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
// converts a message stream into a stream of signed messages.
|
// converts a message stream into a stream of signed messages.
|
||||||
// the output stream checks signatures also.
|
// the output stream checks signatures also.
|
||||||
fn checked_message_stream<Block: BlockT, S>(inner: S, voters: Vec<AuthorityId>)
|
fn checked_message_stream<Block: BlockT, S>(inner: S, round: u64, voters: Vec<AuthorityId>)
|
||||||
-> impl Stream<Item=SignedMessage<Block>,Error=Error> where
|
-> impl Stream<Item=SignedMessage<Block>,Error=Error> where
|
||||||
S: Stream<Item=Vec<u8>,Error=()>
|
S: Stream<Item=Vec<u8>,Error=()>
|
||||||
{
|
{
|
||||||
@@ -320,7 +326,7 @@ fn checked_message_stream<Block: BlockT, S>(inner: S, voters: Vec<AuthorityId>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
let as_public = ::ed25519::Public::from_raw(msg.id.0);
|
let as_public = ::ed25519::Public::from_raw(msg.id.0);
|
||||||
let encoded_raw = msg.message.encode();
|
let encoded_raw = round_localized_payload(round, &msg.message);
|
||||||
if ::ed25519::verify_strong(&msg.signature, &encoded_raw, as_public) {
|
if ::ed25519::verify_strong(&msg.signature, &encoded_raw, as_public) {
|
||||||
Ok(Some(msg))
|
Ok(Some(msg))
|
||||||
} else {
|
} else {
|
||||||
@@ -349,9 +355,9 @@ fn outgoing_messages<Block: BlockT, N: Network>(
|
|||||||
let (tx, rx) = mpsc::unbounded();
|
let (tx, rx) = mpsc::unbounded();
|
||||||
let rx = rx
|
let rx = rx
|
||||||
.map(move |msg: Message<Block>| {
|
.map(move |msg: Message<Block>| {
|
||||||
// when locals exist. sign messages on import
|
// when locals exist, sign messages on import
|
||||||
if let Some((ref pair, local_id)) = locals {
|
if let Some((ref pair, local_id)) = locals {
|
||||||
let encoded = msg.encode();
|
let encoded = round_localized_payload(round, &msg);
|
||||||
let signature = pair.sign(&encoded[..]);
|
let signature = pair.sign(&encoded[..]);
|
||||||
let signed = SignedMessage::<Block> {
|
let signed = SignedMessage::<Block> {
|
||||||
message: msg,
|
message: msg,
|
||||||
@@ -477,6 +483,7 @@ impl<B, E, Block: BlockT, N> voter::Environment<Block::Hash> for Environment<B,
|
|||||||
// TODO: dispatch this with `mpsc::spawn`.
|
// TODO: dispatch this with `mpsc::spawn`.
|
||||||
let incoming = checked_message_stream::<Block, _>(
|
let incoming = checked_message_stream::<Block, _>(
|
||||||
self.network.messages_for(round),
|
self.network.messages_for(round),
|
||||||
|
round,
|
||||||
self.config.voters.clone(),
|
self.config.voters.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user