Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions crates/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::time::{Duration, SystemTime};

use ethlambda_state_transition::is_proposer;
use ethlambda_storage::Store;
use ethlambda_types::{
attestation::{Attestation, AttestationData, SignedAttestation},
block::{BlockSignatures, BlockWithAttestation, SignedBlockWithAttestation},
Expand All @@ -12,7 +13,6 @@ use ethlambda_types::{
use spawned_concurrency::tasks::{
CallResponse, CastResponse, GenServer, GenServerHandle, send_after,
};
use store::Store;
use tokio::sync::mpsc;
use tracing::{error, info, warn};

Expand Down Expand Up @@ -109,8 +109,7 @@ impl BlockChainServer {
.flatten();

// Tick the store first - this accepts attestations at interval 0 if we have a proposal
self.store
.on_tick(timestamp, proposer_validator_id.is_some());
store::on_tick(&mut self.store, timestamp, proposer_validator_id.is_some());

// Now build and publish the block (after attestations have been accepted)
if let Some(validator_id) = proposer_validator_id {
Expand Down Expand Up @@ -144,7 +143,7 @@ impl BlockChainServer {
let num_validators = head_state.validators.len() as u64;

// Produce attestation data once for all validators
let attestation_data = self.store.produce_attestation_data(slot);
let attestation_data = store::produce_attestation_data(&self.store, slot);

// For each registered validator, produce and publish attestation
for validator_id in self.key_manager.validator_ids() {
Expand Down Expand Up @@ -191,10 +190,9 @@ impl BlockChainServer {
info!(%slot, %validator_id, "We are the proposer for this slot");

// Build the block with attestation signatures
let Ok((block, attestation_signatures)) = self
.store
.produce_block_with_signatures(slot, validator_id)
.inspect_err(|err| error!(%slot, %validator_id, %err, "Failed to build block"))
let Ok((block, attestation_signatures)) =
store::produce_block_with_signatures(&mut self.store, slot, validator_id)
.inspect_err(|err| error!(%slot, %validator_id, %err, "Failed to build block"))
else {
return;
};
Expand All @@ -208,8 +206,8 @@ impl BlockChainServer {
root: block.tree_hash_root(),
slot: block.slot,
},
target: self.store.get_attestation_target(),
source: *self.store.latest_justified(),
target: store::get_attestation_target(&self.store),
source: self.store.latest_justified(),
},
};

Expand Down Expand Up @@ -261,7 +259,7 @@ impl BlockChainServer {
signed_block: SignedBlockWithAttestation,
) -> Result<(), StoreError> {
let slot = signed_block.message.block.slot;
self.store.on_block(signed_block)?;
store::on_block(&mut self.store, signed_block)?;
metrics::update_head_slot(slot);
metrics::update_latest_justified_slot(self.store.latest_justified().slot);
metrics::update_latest_finalized_slot(self.store.latest_finalized().slot);
Expand All @@ -277,7 +275,7 @@ impl BlockChainServer {
}

fn on_gossip_attestation(&mut self, attestation: SignedAttestation) {
if let Err(err) = self.store.on_gossip_attestation(attestation) {
if let Err(err) = store::on_gossip_attestation(&mut self.store, attestation) {
warn!(%err, "Failed to process gossiped attestation");
}
}
Expand Down
Loading