Add patch for attestation crosslinks
This commit is contained in:
commit
ae8e470d21
@ -492,10 +492,7 @@ where
|
||||
beacon_block_root: self.head().beacon_block_root,
|
||||
target_root,
|
||||
crosslink_data_root: Hash256::zero(),
|
||||
previous_crosslink: Crosslink {
|
||||
epoch: self.state.read().slot.epoch(self.spec.slots_per_epoch),
|
||||
crosslink_data_root: Hash256::zero(),
|
||||
},
|
||||
previous_crosslink: state.latest_crosslinks[shard as usize].clone(),
|
||||
source_epoch: state.current_justified_epoch,
|
||||
source_root: state.current_justified_root,
|
||||
})
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::rpc::methods::BlockRootSlot;
|
||||
use crate::rpc::{RPCEvent, RPCMessage, Rpc};
|
||||
use crate::NetworkConfig;
|
||||
use futures::prelude::*;
|
||||
@ -15,8 +14,7 @@ use libp2p::{
|
||||
};
|
||||
use slog::{debug, o, warn};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use types::Attestation;
|
||||
use types::{Attestation, BeaconBlock};
|
||||
use types::{Topic, TopicHash};
|
||||
|
||||
/// Builds the network behaviour for the libp2p Swarm.
|
||||
@ -198,7 +196,7 @@ pub enum BehaviourEvent {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum PubsubMessage {
|
||||
/// Gossipsub message providing notification of a new block.
|
||||
Block(BlockRootSlot),
|
||||
Block(BeaconBlock),
|
||||
/// Gossipsub message providing notification of a new attestation.
|
||||
Attestation(Attestation),
|
||||
}
|
||||
@ -224,7 +222,7 @@ impl Decodable for PubsubMessage {
|
||||
let (id, index) = u32::ssz_decode(bytes, index)?;
|
||||
match id {
|
||||
0 => {
|
||||
let (block, index) = BlockRootSlot::ssz_decode(bytes, index)?;
|
||||
let (block, index) = BeaconBlock::ssz_decode(bytes, index)?;
|
||||
Ok((PubsubMessage::Block(block), index))
|
||||
}
|
||||
1 => {
|
||||
@ -243,10 +241,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn ssz_encoding() {
|
||||
let original = PubsubMessage::Block(BlockRootSlot {
|
||||
block_root: Hash256::from_slice(&[42; 32]),
|
||||
slot: Slot::new(4),
|
||||
});
|
||||
let original = PubsubMessage::Block(BeaconBlock::empty(&ChainSpec::foundation()));
|
||||
|
||||
let encoded = ssz_encode(&original);
|
||||
|
||||
|
@ -8,7 +8,7 @@ use slog::{debug, error, info, o, warn};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::{Attestation, Epoch, Hash256, Slot};
|
||||
use types::{Attestation, BeaconBlock, Epoch, Hash256, Slot};
|
||||
|
||||
/// The number of slots that we can import blocks ahead of us, before going into full Sync mode.
|
||||
const SLOT_IMPORT_TOLERANCE: u64 = 100;
|
||||
@ -539,7 +539,7 @@ impl SimpleSync {
|
||||
pub fn on_block_gossip(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
msg: BlockRootSlot,
|
||||
block: BeaconBlock,
|
||||
network: &mut NetworkContext,
|
||||
) {
|
||||
info!(
|
||||
@ -548,6 +548,7 @@ impl SimpleSync {
|
||||
"peer" => format!("{:?}", peer_id),
|
||||
);
|
||||
|
||||
/*
|
||||
// Ignore any block from a finalized slot.
|
||||
if self.slot_is_finalized(msg.slot) {
|
||||
warn!(
|
||||
@ -558,11 +559,13 @@ impl SimpleSync {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: if the block is a few more slots ahead, try to get all block roots from then until
|
||||
// now.
|
||||
//
|
||||
// Note: only requests the new block -- will fail if we don't have its parents.
|
||||
if self.import_queue.is_new_block(&msg.block_root) {
|
||||
// Ignore any block that the chain already knows about.
|
||||
if self.chain_has_seen_block(&msg.block_root) {
|
||||
return;
|
||||
}
|
||||
|
||||
// k
|
||||
if msg.slot == self.chain.hello_message().best_slot + 1 {
|
||||
self.request_block_headers(
|
||||
peer_id,
|
||||
BeaconBlockHeadersRequest {
|
||||
@ -574,6 +577,24 @@ impl SimpleSync {
|
||||
network,
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: if the block is a few more slots ahead, try to get all block roots from then until
|
||||
// now.
|
||||
//
|
||||
// Note: only requests the new block -- will fail if we don't have its parents.
|
||||
if !self.chain_has_seen_block(&msg.block_root) {
|
||||
self.request_block_headers(
|
||||
peer_id,
|
||||
BeaconBlockHeadersRequest {
|
||||
start_root: msg.block_root,
|
||||
start_slot: msg.slot,
|
||||
max_headers: 1,
|
||||
skip_slots: 0,
|
||||
},
|
||||
network,
|
||||
)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// Process a gossip message declaring a new attestation.
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::beacon_chain::BeaconChain;
|
||||
use crossbeam_channel;
|
||||
use eth2_libp2p::rpc::methods::BlockRootSlot;
|
||||
use eth2_libp2p::PubsubMessage;
|
||||
use futures::Future;
|
||||
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
|
||||
@ -12,9 +11,9 @@ use protos::services::{
|
||||
use protos::services_grpc::BeaconBlockService;
|
||||
use slog::Logger;
|
||||
use slog::{error, info, trace, warn};
|
||||
use ssz::{ssz_encode, Decodable, TreeHash};
|
||||
use ssz::{ssz_encode, Decodable};
|
||||
use std::sync::Arc;
|
||||
use types::{BeaconBlock, Hash256, Signature, Slot};
|
||||
use types::{BeaconBlock, Signature, Slot};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BeaconBlockServiceInstance {
|
||||
@ -94,8 +93,6 @@ impl BeaconBlockService for BeaconBlockServiceInstance {
|
||||
|
||||
match BeaconBlock::ssz_decode(ssz_serialized_block, 0) {
|
||||
Ok((block, _i)) => {
|
||||
let block_root = Hash256::from_slice(&block.hash_tree_root()[..]);
|
||||
|
||||
match self.chain.process_block(block.clone()) {
|
||||
Ok(outcome) => {
|
||||
if outcome.sucessfully_processed() {
|
||||
@ -111,21 +108,22 @@ impl BeaconBlockService for BeaconBlockServiceInstance {
|
||||
// TODO: Obtain topics from the network service properly.
|
||||
let topic =
|
||||
types::TopicBuilder::new("beacon_chain".to_string()).build();
|
||||
let message = PubsubMessage::Block(BlockRootSlot {
|
||||
block_root,
|
||||
slot: block.slot,
|
||||
});
|
||||
let message = PubsubMessage::Block(block);
|
||||
|
||||
match self.network_chan.send(NetworkMessage::Publish {
|
||||
topics: vec![topic],
|
||||
message,
|
||||
}) {
|
||||
Ok(_) => {}
|
||||
Err(_) => warn!(
|
||||
self.log,
|
||||
"Could not send published block to the network service"
|
||||
),
|
||||
}
|
||||
// Publish the block to the p2p network via gossipsub.
|
||||
self.network_chan
|
||||
.send(NetworkMessage::Publish {
|
||||
topics: vec![topic],
|
||||
message,
|
||||
})
|
||||
.unwrap_or_else(|e| {
|
||||
error!(
|
||||
self.log,
|
||||
"PublishBeaconBlock";
|
||||
"type" => "failed to publish to gossipsub",
|
||||
"error" => format!("{:?}", e)
|
||||
);
|
||||
});
|
||||
|
||||
resp.set_success(true);
|
||||
} else if outcome.is_invalid() {
|
||||
|
Loading…
Reference in New Issue
Block a user