diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-02-22 18:48:14 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-02-23 01:12:43 +0800 |
commit | 5cf1d354704cd2cbc5c64c96d4aaabeeec7dd161 (patch) | |
tree | 10c38cbf3cd5a0e796d6df6c667cc84ce57e2a34 /light | |
parent | 45352477933d71ec5055504da74547b0cdf0274b (diff) | |
download | dexon-5cf1d354704cd2cbc5c64c96d4aaabeeec7dd161.tar.gz dexon-5cf1d354704cd2cbc5c64c96d4aaabeeec7dd161.tar.zst dexon-5cf1d354704cd2cbc5c64c96d4aaabeeec7dd161.zip |
eth, les, light: filter on logs only, derive receipts on demand
Diffstat (limited to 'light')
-rw-r--r-- | light/odr_util.go | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/light/odr_util.go b/light/odr_util.go index 8f92d6442..97ba440ac 100644 --- a/light/odr_util.go +++ b/light/odr_util.go @@ -126,15 +126,48 @@ func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint // GetBlockReceipts retrieves the receipts generated by the transactions included // in a block given by its hash. func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (types.Receipts, error) { + // Retrieve the potentially incomplete receipts from disk or network receipts := core.GetBlockReceipts(odr.Database(), hash, number) - if receipts != nil { - return receipts, nil + if receipts == nil { + r := &ReceiptsRequest{Hash: hash, Number: number} + if err := odr.Retrieve(ctx, r); err != nil { + return nil, err + } + receipts = r.Receipts } - r := &ReceiptsRequest{Hash: hash, Number: number} - if err := odr.Retrieve(ctx, r); err != nil { - return nil, err + // If the receipts are incomplete, fill the derived fields + if len(receipts) > 0 && receipts[0].TxHash == (common.Hash{}) { + block, err := GetBlock(ctx, odr, hash, number) + if err != nil { + return nil, err + } + genesis := core.GetCanonicalHash(odr.Database(), 0) + config, _ := core.GetChainConfig(odr.Database(), genesis) + + core.SetReceiptsData(config, block, receipts) + core.WriteBlockReceipts(odr.Database(), hash, number, receipts) + } + return receipts, nil +} + +// GetBlockLogs retrieves the logs generated by the transactions included in a +// block given by its hash. +func GetBlockLogs(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) ([][]*types.Log, error) { + // Retrieve the potentially incomplete receipts from disk or network + receipts := core.GetBlockReceipts(odr.Database(), hash, number) + if receipts == nil { + r := &ReceiptsRequest{Hash: hash, Number: number} + if err := odr.Retrieve(ctx, r); err != nil { + return nil, err + } + receipts = r.Receipts + } + // Return the logs without deriving any computed fields on the receipts + logs := make([][]*types.Log, len(receipts)) + for i, receipt := range receipts { + logs[i] = receipt.Logs } - return r.Receipts, nil + return logs, nil } // GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to the given bit index and section indexes |