Skip to content

Commit 1070f7c

Browse files
committed
add memoize elsewehre
1 parent c8d0622 commit 1070f7c

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

block/internal/executing/executor.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ func (e *Executor) initializeState() error {
263263
if err != nil {
264264
return fmt.Errorf("failed to get header at %d for sync check: %w", state.LastBlockHeight, err)
265265
}
266-
if !bytes.Equal(header.Hash(), raftState.Hash) {
267-
return fmt.Errorf("invalid state: block hash mismatch at height %d: raft=%x local=%x", state.LastBlockHeight, raftState.Hash, header.Hash())
266+
headerHash := header.MemoizeHash()
267+
if !bytes.Equal(headerHash, raftState.Hash) {
268+
return fmt.Errorf("invalid state: block hash mismatch at height %d: raft=%x local=%x", state.LastBlockHeight, raftState.Hash, headerHash)
268269
}
269270
}
270271
}
@@ -358,8 +359,9 @@ func (e *Executor) initializeState() error {
358359
if err != nil {
359360
return fmt.Errorf("get header at %d: %w", newState.LastBlockHeight, err)
360361
}
361-
if !bytes.Equal(header.Hash(), raftState.Hash) {
362-
return fmt.Errorf("CRITICAL: content mismatch after replay! local=%x raft=%x. This indicates a 'Dual-Store Conflict' where data diverged from Raft", header.Hash(), raftState.Hash)
362+
headerHash := header.MemoizeHash()
363+
if !bytes.Equal(headerHash, raftState.Hash) {
364+
return fmt.Errorf("CRITICAL: content mismatch after replay! local=%x raft=%x. This indicates a 'Dual-Store Conflict' where data diverged from Raft", headerHash, raftState.Hash)
363365
}
364366
}
365367
}
@@ -917,8 +919,9 @@ func (e *Executor) IsSyncedWithRaft(raftState *raft.RaftBlockState) (int, error)
917919
return 0, fmt.Errorf("get header for sync check at height %d: %w", raftState.Height, err)
918920
}
919921

920-
if !bytes.Equal(header.Hash(), raftState.Hash) {
921-
return 0, fmt.Errorf("block hash mismatch: %s != %s", header.Hash(), raftState.Hash)
922+
headerHash := header.MemoizeHash()
923+
if !bytes.Equal(headerHash, raftState.Hash) {
924+
return 0, fmt.Errorf("block hash mismatch: %s != %s", headerHash, raftState.Hash)
922925
}
923926

924927
return 0, nil

block/internal/syncing/da_retriever.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (r *daRetriever) tryDecodeHeader(bz []byte, daHeight uint64) *types.SignedH
312312
// Optimistically mark as DA included
313313
// This has to be done for all fetched DA headers prior to validation because P2P does not confirm
314314
// da inclusion. This is not an issue, as an invalid header will be rejected. There cannot be hash collisions.
315-
headerHash := header.Hash().String()
315+
headerHash := header.MemoizeHash().String()
316316
r.cache.SetHeaderDAIncluded(headerHash, daHeight, header.Height())
317317

318318
r.logger.Debug().

block/internal/syncing/p2p_handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func (h *P2PHandler) ProcessHeight(ctx context.Context, height uint64, heightInC
100100
return err
101101
}
102102

103+
// Memoize hash before the header enters the event pipeline so that downstream
104+
// callers (processHeightEvent, TrySyncNextBlock) get cache hits.
105+
p2pHeader.SignedHeader.MemoizeHash()
106+
103107
// further header validation (signature) is done in validateBlock.
104108
// we need to be sure that the previous block n-1 was executed before validating block n
105109
event := common.DAHeightEvent{

0 commit comments

Comments
 (0)