Skip to content

Commit

Permalink
eth/downloader, core/types: take withdrawals-size into account in dow…
Browse files Browse the repository at this point in the history
…nloader queue (ethereum#30276)

Fixes a slight miscalculation in the downloader queue, which was not accurately taking block withdrawals into account when calculating the size of the items in the queue
  • Loading branch information
psogv0308 authored and leeren committed Aug 16, 2024
1 parent b9ea8d8 commit ce7a227
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/types/withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package types

import (
"bytes"
"reflect"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -48,6 +49,12 @@ type Withdrawals []*Withdrawal
// Len returns the length of s.
func (s Withdrawals) Len() int { return len(s) }

var withdrawalSize = int(reflect.TypeOf(Withdrawal{}).Size())

func (s Withdrawals) Size() int {
return withdrawalSize * len(s)
}

// EncodeIndex encodes the i'th withdrawal to w. Note that this does not check for errors
// because we assume that *Withdrawal will only ever contain valid withdrawals that were either
// constructed by decoding or via public API in this package.
Expand Down
1 change: 1 addition & 0 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func (q *queue) Results(block bool) []*fetchResult {
for _, tx := range result.Transactions {
size += common.StorageSize(tx.Size())
}
size += common.StorageSize(result.Withdrawals.Size())
q.resultSize = common.StorageSize(blockCacheSizeWeight)*size +
(1-common.StorageSize(blockCacheSizeWeight))*q.resultSize
}
Expand Down

0 comments on commit ce7a227

Please sign in to comment.