diff --git a/indexer/constructor.go b/indexer/constructor.go index bb288fd..13f6d65 100644 --- a/indexer/constructor.go +++ b/indexer/constructor.go @@ -50,8 +50,7 @@ func NewStateDiffIndexer( if !ok { return nil, nil, fmt.Errorf("file config is not the correct type: got %T, expected %T", config, file.Config{}) } - fc.NodeInfo = nodeInfo - ind, err := file.NewStateDiffIndexer(chainConfig, fc) + ind, err := file.NewStateDiffIndexer(chainConfig, fc, nodeInfo) return nil, ind, err case shared.POSTGRES: log.Info("Starting statediff service in Postgres writing mode") diff --git a/indexer/database/file/config.go b/indexer/database/file/config.go index fc8fd8c..9c01327 100644 --- a/indexer/database/file/config.go +++ b/indexer/database/file/config.go @@ -20,7 +20,6 @@ import ( "fmt" "strings" - "github.com/cerc-io/plugeth-statediff/indexer/node" "github.com/cerc-io/plugeth-statediff/indexer/shared" ) @@ -30,7 +29,6 @@ type Config struct { OutputDir string FilePath string WatchedAddressesFilePath string - NodeInfo node.Info } // FileMode to explicitly type the mode of file writer we are using @@ -70,20 +68,11 @@ func (c Config) Type() shared.DBType { return shared.FILE } -var nodeInfo = node.Info{ - GenesisBlock: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", - NetworkID: "1", - ChainID: 1, - ID: "mockNodeID", - ClientName: "go-ethereum", -} - // CSVTestConfig config for unit tests var CSVTestConfig = Config{ Mode: CSV, OutputDir: "./statediffing_test", WatchedAddressesFilePath: "./statediffing_watched_addresses_test_file.csv", - NodeInfo: nodeInfo, } // SQLTestConfig config for unit tests @@ -91,5 +80,4 @@ var SQLTestConfig = Config{ Mode: SQL, FilePath: "./statediffing_test_file.sql", WatchedAddressesFilePath: "./statediffing_watched_addresses_test_file.sql", - NodeInfo: nodeInfo, } diff --git a/indexer/database/file/csv_indexer_legacy_test.go b/indexer/database/file/csv_indexer_legacy_test.go index c117f75..238423b 100644 --- a/indexer/database/file/csv_indexer_legacy_test.go +++ b/indexer/database/file/csv_indexer_legacy_test.go @@ -43,7 +43,7 @@ func setupLegacyCSVIndexer(t *testing.T) { require.NoError(t, err) } - ind, err = file.NewStateDiffIndexer(test.LegacyConfig, file.CSVTestConfig) + ind, err = file.NewStateDiffIndexer(test.LegacyConfig, file.CSVTestConfig, test.LegacyNodeInfo) require.NoError(t, err) db, err = postgres.SetupSQLXDB() diff --git a/indexer/database/file/csv_indexer_test.go b/indexer/database/file/csv_indexer_test.go index 4e6526f..06aa366 100644 --- a/indexer/database/file/csv_indexer_test.go +++ b/indexer/database/file/csv_indexer_test.go @@ -41,7 +41,7 @@ func setupCSVIndexer(t *testing.T) { require.NoError(t, err) } - ind, err = file.NewStateDiffIndexer(mocks.TestChainConfig, file.CSVTestConfig) + ind, err = file.NewStateDiffIndexer(mocks.TestChainConfig, file.CSVTestConfig, test.LegacyNodeInfo) require.NoError(t, err) db, err = postgres.SetupSQLXDB() diff --git a/indexer/database/file/indexer.go b/indexer/database/file/indexer.go index b213f91..ce56acb 100644 --- a/indexer/database/file/indexer.go +++ b/indexer/database/file/indexer.go @@ -38,6 +38,7 @@ import ( "github.com/cerc-io/plugeth-statediff/indexer/interfaces" "github.com/cerc-io/plugeth-statediff/indexer/ipld" "github.com/cerc-io/plugeth-statediff/indexer/models" + "github.com/cerc-io/plugeth-statediff/indexer/node" "github.com/cerc-io/plugeth-statediff/indexer/shared" sdtypes "github.com/cerc-io/plugeth-statediff/types" "github.com/cerc-io/plugeth-statediff/utils/log" @@ -62,7 +63,7 @@ type StateDiffIndexer struct { } // NewStateDiffIndexer creates a void implementation of interfaces.StateDiffIndexer -func NewStateDiffIndexer(chainConfig *params.ChainConfig, config Config) (*StateDiffIndexer, error) { +func NewStateDiffIndexer(chainConfig *params.ChainConfig, config Config, nodeInfo node.Info) (*StateDiffIndexer, error) { var err error var writer FileWriter @@ -115,12 +116,12 @@ func NewStateDiffIndexer(chainConfig *params.ChainConfig, config Config) (*State wg := new(sync.WaitGroup) writer.Loop() - writer.upsertNode(config.NodeInfo) + writer.upsertNode(nodeInfo) return &StateDiffIndexer{ fileWriter: writer, chainConfig: chainConfig, - nodeID: config.NodeInfo.ID, + nodeID: nodeInfo.ID, wg: wg, }, nil } diff --git a/indexer/database/file/mainnet_tests/indexer_test.go b/indexer/database/file/mainnet_tests/indexer_test.go index 3fe53a0..cdb8042 100644 --- a/indexer/database/file/mainnet_tests/indexer_test.go +++ b/indexer/database/file/mainnet_tests/indexer_test.go @@ -83,7 +83,7 @@ func setupMainnetIndexer(t *testing.T) { require.NoError(t, err) } - ind, err = file.NewStateDiffIndexer(chainConf, file.CSVTestConfig) + ind, err = file.NewStateDiffIndexer(chainConf, file.CSVTestConfig, test.LegacyNodeInfo) require.NoError(t, err) db, err = postgres.SetupSQLXDB() diff --git a/indexer/database/file/sql_indexer_legacy_test.go b/indexer/database/file/sql_indexer_legacy_test.go index b46348a..6d721d5 100644 --- a/indexer/database/file/sql_indexer_legacy_test.go +++ b/indexer/database/file/sql_indexer_legacy_test.go @@ -44,7 +44,7 @@ func setupLegacySQLIndexer(t *testing.T) { require.NoError(t, err) } - ind, err = file.NewStateDiffIndexer(test.LegacyConfig, file.SQLTestConfig) + ind, err = file.NewStateDiffIndexer(test.LegacyConfig, file.SQLTestConfig, test.LegacyNodeInfo) require.NoError(t, err) db, err = postgres.SetupSQLXDB() diff --git a/indexer/database/file/sql_indexer_test.go b/indexer/database/file/sql_indexer_test.go index 8663f27..3aab7b8 100644 --- a/indexer/database/file/sql_indexer_test.go +++ b/indexer/database/file/sql_indexer_test.go @@ -41,7 +41,7 @@ func setupIndexer(t *testing.T) { require.NoError(t, err) } - ind, err = file.NewStateDiffIndexer(mocks.TestChainConfig, file.SQLTestConfig) + ind, err = file.NewStateDiffIndexer(mocks.TestChainConfig, file.SQLTestConfig, test.LegacyNodeInfo) require.NoError(t, err) db, err = postgres.SetupSQLXDB() diff --git a/indexer/database/sql/postgres/config.go b/indexer/database/sql/postgres/config.go index a2c63b4..cb26e53 100644 --- a/indexer/database/sql/postgres/config.go +++ b/indexer/database/sql/postgres/config.go @@ -44,10 +44,6 @@ type Config struct { ConnTimeout time.Duration LogStatements bool - // node info params - ID string - ClientName string - // driver type Driver DriverType diff --git a/indexer/test/test_legacy.go b/indexer/test/test_legacy.go index 8878edc..efe5664 100644 --- a/indexer/test/test_legacy.go +++ b/indexer/test/test_legacy.go @@ -24,6 +24,7 @@ import ( "github.com/cerc-io/plugeth-statediff/indexer/interfaces" "github.com/cerc-io/plugeth-statediff/indexer/ipld" "github.com/cerc-io/plugeth-statediff/indexer/mocks" + "github.com/cerc-io/plugeth-statediff/indexer/node" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" "github.com/ipfs/go-cid" @@ -36,6 +37,14 @@ var ( legacyData = mocks.NewLegacyData(LegacyConfig) mockLegacyBlock *types.Block legacyHeaderCID cid.Cid + // Mainnet node info + LegacyNodeInfo = node.Info{ + GenesisBlock: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", + NetworkID: "1", + ChainID: 1, + ID: "mockNodeID", + ClientName: "go-ethereum", + } ) func SetupLegacyTestData(t *testing.T, ind interfaces.StateDiffIndexer) { diff --git a/main/flags.go b/main/flags.go index c1f5c1a..27cd497 100644 --- a/main/flags.go +++ b/main/flags.go @@ -173,8 +173,6 @@ func initConfig() { case shared.FILE: indexerConfig = fileConfig case shared.POSTGRES: - dbConfig.ID = config.ID - dbConfig.ClientName = config.ClientName indexerConfig = dbConfig case shared.DUMP: switch dbDumpDst {