diff --git a/chain/eth_transaction_hash_lookup.go b/chain/ethhashlookup/eth_transaction_hash_lookup.go similarity index 86% rename from chain/eth_transaction_hash_lookup.go rename to chain/ethhashlookup/eth_transaction_hash_lookup.go index a7debc5a6..e57d050a5 100644 --- a/chain/eth_transaction_hash_lookup.go +++ b/chain/ethhashlookup/eth_transaction_hash_lookup.go @@ -1,4 +1,4 @@ -package chain +package ethhashlookup import ( "database/sql" @@ -25,12 +25,14 @@ var pragmas = []string{ } var ddls = []string{ - `CREATE TABLE IF NOT EXISTS tx_hash_lookup ( - hash TEXT PRIMARY KEY, - cid TEXT NOT NULL, + `CREATE TABLE IF NOT EXISTS eth_tx_hashes ( + hash TEXT PRIMARY KEY NOT NULL, + cid TEXT NOT NULL UNIQUE, epoch INT NOT NULL )`, + `CREATE INDEX IF NOT EXISTS eth_tx_hashes_epoch_index ON eth_tx_hashes (epoch)`, + // metadata containing version of schema `CREATE TABLE IF NOT EXISTS _meta ( version UINT64 NOT NULL UNIQUE @@ -44,7 +46,7 @@ const schemaVersion = 1 const MemPoolEpoch = math.MaxInt64 const ( - insertTxHash = `INSERT INTO tx_hash_lookup + insertTxHash = `INSERT INTO eth_tx_hashes (hash, cid, epoch) VALUES(?, ?, ?) ON CONFLICT (hash) DO UPDATE SET epoch = EXCLUDED.epoch @@ -66,7 +68,7 @@ func (ei *TransactionHashLookup) InsertTxHash(txHash ethtypes.EthHash, c cid.Cid } func (ei *TransactionHashLookup) LookupCidFromTxHash(txHash ethtypes.EthHash) (cid.Cid, error) { - q, err := ei.db.Query("SELECT cid FROM tx_hash_lookup WHERE hash = :hash;", sql.Named("hash", txHash.String())) + q, err := ei.db.Query("SELECT cid FROM eth_tx_hashes WHERE hash = :hash;", sql.Named("hash", txHash.String())) if err != nil { return cid.Undef, err } @@ -83,7 +85,7 @@ func (ei *TransactionHashLookup) LookupCidFromTxHash(txHash ethtypes.EthHash) (c } func (ei *TransactionHashLookup) LookupTxHashFromCid(c cid.Cid) (ethtypes.EthHash, error) { - q, err := ei.db.Query("SELECT hash FROM tx_hash_lookup WHERE cid = :cid;", sql.Named("cid", c.String())) + q, err := ei.db.Query("SELECT hash FROM eth_tx_hashes WHERE cid = :cid;", sql.Named("cid", c.String())) if err != nil { return ethtypes.EmptyEthHash, err } @@ -100,7 +102,7 @@ func (ei *TransactionHashLookup) LookupTxHashFromCid(c cid.Cid) (ethtypes.EthHas } func (ei *TransactionHashLookup) RemoveEntriesOlderThan(epoch abi.ChainEpoch) (int64, error) { - res, err := ei.db.Exec("DELETE FROM tx_hash_lookup WHERE epoch < :epoch;", sql.Named("epoch", epoch)) + res, err := ei.db.Exec("DELETE FROM eth_tx_hashes WHERE epoch < :epoch;", sql.Named("epoch", epoch)) if err != nil { return 0, err } diff --git a/documentation/en/default-lotus-config.toml b/documentation/en/default-lotus-config.toml index 4f2148552..0191950f5 100644 --- a/documentation/en/default-lotus-config.toml +++ b/documentation/en/default-lotus-config.toml @@ -343,11 +343,11 @@ #ActorEventDatabasePath = "" -[EthTxHashConfig] +[Fevm] # EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids # # type: bool - # env var: LOTUS_ETHTXHASHCONFIG_ENABLEETHHASHTOFILECOINCIDMAPPING - #EnableEthHashToFilecoinCidMapping = true + # env var: LOTUS_FEVM_ENABLEETHHASHTOFILECOINCIDMAPPING + #EnableEthHashToFilecoinCidMapping = false diff --git a/itests/eth_hash_lookup_test.go b/itests/eth_hash_lookup_test.go index 7188a34e4..37948c768 100644 --- a/itests/eth_hash_lookup_test.go +++ b/itests/eth_hash_lookup_test.go @@ -37,7 +37,7 @@ func TestTransactionHashLookup(t *testing.T) { defer cancel() // install contract - contractHex, err := os.ReadFile("./contracts/SimpleCoin.bin") + contractHex, err := os.ReadFile("./contracts/SimpleCoin.hex") require.NoError(t, err) contract, err := hex.DecodeString(string(contractHex)) @@ -122,7 +122,7 @@ func TestTransactionHashLookupNoDb(t *testing.T) { kit.MockProofs(), kit.ThroughRPC(), kit.WithCfgOpt(func(cfg *config.FullNode) error { - cfg.EthTxHashConfig.EnableEthHashToFilecoinCidMapping = false + cfg.Fevm.EnableEthHashToFilecoinCidMapping = false return nil }), ) @@ -132,7 +132,7 @@ func TestTransactionHashLookupNoDb(t *testing.T) { defer cancel() // install contract - contractHex, err := os.ReadFile("./contracts/SimpleCoin.bin") + contractHex, err := os.ReadFile("./contracts/SimpleCoin.hex") require.NoError(t, err) contract, err := hex.DecodeString(string(contractHex)) diff --git a/itests/fevm_test.go b/itests/fevm_test.go index af29f83a8..f6d635142 100644 --- a/itests/fevm_test.go +++ b/itests/fevm_test.go @@ -19,7 +19,7 @@ import ( "github.com/filecoin-project/lotus/itests/kit" ) -// TestFEVMBasic does a basic fevm contract installation and invocation +// TestFEVMBasic does a basic ethhash contract installation and invocation func TestFEVMBasic(t *testing.T) { // TODO the contract installation and invocation can be lifted into utility methods // He who writes the second test, shall do that. diff --git a/itests/kit/node_opts.go b/itests/kit/node_opts.go index aed6772c5..efaed8861 100644 --- a/itests/kit/node_opts.go +++ b/itests/kit/node_opts.go @@ -299,7 +299,7 @@ func HistoricFilterAPI(dbpath string) NodeOpt { func EthTxHashLookup() NodeOpt { return WithCfgOpt(func(cfg *config.FullNode) error { - cfg.EthTxHashConfig.EnableEthHashToFilecoinCidMapping = true + cfg.Fevm.EnableEthHashToFilecoinCidMapping = true return nil }) } diff --git a/node/builder_chain.go b/node/builder_chain.go index ae3c326de..221150be1 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -261,7 +261,7 @@ 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.EthTxHashConfig)), + Override(new(full.EthModuleAPI), modules.EthModuleAPI(cfg.Fevm)), ) } diff --git a/node/config/def.go b/node/config/def.go index 079023417..cc301b276 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -107,8 +107,8 @@ func DefaultFullNode() *FullNode { MaxFilterResults: 10000, MaxFilterHeightRange: 2880, // conservative limit of one day }, - EthTxHashConfig: EthTxHashConfig{ - EnableEthHashToFilecoinCidMapping: true, + Fevm: FevmConfig{ + EnableEthHashToFilecoinCidMapping: false, }, } } diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index ed60cea36..b411e8bf9 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -391,14 +391,6 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/# Comment: ``, }, }, - "EthTxHashConfig": []DocField{ - { - Name: "EnableEthHashToFilecoinCidMapping", - Type: "bool", - - Comment: `EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids`, - }, - }, "FeeConfig": []DocField{ { Name: "DefaultMaxFee", @@ -407,6 +399,14 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/# Comment: ``, }, }, + "FevmConfig": []DocField{ + { + Name: "EnableEthHashToFilecoinCidMapping", + Type: "bool", + + Comment: `EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids`, + }, + }, "FullNode": []DocField{ { Name: "Client", @@ -445,8 +445,8 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/# Comment: ``, }, { - Name: "EthTxHashConfig", - Type: "EthTxHashConfig", + Name: "Fevm", + Type: "FevmConfig", Comment: ``, }, diff --git a/node/config/types.go b/node/config/types.go index 9d9634570..c64f14a5d 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -22,13 +22,13 @@ type Common struct { // FullNode is a full node config type FullNode struct { Common - Client Client - Wallet Wallet - Fees FeeConfig - Chainstore Chainstore - Cluster UserRaftConfig - ActorEvent ActorEventConfig - EthTxHashConfig EthTxHashConfig + Client Client + Wallet Wallet + Fees FeeConfig + Chainstore Chainstore + Cluster UserRaftConfig + ActorEvent ActorEventConfig + Fevm FevmConfig } // // Common @@ -694,7 +694,7 @@ type ActorEventConfig struct { // Set upper bound on index size } -type EthTxHashConfig struct { +type FevmConfig struct { // EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids EnableEthHashToFilecoinCidMapping bool } diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 5d696993e..05c949f0d 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -25,9 +25,9 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/actors" builtinactors "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/ethhashlookup" "github.com/filecoin-project/lotus/chain/events/filter" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/stmgr" @@ -1760,7 +1760,7 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook return receipt, nil } -func (m EthTxHashManager) Apply(ctx context.Context, from, to *types.TipSet) error { +func (m *EthTxHashManager) Apply(ctx context.Context, from, to *types.TipSet) error { for _, blk := range to.Blocks() { _, smsgs, err := m.StateAPI.Chain.MessagesForBlock(ctx, blk) if err != nil { @@ -1789,10 +1789,10 @@ func (m EthTxHashManager) Apply(ctx context.Context, from, to *types.TipSet) err type EthTxHashManager struct { StateAPI StateAPI - TransactionHashLookup *chain.TransactionHashLookup + TransactionHashLookup *ethhashlookup.TransactionHashLookup } -func (m EthTxHashManager) Revert(ctx context.Context, from, to *types.TipSet) error { +func (m *EthTxHashManager) Revert(ctx context.Context, from, to *types.TipSet) error { return nil } @@ -1814,7 +1814,7 @@ func WaitForMpoolUpdates(ctx context.Context, ch <-chan api.MpoolUpdate, manager log.Errorf("error converting filecoin message to eth tx: %s", err) } - err = manager.TransactionHashLookup.InsertTxHash(ethTx.Hash, u.Message.Cid(), chain.MemPoolEpoch) + err = manager.TransactionHashLookup.InsertTxHash(ethTx.Hash, u.Message.Cid(), ethhashlookup.MemPoolEpoch) if err != nil { log.Errorf("error inserting tx mapping to db: %s", err) } diff --git a/node/modules/ethmodule.go b/node/modules/ethmodule.go index a16b7534d..9a4bcce09 100644 --- a/node/modules/ethmodule.go +++ b/node/modules/ethmodule.go @@ -6,7 +6,7 @@ import ( "go.uber.org/fx" - "github.com/filecoin-project/lotus/chain" + "github.com/filecoin-project/lotus/chain/ethhashlookup" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/stmgr" @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/lotus/node/repo" ) -func EthModuleAPI(cfg config.EthTxHashConfig) func(helpers.MetricsCtx, repo.LockedRepo, fx.Lifecycle, *store.ChainStore, *stmgr.StateManager, EventAPI, *messagepool.MessagePool, full.StateAPI, full.ChainAPI, full.MpoolAPI) (*full.EthModule, error) { +func EthModuleAPI(cfg config.FevmConfig) func(helpers.MetricsCtx, repo.LockedRepo, fx.Lifecycle, *store.ChainStore, *stmgr.StateManager, EventAPI, *messagepool.MessagePool, full.StateAPI, full.ChainAPI, full.MpoolAPI) (*full.EthModule, error) { return func(mctx helpers.MetricsCtx, r repo.LockedRepo, lc fx.Lifecycle, cs *store.ChainStore, sm *stmgr.StateManager, evapi EventAPI, mp *messagepool.MessagePool, stateapi full.StateAPI, chainapi full.ChainAPI, mpoolapi full.MpoolAPI) (*full.EthModule, error) { em := &full.EthModule{ Chain: cs, @@ -38,7 +38,7 @@ func EthModuleAPI(cfg config.EthTxHashConfig) func(helpers.MetricsCtx, repo.Lock return nil, err } - transactionHashLookup, err := chain.NewTransactionHashLookup(filepath.Join(dbPath + "txHash.db")) + transactionHashLookup, err := ethhashlookup.NewTransactionHashLookup(filepath.Join(dbPath, "txhash.db")) if err != nil { return nil, err }