integrate upsert mode toggle into CLI
This commit is contained in:
parent
248b558e96
commit
47297d6724
@ -244,6 +244,9 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
|||||||
ClientName: clientName,
|
ClientName: clientName,
|
||||||
Driver: driverType,
|
Driver: driverType,
|
||||||
}
|
}
|
||||||
|
if ctx.IsSet(utils.StateDiffUpsert.Name) {
|
||||||
|
pgConfig.Upsert = ctx.Bool(utils.StateDiffUpsert.Name)
|
||||||
|
}
|
||||||
if ctx.IsSet(utils.StateDiffDBMinConns.Name) {
|
if ctx.IsSet(utils.StateDiffDBMinConns.Name) {
|
||||||
pgConfig.MinConns = ctx.Int(utils.StateDiffDBMinConns.Name)
|
pgConfig.MinConns = ctx.Int(utils.StateDiffDBMinConns.Name)
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,7 @@ var (
|
|||||||
utils.StateDiffKnownGapsFilePath,
|
utils.StateDiffKnownGapsFilePath,
|
||||||
utils.StateDiffWaitForSync,
|
utils.StateDiffWaitForSync,
|
||||||
utils.StateDiffWatchedAddressesFilePath,
|
utils.StateDiffWatchedAddressesFilePath,
|
||||||
|
utils.StateDiffUpsert,
|
||||||
configFileFlag,
|
configFileFlag,
|
||||||
}, utils.NetworkFlags, utils.DatabasePathFlags)
|
}, utils.NetworkFlags, utils.DatabasePathFlags)
|
||||||
|
|
||||||
|
@ -1078,6 +1078,11 @@ var (
|
|||||||
Usage: "Client name to use when writing state diffs to database",
|
Usage: "Client name to use when writing state diffs to database",
|
||||||
Value: "go-ethereum",
|
Value: "go-ethereum",
|
||||||
}
|
}
|
||||||
|
StateDiffUpsert = &cli.BoolFlag{
|
||||||
|
Name: "statediff.db.upsert",
|
||||||
|
Usage: "Should the statediff service overwrite data existing in the database?",
|
||||||
|
Value: false,
|
||||||
|
}
|
||||||
StateDiffWritingFlag = &cli.BoolFlag{
|
StateDiffWritingFlag = &cli.BoolFlag{
|
||||||
Name: "statediff.writing",
|
Name: "statediff.writing",
|
||||||
Usage: "Activates progressive writing of state diffs to database as new block are synced",
|
Usage: "Activates progressive writing of state diffs to database as new block are synced",
|
||||||
|
@ -118,6 +118,8 @@ This service introduces a CLI flag namespace `statediff`
|
|||||||
|
|
||||||
`--statediff.db.clientname` is the client name to use in the Postgres database
|
`--statediff.db.clientname` is the client name to use in the Postgres database
|
||||||
|
|
||||||
|
`--statediff.db.upsert` whether or not the service, when operating in a direct database writing mode, should overwrite any existing conflicting data
|
||||||
|
|
||||||
`--statediff.file.path` full path (including filename) to write statediff data out to when operating in file mode
|
`--statediff.file.path` full path (including filename) to write statediff data out to when operating in file mode
|
||||||
|
|
||||||
`--statediff.file.wapath` full path (including filename) to write statediff watched addresses out to when operating in file mode
|
`--statediff.file.wapath` full path (including filename) to write statediff watched addresses out to when operating in file mode
|
||||||
|
@ -65,7 +65,7 @@ func NewStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, n
|
|||||||
default:
|
default:
|
||||||
return nil, nil, fmt.Errorf("unrecognized Postgres driver type: %s", pgc.Driver)
|
return nil, nil, fmt.Errorf("unrecognized Postgres driver type: %s", pgc.Driver)
|
||||||
}
|
}
|
||||||
db := postgres.NewPostgresDB(driver)
|
db := postgres.NewPostgresDB(driver, pgc.Upsert)
|
||||||
ind, err := sql.NewStateDiffIndexer(ctx, chainConfig, db)
|
ind, err := sql.NewStateDiffIndexer(ctx, chainConfig, db)
|
||||||
return db, ind, err
|
return db, ind, err
|
||||||
case shared.DUMP:
|
case shared.DUMP:
|
||||||
|
@ -77,6 +77,9 @@ type Config struct {
|
|||||||
|
|
||||||
// driver type
|
// driver type
|
||||||
Driver DriverType
|
Driver DriverType
|
||||||
|
|
||||||
|
// toggle on/off upserts
|
||||||
|
Upsert bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type satisfies interfaces.Config
|
// Type satisfies interfaces.Config
|
||||||
|
@ -31,7 +31,7 @@ func SetupSQLXDB() (sql.Database, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewPostgresDB(driver), nil
|
return NewPostgresDB(driver, false), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupPGXDB is used to setup a pgx db for tests
|
// SetupPGXDB is used to setup a pgx db for tests
|
||||||
@ -40,5 +40,5 @@ func SetupPGXDB() (sql.Database, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewPostgresDB(driver), nil
|
return NewPostgresDB(driver, false), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user