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{} 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 { type StateDiffIndexer struct {
ctx context.Context ctx context.Context
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
@ -51,11 +51,25 @@ type StateDiffIndexer struct {
} }
// NewStateDiffIndexer creates a sql implementation of interfaces.StateDiffIndexer // 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{ return &StateDiffIndexer{
ctx: ctx, ctx: ctx,
chainConfig: chainConfig, 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 }, nil
} }

View File

@ -35,12 +35,14 @@ import (
// Writer handles processing and writing of indexed IPLD objects to Postgres // Writer handles processing and writing of indexed IPLD objects to Postgres
type Writer struct { type Writer struct {
db Database db Database
isDiff bool
} }
// NewWriter creates a new pointer to a Writer // NewWriter creates a new pointer to a Writer. `diff` indicates whether this is part of an
func NewWriter(db Database) *Writer { // incremental diff (as opposed to a snapshot).
func NewWriter(db Database, diff bool) *Writer {
return &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.HeaderID,
stateNode.StateKey, stateNode.StateKey,
stateNode.CID, stateNode.CID,
true, w.isDiff,
bal, bal,
stateNode.Nonce, stateNode.Nonce,
stateNode.CodeHash, stateNode.CodeHash,