Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Dec 4, 2023
1 parent 0374eb8 commit 2af8ae5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions turbo/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ func (r *BlockReader) BodyRlp(ctx context.Context, tx kv.Getter, hash common.Has
}

func (r *BlockReader) Body(ctx context.Context, tx kv.Getter, hash common.Hash, blockHeight uint64) (body *types.Body, txAmount uint32, err error) {
blocksAvailable := r.sn.BlocksAvailable()
if blocksAvailable == 0 || blockHeight > blocksAvailable {
maxBlockNumInFiles := r.sn.BlocksAvailable()
if maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles {
body, _, txAmount = rawdb.ReadBody(tx, hash, blockHeight)
return body, txAmount, nil
}
Expand All @@ -459,8 +459,8 @@ func (r *BlockReader) Body(ctx context.Context, tx kv.Getter, hash common.Hash,
}

func (r *BlockReader) HasSenders(ctx context.Context, tx kv.Getter, hash common.Hash, blockHeight uint64) (bool, error) {
blocksAvailable := r.sn.BlocksAvailable()
if blocksAvailable == 0 || blockHeight > blocksAvailable {
maxBlockNumInFiles := r.sn.BlocksAvailable()
if maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles {
return rawdb.HasSenders(tx, hash, blockHeight)
}
return true, nil
Expand All @@ -470,8 +470,8 @@ func (r *BlockReader) BlockWithSenders(ctx context.Context, tx kv.Getter, hash c
return r.blockWithSenders(ctx, tx, hash, blockHeight, false)
}
func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash common.Hash, blockHeight uint64, forceCanonical bool) (block *types.Block, senders []common.Address, err error) {
blocksAvailable := r.sn.BlocksAvailable()
if blocksAvailable == 0 || blockHeight > blocksAvailable {
maxBlockNumInFiles := r.sn.BlocksAvailable()
if maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles {
if forceCanonical {
canonicalHash, err := rawdb.ReadCanonicalHash(tx, blockHeight)
if err != nil {
Expand Down Expand Up @@ -756,8 +756,8 @@ func (r *BlockReader) txnByHash(txnHash common.Hash, segments []*TxnSegment, buf
// TxnByIdxInBlock - doesn't include system-transactions in the begin/end of block
// return nil if 0 < i < body.TxAmount
func (r *BlockReader) TxnByIdxInBlock(ctx context.Context, tx kv.Getter, blockNum uint64, txIdxInBlock int) (txn types.Transaction, err error) {
blocksAvailable := r.sn.BlocksAvailable()
if blocksAvailable == 0 || blockNum > blocksAvailable {
maxBlockNumInFiles := r.sn.BlocksAvailable()
if maxBlockNumInFiles == 0 || blockNum > maxBlockNumInFiles {
canonicalHash, err := rawdb.ReadCanonicalHash(tx, blockNum)
if err != nil {
return nil, err
Expand Down Expand Up @@ -991,7 +991,8 @@ func (r *BlockReader) borBlockByEventHash(txnHash common.Hash, segments []*BorEv
}

func (r *BlockReader) EventsByBlock(ctx context.Context, tx kv.Tx, hash common.Hash, blockHeight uint64) ([]rlp.RawValue, error) {
if blockHeight > r.FrozenBorBlocks() {
maxBlockNumInFiles := r.FrozenBorBlocks()
if maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles {
c, err := tx.Cursor(kv.BorEventNums)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1109,7 +1110,8 @@ func (r *BlockReader) Span(ctx context.Context, tx kv.Getter, spanId uint64) ([]
}
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], spanId)
if endBlock > r.FrozenBorBlocks() {
maxBlockNumInFiles := r.FrozenBorBlocks()
if maxBlockNumInFiles == 0 || endBlock > maxBlockNumInFiles {
v, err := tx.GetOne(kv.BorSpans, buf[:])
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,12 @@ func (s *RoSnapshots) Files() (list []string) {
defer s.Bodies.lock.RUnlock()
s.Txs.lock.RLock()
defer s.Txs.lock.RUnlock()
max := s.BlocksAvailable()
maxBlockNumInFiles := s.BlocksAvailable()
for _, seg := range s.Bodies.segments {
if seg.seg == nil {
continue
}
if seg.ranges.from > max {
if seg.ranges.from > maxBlockNumInFiles {
continue
}
_, fName := filepath.Split(seg.seg.FilePath())
Expand All @@ -511,7 +511,7 @@ func (s *RoSnapshots) Files() (list []string) {
if seg.seg == nil {
continue
}
if seg.ranges.from > max {
if seg.ranges.from > maxBlockNumInFiles {
continue
}
_, fName := filepath.Split(seg.seg.FilePath())
Expand All @@ -521,7 +521,7 @@ func (s *RoSnapshots) Files() (list []string) {
if seg.Seg == nil {
continue
}
if seg.ranges.from > max {
if seg.ranges.from > maxBlockNumInFiles {
continue
}
_, fName := filepath.Split(seg.Seg.FilePath())
Expand Down

0 comments on commit 2af8ae5

Please sign in to comment.