review fixes

This commit is contained in:
Geoff Stuart 2023-01-13 11:49:01 -05:00
parent a8436074a6
commit f8dee0983a
11 changed files with 47 additions and 45 deletions

View File

@ -1,4 +1,4 @@
package chain package ethhashlookup
import ( import (
"database/sql" "database/sql"
@ -25,12 +25,14 @@ var pragmas = []string{
} }
var ddls = []string{ var ddls = []string{
`CREATE TABLE IF NOT EXISTS tx_hash_lookup ( `CREATE TABLE IF NOT EXISTS eth_tx_hashes (
hash TEXT PRIMARY KEY, hash TEXT PRIMARY KEY NOT NULL,
cid TEXT NOT NULL, cid TEXT NOT NULL UNIQUE,
epoch INT NOT NULL epoch INT NOT NULL
)`, )`,
`CREATE INDEX IF NOT EXISTS eth_tx_hashes_epoch_index ON eth_tx_hashes (epoch)`,
// metadata containing version of schema // metadata containing version of schema
`CREATE TABLE IF NOT EXISTS _meta ( `CREATE TABLE IF NOT EXISTS _meta (
version UINT64 NOT NULL UNIQUE version UINT64 NOT NULL UNIQUE
@ -44,7 +46,7 @@ const schemaVersion = 1
const MemPoolEpoch = math.MaxInt64 const MemPoolEpoch = math.MaxInt64
const ( const (
insertTxHash = `INSERT INTO tx_hash_lookup insertTxHash = `INSERT INTO eth_tx_hashes
(hash, cid, epoch) (hash, cid, epoch)
VALUES(?, ?, ?) VALUES(?, ?, ?)
ON CONFLICT (hash) DO UPDATE SET epoch = EXCLUDED.epoch 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) { 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 { if err != nil {
return cid.Undef, err 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) { 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 { if err != nil {
return ethtypes.EmptyEthHash, err 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) { 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 { if err != nil {
return 0, err return 0, err
} }

View File

@ -343,11 +343,11 @@
#ActorEventDatabasePath = "" #ActorEventDatabasePath = ""
[EthTxHashConfig] [Fevm]
# EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids # EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids
# #
# type: bool # type: bool
# env var: LOTUS_ETHTXHASHCONFIG_ENABLEETHHASHTOFILECOINCIDMAPPING # env var: LOTUS_FEVM_ENABLEETHHASHTOFILECOINCIDMAPPING
#EnableEthHashToFilecoinCidMapping = true #EnableEthHashToFilecoinCidMapping = false

View File

@ -37,7 +37,7 @@ func TestTransactionHashLookup(t *testing.T) {
defer cancel() defer cancel()
// install contract // install contract
contractHex, err := os.ReadFile("./contracts/SimpleCoin.bin") contractHex, err := os.ReadFile("./contracts/SimpleCoin.hex")
require.NoError(t, err) require.NoError(t, err)
contract, err := hex.DecodeString(string(contractHex)) contract, err := hex.DecodeString(string(contractHex))
@ -122,7 +122,7 @@ func TestTransactionHashLookupNoDb(t *testing.T) {
kit.MockProofs(), kit.MockProofs(),
kit.ThroughRPC(), kit.ThroughRPC(),
kit.WithCfgOpt(func(cfg *config.FullNode) error { kit.WithCfgOpt(func(cfg *config.FullNode) error {
cfg.EthTxHashConfig.EnableEthHashToFilecoinCidMapping = false cfg.Fevm.EnableEthHashToFilecoinCidMapping = false
return nil return nil
}), }),
) )
@ -132,7 +132,7 @@ func TestTransactionHashLookupNoDb(t *testing.T) {
defer cancel() defer cancel()
// install contract // install contract
contractHex, err := os.ReadFile("./contracts/SimpleCoin.bin") contractHex, err := os.ReadFile("./contracts/SimpleCoin.hex")
require.NoError(t, err) require.NoError(t, err)
contract, err := hex.DecodeString(string(contractHex)) contract, err := hex.DecodeString(string(contractHex))

View File

@ -19,7 +19,7 @@ import (
"github.com/filecoin-project/lotus/itests/kit" "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) { func TestFEVMBasic(t *testing.T) {
// TODO the contract installation and invocation can be lifted into utility methods // TODO the contract installation and invocation can be lifted into utility methods
// He who writes the second test, shall do that. // He who writes the second test, shall do that.

View File

@ -299,7 +299,7 @@ func HistoricFilterAPI(dbpath string) NodeOpt {
func EthTxHashLookup() NodeOpt { func EthTxHashLookup() NodeOpt {
return WithCfgOpt(func(cfg *config.FullNode) error { return WithCfgOpt(func(cfg *config.FullNode) error {
cfg.EthTxHashConfig.EnableEthHashToFilecoinCidMapping = true cfg.Fevm.EnableEthHashToFilecoinCidMapping = true
return nil return nil
}) })
} }

View File

@ -261,7 +261,7 @@ func ConfigFullNode(c interface{}) Option {
// in lite-mode Eth event api is provided by gateway // in lite-mode Eth event api is provided by gateway
ApplyIf(isFullNode, Override(new(full.EthEventAPI), modules.EthEventAPI(cfg.ActorEvent))), 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)),
) )
} }

View File

@ -107,8 +107,8 @@ func DefaultFullNode() *FullNode {
MaxFilterResults: 10000, MaxFilterResults: 10000,
MaxFilterHeightRange: 2880, // conservative limit of one day MaxFilterHeightRange: 2880, // conservative limit of one day
}, },
EthTxHashConfig: EthTxHashConfig{ Fevm: FevmConfig{
EnableEthHashToFilecoinCidMapping: true, EnableEthHashToFilecoinCidMapping: false,
}, },
} }
} }

View File

@ -391,14 +391,6 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/#
Comment: ``, Comment: ``,
}, },
}, },
"EthTxHashConfig": []DocField{
{
Name: "EnableEthHashToFilecoinCidMapping",
Type: "bool",
Comment: `EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids`,
},
},
"FeeConfig": []DocField{ "FeeConfig": []DocField{
{ {
Name: "DefaultMaxFee", Name: "DefaultMaxFee",
@ -407,6 +399,14 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/#
Comment: ``, Comment: ``,
}, },
}, },
"FevmConfig": []DocField{
{
Name: "EnableEthHashToFilecoinCidMapping",
Type: "bool",
Comment: `EnableEthHashToFilecoinCidMapping enables storing a mapping of eth transaction hashes to filecoin message Cids`,
},
},
"FullNode": []DocField{ "FullNode": []DocField{
{ {
Name: "Client", Name: "Client",
@ -445,8 +445,8 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/#
Comment: ``, Comment: ``,
}, },
{ {
Name: "EthTxHashConfig", Name: "Fevm",
Type: "EthTxHashConfig", Type: "FevmConfig",
Comment: ``, Comment: ``,
}, },

View File

@ -22,13 +22,13 @@ type Common struct {
// FullNode is a full node config // FullNode is a full node config
type FullNode struct { type FullNode struct {
Common Common
Client Client Client Client
Wallet Wallet Wallet Wallet
Fees FeeConfig Fees FeeConfig
Chainstore Chainstore Chainstore Chainstore
Cluster UserRaftConfig Cluster UserRaftConfig
ActorEvent ActorEventConfig ActorEvent ActorEventConfig
EthTxHashConfig EthTxHashConfig Fevm FevmConfig
} }
// // Common // // Common
@ -694,7 +694,7 @@ type ActorEventConfig struct {
// Set upper bound on index size // 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 enables storing a mapping of eth transaction hashes to filecoin message Cids
EnableEthHashToFilecoinCidMapping bool EnableEthHashToFilecoinCidMapping bool
} }

View File

@ -25,9 +25,9 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
builtinactors "github.com/filecoin-project/lotus/chain/actors/builtin" 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/events/filter"
"github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/stmgr" "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 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() { for _, blk := range to.Blocks() {
_, smsgs, err := m.StateAPI.Chain.MessagesForBlock(ctx, blk) _, smsgs, err := m.StateAPI.Chain.MessagesForBlock(ctx, blk)
if err != nil { if err != nil {
@ -1789,10 +1789,10 @@ func (m EthTxHashManager) Apply(ctx context.Context, from, to *types.TipSet) err
type EthTxHashManager struct { type EthTxHashManager struct {
StateAPI StateAPI 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 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) 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 { if err != nil {
log.Errorf("error inserting tx mapping to db: %s", err) log.Errorf("error inserting tx mapping to db: %s", err)
} }

View File

@ -6,7 +6,7 @@ import (
"go.uber.org/fx" "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/events"
"github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/stmgr"
@ -17,7 +17,7 @@ import (
"github.com/filecoin-project/lotus/node/repo" "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) { 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{ em := &full.EthModule{
Chain: cs, Chain: cs,
@ -38,7 +38,7 @@ func EthModuleAPI(cfg config.EthTxHashConfig) func(helpers.MetricsCtx, repo.Lock
return nil, err return nil, err
} }
transactionHashLookup, err := chain.NewTransactionHashLookup(filepath.Join(dbPath + "txHash.db")) transactionHashLookup, err := ethhashlookup.NewTransactionHashLookup(filepath.Join(dbPath, "txhash.db"))
if err != nil { if err != nil {
return nil, err return nil, err
} }