Skip to content

Commit

Permalink
Using fetch raw header api and not to marshal header
Browse files Browse the repository at this point in the history
This will increase performance
  • Loading branch information
ImJeremyHe committed Dec 18, 2024
1 parent 5379751 commit 1297993
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 677 deletions.
14 changes: 8 additions & 6 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,11 +1274,17 @@ func (s *TransactionStreamer) pollSubmittedTransactionForFinality(ctx context.Co

height := data.BlockHeight

header, err := s.espressoClient.FetchHeaderByHeight(ctx, height)
jsonHeader, err := s.espressoClient.FetchRawHeaderByHeight(ctx, height)
if err != nil {
return fmt.Errorf("could not get the header (height: %d): %w", height, err)
}

var header espressoTypes.HeaderImpl
err = json.Unmarshal(jsonHeader, &header)
if err != nil {
return fmt.Errorf("could not unmarshal header from bytes (height: %d): %w", height, err)
}

// Verify the merkle proof
snapshot, err := s.lightClientReader.FetchMerkleRoot(height, nil)
if err != nil {
Expand All @@ -1300,12 +1306,8 @@ func (s *TransactionStreamer) pollSubmittedTransactionForFinality(ctx context.Co
}

blockMerkleTreeRoot := nextHeader.Header.GetBlockMerkleTreeRoot()
jstHeader, err := json.Marshal(header)
if err != nil {
return fmt.Errorf("failed to marshal the header: %w", err)
}

ok := espressocrypto.VerifyMerkleProof(proof.Proof, jstHeader, *blockMerkleTreeRoot, snapshot.Root)
ok := espressocrypto.VerifyMerkleProof(proof.Proof, jsonHeader, *blockMerkleTreeRoot, snapshot.Root)
if !ok {
return fmt.Errorf("error validating merkle proof (height: %d, snapshot height: %d)", height, snapshot.Height)
}
Expand Down
Loading

0 comments on commit 1297993

Please sign in to comment.