Skip to content

Commit

Permalink
Fix RPC handling for full state retrieval (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun authored Nov 21, 2024
1 parent 5f8cd09 commit 26b5ad6
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 34 deletions.
12 changes: 7 additions & 5 deletions rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func nativeSpaceApis(
gashandler *handler.CfxGasStationHandler,
option ...CfxAPIOption,
) []API {
stateHandler := handler.NewCfxStateHandler(clientProvider)
return []API{
{
Namespace: "cfx",
Expand All @@ -73,12 +74,12 @@ func nativeSpaceApis(
}, {
Namespace: "pos",
Version: "1.0",
Service: &posAPI{},
Service: &posAPI{stateHandler},
Public: true,
}, {
Namespace: "trace",
Version: "1.0",
Service: &traceAPI{},
Service: &traceAPI{stateHandler},
Public: false,
}, {
Namespace: service.Namespace,
Expand All @@ -93,7 +94,7 @@ func nativeSpaceApis(
}, {
Namespace: "debug",
Version: "1.0",
Service: &cfxDebugAPI{},
Service: &cfxDebugAPI{stateHandler},
Public: false,
},
}
Expand All @@ -104,6 +105,7 @@ func evmSpaceApis(
clientProvider *node.EthClientProvider,
gashandler *handler.EthGasStationHandler,
option ...EthAPIOption) ([]API, error) {
stateHandler := handler.NewEthStateHandler(clientProvider)
return []API{
{
Namespace: "eth",
Expand All @@ -123,7 +125,7 @@ func evmSpaceApis(
}, {
Namespace: "trace",
Version: "1.0",
Service: &ethTraceAPI{},
Service: &ethTraceAPI{stateHandler},
Public: false,
}, {
Namespace: "parity",
Expand All @@ -133,7 +135,7 @@ func evmSpaceApis(
}, {
Namespace: "debug",
Version: "1.0",
Service: &ethDebugAPI{},
Service: &ethDebugAPI{stateHandler},
Public: false,
}, {
Namespace: "gasstation",
Expand Down
14 changes: 10 additions & 4 deletions rpc/cfx_debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ package rpc
import (
"context"

"github.com/Conflux-Chain/confura/rpc/handler"
"github.com/Conflux-Chain/go-conflux-sdk/types"
)

type cfxDebugAPI struct{}
type cfxDebugAPI struct {
stateHandler *handler.CfxStateHandler
}

func (api *cfxDebugAPI) GetEpochReceiptProofByTransaction(ctx context.Context, hash types.Hash) (proof *types.EpochReceiptProof, err error) {
return GetCfxClientFromContext(ctx).Debug().GetEpochReceiptProofByTransaction(hash)
cfx := GetCfxClientFromContext(ctx)
return api.stateHandler.DebugGetEpochReceiptProofByTransaction(ctx, cfx, hash)
}

func (api *cfxDebugAPI) GetTransactionsByEpoch(
ctx context.Context, epoch types.Epoch) (wrapTransactions []types.WrapTransaction, err error) {
return GetCfxClientFromContext(ctx).Debug().GetTransactionsByEpoch(epoch)
cfx := GetCfxClientFromContext(ctx)
return api.stateHandler.DebugGetTransactionsByEpoch(ctx, cfx, epoch)
}

func (api *cfxDebugAPI) GetTransactionsByBlock(ctx context.Context, hash types.Hash) (wrapTransactions []types.WrapTransaction, err error) {
return GetCfxClientFromContext(ctx).Debug().GetTransactionsByBlock(hash)
cfx := GetCfxClientFromContext(ctx)
return api.stateHandler.DebugGetTransactionsByBlock(ctx, cfx, hash)
}
17 changes: 12 additions & 5 deletions rpc/eth_debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@ package rpc
import (
"context"

"github.com/Conflux-Chain/confura/rpc/handler"
"github.com/ethereum/go-ethereum/common"
"github.com/openweb3/web3go/types"
)

type ethDebugAPI struct{}
type ethDebugAPI struct {
stateHandler *handler.EthStateHandler
}

func (api *ethDebugAPI) TraceTransaction(
ctx context.Context, txnHash common.Hash, opts ...*types.GethDebugTracingOptions) (*types.GethTrace, error) {
return GetEthClientFromContext(ctx).Debug.TraceTransaction(txnHash, opts...)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.DebugTraceTransaction(ctx, w3c, txnHash, opts...)
}

func (api *ethDebugAPI) TraceBlockByHash(
ctx context.Context, blockHash common.Hash, opts ...*types.GethDebugTracingOptions) ([]*types.GethTraceResult, error) {
return GetEthClientFromContext(ctx).Debug.TraceBlockByHash(blockHash, opts...)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.DebugTraceBlockByHash(ctx, w3c, blockHash, opts...)
}

func (api *ethDebugAPI) TraceBlockByNumber(
ctx context.Context, blockNumber types.BlockNumber, opts ...*types.GethDebugTracingOptions) ([]*types.GethTraceResult, error) {
return GetEthClientFromContext(ctx).Debug.TraceBlockByNumber(blockNumber, opts...)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.DebugTraceBlockByNumber(ctx, w3c, blockNumber, opts...)
}

func (api *ethDebugAPI) TraceCall(
ctx context.Context, request types.CallRequest, blockNumber *types.BlockNumber, opts ...*types.GethDebugTracingOptions,
) (*types.GethTrace, error) {
return GetEthClientFromContext(ctx).Debug.TraceCall(request, blockNumber, opts...)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.DebugTraceCall(ctx, w3c, request, blockNumber, opts...)
}
14 changes: 10 additions & 4 deletions rpc/eth_trace_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ package rpc
import (
"context"

"github.com/Conflux-Chain/confura/rpc/handler"
"github.com/ethereum/go-ethereum/common"
"github.com/openweb3/web3go/types"
)

// ethTraceAPI provides evm space trace RPC proxy API.
type ethTraceAPI struct{}
type ethTraceAPI struct {
stateHandler *handler.EthStateHandler
}

func (api *ethTraceAPI) Block(ctx context.Context, blockNumOrHash types.BlockNumberOrHash) ([]types.LocalizedTrace, error) {
return GetEthClientFromContext(ctx).Trace.Blocks(blockNumOrHash)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.TraceBlock(ctx, w3c, blockNumOrHash)
}

func (api *ethTraceAPI) Filter(ctx context.Context, filter types.TraceFilter) ([]types.LocalizedTrace, error) {
return GetEthClientFromContext(ctx).Trace.Filter(filter)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.TraceFilter(ctx, w3c, filter)
}

func (api *ethTraceAPI) Transaction(ctx context.Context, txHash common.Hash) ([]types.LocalizedTrace, error) {
return GetEthClientFromContext(ctx).Trace.Transactions(txHash)
w3c := GetEthClientFromContext(ctx)
return api.stateHandler.TraceTransaction(ctx, w3c, txHash)
}
Loading

0 comments on commit 26b5ad6

Please sign in to comment.