|
|
|
@ -669,7 +669,7 @@ func deriveLogFields(receipts []*receiptLogs, hash common.Hash, number uint64, t |
|
|
|
|
// ReadLogs retrieves the logs for all transactions in a block. The log fields
|
|
|
|
|
// are populated with metadata. In case the receipts or the block body
|
|
|
|
|
// are not found, a nil is returned.
|
|
|
|
|
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log { |
|
|
|
|
func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64, config *params.ChainConfig) [][]*types.Log { |
|
|
|
|
// Retrieve the flattened receipt slice
|
|
|
|
|
data := ReadReceiptsRLP(db, hash, number) |
|
|
|
|
if len(data) == 0 { |
|
|
|
@ -677,7 +677,12 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log { |
|
|
|
|
} |
|
|
|
|
receipts := []*receiptLogs{} |
|
|
|
|
if err := rlp.DecodeBytes(data, &receipts); err != nil { |
|
|
|
|
log.Error("Invalid receipt array RLP", "hash", hash, "err", err) |
|
|
|
|
// Receipts might be in the legacy format, try decoding that.
|
|
|
|
|
// TODO: to be removed after users migrated
|
|
|
|
|
if logs := readLegacyLogs(db, hash, number, config); logs != nil { |
|
|
|
|
return logs |
|
|
|
|
} |
|
|
|
|
log.Error("Invalid receipt array RLP", "hash", "err", err) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -697,6 +702,21 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log { |
|
|
|
|
return logs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// readLegacyLogs is a temporary workaround for when trying to read logs
|
|
|
|
|
// from a block which has its receipt stored in the legacy format. It'll
|
|
|
|
|
// be removed after users have migrated their freezer databases.
|
|
|
|
|
func readLegacyLogs(db ethdb.Reader, hash common.Hash, number uint64, config *params.ChainConfig) [][]*types.Log { |
|
|
|
|
receipts := ReadReceipts(db, hash, number, config) |
|
|
|
|
if receipts == nil { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
logs := make([][]*types.Log, len(receipts)) |
|
|
|
|
for i, receipt := range receipts { |
|
|
|
|
logs[i] = receipt.Logs |
|
|
|
|
} |
|
|
|
|
return logs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ReadBlock retrieves an entire block corresponding to the hash, assembling it
|
|
|
|
|
// back from the stored header and body. If either the header or body could not
|
|
|
|
|
// be retrieved nil is returned.
|
|
|
|
|