Skip to content

Conversation

andrussal
Copy link
Contributor

@andrussal andrussal commented Sep 5, 2025

1. What does this PR implement?

Reconstructs block from Proposal. When receiving Proposal from network(which contains only transaction references), we need to retrieve transactions from mempool and construct full block. Spec


DON'T MEGRE TO MASTER UNTIL FULL FLOW WITH PROPOSALS IS WORKING

2. Does the code have enough context to be clearly understood?

Yes

3. Who are the specification authors and who is accountable for this PR?

@andrussal

4. Is the specification accurate and complete?

Yes

5. Does the implementation introduce changes in the specification?

Yes

Checklist

  • 1. The PR title follows the Conventional Commits specification.
  • 2. Description added.
  • 3. Context and links to Specification document(s) added.
  • 4. Main contact(s) (developers and specification authors) added
  • 5. Implementation and Specification are 100% in sync including changes. This is critical.
  • 6. Link PR to a specific milestone.

@andrussal andrussal marked this pull request as draft September 5, 2025 14:42
@andrussal andrussal changed the title WIP: feat(chain): block reconstruction [DRAFT] feat(chain): block reconstruction Sep 5, 2025
@andrussal andrussal added the chain label Sep 5, 2025
@andrussal andrussal added this to the Iteration 15 milestone Sep 5, 2025
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch 2 times, most recently from b51d554 to 3746c59 Compare September 8, 2025 11:27
Base automatically changed from zeegomo/block to master September 8, 2025 11:29
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch 3 times, most recently from a0194b9 to 3cbdd17 Compare September 8, 2025 14:52
@andrussal andrussal marked this pull request as ready for review September 8, 2025 15:20
@andrussal andrussal changed the title [DRAFT] feat(chain): block reconstruction feat(chain): block reconstruction Sep 8, 2025
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from 282ac09 to 0a7aa82 Compare September 9, 2025 06:51
Copy link
Contributor

@zeegomo zeegomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this in a separate branch until we can re-enable tests since those are critical and we need to be sure everything is working

/// A block
#[expect(
clippy::unsafe_derive_deserialize,
reason = "Temporary dummy signature"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the signature supposed to be added to the block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I added signature to block so we can construct Proposal and also store it. Please let me know if this is correct.

@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from 45587dc to 1dbe1af Compare September 10, 2025 07:42
@andrussal andrussal changed the base branch from master to feat/consensus-refactor-base September 10, 2025 08:05
@andrussal
Copy link
Contributor Author

I think we should keep this in a separate branch until we can re-enable tests since those are critical and we need to be sure everything is working

I created new branch where we maybe can merge meanwhile? feat/consensus-refactor-base

@andrussal andrussal requested a review from zeegomo September 10, 2025 08:13
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from f3a4e23 to 4230f7e Compare September 16, 2025 10:20
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from 4230f7e to 063440f Compare September 17, 2025 08:55
@andrussal andrussal changed the base branch from feat/consensus-refactor-base to master September 17, 2025 09:19
@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from 063440f to c58fc59 Compare September 17, 2025 09:33
@danielSanchezQ
Copy link
Collaborator

@andrussal what is the status of this? If we need other stuff before, maybe lets move it to draft for the time being?

@andrussal andrussal force-pushed the feat/chain-block-reconstruction branch from c58fc59 to 0665313 Compare September 23, 2025 13:42
@andrussal andrussal changed the base branch from master to feat/consensus-refactor-base September 23, 2025 13:42
Copy link
Contributor

@zeegomo zeegomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement! I left a few additional comments, we're close 🚀

pub struct Block<Tx> {
header: Header,
signature: ed25519_dalek::Signature,
service_reward: Option<Fr>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably resolve this to a Tx anyway

Comment on lines +108 to +131
pub fn validate(&self) -> Result<(), Error>
where
Tx: Transaction,
Tx::Hash: Into<Fr>,
{
if !self.header.is_valid_bedrock_version() {
return Err(Error::Signing("Invalid header version".to_owned()));
}

if self.transactions.len() > MAX_TRANSACTIONS {
return Err(Error::Signing(format!(
"Too many transactions (max {MAX_TRANSACTIONS})"
)));
}

let leader_public_key = self.header.leader_proof().leader_key();
let header_bytes = <Header as SerdeOp>::serialize(&self.header)?;

leader_public_key
.verify(&header_bytes, &self.signature)
.map_err(|e| Error::Signing(format!("Invalid signature: {e}")))?;

Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make it so it's impossible to build an invalid block instead of requiring validation

let mempool_transactions: Vec<Fr> = self
.transactions
.iter()
.map(|tx| tx.hash().into())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if reference is not a list of TxHash we should probably update it

Comment on lines +27 to +28
pub proposal_version: u8,
pub cryptarchia_version: u8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are these coming from?

Comment on lines +825 to +828
let Ok(signature) = header.sign(&dummy_signing_key) else {
error!("Failed to sign header in block provider");
return None;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this should fail in tests?

Comment on lines -854 to -867
match Self::process_block_and_update_state(
cryptarchia.clone(),
&leader,
block.clone(),
blob_validation.as_ref(),
&storage_blocks_to_remove,
&relays,
&self.new_block_subscription_sender,
&self.lib_subscription_sender,
&self.service_resources_handle.state_updater
).await {
Ok((new_cryptarchia, new_storage_blocks_to_remove)) => {
cryptarchia = new_cryptarchia;
storage_blocks_to_remove = new_storage_blocks_to_remove;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's pre-existing, but can't we merge these two branches?

Comment on lines +1773 to +1780
.into_iter()
.filter(|hash| {
!reconstructed_transactions
.iter()
.any(|tx| tx.hash() == *hash)
})
.collect();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should return the unmatched ones in the error variant?


let header = proposal.header().clone();
let service_reward = proposal.references().service_reward;
let signature = *proposal.signature();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where we should probably recover the reward tx imo, but ofc not something to add now because we need some additional work on sdp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants