Skip to content

Commit

Permalink
consensus: use batch for genesis queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 1, 2024
1 parent 56baec8 commit faf3cbd
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 391 deletions.
20 changes: 11 additions & 9 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,25 @@ func (m *processor) debugDumpGenesisJSON(genesisDoc *genesis.Document, heightOrN
func (m *processor) processGenesis(ctx context.Context, genesisDoc *genesis.Document, nodesOverride []nodeapi.Node) error {
m.logger.Info("processing genesis document")
gen := NewGenesisProcessor(m.logger.With("height", "genesis"))
queries, err := gen.Process(genesisDoc, nodesOverride)
batch, err := gen.Process(genesisDoc, nodesOverride)
if err != nil {
return err
}

// Debug: log the SQL into a file if requested.
debugPath := os.Getenv("NEXUS_DUMP_GENESIS_SQL")
if debugPath != "" {
sql := strings.Join(queries, "\n")
if err := os.WriteFile(debugPath, []byte(sql), 0o600 /* Permissions: rw------- */); err != nil {
gen.logger.Error("failed to write genesis sql to file", "err", err)
queries, err := json.Marshal(batch.Queries())
if err != nil {
return err
}
if err := os.WriteFile(debugPath, queries, 0o600 /* Permissions: rw------- */); err != nil {
gen.logger.Error("failed to write genesis queries to file", "err", err)
} else {
gen.logger.Info("wrote genesis sql to file", "path", debugPath)
gen.logger.Info("wrote genesis queries to file", "path", debugPath)
}
}

batch := &storage.QueryBatch{}
for _, query := range queries {
batch.Queue(query)
}
if err := m.target.SendBatch(ctx, batch); err != nil {
return err
}
Expand Down Expand Up @@ -1013,6 +1012,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
submission.Content.Upgrade.Epoch,
submission.CreatedAt,
submission.ClosesAt,
0,
)
case submission.Content.CancelUpgrade != nil:
batch.Queue(queries.ConsensusProposalSubmissionCancelInsert,
Expand All @@ -1023,6 +1023,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
submission.Content.CancelUpgrade.ProposalID,
submission.CreatedAt,
submission.ClosesAt,
0,
)
case submission.Content.ChangeParameters != nil:
batch.Queue(queries.ConsensusProposalSubmissionChangeParametersInsert,
Expand All @@ -1034,6 +1035,7 @@ func (m *processor) queueSubmissions(batch *storage.QueryBatch, data *governance
[]byte(submission.Content.ChangeParameters.Changes),
submission.CreatedAt,
submission.ClosesAt,
0,
)
default:
m.logger.Warn("unknown proposal content type", "proposal_id", submission.ID, "content", submission.Content)
Expand Down
Loading

0 comments on commit faf3cbd

Please sign in to comment.