Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
444f858
refactor(db): move announces from BlockMeta to AnnounceStorage
playX18 Jan 7, 2026
9a042d4
refactor(ethexe/compute): use AnnounceStorage
playX18 Jan 7, 2026
4a06652
refactor(ethexe/common): use AnnounceStorage for block announces
playX18 Jan 7, 2026
8236477
refactor(ethexe/consensus): use AnnounceStorage for block announces
playX18 Jan 7, 2026
642dd9d
refactor(ethexe/db): use AnnounceStorage for block announces
playX18 Jan 7, 2026
587480a
refactor(ethexe/network): use AnnounceStorage for block announces
playX18 Jan 7, 2026
98b9839
refactor(ethexe/processor): use AnnounceStorage for block announces
playX18 Jan 7, 2026
0551255
refactor(ethexe/processor): use AnnounceStorage for block announces
playX18 Jan 7, 2026
096c614
refactor(ethexe/service/tests): use AnnounceStorage for block announces
playX18 Jan 7, 2026
a96428e
Merge branch 'master' into ap-move-anounces
playX18 Jan 7, 2026
48dc70b
update tests.rs
playX18 Jan 8, 2026
9c61733
feat(ethexe/db): add take_block_announces
playX18 Jan 8, 2026
7a9c824
fix(ethexe/mock): take block announces in setup if there are any
playX18 Jan 8, 2026
6b85d24
Merge branch 'master' into ap-move-anounces
playX18 Jan 15, 2026
8b62bee
Merge branch 'master' into ap-move-anounces
playX18 Feb 4, 2026
63427f6
typos fix
playX18 Feb 4, 2026
d604972
Merge remote-tracking branch 'origin/master' into ap-move-anounces
playX18 Mar 24, 2026
d5ace9c
fix after merge
playX18 Mar 24, 2026
e159986
remove take_block_announces
playX18 Mar 24, 2026
55a6c03
fmt
playX18 Mar 24, 2026
a8dceb2
clean db in process_announces_response_rejected
playX18 Mar 24, 2026
e047fbc
Merge branch 'master' into ap-move-anounces
playX18 Mar 25, 2026
f8493ef
Change `Key::BlockAnnounces` variant position and discriminant
liferooter Mar 25, 2026
b538521
Add a migration
liferooter Mar 25, 2026
d0d9e8a
Slight adjustments
liferooter Mar 25, 2026
774939a
Update type info hash
liferooter Mar 25, 2026
b6f9405
refactor: merge `LatestEraValidatorsCommitted` into `BlockMeta`
liferooter Mar 16, 2026
e844797
Update version in the end of v2 migration
liferooter Mar 23, 2026
5c921a0
Update db types hash
liferooter Mar 24, 2026
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 10 additions & 19 deletions ethexe/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,14 @@ pub struct BlockMeta {
/// Block has been prepared, meaning:
/// all metadata is ready, all predecessors till start block are prepared too.
pub prepared: bool,
// TODO: #4945 remove announces from here
/// Set of announces included in the block.
pub announces: Option<BTreeSet<HashOf<Announce>>>,
/// Queue of code ids waiting for validation status commitment on-chain.
pub codes_queue: Option<VecDeque<CodeId>>,
/// Last committed on-chain batch hash.
pub last_committed_batch: Option<Digest>,
/// Last committed on-chain announce hash.
pub last_committed_announce: Option<HashOf<Announce>>,
}

impl BlockMeta {
pub fn default_prepared() -> Self {
Self {
prepared: true,
announces: Some(Default::default()),
codes_queue: Some(Default::default()),
last_committed_batch: Some(Default::default()),
last_committed_announce: Some(Default::default()),
}
}
/// Latest era with committed validators.
pub latest_era_validators_committed: u64,
}

#[auto_impl::auto_impl(&, Box)]
Expand Down Expand Up @@ -112,8 +99,6 @@ pub trait OnChainStorageRO {
fn code_blob_info(&self, code_id: CodeId) -> Option<CodeBlobInfo>;
fn block_synced(&self, block_hash: H256) -> bool;
fn validators(&self, era_index: u64) -> Option<ValidatorsVec>;
// TODO kuzmindev: temporal solution - must move into block meta or something else.
fn block_validators_committed_for_era(&self, block_hash: H256) -> Option<u64>;
}

#[auto_impl::auto_impl(&)]
Expand All @@ -122,7 +107,6 @@ pub trait OnChainStorageRW: OnChainStorageRO {
fn set_block_events(&self, block_hash: H256, events: &[BlockEvent]);
fn set_code_blob_info(&self, code_id: CodeId, code_info: CodeBlobInfo);
fn set_validators(&self, era_index: u64, validator_set: ValidatorsVec);
fn set_block_validators_committed_for_era(&self, block_hash: H256, era_index: u64);
fn set_block_synced(&self, block_hash: H256);
}

Expand Down Expand Up @@ -152,11 +136,13 @@ pub trait AnnounceStorageRO {
fn announce_outcome(&self, announce_hash: HashOf<Announce>) -> Option<Vec<StateTransition>>;
fn announce_schedule(&self, announce_hash: HashOf<Announce>) -> Option<Schedule>;
fn announce_meta(&self, announce_hash: HashOf<Announce>) -> AnnounceMeta;
fn block_announces(&self, block_hash: H256) -> Option<BTreeSet<HashOf<Announce>>>;
}

#[auto_impl::auto_impl(&)]
pub trait AnnounceStorageRW: AnnounceStorageRO {
fn set_announce(&self, announce: Announce) -> HashOf<Announce>;
fn set_block_announces(&self, block_hash: H256, announces: BTreeSet<HashOf<Announce>>);
fn set_announce_program_states(
&self,
announce_hash: HashOf<Announce>,
Expand All @@ -170,6 +156,11 @@ pub trait AnnounceStorageRW: AnnounceStorageRO {
announce_hash: HashOf<Announce>,
f: impl FnOnce(&mut AnnounceMeta),
);
fn mutate_block_announces(
&self,
block_hash: H256,
f: impl FnOnce(&mut BTreeSet<HashOf<Announce>>),
);
}

pub struct PreparedBlockData {
Expand Down Expand Up @@ -260,7 +251,7 @@ mod tests {
#[test]
fn ensure_types_unchanged() {
const EXPECTED_TYPE_INFO_HASH: &str =
"36d0e8436bb8fa8ea920012e1b4b079f9b6a83414e016771afc977568d30f29b";
"4d2864a076a65fc8abf5a4d7a0def202bd3982b086e14751d04e4ff711bc536a";

let types = [
meta_type::<BlockMeta>(),
Expand Down
58 changes: 24 additions & 34 deletions ethexe/common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,26 @@ pub struct PreparedBlockData {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlockFullData {
pub hash: H256,
pub synced: Option<SyncedBlockData>,
pub synced: SyncedBlockData,
pub prepared: Option<PreparedBlockData>,
}

impl BlockFullData {
#[track_caller]
pub fn as_synced(&self) -> &SyncedBlockData {
self.synced.as_ref().expect("block not synced")
pub fn assert_prepared(&self) -> &PreparedBlockData {
self.prepared.as_ref().expect("block is not prepared")
}

#[track_caller]
pub fn as_prepared(&self) -> &PreparedBlockData {
self.prepared.as_ref().expect("block not prepared")
}

#[track_caller]
pub fn as_synced_mut(&mut self) -> &mut SyncedBlockData {
self.synced.as_mut().expect("block not synced")
}

#[track_caller]
pub fn as_prepared_mut(&mut self) -> &mut PreparedBlockData {
self.prepared.as_mut().expect("block not prepared")
pub fn assert_prepared_mut(&mut self) -> &mut PreparedBlockData {
self.prepared.as_mut().expect("block is not prepared")
}

#[track_caller]
pub fn to_simple(&self) -> SimpleBlockData {
SimpleBlockData {
hash: self.hash,
header: self.as_synced().header,
header: self.synced.header,
}
}
}
Expand Down Expand Up @@ -336,7 +326,7 @@ impl BlockChain {
self.blocks
.get(block_index)
.expect("block index overflow")
.as_prepared()
.assert_prepared()
.announces
.iter()
.flatten()
Expand Down Expand Up @@ -385,7 +375,7 @@ impl BlockChain {
self.announces.insert(new_announce_hash, announce_data);

self.blocks[block_index]
.as_prepared_mut()
.assert_prepared_mut()
.announces
.as_mut()
.expect("block announces not found")
Expand Down Expand Up @@ -418,19 +408,16 @@ impl BlockChain {

for BlockFullData {
hash,
synced,
synced: SyncedBlockData { header, events },
prepared,
} in blocks
{
if let Some(SyncedBlockData { header, events }) = synced {
db.set_block_header(hash, header);
db.set_block_events(hash, &events);
db.set_block_synced(hash);

let block_era = config.timelines.era_from_ts(header.timestamp);
db.set_validators(block_era, validators.clone());
db.set_block_validators_committed_for_era(hash, block_era);
}
db.set_block_header(hash, header);
db.set_block_events(hash, &events);
db.set_block_synced(hash);

let block_era = config.timelines.era_from_ts(header.timestamp);
db.set_validators(block_era, validators.clone());

if let Some(PreparedBlockData {
codes_queue,
Expand All @@ -439,13 +426,17 @@ impl BlockChain {
last_committed_announce,
}) = prepared
{
if let Some(announces) = announces {
db.set_block_announces(hash, announces);
}

db.mutate_block_meta(hash, |meta| {
*meta = BlockMeta {
prepared: true,
announces,
codes_queue: Some(codes_queue),
last_committed_batch: Some(last_committed_batch),
last_committed_announce: Some(last_committed_announce),
latest_era_validators_committed: block_era,
}
});
}
Expand Down Expand Up @@ -507,14 +498,14 @@ impl Mock<(u32, ValidatorsVec)> for BlockChain {
|((parent_hash, _, _), (block_hash, block_height, block_timestamp))| {
BlockFullData {
hash: block_hash,
synced: Some(SyncedBlockData {
synced: SyncedBlockData {
header: BlockHeader {
height: block_height,
timestamp: block_timestamp as u64,
parent_hash,
},
events: Default::default(),
}),
},
prepared: Some(PreparedBlockData {
codes_queue: Default::default(),
announces: Some(Default::default()), // empty here, filled below with announces
Expand Down Expand Up @@ -601,7 +592,7 @@ pub trait DBMockExt {
fn top_announce_hash(&self, block: H256) -> HashOf<Announce>;
}

impl<DB: OnChainStorageRO + BlockMetaStorageRO> DBMockExt for DB {
impl<DB: OnChainStorageRO + BlockMetaStorageRO + AnnounceStorageRO> DBMockExt for DB {
#[track_caller]
fn simple_block_data(&self, block: H256) -> SimpleBlockData {
let header = self.block_header(block).expect("block header not found");
Expand All @@ -613,8 +604,7 @@ impl<DB: OnChainStorageRO + BlockMetaStorageRO> DBMockExt for DB {

#[track_caller]
fn top_announce_hash(&self, block: H256) -> HashOf<Announce> {
self.block_meta(block)
.announces
self.block_announces(block)
.expect("block announces not found")
.into_iter()
.next()
Expand Down
11 changes: 4 additions & 7 deletions ethexe/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub const fn u64_into_uint48_be_bytes_lossy(val: u64) -> [u8; 6] {
[b1, b2, b3, b4, b5, b6]
}

pub fn setup_block_in_db<DB: OnChainStorageRW + BlockMetaStorageRW>(
pub fn setup_block_in_db<DB: OnChainStorageRW + BlockMetaStorageRW + AnnounceStorageRW>(
db: &DB,
block_hash: H256,
block_data: PreparedBlockData,
Expand All @@ -53,20 +53,17 @@ pub fn setup_block_in_db<DB: OnChainStorageRW + BlockMetaStorageRW>(
db.set_block_events(block_hash, &block_data.events);
db.set_block_synced(block_hash);

db.set_block_announces(block_hash, block_data.announces);

db.mutate_block_meta(block_hash, |meta| {
*meta = BlockMeta {
prepared: true,
announces: Some(block_data.announces),
codes_queue: Some(block_data.codes_queue),
last_committed_batch: Some(block_data.last_committed_batch),
last_committed_announce: Some(block_data.last_committed_announce),
latest_era_validators_committed: block_data.latest_era_with_committed_validators,
}
});

db.set_block_validators_committed_for_era(
block_hash,
block_data.latest_era_with_committed_validators,
);
}

pub fn setup_announce_in_db<DB: AnnounceStorageRW>(
Expand Down
9 changes: 3 additions & 6 deletions ethexe/compute/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ fn prepare_one_block<DB: BlockMetaStorageRW + OnChainStorageRW + GlobalsStorageR

let mut last_committed_announce_hash = None;

let mut latest_validators_committed_era = db
.block_validators_committed_for_era(parent)
.ok_or(ComputeError::CommittedEraNotFound(parent))?;
let mut latest_validators_committed_era = parent_meta.latest_era_validators_committed;

for event in block.events {
match event {
Expand Down Expand Up @@ -350,13 +348,12 @@ fn prepare_one_block<DB: BlockMetaStorageRW + OnChainStorageRW + GlobalsStorageR
.ok_or(ComputeError::LastCommittedHeadNotFound(parent))?
};

db.set_block_validators_committed_for_era(block.hash, latest_validators_committed_era);

db.mutate_block_meta(block.hash, |meta| {
meta.last_committed_batch = Some(last_committed_batch);
meta.codes_queue = Some(codes_queue);
meta.last_committed_announce = Some(last_committed_announce_hash);
meta.prepared = true;
meta.latest_era_validators_committed = latest_validators_committed_era;
});

db.globals_mutate(|globals| {
Expand Down Expand Up @@ -502,7 +499,7 @@ mod tests {

let chain = BlockChain::mock(1)
.tap_mut(|chain| {
chain.blocks[1].as_prepared_mut().codes_queue =
chain.blocks[1].assert_prepared_mut().codes_queue =
[parent_block_code_id, parent_block_loaded_code_id].into();
chain.codes.insert(
parent_block_loaded_code_id,
Expand Down
20 changes: 10 additions & 10 deletions ethexe/compute/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn create_new_code(nonce: u32) -> Vec<u8> {
// Return a map with `CodeId` and corresponding code bytes
fn insert_code_events(chain: &mut BlockChain, events_in_block: u32) {
let mut nonce = 0;
for data in chain.blocks.iter_mut().map(|data| data.as_synced_mut()) {
for BlockFullData { synced: data, .. } in &mut chain.blocks {
data.events = (0..events_in_block)
.map(|_| {
nonce += 1;
Expand Down Expand Up @@ -226,9 +226,10 @@ impl TestEnv {
let computed_announce = event.unwrap_announce_computed();
assert_eq!(computed_announce, announce_hash);

self.db.mutate_block_meta(announce.block_hash, |meta| {
meta.announces.get_or_insert_default().insert(announce_hash);
});
self.db
.mutate_block_announces(announce.block_hash, |announces| {
announces.insert(announce_hash);
});
}
}

Expand Down Expand Up @@ -273,11 +274,10 @@ async fn multiple_preparation_and_one_processing() -> Result<()> {
// append announces to prepared blocks, except the last one, so that it can be computed
for i in 1..3 {
let announce = new_announce(&env.db, env.chain.blocks[i].hash, Some(100));
env.db.mutate_block_meta(announce.block_hash, |meta| {
meta.announces
.get_or_insert_default()
.insert(announce.to_hash());
});
env.db
.mutate_block_announces(announce.block_hash, |announces| {
announces.insert(announce.to_hash());
});
env.db.set_announce(announce);
}

Expand Down Expand Up @@ -309,7 +309,7 @@ async fn code_validation_request_does_not_block_preparation() -> Result<()> {

let mut env = TestEnv::new(1, 3);

let mut block_events = env.chain.blocks[1].as_synced().events.clone();
let mut block_events = env.chain.blocks[1].synced.events.clone();

// add invalid event which shouldn't stop block prepare
block_events.push(BlockEvent::Router(RouterEvent::CodeValidationRequested(
Expand Down
Loading
Loading