fixed chainconfig (#1027)

This commit is contained in:
Giulio rebuffo 2020-09-01 21:44:05 +02:00 committed by GitHub
parent b47b8cb989
commit 050ef8773f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package commands
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil" "github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/core" "github.com/ledgerwatch/turbo-geth/core"
@ -12,7 +13,6 @@ import (
"github.com/ledgerwatch/turbo-geth/eth" "github.com/ledgerwatch/turbo-geth/eth"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages" "github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
"github.com/ledgerwatch/turbo-geth/ethdb" "github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/params"
"github.com/ledgerwatch/turbo-geth/rpc" "github.com/ledgerwatch/turbo-geth/rpc"
"github.com/ledgerwatch/turbo-geth/turbo/adapter" "github.com/ledgerwatch/turbo-geth/turbo/adapter"
"github.com/ledgerwatch/turbo-geth/turbo/transactions" "github.com/ledgerwatch/turbo-geth/turbo/transactions"
@ -46,7 +46,9 @@ func NewPrivateDebugAPI(db ethdb.KV, dbReader ethdb.Getter) *PrivateDebugAPIImpl
func (api *PrivateDebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex uint64, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) { func (api *PrivateDebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash common.Hash, txIndex uint64, contractAddress common.Address, keyStart hexutil.Bytes, maxResult int) (StorageRangeResult, error) {
bc := adapter.NewBlockGetter(api.dbReader) bc := adapter.NewBlockGetter(api.dbReader)
cc := adapter.NewChainContext(api.dbReader) cc := adapter.NewChainContext(api.dbReader)
_, _, _, stateReader, err := transactions.ComputeTxEnv(ctx, bc, params.MainnetChainConfig, cc, api.db, blockHash, txIndex) genesisHash := rawdb.ReadBlockByNumber(api.dbReader, 0).Hash()
chainConfig := rawdb.ReadChainConfig(api.dbReader, genesisHash)
_, _, _, stateReader, err := transactions.ComputeTxEnv(ctx, bc, chainConfig, cc, api.db, blockHash, txIndex)
if err != nil { if err != nil {
return StorageRangeResult{}, err return StorageRangeResult{}, err
} }

View File

@ -3,6 +3,7 @@ package commands
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/ledgerwatch/turbo-geth/turbo/adapter" "github.com/ledgerwatch/turbo-geth/turbo/adapter"
"github.com/ledgerwatch/turbo-geth/turbo/transactions" "github.com/ledgerwatch/turbo-geth/turbo/transactions"
@ -29,7 +30,9 @@ func GetReceipts(ctx context.Context, db rawdb.DatabaseReader, cfg *params.Chain
cc := adapter.NewChainContext(db) cc := adapter.NewChainContext(db)
bc := adapter.NewBlockGetter(db) bc := adapter.NewBlockGetter(db)
_, _, ibs, dbstate, err := transactions.ComputeTxEnv(ctx, bc, params.MainnetChainConfig, cc, db.(ethdb.HasKV).KV(), hash, 0) genesisHash := rawdb.ReadBlockByNumber(db, 0).Hash()
chainConfig := rawdb.ReadChainConfig(db, genesisHash)
_, _, ibs, dbstate, err := transactions.ComputeTxEnv(ctx, bc, chainConfig, cc, db.(ethdb.HasKV).KV(), hash, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -41,7 +44,7 @@ func GetReceipts(ctx context.Context, db rawdb.DatabaseReader, cfg *params.Chain
ibs.Prepare(tx.Hash(), block.Hash(), i) ibs.Prepare(tx.Hash(), block.Hash(), i)
header := rawdb.ReadHeader(db, hash, *number) header := rawdb.ReadHeader(db, hash, *number)
receipt, err := core.ApplyTransaction(params.MainnetChainConfig, cc, nil, gp, ibs, dbstate, header, tx, usedGas, vm.Config{}) receipt, err := core.ApplyTransaction(chainConfig, cc, nil, gp, ibs, dbstate, header, tx, usedGas, vm.Config{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,8 +59,10 @@ func (api *APIImpl) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.L
if number == nil { if number == nil {
return nil, fmt.Errorf("block not found: %x", hash) return nil, fmt.Errorf("block not found: %x", hash)
} }
genesisHash := rawdb.ReadBlockByNumber(api.dbReader, 0).Hash()
chainConfig := rawdb.ReadChainConfig(api.dbReader, genesisHash)
receipts, err := GetReceipts(ctx, api.dbReader, params.MainnetChainConfig, hash) receipts, err := GetReceipts(ctx, api.dbReader, chainConfig, hash)
if err != nil { if err != nil {
return nil, fmt.Errorf("getReceipt error: %v", err) return nil, fmt.Errorf("getReceipt error: %v", err)
} }
@ -75,7 +80,10 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, hash common.Hash)
return nil, fmt.Errorf("transaction %#x not found", hash) return nil, fmt.Errorf("transaction %#x not found", hash)
} }
receipts, err := GetReceipts(ctx, api.dbReader, params.MainnetChainConfig, blockHash) genesisHash := rawdb.ReadBlockByNumber(api.dbReader, 0).Hash()
chainConfig := rawdb.ReadChainConfig(api.dbReader, genesisHash)
receipts, err := GetReceipts(ctx, api.dbReader, chainConfig, blockHash)
if err != nil { if err != nil {
return nil, fmt.Errorf("getReceipt error: %v", err) return nil, fmt.Errorf("getReceipt error: %v", err)
} }