-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add publisher mode option #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ api: | |
|
|
||
| publisher: | ||
| enabled: false | ||
| mode: default | ||
|
|
||
| validation: | ||
| mode: minimal | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1075,6 +1075,31 @@ func (c *ClickHouseConnector) DeleteStagingData(data []common.BlockData) error { | |||||||||||||||||||||||
| return batch.Send() | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| func (c *ClickHouseConnector) GetLastPublishedBlockNumber(chainId *big.Int) (*big.Int, error) { | ||||||||||||||||||||||||
| query := fmt.Sprintf("SELECT cursor_value FROM %s.cursors FINAL WHERE cursor_type = 'publish'", c.cfg.Database) | ||||||||||||||||||||||||
| if chainId != nil && chainId.Sign() > 0 { | ||||||||||||||||||||||||
| query += fmt.Sprintf(" AND chain_id = %s", chainId.String()) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| var blockNumberString string | ||||||||||||||||||||||||
| err := c.conn.QueryRow(context.Background(), query).Scan(&blockNumberString) | ||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||
| if err == sql.ErrNoRows { | ||||||||||||||||||||||||
| return big.NewInt(0), nil | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| blockNumber, ok := new(big.Int).SetString(blockNumberString, 10) | ||||||||||||||||||||||||
| if !ok { | ||||||||||||||||||||||||
| return nil, fmt.Errorf("failed to parse block number: %s", blockNumberString) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return blockNumber, nil | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| func (c *ClickHouseConnector) SetLastPublishedBlockNumber(chainId *big.Int, blockNumber *big.Int) error { | ||||||||||||||||||||||||
| query := fmt.Sprintf("INSERT INTO %s.cursors (chain_id, cursor_type, cursor_value) VALUES (%s, 'publish', '%s')", c.cfg.Database, chainId, blockNumber.String()) | ||||||||||||||||||||||||
| return c.conn.Exec(context.Background(), query) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+1098
to
+1101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use placeholders instead of string interpolation; fix
-func (c *ClickHouseConnector) SetLastPublishedBlockNumber(chainId *big.Int, blockNumber *big.Int) error {
- query := fmt.Sprintf("INSERT INTO %s.cursors (chain_id, cursor_type, cursor_value) VALUES (%s, 'publish', '%s')", c.cfg.Database, chainId, blockNumber.String())
- return c.conn.Exec(context.Background(), query)
-}
+func (c *ClickHouseConnector) SetLastPublishedBlockNumber(chainId *big.Int, blockNumber *big.Int) error {
+ query := fmt.Sprintf("INSERT INTO %s.cursors (chain_id, cursor_type, cursor_value) VALUES (?, 'publish', ?)", c.cfg.Database)
+ return c.conn.Exec(context.Background(), query, chainId, blockNumber.String())
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| func (c *ClickHouseConnector) GetLastReorgCheckedBlockNumber(chainId *big.Int) (*big.Int, error) { | ||||||||||||||||||||||||
| query := fmt.Sprintf("SELECT cursor_value FROM %s.cursors FINAL WHERE cursor_type = 'reorg'", c.cfg.Database) | ||||||||||||||||||||||||
| if chainId.Sign() > 0 { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,8 @@ type IStagingStorage interface { | |
| GetStagingData(qf QueryFilter) (data []common.BlockData, err error) | ||
| DeleteStagingData(data []common.BlockData) error | ||
| GetLastStagedBlockNumber(chainId *big.Int, rangeStart *big.Int, rangeEnd *big.Int) (maxBlockNumber *big.Int, err error) | ||
| GetLastPublishedBlockNumber(chainId *big.Int) (maxBlockNumber *big.Int, err error) | ||
| SetLastPublishedBlockNumber(chainId *big.Int, blockNumber *big.Int) error | ||
| DeleteOlderThan(chainId *big.Int, blockNumber *big.Int) error | ||
|
Comment on lines
+86
to
88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainSpecify “not found” and concurrency semantics for publisher cursor methods Ambiguity here can lead to bugs across drivers:
To confirm coverage and consistency, run: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Search implementations of new cursor methods..."
rg -n "GetLastPublishedBlockNumber\(" -A 2
rg -n "SetLastPublishedBlockNumber\(" -A 2
echo "Check committer uses of publisher mode and cursor methods..."
rg -n "publisher\.mode|pre-commit|post-commit|GetLastPublishedBlockNumber|SetLastPublishedBlockNumber" -A 3 internalLength of output: 10576 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Locate DeleteOlderThan implementations in storage connectors..."
rg -n "func .*DeleteOlderThan" -A 10 internal/storageLength of output: 1746 Specify “not found” semantics and ensure idempotent upsert for publisher cursor methods We need to be explicit about what “no cursor yet” means and make sure both drivers handle and document it uniformly, as well as guarantee that setting the cursor is safe under concurrent pre-commit runs. – internal/storage/connector.go: – internal/storage/postgres.go: – internal/storage/clickhouse.go: – Tests: 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Validate and constrain
publisher.modeto known valuesModeis a free-form string. Add typed constants and validate/normalize it during config load to prevent silent misconfiguration.Example (outside this line range):
Optional: expose these constants to other packages to avoid stringly-typed comparisons across the codebase.
🤖 Prompt for AI Agents