-
Notifications
You must be signed in to change notification settings - Fork 28
feat(chain): block reconstruction #1650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/consensus-refactor-base
Are you sure you want to change the base?
feat(chain): block reconstruction #1650
Conversation
b51d554
to
3746c59
Compare
a0194b9
to
3cbdd17
Compare
282ac09
to
0a7aa82
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
45587dc
to
1dbe1af
Compare
I created new branch where we maybe can merge meanwhile? feat/consensus-refactor-base |
f3a4e23
to
4230f7e
Compare
4230f7e
to
063440f
Compare
063440f
to
c58fc59
Compare
@andrussal what is the status of this? If we need other stuff before, maybe lets move it to draft for the time being? |
c58fc59
to
0665313
Compare
There was a problem hiding this 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>, |
There was a problem hiding this comment.
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
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(()) | ||
} |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
pub proposal_version: u8, | ||
pub cryptarchia_version: u8, |
There was a problem hiding this comment.
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?
let Ok(signature) = header.sign(&dummy_signing_key) else { | ||
error!("Failed to sign header in block provider"); | ||
return None; | ||
}; |
There was a problem hiding this comment.
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?
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; |
There was a problem hiding this comment.
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?
.into_iter() | ||
.filter(|hash| { | ||
!reconstructed_transactions | ||
.iter() | ||
.any(|tx| tx.hash() == *hash) | ||
}) | ||
.collect(); | ||
|
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
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