Skip to content

Commit

Permalink
Fix proofs for RequestTransactionsProof for ongoing epochs
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Mar 2, 2023
1 parent ffe9ebe commit 8e78b49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
5 changes: 3 additions & 2 deletions consensus/src/consensus/consensus_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ impl<N: Network> ConsensusProxy<N> {
.map_or(false, |result| result);

if verification_result {
verified_transactions
.insert(transaction.tx_hash(), transaction);
for tx in proof.history {
verified_transactions.insert(tx.tx_hash(), tx);
}
} else {
// The proof didn't verify so we disconnect from this peer
log::debug!(peer=%peer_id,"Disconnecting from peer because the transaction proof didn't verify");
Expand Down
40 changes: 27 additions & 13 deletions consensus/src/messages/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,34 @@ impl Handle<ResponseTransactionsProof, Arc<RwLock<Blockchain>>> for RequestTrans
.history_store
.prove(Policy::epoch_at(self.block_number), hashes, None);

//If we obtained a proof, we need to supply the corresponding block
// If we obtained a proof, we need to supply the corresponding block
if proof.is_some() {
block = blockchain
.chain_store
.get_block_at(self.block_number, false, None)
.ok()
.and_then(|block| {
if block.is_macro() {
// We expect a macro block
Some(block)
} else {
None
}
});
// If the block_number to proof is in a finalized epoch, use the epoch's finalization block
let election_block_number = if Policy::is_election_block_at(self.block_number) {
self.block_number
} else {
Policy::election_block_after(self.block_number)
};

if election_block_number <= blockchain.block_number() {
block = blockchain
.chain_store
.get_block_at(election_block_number, false, None)
.ok();
} else {
// Otherwise, the transaction proof was made at the current history store state, so return the current
// head block to prove it.
let mut head = blockchain.head();

// Convert to light block by removing the block body
match head {
Block::Macro(ref mut block) => block.body = None,
Block::Micro(ref mut block) => block.body = None,
}

block = Some(head);
}

if block.is_none() {
log::error!("We are supplying a transaction proof but not a block, which can be interpreted as malicious behaviour");
}
Expand Down

0 comments on commit 8e78b49

Please sign in to comment.