@@ -18,6 +18,7 @@ package main
1818
1919import (
2020 "bufio"
21+ "context"
2122 "errors"
2223 "fmt"
2324 "math/big"
@@ -26,10 +27,7 @@ import (
2627 "time"
2728 "unicode"
2829
29- "github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
30-
31- "github.com/ethereum/go-ethereum/eth/downloader"
32- "github.com/ethereum/go-ethereum/statediff"
30+ "github.com/naoina/toml"
3331 "gopkg.in/urfave/cli.v1"
3432
3533 "github.com/ethereum/go-ethereum/accounts/external"
@@ -38,13 +36,18 @@ import (
3836 "github.com/ethereum/go-ethereum/accounts/usbwallet"
3937 "github.com/ethereum/go-ethereum/cmd/utils"
4038 "github.com/ethereum/go-ethereum/eth/catalyst"
39+ "github.com/ethereum/go-ethereum/eth/downloader"
4140 "github.com/ethereum/go-ethereum/eth/ethconfig"
4241 "github.com/ethereum/go-ethereum/internal/ethapi"
4342 "github.com/ethereum/go-ethereum/log"
4443 "github.com/ethereum/go-ethereum/metrics"
4544 "github.com/ethereum/go-ethereum/node"
4645 "github.com/ethereum/go-ethereum/params"
47- "github.com/naoina/toml"
46+ "github.com/ethereum/go-ethereum/statediff"
47+ dumpdb "github.com/ethereum/go-ethereum/statediff/indexer/database/dump"
48+ "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
49+ "github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
50+ "github.com/ethereum/go-ethereum/statediff/indexer/shared"
4851)
4952
5053var (
@@ -185,48 +188,82 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
185188 }
186189
187190 if ctx .GlobalBool (utils .StateDiffFlag .Name ) {
188- var dbConfig * sql.Config
191+ var indexerConfig interfaces.Config
192+ var clientName , nodeID string
189193 if ctx .GlobalIsSet (utils .StateDiffWritingFlag .Name ) {
190- dbConfig = new (sql.Config )
191- dbConfig .Hostname = ctx .GlobalString (utils .StateDiffDBHostFlag .Name )
192- dbConfig .Port = ctx .GlobalInt (utils .StateDiffDBPortFlag .Name )
193- dbConfig .DatabaseName = ctx .GlobalString (utils .StateDiffDBNameFlag .Name )
194- dbConfig .Username = ctx .GlobalString (utils .StateDiffDBUserFlag .Name )
195- dbConfig .Password = ctx .GlobalString (utils .StateDiffDBPasswordFlag .Name )
196-
194+ clientName = ctx .GlobalString (utils .StateDiffDBClientNameFlag .Name )
197195 if ctx .GlobalIsSet (utils .StateDiffDBNodeIDFlag .Name ) {
198- dbConfig . ID = ctx .GlobalString (utils .StateDiffDBNodeIDFlag .Name )
196+ nodeID = ctx .GlobalString (utils .StateDiffDBNodeIDFlag .Name )
199197 } else {
200198 utils .Fatalf ("Must specify node ID for statediff DB output" )
201199 }
202200
203- if ctx .GlobalIsSet (utils .StateDiffDBClientNameFlag .Name ) {
204- dbConfig .ClientName = ctx .GlobalString (utils .StateDiffDBClientNameFlag .Name )
205- } else {
206- utils .Fatalf ("Must specify client name for statediff DB output" )
207- }
208-
209- if ctx .GlobalIsSet (utils .StateDiffDBMinConns .Name ) {
210- dbConfig .MinConns = ctx .GlobalInt (utils .StateDiffDBMinConns .Name )
211- }
212- if ctx .GlobalIsSet (utils .StateDiffDBMaxConns .Name ) {
213- dbConfig .MaxConns = ctx .GlobalInt (utils .StateDiffDBMaxConns .Name )
214- }
215- if ctx .GlobalIsSet (utils .StateDiffDBMaxIdleConns .Name ) {
216- dbConfig .MaxIdle = ctx .GlobalInt (utils .StateDiffDBMaxIdleConns .Name )
217- }
218- if ctx .GlobalIsSet (utils .StateDiffDBMaxConnLifetime .Name ) {
219- dbConfig .MaxConnLifetime = ctx .GlobalDuration (utils .StateDiffDBMaxConnLifetime .Name ) * time .Second
220- }
221- if ctx .GlobalIsSet (utils .StateDiffDBMaxConnIdleTime .Name ) {
222- dbConfig .MaxConnIdleTime = ctx .GlobalDuration (utils .StateDiffDBMaxConnIdleTime .Name ) * time .Second
201+ dbTypeStr := ctx .GlobalString (utils .StateDiffDBTypeFlag .Name )
202+ dbType , err := shared .ResolveDBType (dbTypeStr )
203+ if err != nil {
204+ utils .Fatalf ("%v" , err )
223205 }
224- if ctx .GlobalIsSet (utils .StateDiffDBConnTimeout .Name ) {
225- dbConfig .ConnTimeout = ctx .GlobalDuration (utils .StateDiffDBConnTimeout .Name ) * time .Second
206+ switch dbType {
207+ case shared .POSTGRES :
208+ driverTypeStr := ctx .GlobalString (utils .StateDiffDBDriverTypeFlag .Name )
209+ driverType , err := postgres .ResolveDriverType (driverTypeStr )
210+ if err != nil {
211+ utils .Fatalf ("%v" , err )
212+ }
213+ pgConfig := postgres.Config {
214+ Hostname : ctx .GlobalString (utils .StateDiffDBHostFlag .Name ),
215+ Port : ctx .GlobalInt (utils .StateDiffDBPortFlag .Name ),
216+ DatabaseName : ctx .GlobalString (utils .StateDiffDBNameFlag .Name ),
217+ Username : ctx .GlobalString (utils .StateDiffDBUserFlag .Name ),
218+ Password : ctx .GlobalString (utils .StateDiffDBPasswordFlag .Name ),
219+ ID : nodeID ,
220+ ClientName : clientName ,
221+ Driver : driverType ,
222+ }
223+ if ctx .GlobalIsSet (utils .StateDiffDBMinConns .Name ) {
224+ pgConfig .MinConns = ctx .GlobalInt (utils .StateDiffDBMinConns .Name )
225+ }
226+ if ctx .GlobalIsSet (utils .StateDiffDBMaxConns .Name ) {
227+ pgConfig .MaxConns = ctx .GlobalInt (utils .StateDiffDBMaxConns .Name )
228+ }
229+ if ctx .GlobalIsSet (utils .StateDiffDBMaxIdleConns .Name ) {
230+ pgConfig .MaxIdle = ctx .GlobalInt (utils .StateDiffDBMaxIdleConns .Name )
231+ }
232+ if ctx .GlobalIsSet (utils .StateDiffDBMaxConnLifetime .Name ) {
233+ pgConfig .MaxConnLifetime = ctx .GlobalDuration (utils .StateDiffDBMaxConnLifetime .Name ) * time .Second
234+ }
235+ if ctx .GlobalIsSet (utils .StateDiffDBMaxConnIdleTime .Name ) {
236+ pgConfig .MaxConnIdleTime = ctx .GlobalDuration (utils .StateDiffDBMaxConnIdleTime .Name ) * time .Second
237+ }
238+ if ctx .GlobalIsSet (utils .StateDiffDBConnTimeout .Name ) {
239+ pgConfig .ConnTimeout = ctx .GlobalDuration (utils .StateDiffDBConnTimeout .Name ) * time .Second
240+ }
241+ indexerConfig = pgConfig
242+ case shared .DUMP :
243+ dumpTypeStr := ctx .GlobalString (utils .StateDiffDBDumpDst .Name )
244+ dumpType , err := dumpdb .ResolveDumpType (dumpTypeStr )
245+ if err != nil {
246+ utils .Fatalf ("%v" , err )
247+ }
248+ switch dumpType {
249+ case dumpdb .STDERR :
250+ indexerConfig = dumpdb.Config {Dump : os .Stdout }
251+ case dumpdb .STDOUT :
252+ indexerConfig = dumpdb.Config {Dump : os .Stderr }
253+ case dumpdb .DISCARD :
254+ indexerConfig = dumpdb.Config {Dump : dumpdb .NewDiscardWriterCloser ()}
255+ default :
256+ utils .Fatalf ("unrecognized dump destination: %s" , dumpType )
257+ }
258+ default :
259+ utils .Fatalf ("unrecognized database type: %s" , dbType )
226260 }
227261 }
228- p := statediff.ServiceParams {
229- DBParams : dbConfig ,
262+ p := statediff.Config {
263+ IndexerConfig : indexerConfig ,
264+ ID : nodeID ,
265+ ClientName : clientName ,
266+ Context : context .Background (),
230267 EnableWriteLoop : ctx .GlobalBool (utils .StateDiffWritingFlag .Name ),
231268 NumWorkers : ctx .GlobalUint (utils .StateDiffWorkersFlag .Name ),
232269 }
0 commit comments