mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-17 04:11:37 +00:00
extract log size calculation to receipt.go
This commit is contained in:
parent
7926650d0b
commit
9ba076e0b1
2 changed files with 28 additions and 19 deletions
|
|
@ -524,7 +524,6 @@ func (p *Peer) validateLastBlockReceipt(receiptLists []*ReceiptList, id uint64,
|
||||||
// This case happens only if len(receiptLists) == 1 && incomplete == true && buffered before.
|
// This case happens only if len(receiptLists) == 1 && incomplete == true && buffered before.
|
||||||
var previousTxs int
|
var previousTxs int
|
||||||
var previousLog uint64
|
var previousLog uint64
|
||||||
var log uint64
|
|
||||||
if buffer, ok := p.receiptBuffer[id]; ok && len(buffer.list) > 0 && len(receiptLists) == 1 {
|
if buffer, ok := p.receiptBuffer[id]; ok && len(buffer.list) > 0 && len(receiptLists) == 1 {
|
||||||
previousTxs = buffer.list[len(buffer.list)-1].items.Len()
|
previousTxs = buffer.list[len(buffer.list)-1].items.Len()
|
||||||
previousLog = buffer.lastLogSize
|
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")
|
return 0, fmt.Errorf("total number of tx exceeded limit")
|
||||||
}
|
}
|
||||||
// Count log size per receipt
|
// Count log size per receipt
|
||||||
it := lastReceipts.items.ContentIterator()
|
log, err := lastReceipts.LogsSize()
|
||||||
for it.Next() {
|
if err != nil {
|
||||||
content, _, err := rlp.SplitList(it.Value())
|
return 0, err
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
// Verify that the overall downloaded receipt size does not exceed the block gas limit.
|
// Verify that the overall downloaded receipt size does not exceed the block gas limit.
|
||||||
if previousLog+log > gasUsed/params.LogDataGas {
|
if previousLog+log > gasUsed/params.LogDataGas {
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,31 @@ func (rl *ReceiptList) Append(other *ReceiptList) {
|
||||||
rl.items.AppendList(&other.items)
|
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,
|
// blockReceiptsToNetwork takes a slice of rlp-encoded receipts, and transactions,
|
||||||
// and re-encodes them for the network protocol.
|
// and re-encodes them for the network protocol.
|
||||||
func blockReceiptsToNetwork(blockReceipts, blockBody rlp.RawValue) ([]byte, error) {
|
func blockReceiptsToNetwork(blockReceipts, blockBody rlp.RawValue) ([]byte, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue