-
Notifications
You must be signed in to change notification settings - Fork 33
VDB-696 Update transformer execute #101
Changes from all commits
ee13d5c
ede6ad1
adf91df
f292888
fd126c7
948246c
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 |
---|---|---|
|
@@ -20,7 +20,6 @@ import ( | |
"github.com/ethereum/go-ethereum/core/types" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/vulcanize/vulcanizedb/libraries/shared/constants" | ||
"github.com/vulcanize/vulcanizedb/libraries/shared/transformer" | ||
"github.com/vulcanize/vulcanizedb/pkg/core" | ||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" | ||
|
@@ -37,7 +36,7 @@ func (transformer Transformer) NewTransformer(db *postgres.DB) transformer.Event | |
return transformer | ||
} | ||
|
||
func (transformer Transformer) Execute(logs []types.Log, header core.Header, recheckHeaders constants.TransformerExecution) error { | ||
func (transformer Transformer) Execute(logs []types.Log, header core.Header) error { | ||
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. This |
||
transformerName := transformer.Config.TransformerName | ||
config := transformer.Config | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,31 +69,6 @@ func MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.D | |
return result, err | ||
} | ||
|
||
func RecheckHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.DB, checkedHeadersColumn string) ([]core.Header, error) { | ||
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. Looks like this method wasn't being called any longer. Also, something else I hadn't realized previously was that in order to allow for rechecking headers, we need to pass in a CLI argument |
||
var result []core.Header | ||
var query string | ||
var err error | ||
|
||
if endingBlockNumber == -1 { | ||
query = `SELECT headers.id, headers.block_number, headers.hash FROM headers | ||
LEFT JOIN checked_headers on headers.id = header_id | ||
WHERE ` + checkedHeadersColumn + ` between 1 and ` + constants.RecheckHeaderCap + ` | ||
AND headers.block_number >= $1 | ||
AND headers.eth_node_fingerprint = $2` | ||
err = db.Select(&result, query, startingBlockNumber, db.Node.ID) | ||
} else { | ||
query = `SELECT headers.id, headers.block_number, headers.hash FROM headers | ||
LEFT JOIN checked_headers on headers.id = header_id | ||
WHERE ` + checkedHeadersColumn + ` between 1 and ` + constants.RecheckHeaderCap + ` | ||
AND headers.block_number >= $1 | ||
AND headers.block_number <= $2 | ||
AND headers.eth_node_fingerprint = $3` | ||
err = db.Select(&result, query, startingBlockNumber, endingBlockNumber, db.Node.ID) | ||
} | ||
|
||
return result, err | ||
} | ||
|
||
func GetCheckedColumnNames(db *postgres.DB) ([]string, error) { | ||
// Query returns `[]driver.Value`, nullable polymorphic interface | ||
var queryResult []driver.Value | ||
|
@@ -121,37 +96,47 @@ func GetCheckedColumnNames(db *postgres.DB) ([]string, error) { | |
return columnNames, nil | ||
} | ||
|
||
// Builds a SQL string that checks if any column value is 0, given the column names. | ||
// Builds a SQL string that checks if any column should be checked/rechecked. | ||
// Defaults to FALSE when no columns are provided. | ||
// Ex: ["columnA", "columnB"] => "NOT (columnA!=0 AND columnB!=0)" | ||
// [] => "FALSE" | ||
func CreateNotCheckedSQL(boolColumns []string, recheckHeaders constants.TransformerExecution) string { | ||
|
||
var result bytes.Buffer | ||
|
||
func CreateHeaderCheckedPredicateSQL(boolColumns []string, recheckHeaders constants.TransformerExecution) string { | ||
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. I refactored this method into two smaller ones & changed the name as I was trying to understand how it was working. If folks don't find this refactoring helpful, I'm happy to undo it. 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. I think it makes more sense this way 💯 |
||
if len(boolColumns) == 0 { | ||
return "FALSE" | ||
} | ||
|
||
result.WriteString("NOT (") | ||
if recheckHeaders { | ||
return createHeaderCheckedPredicateSQLForRecheckedHeaders(boolColumns) | ||
} else { | ||
return createHeaderCheckedPredicateSQLForMissingHeaders(boolColumns) | ||
} | ||
} | ||
|
||
func createHeaderCheckedPredicateSQLForMissingHeaders(boolColumns []string) string { | ||
var result bytes.Buffer | ||
result.WriteString(" (") | ||
|
||
// Loop excluding last column name | ||
for _, column := range boolColumns[:len(boolColumns)-1] { | ||
|
||
if recheckHeaders { | ||
result.WriteString(fmt.Sprintf("%v>=%s AND ", column, constants.RecheckHeaderCap)) | ||
} else { | ||
result.WriteString(fmt.Sprintf("%v!=0 AND ", column)) | ||
} | ||
result.WriteString(fmt.Sprintf("%v=0 OR ", column)) | ||
} | ||
|
||
// No trailing "OR" for the last column name | ||
if recheckHeaders { | ||
result.WriteString(fmt.Sprintf("%v>=%s)", boolColumns[len(boolColumns)-1], constants.RecheckHeaderCap)) | ||
} else { | ||
result.WriteString(fmt.Sprintf("%v!=0)", boolColumns[len(boolColumns)-1])) | ||
result.WriteString(fmt.Sprintf("%v=0)", boolColumns[len(boolColumns)-1])) | ||
|
||
return result.String() | ||
} | ||
|
||
func createHeaderCheckedPredicateSQLForRecheckedHeaders(boolColumns []string) string { | ||
var result bytes.Buffer | ||
result.WriteString(" (") | ||
|
||
// Loop excluding last column name | ||
for _, column := range boolColumns[:len(boolColumns)-1] { | ||
result.WriteString(fmt.Sprintf("%v<%s OR ", column, constants.RecheckHeaderCap)) | ||
} | ||
|
||
// No trailing "OR" for the last column name | ||
result.WriteString(fmt.Sprintf("%v<%s)", boolColumns[len(boolColumns)-1], constants.RecheckHeaderCap)) | ||
|
||
return result.String() | ||
} |
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.
This transformer specific
MissingHeaders
method was never being used. Instead this genericMissingHeaders
method is being called the watcher and then the headers are passed intoTransformer.Execute
.