Set state node diff field to false for snapshots
Some checks reported warnings
Test / Run unit tests (pull_request) Successful in 16m11s
Test / Run compliance tests (pull_request) Successful in 3m51s
Test / Run integration tests (pull_request) Has been cancelled

This commit is contained in:
Roy Crihfield 2023-09-28 18:01:51 +08:00
parent b8fec4b571
commit b50e636204
2 changed files with 24 additions and 8 deletions

View File

@ -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,25 @@ type StateDiffIndexer struct {
}
// NewStateDiffIndexer creates a sql implementation of interfaces.StateDiffIndexer
func NewStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, db Database) (*StateDiffIndexer, error) {
func NewStateDiffIndexer(
ctx context.Context, chainConfig *params.ChainConfig, db Database,
) (*StateDiffIndexer, error) {
return &StateDiffIndexer{
ctx: ctx,
chainConfig: chainConfig,
dbWriter: NewWriter(db),
dbWriter: NewWriter(db, true),
}, nil
}
// NewStateDiffIndexer creates a sql implementation of interfaces.StateDiffIndexer for writing full
// snapshots (meaning inserted nodes have the `diff` field set to false).
func NewSnapshotIndexer(
ctx context.Context, chainConfig *params.ChainConfig, db Database,
) (*StateDiffIndexer, error) {
return &StateDiffIndexer{
ctx: ctx,
chainConfig: chainConfig,
dbWriter: NewWriter(db, false),
}, nil
}

View File

@ -35,12 +35,14 @@ import (
// Writer handles processing and writing of indexed IPLD objects to Postgres
type Writer struct {
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,
}
}
@ -318,7 +320,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,