mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-17 04:11:37 +00:00
eth/protocols/eth: add comments in LogsSize
This commit is contained in:
parent
59ca98ddbe
commit
130470832f
1 changed files with 9 additions and 1 deletions
|
|
@ -207,15 +207,22 @@ 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.
|
// LogsSize returns the total size of log data across all receipts of the list.
|
||||||
func (rl *ReceiptList) LogsSize() (uint64, error) {
|
func (rl *ReceiptList) LogsSize() (uint64, error) {
|
||||||
var size uint64
|
var size uint64
|
||||||
it := rl.items.ContentIterator()
|
it := rl.items.ContentIterator()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
|
// The encoded receipts are of the form:
|
||||||
|
//
|
||||||
|
// [txType, status, cumulativeGasUsed, [logs...]]
|
||||||
|
//
|
||||||
|
// We want to count the size of logs.
|
||||||
|
// So we strip the outer list first:
|
||||||
content, _, err := rlp.SplitList(it.Value())
|
content, _, err := rlp.SplitList(it.Value())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("invalid receipt structure: %v", err)
|
return 0, fmt.Errorf("invalid receipt structure: %v", err)
|
||||||
}
|
}
|
||||||
|
// then skip over txType, status, cumulativeGasUsed:
|
||||||
rest := content
|
rest := content
|
||||||
for range 3 {
|
for range 3 {
|
||||||
_, _, rest, err = rlp.Split(rest)
|
_, _, rest, err = rlp.Split(rest)
|
||||||
|
|
@ -223,6 +230,7 @@ func (rl *ReceiptList) LogsSize() (uint64, error) {
|
||||||
return 0, fmt.Errorf("invalid receipt structure: %v", err)
|
return 0, fmt.Errorf("invalid receipt structure: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// and finally access the logs list to get its inner size:
|
||||||
logsContent, _, err := rlp.SplitList(rest)
|
logsContent, _, err := rlp.SplitList(rest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("invalid receipt logs: %v", err)
|
return 0, fmt.Errorf("invalid receipt logs: %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue