Skip to content

Commit

Permalink
fixup! chore(eth): refactor eth API module into separate pieces in ne…
Browse files Browse the repository at this point in the history
…w pkg
  • Loading branch information
rvagg committed Dec 20, 2024
1 parent d169446 commit 3f16e1b
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 236 deletions.
56 changes: 29 additions & 27 deletions node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,16 @@ var ChainNode = Options(
Override(new(full.StateModuleAPI), From(new(api.Gateway))),
Override(new(stmgr.StateManagerAPI), rpcstmgr.NewRPCStateManager),
Override(new(full.ActorEventAPI), From(new(api.Gateway))),
Override(new(eth.EthFilecoin), From(new(api.Gateway))),
Override(new(eth.EthBasic), From(new(api.Gateway))),
Override(new(eth.EthEvents), From(new(api.Gateway))),
Override(new(eth.EthTransaction), From(new(api.Gateway))),
Override(new(eth.EthLookup), From(new(api.Gateway))),
Override(new(eth.EthTrace), From(new(api.Gateway))),
Override(new(eth.EthGas), From(new(api.Gateway))),
Override(new(eth.EthSend), new(modules.GatewayEthSend)),
Override(new(eth.EthFilecoinAPI), From(new(api.Gateway))),
Override(new(eth.EthBasicAPI), From(new(api.Gateway))),
Override(new(eth.EthEventsAPI), From(new(api.Gateway))),
Override(new(eth.EthTransactionAPI), From(new(api.Gateway))),
Override(new(eth.EthLookupAPI), From(new(api.Gateway))),
Override(new(eth.EthTraceAPI), From(new(api.Gateway))),
Override(new(eth.EthGasAPI), From(new(api.Gateway))),
// EthSendAPI is a special case, we block the Untrusted method via GatewayEthSend even though it
// shouldn't be exposed on the Gateway API.
Override(new(eth.EthSendAPI), new(modules.GatewayEthSend)),

Override(new(index.Indexer), modules.ChainIndexer(config.ChainIndexerConfig{
EnableIndexer: false,
Expand Down Expand Up @@ -277,34 +279,34 @@ func ConfigFullNode(c interface{}) Option {
Override(new(*filter.EventFilterManager), modules.MakeEventFilterManager(cfg.Events)),
),

Override(new(eth.ChainStoreAPI), From(new(*store.ChainStore))),
Override(new(eth.StateManagerAPI), From(new(*stmgr.StateManager))),
Override(new(eth.EthFilecoin), eth.NewEthFilecoin),
Override(new(eth.ChainStore), From(new(*store.ChainStore))),
Override(new(eth.StateManager), From(new(*stmgr.StateManager))),
Override(new(eth.EthFilecoinAPI), eth.NewEthFilecoinAPI),

If(cfg.Fevm.EnableEthRPC,
Override(new(eth.StateAPI), From(new(full.StateAPI))),
Override(new(eth.SyncAPI), From(new(full.SyncAPI))),
Override(new(eth.MpoolAPI), From(new(full.MpoolAPI))),
Override(new(eth.MessagePoolAPI), From(new(*messagepool.MessagePool))),
Override(new(eth.MessagePool), From(new(*messagepool.MessagePool))),
Override(new(eth.GasAPI), From(new(full.GasModule))),

Override(new(eth.EthBasic), eth.NewEthBasic),
Override(new(eth.EthEventsExtended), modules.MakeEthEventsExtended(cfg.Events, cfg.Fevm.EnableEthRPC)),
Override(new(eth.EthEvents), From(new(eth.EthEventsExtended))),
Override(new(eth.EthTransaction), modules.MakeEthTransaction(cfg.Fevm)),
Override(new(eth.EthLookup), eth.NewEthLookup),
Override(new(eth.EthTrace), modules.MakeEthTrace(cfg.Fevm)),
Override(new(eth.EthGas), eth.NewEthGas),
Override(new(eth.EthSend), eth.NewEthSend),
Override(new(eth.EthBasicAPI), eth.NewEthBasicAPI),
Override(new(eth.EthEventsInternal), modules.MakeEthEventsExtended(cfg.Events, cfg.Fevm.EnableEthRPC)),
Override(new(eth.EthEventsAPI), From(new(eth.EthEventsInternal))),
Override(new(eth.EthTransactionAPI), modules.MakeEthTransaction(cfg.Fevm)),
Override(new(eth.EthLookupAPI), eth.NewEthLookupAPI),
Override(new(eth.EthTraceAPI), modules.MakeEthTrace(cfg.Fevm)),
Override(new(eth.EthGasAPI), eth.NewEthGasAPI),
Override(new(eth.EthSendAPI), eth.NewEthSendAPI),
),
If(!cfg.Fevm.EnableEthRPC,
Override(new(eth.EthBasic), &eth.EthBasicDisabled{}),
Override(new(eth.EthTransaction), &eth.EthTransactionDisabled{}),
Override(new(eth.EthLookup), &eth.EthLookupDisabled{}),
Override(new(eth.EthTrace), &eth.EthTraceDisabled{}),
Override(new(eth.EthGas), &eth.EthGasDisabled{}),
Override(new(eth.EthEvents), &eth.EthEventsDisabled{}),
Override(new(eth.EthSend), &eth.EthSendDisabled{}),
Override(new(eth.EthBasicAPI), &eth.EthBasicDisabled{}),
Override(new(eth.EthTransactionAPI), &eth.EthTransactionDisabled{}),
Override(new(eth.EthLookupAPI), &eth.EthLookupDisabled{}),
Override(new(eth.EthTraceAPI), &eth.EthTraceDisabled{}),
Override(new(eth.EthGasAPI), &eth.EthGasDisabled{}),
Override(new(eth.EthEventsAPI), &eth.EthEventsDisabled{}),
Override(new(eth.EthSendAPI), &eth.EthSendDisabled{}),
),

If(cfg.Events.EnableActorEventsAPI,
Expand Down
16 changes: 8 additions & 8 deletions node/impl/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ var (
ErrModuleDisabled = xerrors.New("module disabled, enable with Fevm.EnableEthRPC / LOTUS_FEVM_ENABLEETHRPC")
)

var log = logging.Logger("fullnode/eth")
var log = logging.Logger("node/eth")

// SyncAPI is a minimal version of full.SyncAPI
type SyncAPI interface {
SyncState(ctx context.Context) (*api.SyncState, error)
}

// ChainStoreAPI is a minimal version of store.ChainStoreAPI just for tipsets
type ChainStoreAPI interface {
// ChainStore is a minimal version of store.ChainStore just for tipsets
type ChainStore interface {
// TipSets
GetHeaviestTipSet() *types.TipSet
GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, ts *types.TipSet, prev bool) (*types.TipSet, error)
Expand All @@ -55,8 +55,8 @@ type StateAPI interface {
StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error)
}

// StateManagerAPI is a minimal version of stmgr.StateManagerAPI
type StateManagerAPI interface {
// StateManager is a minimal version of stmgr.StateManager
type StateManager interface {
GetNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version

TipSetState(ctx context.Context, ts *types.TipSet) (cid.Cid, cid.Cid, error)
Expand All @@ -76,16 +76,16 @@ type StateManagerAPI interface {
HasExpensiveForkBetween(parent, height abi.ChainEpoch) bool
}

// MpoolAPI is a minimal version of MpoolAPI
// MpoolAPI is a minimal version of full.MpoolAPI
type MpoolAPI interface {
MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error)
MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error)
MpoolPushUntrusted(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error)
MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error)
}

// MessagePoolAPI is a minimal version of messagepool.MessagePool
type MessagePoolAPI interface {
// MessagePool is a minimal version of messagepool.MessagePool
type MessagePool interface {
PendingFor(ctx context.Context, a address.Address) ([]*types.SignedMessage, *types.TipSet)
GetConfig() *types.MpoolConfig
}
Expand Down
22 changes: 9 additions & 13 deletions node/impl/eth/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/filecoin-project/lotus/chain/types/ethtypes"
)

type EthBasic interface {
type EthBasicAPI interface {
Web3ClientVersion(ctx context.Context) (string, error)
EthChainId(ctx context.Context) (ethtypes.EthUint64, error)
NetVersion(ctx context.Context) (string, error)
Expand All @@ -23,24 +23,20 @@ type EthBasic interface {
}

var (
_ EthBasic = (*ethBasic)(nil)
_ EthBasic = (*EthBasicDisabled)(nil)
_ EthBasicAPI = (*ethBasic)(nil)
_ EthBasicAPI = (*EthBasicDisabled)(nil)
)

type ethBasic struct {
chainStore ChainStoreAPI
syncAPI SyncAPI
stateManager StateManagerAPI
chainStore ChainStore
syncApi SyncAPI
stateManager StateManager
}

func NewEthBasic(
chainStore ChainStoreAPI,
syncAPI SyncAPI,
stateManager StateManagerAPI,
) EthBasic {
func NewEthBasicAPI(chainStore ChainStore, syncApi SyncAPI, stateManager StateManager) EthBasicAPI {
return &ethBasic{
chainStore: chainStore,
syncAPI: syncAPI,
syncApi: syncApi,
stateManager: stateManager,
}
}
Expand All @@ -67,7 +63,7 @@ func (e *ethBasic) EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64,
}

func (e *ethBasic) EthSyncing(ctx context.Context) (ethtypes.EthSyncingResult, error) {
state, err := e.syncAPI.SyncState(ctx)
state, err := e.syncApi.SyncState(ctx)
if err != nil {
return ethtypes.EthSyncingResult{}, xerrors.Errorf("failed calling SyncState: %w", err)
}
Expand Down
46 changes: 23 additions & 23 deletions node/impl/eth/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
EthSubscribeEventTypePendingTransactions = "newPendingTransactions"
)

type EthEvents interface {
type EthEventsAPI interface {
EthGetLogs(ctx context.Context, filter *ethtypes.EthFilterSpec) (*ethtypes.EthFilterResult, error)
EthNewBlockFilter(ctx context.Context) (ethtypes.EthFilterID, error)
EthNewPendingTransactionFilter(ctx context.Context) (ethtypes.EthFilterID, error)
Expand All @@ -40,10 +40,10 @@ type EthEvents interface {
EthUnsubscribe(ctx context.Context, id ethtypes.EthSubscriptionID) (bool, error)
}

// EthEventsExtended extends the EthEvents interface with additional methods that are not exposed
// EthEventsInternal extends the EthEvents interface with additional methods that are not exposed
// on the JSON-RPC API.
type EthEventsExtended interface {
EthEvents
type EthEventsInternal interface {
EthEventsAPI

// GetEthLogsForBlockAndTransaction returns the logs for a block and transaction, it is intended
// for internal use rather than being exposed via the JSON-RPC API.
Expand All @@ -54,9 +54,9 @@ type EthEventsExtended interface {
}

var (
_ EthEvents = (*ethEvents)(nil)
_ EthEventsExtended = (*ethEvents)(nil)
_ EthEvents = (*EthEventsDisabled)(nil)
_ EthEventsAPI = (*ethEvents)(nil)
_ EthEventsInternal = (*ethEvents)(nil)
_ EthEventsAPI = (*EthEventsDisabled)(nil)
)

type filterEventCollector interface {
Expand All @@ -72,9 +72,9 @@ type filterTipSetCollector interface {
}

type ethEvents struct {
subscribtionCtx context.Context
chainStore ChainStoreAPI
stateManager StateManagerAPI
subscriptionCtx context.Context
chainStore ChainStore
stateManager StateManager
chainIndexer index.Indexer
eventFilterManager *filter.EventFilterManager
tipSetFilterManager *filter.TipSetFilterManager
Expand All @@ -84,20 +84,20 @@ type ethEvents struct {
maxFilterHeightRange abi.ChainEpoch
}

func NewEthEvents(
subscribtionCtx context.Context,
chainStore ChainStoreAPI,
stateManager StateManagerAPI,
func NewEthEventsAPI(
subscriptionCtx context.Context,
chainStore ChainStore,
stateManager StateManager,
chainIndexer index.Indexer,
eventFilterManager *filter.EventFilterManager,
tipSetFilterManager *filter.TipSetFilterManager,
memPoolFilterManager *filter.MemPoolFilterManager,
filterStore filter.FilterStore,
subscriptionManager *EthSubscriptionManager,
maxFilterHeightRange abi.ChainEpoch,
) EthEventsExtended {
) EthEventsInternal {
return &ethEvents{
subscribtionCtx: subscribtionCtx,
subscriptionCtx: subscriptionCtx,
chainStore: chainStore,
stateManager: stateManager,
chainIndexer: chainIndexer,
Expand Down Expand Up @@ -266,7 +266,7 @@ func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (etht
return ethtypes.EthSubscriptionID{}, xerrors.New("connection doesn't support callbacks")
}

sub, err := e.subscriptionManager.StartSubscription(e.subscribtionCtx, ethCb.EthSubscription, e.uninstallFilter)
sub, err := e.subscriptionManager.StartSubscription(e.subscriptionCtx, ethCb.EthSubscription, e.uninstallFilter)
if err != nil {
return ethtypes.EthSubscriptionID{}, err
}
Expand All @@ -279,7 +279,7 @@ func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (etht
_, _ = e.EthUnsubscribe(ctx, sub.id)
return ethtypes.EthSubscriptionID{}, err
}
sub.addFilter(ctx, f)
sub.addFilter(f)

case EthSubscribeEventTypeLogs:
keys := map[string][][]byte{}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (etht
_, _ = e.EthUnsubscribe(ctx, sub.id)
return ethtypes.EthSubscriptionID{}, err
}
sub.addFilter(ctx, f)
sub.addFilter(f)
case EthSubscribeEventTypePendingTransactions:
f, err := e.memPoolFilterManager.Install(ctx)
if err != nil {
Expand All @@ -319,7 +319,7 @@ func (e *ethEvents) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (etht
return ethtypes.EthSubscriptionID{}, err
}

sub.addFilter(ctx, f)
sub.addFilter(f)
default:
return ethtypes.EthSubscriptionID{}, xerrors.Errorf("unsupported event type: %s", params.EventType)
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func (e *ethEvents) ethGetEventsForFilter(ctx context.Context, filterSpec *ethty
return ces, nil
}

func ethFilterResultFromEvents(ctx context.Context, evs []*index.CollectedEvent, cs ChainStoreAPI, sa StateManagerAPI) (*ethtypes.EthFilterResult, error) {
func ethFilterResultFromEvents(ctx context.Context, evs []*index.CollectedEvent, cs ChainStore, sa StateManager) (*ethtypes.EthFilterResult, error) {
logs, err := ethFilterLogsFromEvents(ctx, evs, cs, sa)
if err != nil {
return nil, err
Expand Down Expand Up @@ -478,7 +478,7 @@ func ethFilterResultFromMessages(cs []*types.SignedMessage) (*ethtypes.EthFilter
return res, nil
}

func ethFilterLogsFromEvents(ctx context.Context, evs []*index.CollectedEvent, cs ChainStoreAPI, sa StateManagerAPI) ([]ethtypes.EthLog, error) {
func ethFilterLogsFromEvents(ctx context.Context, evs []*index.CollectedEvent, cs ChainStore, sa StateManager) ([]ethtypes.EthLog, error) {
var logs []ethtypes.EthLog
for _, ev := range evs {
log := ethtypes.EthLog{
Expand Down Expand Up @@ -588,7 +588,7 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes
return data, topics, true
}

func ethTxHashFromMessageCid(ctx context.Context, c cid.Cid, cs ChainStoreAPI) (ethtypes.EthHash, error) {
func ethTxHashFromMessageCid(ctx context.Context, c cid.Cid, cs ChainStore) (ethtypes.EthHash, error) {
smsg, err := cs.GetSignedMessage(ctx, c)
if err == nil {
// This is an Eth Tx, Secp message, Or BLS message in the mpool
Expand Down
13 changes: 5 additions & 8 deletions node/impl/eth/filecoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ import (
"github.com/filecoin-project/lotus/chain/types/ethtypes"
)

type EthFilecoin interface {
type EthFilecoinAPI interface {
EthAddressToFilecoinAddress(ctx context.Context, ethAddress ethtypes.EthAddress) (address.Address, error)
FilecoinAddressToEthAddress(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthAddress, error)
}

var _ EthFilecoin = (*ethFilecoin)(nil)
var _ EthFilecoinAPI = (*ethFilecoin)(nil)

type ethFilecoin struct {
chainStore ChainStoreAPI
stateManager StateManagerAPI
chainStore ChainStore
stateManager StateManager
}

func NewEthFilecoin(
chainStore ChainStoreAPI,
stateManager StateManagerAPI,
) EthFilecoin {
func NewEthFilecoinAPI(chainStore ChainStore, stateManager StateManager) EthFilecoinAPI {
return &ethFilecoin{
chainStore: chainStore,
stateManager: stateManager,
Expand Down
Loading

0 comments on commit 3f16e1b

Please sign in to comment.