diff options
author | Matthew Halpern <matthalp@gmail.com> | 2019-03-28 00:11:24 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-04-15 18:15:39 +0800 |
commit | 6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c (patch) | |
tree | 0bc1492a2e13c62ea049bcddac6b31cf06f19c7e /light | |
parent | 1528b791ac81203aa5019d091f10ae6a0dde53a8 (diff) | |
download | go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar.gz go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar.bz2 go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar.lz go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar.xz go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.tar.zst go-tangerine-6b0ddd141e2e12bb09b33e14e67aed4d5a68d66c.zip |
core, eth, les, light: store transaction receipts without txHash and gasCost
Diffstat (limited to 'light')
-rw-r--r-- | light/odr_test.go | 2 | ||||
-rw-r--r-- | light/odr_util.go | 20 |
2 files changed, 10 insertions, 12 deletions
diff --git a/light/odr_test.go b/light/odr_test.go index 55725d84e..57b377c41 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -79,7 +79,7 @@ func (odr *testOdr) Retrieve(ctx context.Context, req OdrRequest) error { case *ReceiptsRequest: number := rawdb.ReadHeaderNumber(odr.sdb, req.Hash) if number != nil { - req.Receipts = rawdb.ReadReceipts(odr.sdb, req.Hash, *number) + req.Receipts = rawdb.ReadRawReceipts(odr.sdb, req.Hash, *number) } case *TrieRequest: t, _ := trie.New(req.Id.Root, trie.NewDatabase(odr.sdb)) diff --git a/light/odr_util.go b/light/odr_util.go index 00103a76b..f84de6671 100644 --- a/light/odr_util.go +++ b/light/odr_util.go @@ -21,7 +21,6 @@ import ( "context" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -127,8 +126,8 @@ 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 := rawdb.ReadReceipts(odr.Database(), hash, number) + // Assume receipts are already stored locally and attempt to retrieve. + receipts := rawdb.ReadRawReceipts(odr.Database(), hash, number) if receipts == nil { r := &ReceiptsRequest{Hash: hash, Number: number} if err := odr.Retrieve(ctx, r); err != nil { @@ -136,6 +135,7 @@ func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, num } receipts = r.Receipts } + // 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) @@ -145,11 +145,12 @@ func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, num genesis := rawdb.ReadCanonicalHash(odr.Database(), 0) config := rawdb.ReadChainConfig(odr.Database(), genesis) - if err := core.SetReceiptsData(config, block, receipts); err != nil { + if err := rawdb.SetReceiptsData(config, block.Hash(), block.Number(), block.Body(), receipts); err != nil { return nil, err } rawdb.WriteReceipts(odr.Database(), hash, number, receipts) } + return receipts, nil } @@ -157,14 +158,11 @@ func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, num // 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 := rawdb.ReadReceipts(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 + receipts, err := GetBlockReceipts(ctx, odr, hash, number) + if err != nil { + return nil, err } + // Return the logs without deriving any computed fields on the receipts logs := make([][]*types.Log, len(receipts)) for i, receipt := range receipts { |