Set state node diff field to false for snapshots (#18)
Needed for cerc-io/ipld-eth-state-snapshot#1 Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
@@ -43,7 +43,7 @@ import (
|
||||
|
||||
var _ interfaces.StateDiffIndexer = &StateDiffIndexer{}
|
||||
|
||||
// StateDiffIndexer satisfies the indexer.StateDiffIndexer interface for ethereum statediff objects on top of an SQL sql
|
||||
// StateDiffIndexer satisfies the indexer.StateDiffIndexer interface for ethereum statediff objects on top of an SQL DB.
|
||||
type StateDiffIndexer struct {
|
||||
ctx context.Context
|
||||
chainConfig *params.ChainConfig
|
||||
@@ -51,11 +51,17 @@ type StateDiffIndexer struct {
|
||||
}
|
||||
|
||||
// NewStateDiffIndexer creates a sql implementation of interfaces.StateDiffIndexer
|
||||
func NewStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, db Database) (*StateDiffIndexer, error) {
|
||||
// `ctx` is used to cancel the underlying DB connection.
|
||||
// `chainConfig` is used when processing chain state.
|
||||
// `db` is the backing database to use.
|
||||
// `isDiff` means to mark state nodes as belonging to an incremental diff, as opposed to a full snapshot.
|
||||
func NewStateDiffIndexer(
|
||||
ctx context.Context, chainConfig *params.ChainConfig, db Database, isDiff bool,
|
||||
) (*StateDiffIndexer, error) {
|
||||
return &StateDiffIndexer{
|
||||
ctx: ctx,
|
||||
chainConfig: chainConfig,
|
||||
dbWriter: NewWriter(db),
|
||||
dbWriter: NewWriter(db, isDiff),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func setupMainnetIndexer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), chainConf, db)
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), chainConf, db, true)
|
||||
}
|
||||
|
||||
func checkTxClosure(t *testing.T, idle, inUse, open int64) {
|
||||
|
||||
@@ -33,7 +33,7 @@ func setupLegacyPGXIndexer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), test.LegacyConfig, db)
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), test.LegacyConfig, db, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func setupPGXIndexer(t *testing.T, config postgres.Config) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db)
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func setupLegacySQLXIndexer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), test.LegacyConfig, db)
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), test.LegacyConfig, db, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func setupSQLXIndexer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db)
|
||||
ind, err = sql.NewStateDiffIndexer(context.Background(), mocks.TestChainConfig, db, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,15 @@ import (
|
||||
|
||||
// Writer handles processing and writing of indexed IPLD objects to Postgres
|
||||
type Writer struct {
|
||||
db Database
|
||||
db Database
|
||||
isDiff bool
|
||||
}
|
||||
|
||||
// NewWriter creates a new pointer to a Writer
|
||||
func NewWriter(db Database) *Writer {
|
||||
// NewWriter creates a new pointer to a Writer. `diff` indicates whether this is part of an
|
||||
// incremental diff (as opposed to a snapshot).
|
||||
func NewWriter(db Database, diff bool) *Writer {
|
||||
return &Writer{
|
||||
db: db,
|
||||
db: db, isDiff: diff,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +310,8 @@ func (w *Writer) upsertStateCID(tx Tx, stateNode models.StateNodeModel) error {
|
||||
_, err = tx.CopyFrom(w.db.Context(),
|
||||
schema.TableStateNode.TableName(), schema.TableStateNode.ColumnNames(),
|
||||
toRows(toRow(blockNum, stateNode.HeaderID, stateNode.StateKey, stateNode.CID,
|
||||
true, balance, stateNode.Nonce, stateNode.CodeHash, stateNode.StorageRoot, stateNode.Removed)))
|
||||
w.isDiff, balance, stateNode.Nonce, stateNode.CodeHash, stateNode.StorageRoot,
|
||||
stateNode.Removed)))
|
||||
if err != nil {
|
||||
return insertError{"eth.state_cids", err, "COPY", stateNode}
|
||||
}
|
||||
@@ -318,7 +321,7 @@ func (w *Writer) upsertStateCID(tx Tx, stateNode models.StateNodeModel) error {
|
||||
stateNode.HeaderID,
|
||||
stateNode.StateKey,
|
||||
stateNode.CID,
|
||||
true,
|
||||
w.isDiff,
|
||||
bal,
|
||||
stateNode.Nonce,
|
||||
stateNode.CodeHash,
|
||||
@@ -346,7 +349,7 @@ func (w *Writer) upsertStorageCID(tx Tx, storageCID models.StorageNodeModel) err
|
||||
_, err = tx.CopyFrom(w.db.Context(),
|
||||
schema.TableStorageNode.TableName(), schema.TableStorageNode.ColumnNames(),
|
||||
toRows(toRow(blockNum, storageCID.HeaderID, storageCID.StateKey, storageCID.StorageKey, storageCID.CID,
|
||||
true, storageCID.Value, storageCID.Removed)))
|
||||
w.isDiff, storageCID.Value, storageCID.Removed)))
|
||||
if err != nil {
|
||||
return insertError{"eth.storage_cids", err, "COPY", storageCID}
|
||||
}
|
||||
@@ -357,7 +360,7 @@ func (w *Writer) upsertStorageCID(tx Tx, storageCID models.StorageNodeModel) err
|
||||
storageCID.StateKey,
|
||||
storageCID.StorageKey,
|
||||
storageCID.CID,
|
||||
true,
|
||||
w.isDiff,
|
||||
storageCID.Value,
|
||||
storageCID.Removed,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user