From 66f5ee4ae9a46cb56377a420bcc46cb7b3fbd24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 19 Jan 2023 18:06:59 +0100 Subject: [PATCH] config: Fevm.EnableEthPRC --- documentation/en/default-lotus-config.toml | 7 +- itests/eth_deploy_test.go | 2 +- itests/eth_filter_test.go | 2 +- itests/eth_hash_lookup_test.go | 95 ++-------------------- itests/eth_transactions_test.go | 6 +- itests/kit/node_opts.go | 4 +- node/builder_chain.go | 3 +- node/config/def.go | 4 +- node/config/doc_gen.go | 5 +- node/config/types.go | 6 +- node/impl/full/dummy.go | 62 ++++++++------ node/impl/full/eth.go | 2 +- node/modules/ethmodule.go | 5 -- 13 files changed, 64 insertions(+), 139 deletions(-) diff --git a/documentation/en/default-lotus-config.toml b/documentation/en/default-lotus-config.toml index fbdbc852c..a12dbf2ec 100644 --- a/documentation/en/default-lotus-config.toml +++ b/documentation/en/default-lotus-config.toml @@ -344,12 +344,11 @@ [Fevm] - # EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids - # You will not be able to look up ethereum transactions by their hash if this is disabled. + # EnableEthPRC enables eth_ rpc, and enables storing a mapping of eth transaction hashes to filecoin message Cids. # # type: bool - # env var: LOTUS_FEVM_ENABLEETHHASHTOFILECOINCIDMAPPING - #EnableEthHashToFilecoinCidMapping = false + # env var: LOTUS_FEVM_ENABLEETHPRC + #EnableEthPRC = false # EthTxHashMappingLifetimeDays the transaction hash lookup database will delete mappings that have been stored for more than x days # Set to 0 to keep all mappings diff --git a/itests/eth_deploy_test.go b/itests/eth_deploy_test.go index f73076d02..b5f0b647c 100644 --- a/itests/eth_deploy_test.go +++ b/itests/eth_deploy_test.go @@ -41,7 +41,7 @@ func TestDeployment(t *testing.T) { cfg.ActorEvent.EnableRealTimeFilterAPI = true return nil }), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blockTime) diff --git a/itests/eth_filter_test.go b/itests/eth_filter_test.go index 3d2d3064a..ad2034af6 100644 --- a/itests/eth_filter_test.go +++ b/itests/eth_filter_test.go @@ -204,7 +204,7 @@ func TestEthNewFilterCatchAll(t *testing.T) { kit.QuietMiningLogs() blockTime := 100 * time.Millisecond - client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.RealTimeFilterAPI(), kit.EthTxHashLookup()) + client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.RealTimeFilterAPI(), kit.EthRPC()) ens.InterconnectAll().BeginMining(blockTime) ctx, cancel := context.WithTimeout(context.Background(), time.Minute) diff --git a/itests/eth_hash_lookup_test.go b/itests/eth_hash_lookup_test.go index bad705fe1..4fe77b2bc 100644 --- a/itests/eth_hash_lookup_test.go +++ b/itests/eth_hash_lookup_test.go @@ -16,7 +16,6 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/ethtypes" "github.com/filecoin-project/lotus/itests/kit" - "github.com/filecoin-project/lotus/node/config" ) // TestTransactionHashLookup tests to see if lotus correctly stores a mapping from ethereum transaction hash to @@ -29,7 +28,7 @@ func TestTransactionHashLookup(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -112,86 +111,6 @@ func TestTransactionHashLookup(t *testing.T) { require.Equal(t, uint64(*chainTx.TransactionIndex), uint64(0)) // only transaction } -// TestTransactionHashLookupNoDb tests to see if looking up eth transactions by hash breaks without the lookup table -func TestTransactionHashLookupNoDb(t *testing.T) { - kit.QuietMiningLogs() - - blocktime := 1 * time.Second - client, _, ens := kit.EnsembleMinimal( - t, - kit.MockProofs(), - kit.ThroughRPC(), - kit.WithCfgOpt(func(cfg *config.FullNode) error { - cfg.Fevm.EnableEthHashToFilecoinCidMapping = false - return nil - }), - ) - ens.InterconnectAll().BeginMining(blocktime) - - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - - // install contract - contractHex, err := os.ReadFile("./contracts/SimpleCoin.hex") - require.NoError(t, err) - - contract, err := hex.DecodeString(string(contractHex)) - require.NoError(t, err) - - // create a new Ethereum account - key, ethAddr, deployer := client.EVM().NewAccount() - - // send some funds to the f410 address - kit.SendFunds(ctx, t, client, deployer, types.FromFil(10)) - - gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{ - From: ðAddr, - Data: contract, - }) - require.NoError(t, err) - - maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx) - require.NoError(t, err) - - // now deploy a contract from the embryo, and validate it went well - tx := ethtypes.EthTxArgs{ - ChainID: build.Eip155ChainId, - Value: big.Zero(), - Nonce: 0, - MaxFeePerGas: types.NanoFil, - MaxPriorityFeePerGas: big.Int(maxPriorityFeePerGas), - GasLimit: int(gaslimit), - Input: contract, - V: big.Zero(), - R: big.Zero(), - S: big.Zero(), - } - - client.EVM().SignTransaction(&tx, key.PrivateKey) - - rawTxHash, err := tx.TxHash() - require.NoError(t, err) - - hash := client.EVM().SubmitTransaction(ctx, &tx) - require.Equal(t, rawTxHash, hash) - - // We shouldn't be able to find the tx - mpoolTx, err := client.EthGetTransactionByHash(ctx, &hash) - require.NoError(t, err) - require.Nil(t, mpoolTx) - - // Wait for message to land on chain, we can't know exactly when because we can't find it. - time.Sleep(20 * blocktime) - receipt, err := client.EthGetTransactionReceipt(ctx, hash) - require.NoError(t, err) - require.Nil(t, receipt) - - // We still shouldn't be able to find the tx - chainTx, err := client.EthGetTransactionByHash(ctx, &hash) - require.NoError(t, err) - require.Nil(t, chainTx) -} - // TestTransactionHashLookupBlsFilecoinMessage tests to see if lotus can find a BLS Filecoin Message using the transaction hash func TestTransactionHashLookupBlsFilecoinMessage(t *testing.T) { kit.QuietMiningLogs() @@ -201,7 +120,7 @@ func TestTransactionHashLookupBlsFilecoinMessage(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -271,7 +190,7 @@ func TestTransactionHashLookupSecpFilecoinMessage(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -348,7 +267,7 @@ func TestTransactionHashLookupNonexistentMessage(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -379,7 +298,7 @@ func TestEthGetMessageCidByTransactionHashEthTx(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -476,7 +395,7 @@ func TestEthGetMessageCidByTransactionHashSecp(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) @@ -547,7 +466,7 @@ func TestEthGetMessageCidByTransactionHashBLS(t *testing.T) { t, kit.MockProofs(), kit.ThroughRPC(), - kit.EthTxHashLookup(), + kit.EthRPC(), ) ens.InterconnectAll().BeginMining(blocktime) diff --git a/itests/eth_transactions_test.go b/itests/eth_transactions_test.go index 052aae3cf..8a86a7c05 100644 --- a/itests/eth_transactions_test.go +++ b/itests/eth_transactions_test.go @@ -21,7 +21,7 @@ import ( func TestValueTransferValidSignature(t *testing.T) { blockTime := 100 * time.Millisecond - client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthTxHashLookup()) + client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthRPC()) ens.InterconnectAll().BeginMining(blockTime) @@ -106,7 +106,7 @@ func TestLegacyTransaction(t *testing.T) { func TestContractDeploymentValidSignature(t *testing.T) { blockTime := 100 * time.Millisecond - client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthTxHashLookup()) + client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthRPC()) ens.InterconnectAll().BeginMining(blockTime) @@ -167,7 +167,7 @@ func TestContractDeploymentValidSignature(t *testing.T) { func TestContractInvocation(t *testing.T) { blockTime := 100 * time.Millisecond - client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthTxHashLookup()) + client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.EthRPC()) ens.InterconnectAll().BeginMining(blockTime) diff --git a/itests/kit/node_opts.go b/itests/kit/node_opts.go index efaed8861..d093bb9c2 100644 --- a/itests/kit/node_opts.go +++ b/itests/kit/node_opts.go @@ -297,9 +297,9 @@ func HistoricFilterAPI(dbpath string) NodeOpt { }) } -func EthTxHashLookup() NodeOpt { +func EthRPC() NodeOpt { return WithCfgOpt(func(cfg *config.FullNode) error { - cfg.Fevm.EnableEthHashToFilecoinCidMapping = true + cfg.Fevm.EnableEthPRC = true return nil }) } diff --git a/node/builder_chain.go b/node/builder_chain.go index 221150be1..e13ab2c63 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -261,7 +261,8 @@ func ConfigFullNode(c interface{}) Option { // in lite-mode Eth event api is provided by gateway ApplyIf(isFullNode, Override(new(full.EthEventAPI), modules.EthEventAPI(cfg.ActorEvent))), - Override(new(full.EthModuleAPI), modules.EthModuleAPI(cfg.Fevm)), + If(cfg.Fevm.EnableEthPRC, Override(new(full.EthModuleAPI), modules.EthModuleAPI(cfg.Fevm))), + If(!cfg.Fevm.EnableEthPRC, Override(new(full.EthModuleAPI), &full.EthModuleDummy{})), ) } diff --git a/node/config/def.go b/node/config/def.go index 12efc408f..c170462f8 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -108,8 +108,8 @@ func DefaultFullNode() *FullNode { MaxFilterHeightRange: 2880, // conservative limit of one day }, Fevm: FevmConfig{ - EnableEthHashToFilecoinCidMapping: false, - EthTxHashMappingLifetimeDays: 0, + EnableEthPRC: false, + EthTxHashMappingLifetimeDays: 0, }, } } diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index c4cf08471..b52f7294f 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -401,11 +401,10 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/# }, "FevmConfig": []DocField{ { - Name: "EnableEthHashToFilecoinCidMapping", + Name: "EnableEthPRC", Type: "bool", - Comment: `EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids -You will not be able to look up ethereum transactions by their hash if this is disabled.`, + Comment: `EnableEthPRC enables eth_ rpc, and enables storing a mapping of eth transaction hashes to filecoin message Cids.`, }, { Name: "EthTxHashMappingLifetimeDays", diff --git a/node/config/types.go b/node/config/types.go index 38671929d..018d8838c 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -695,9 +695,9 @@ type ActorEventConfig struct { } type FevmConfig struct { - // EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids - // You will not be able to look up ethereum transactions by their hash if this is disabled. - EnableEthHashToFilecoinCidMapping bool + // EnableEthPRC enables eth_ rpc, and enables storing a mapping of eth transaction hashes to filecoin message Cids. + EnableEthPRC bool + // EthTxHashMappingLifetimeDays the transaction hash lookup database will delete mappings that have been stored for more than x days // Set to 0 to keep all mappings EthTxHashMappingLifetimeDays int diff --git a/node/impl/full/dummy.go b/node/impl/full/dummy.go index 865e14c9a..3a75e6637 100644 --- a/node/impl/full/dummy.go +++ b/node/impl/full/dummy.go @@ -4,106 +4,118 @@ import ( "context" "errors" + "github.com/ipfs/go-cid" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types/ethtypes" ) -var ErrImplementMe = errors.New("Not implemented yet") +var ErrModuleDisabled = errors.New("module disabled, enable with Fevm.EnableEthPRC / LOTUS_FEVM_ENABLEETHPRC") type EthModuleDummy struct{} +func (e *EthModuleDummy) EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error) { + return nil, ErrModuleDisabled +} + +func (e *EthModuleDummy) EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error) { + return nil, ErrModuleDisabled +} + func (e *EthModuleDummy) EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthAccounts(ctx context.Context) ([]ethtypes.EthAddress, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthGetBlockTransactionCountByNumber(ctx context.Context, blkNum ethtypes.EthUint64) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthGetBlockByHash(ctx context.Context, blkHash ethtypes.EthHash, fullTxInfo bool) (ethtypes.EthBlock, error) { - return ethtypes.EthBlock{}, ErrImplementMe + return ethtypes.EthBlock{}, ErrModuleDisabled } func (e *EthModuleDummy) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error) { - return ethtypes.EthBlock{}, ErrImplementMe + return ethtypes.EthBlock{}, ErrModuleDisabled } func (e *EthModuleDummy) EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkOpt string) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthGetTransactionReceipt(ctx context.Context, txHash ethtypes.EthHash) (*api.EthTxReceipt, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash ethtypes.EthHash, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error) { - return ethtypes.EthTx{}, ErrImplementMe + return ethtypes.EthTx{}, ErrModuleDisabled } func (e *EthModuleDummy) EthGetTransactionByBlockNumberAndIndex(ctx context.Context, blkNum ethtypes.EthUint64, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error) { - return ethtypes.EthTx{}, ErrImplementMe + return ethtypes.EthTx{}, ErrModuleDisabled } func (e *EthModuleDummy) EthGetCode(ctx context.Context, address ethtypes.EthAddress, blkOpt string) (ethtypes.EthBytes, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthGetStorageAt(ctx context.Context, address ethtypes.EthAddress, position ethtypes.EthBytes, blkParam string) (ethtypes.EthBytes, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthGetBalance(ctx context.Context, address ethtypes.EthAddress, blkParam string) (ethtypes.EthBigInt, error) { - return ethtypes.EthBigIntZero, ErrImplementMe + return ethtypes.EthBigIntZero, ErrModuleDisabled } func (e *EthModuleDummy) EthFeeHistory(ctx context.Context, blkCount ethtypes.EthUint64, newestBlk string, rewardPercentiles []float64) (ethtypes.EthFeeHistory, error) { - return ethtypes.EthFeeHistory{}, ErrImplementMe + return ethtypes.EthFeeHistory{}, ErrModuleDisabled } func (e *EthModuleDummy) EthChainId(ctx context.Context) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) NetVersion(ctx context.Context) (string, error) { - return "", ErrImplementMe + return "", ErrModuleDisabled } func (e *EthModuleDummy) NetListening(ctx context.Context) (bool, error) { - return false, ErrImplementMe + return false, ErrModuleDisabled } func (e *EthModuleDummy) EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error) { - return ethtypes.EthBigIntZero, ErrImplementMe + return ethtypes.EthBigIntZero, ErrModuleDisabled } func (e *EthModuleDummy) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error) { - return 0, ErrImplementMe + return 0, ErrModuleDisabled } func (e *EthModuleDummy) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam string) (ethtypes.EthBytes, error) { - return nil, ErrImplementMe + return nil, ErrModuleDisabled } func (e *EthModuleDummy) EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error) { - return ethtypes.EthBigIntZero, ErrImplementMe + return ethtypes.EthBigIntZero, ErrModuleDisabled } func (e *EthModuleDummy) EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error) { - return ethtypes.EthHash{}, ErrImplementMe + return ethtypes.EthHash{}, ErrModuleDisabled } + +var _ EthModuleAPI = &EthModuleDummy{} diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 755aacba1..8c0b43578 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -258,7 +258,7 @@ func (a *EthModule) EthGetTransactionByHash(ctx context.Context, txHash *ethtype } c := cid.Undef - if a.EthTxHashManager != nil { + if a.EthTxHashManager != nil { // todo rm checks var err error c, err = a.EthTxHashManager.TransactionHashLookup.GetCidFromHash(*txHash) if err != nil { diff --git a/node/modules/ethmodule.go b/node/modules/ethmodule.go index 904d09421..e90775b54 100644 --- a/node/modules/ethmodule.go +++ b/node/modules/ethmodule.go @@ -28,11 +28,6 @@ func EthModuleAPI(cfg config.FevmConfig) func(helpers.MetricsCtx, repo.LockedRep StateAPI: stateapi, } - if !cfg.EnableEthHashToFilecoinCidMapping { - // mapping functionality disabled. Nothing to do here - return em, nil - } - dbPath, err := r.SqlitePath() if err != nil { return nil, err