mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Basic Gossip Validator
This commit is contained in:
@@ -36,6 +36,7 @@ sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network-gossip = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-service = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-client-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-consensus = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
43
substrate/tendermint/client/src/gossip.rs
Normal file
43
substrate/tendermint/client/src/gossip.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use sp_core::{Decode, sr25519::Signature};
|
||||
use sp_runtime::traits::{Hash, Header, Block};
|
||||
|
||||
use sc_network::PeerId;
|
||||
use sc_network_gossip::{Validator, ValidatorContext, ValidationResult};
|
||||
|
||||
use tendermint_machine::{SignedMessage, ext::SignatureScheme};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TendermintGossip<S: SignatureScheme<ValidatorId = u16, Signature = Signature>> {
|
||||
number: Arc<RwLock<u64>>,
|
||||
signature_scheme: Arc<S>,
|
||||
}
|
||||
|
||||
impl<B: Block, S: SignatureScheme<ValidatorId = u16, Signature = Signature>> Validator<B>
|
||||
for TendermintGossip<S>
|
||||
{
|
||||
fn validate(
|
||||
&self,
|
||||
_: &mut dyn ValidatorContext<B>,
|
||||
_: &PeerId,
|
||||
data: &[u8],
|
||||
) -> ValidationResult<B::Hash> {
|
||||
let msg = match SignedMessage::<u16, B, Signature>::decode(&mut &*data) {
|
||||
Ok(msg) => msg,
|
||||
Err(_) => return ValidationResult::Discard,
|
||||
};
|
||||
|
||||
if msg.number().0 < *self.number.read().unwrap() {
|
||||
return ValidationResult::Discard;
|
||||
}
|
||||
|
||||
if !msg.verify_signature(&self.signature_scheme) {
|
||||
return ValidationResult::Discard;
|
||||
}
|
||||
|
||||
ValidationResult::ProcessAndKeep(<<B::Header as Header>::Hashing as Hash>::hash(
|
||||
&[b"Tendermint Topic".as_ref(), &msg.number().0.to_le_bytes()].concat(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ mod verifier;
|
||||
mod import_queue;
|
||||
use import_queue::TendermintImportQueue;
|
||||
|
||||
mod gossip;
|
||||
|
||||
mod select_chain;
|
||||
pub use select_chain::TendermintSelectChain;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user