mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
GRANDPA: add commit messages (#1151)
* get compiling with latest version of grandpa * generalize UntilImported to prepare for waiting for commit message targets * extract until_imported out to own module * logic for blocking commits until enough blocks imported * add tests for commit message blocking logic * pass through commit mesage round number as well * extract communication streams to own module * add Error implementation for ExitOrError * introduce stream adapter for checking commit messages * output sink for commits * implement the unimplemented * remove extra line * update to latest version of grandpa api * update finality-grandpa to 0.4.0 * Use filter_map earlier when checking incoming commits messages Co-Authored-By: rphmeier <rphmeier@gmail.com> * address some grumbles
This commit is contained in:
committed by
GitHub
parent
b7e0db725d
commit
59af4de4fd
@@ -157,6 +157,21 @@ fn make_topic(round: u64, set_id: u64) -> Hash {
|
||||
hash
|
||||
}
|
||||
|
||||
fn make_commit_topic(set_id: u64) -> Hash {
|
||||
let mut hash = Hash::default();
|
||||
|
||||
{
|
||||
let raw = hash.as_mut();
|
||||
raw[16..22].copy_from_slice(b"commit");
|
||||
}
|
||||
set_id.using_encoded(|s| {
|
||||
let raw = hash.as_mut();
|
||||
raw[24..].copy_from_slice(s);
|
||||
});
|
||||
|
||||
hash
|
||||
}
|
||||
|
||||
impl Network for MessageRouting {
|
||||
type In = Box<Stream<Item=Vec<u8>,Error=()> + Send>;
|
||||
|
||||
@@ -190,6 +205,27 @@ impl Network for MessageRouting {
|
||||
gossip.collect_garbage(|t| t == &topic)
|
||||
});
|
||||
}
|
||||
|
||||
fn commit_messages(&self, set_id: u64) -> Self::In {
|
||||
let inner = self.inner.lock();
|
||||
let peer = inner.peer(self.peer_id);
|
||||
let mut gossip = peer.consensus_gossip().write();
|
||||
let messages = peer.with_spec(move |_, _| {
|
||||
gossip.messages_for(make_commit_topic(set_id))
|
||||
});
|
||||
|
||||
let messages = messages.map_err(
|
||||
move |_| panic!("Commit messages for set {} dropped too early", set_id)
|
||||
);
|
||||
|
||||
Box::new(messages)
|
||||
}
|
||||
|
||||
fn send_commit(&self, set_id: u64, message: Vec<u8>) {
|
||||
let mut inner = self.inner.lock();
|
||||
inner.peer(self.peer_id).gossip_message(make_commit_topic(set_id), message);
|
||||
inner.route_until_complete();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user