extract log size calculation to receipt.go

This commit is contained in:
healthykim 2026-03-19 02:40:14 +09:00
parent 7926650d0b
commit 9ba076e0b1
2 changed files with 28 additions and 19 deletions

View file

@ -524,7 +524,6 @@ func (p *Peer) validateLastBlockReceipt(receiptLists []*ReceiptList, id uint64,
// This case happens only if len(receiptLists) == 1 && incomplete == true && buffered before.
var previousTxs int
var previousLog uint64
var log uint64
if buffer, ok := p.receiptBuffer[id]; ok && len(buffer.list) > 0 && len(receiptLists) == 1 {
previousTxs = buffer.list[len(buffer.list)-1].items.Len()
previousLog = buffer.lastLogSize
@ -542,24 +541,9 @@ func (p *Peer) validateLastBlockReceipt(receiptLists []*ReceiptList, id uint64,
return 0, fmt.Errorf("total number of tx exceeded limit")
}
// Count log size per receipt
it := lastReceipts.items.ContentIterator()
for it.Next() {
content, _, err := rlp.SplitList(it.Value())
if err != nil {
return 0, fmt.Errorf("invalid receipt structure: %v", err)
}
rest := content
for range 3 {
_, _, rest, err = rlp.Split(rest)
if err != nil {
return 0, fmt.Errorf("invalid receipt structure: %v", err)
}
}
logsContent, _, err := rlp.SplitList(rest)
if err != nil {
return 0, fmt.Errorf("invalid receipt logs: %v", err)
}
log += uint64(len(logsContent))
log, err := lastReceipts.LogsSize()
if err != nil {
return 0, err
}
// Verify that the overall downloaded receipt size does not exceed the block gas limit.
if previousLog+log > gasUsed/params.LogDataGas {

View file

@ -207,6 +207,31 @@ func (rl *ReceiptList) Append(other *ReceiptList) {
rl.items.AppendList(&other.items)
}
// LogsSize returns the total size of log data in this receipts.
func (rl *ReceiptList) LogsSize() (uint64, error) {
var size uint64
it := rl.items.ContentIterator()
for it.Next() {
content, _, err := rlp.SplitList(it.Value())
if err != nil {
return 0, fmt.Errorf("invalid receipt structure: %v", err)
}
rest := content
for range 3 {
_, _, rest, err = rlp.Split(rest)
if err != nil {
return 0, fmt.Errorf("invalid receipt structure: %v", err)
}
}
logsContent, _, err := rlp.SplitList(rest)
if err != nil {
return 0, fmt.Errorf("invalid receipt logs: %v", err)
}
size += uint64(len(logsContent))
}
return size, nil
}
// blockReceiptsToNetwork takes a slice of rlp-encoded receipts, and transactions,
// and re-encodes them for the network protocol.
func blockReceiptsToNetwork(blockReceipts, blockBody rlp.RawValue) ([]byte, error) {