Skip to content
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

New release #209

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parser/v1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (p *Parser) ParseTransactions(ctx context.Context, txsData types.TxsData) (
}
}

transactions = tools.SetNodeMetadataOnTxs(transactions, txsData.Metadata, Version)
transactions = tools.SetNodeMetadata(transactions, txsData.Metadata, Version)

// Clear this cache when we finish processing a tipset.
// Bad addresses in this tipset might be valid in the next one
Expand Down
14 changes: 7 additions & 7 deletions parser/v2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *Parser) ParseTransactions(_ context.Context, txsData types.TxsData) (*t
}
}

transactions = tools.SetNodeMetadataOnTxs(transactions, txsData.Metadata, Version)
transactions = tools.SetNodeMetadata(transactions, txsData.Metadata, Version)

// Clear this cache when we finish processing a tipset.
// Bad addresses in this tipset might be valid in the next one
Expand All @@ -136,7 +136,7 @@ func (p *Parser) ParseTransactions(_ context.Context, txsData types.TxsData) (*t
}

func (p *Parser) ParseNativeEvents(_ context.Context, eventsData types.EventsData) (*types.EventsParsedResult, error) {
var parsed []types.Event
var parsed []*types.Event
nativeEventsTotal, evmEventsTotal := 0, 0
for idx, nativeLog := range eventsData.NativeLog {
event, err := eventTools.ParseNativeLog(eventsData.Tipset, nativeLog, uint64(idx))
Expand All @@ -150,16 +150,16 @@ func (p *Parser) ParseNativeEvents(_ context.Context, eventsData types.EventsDat
nativeEventsTotal++
}

parsed = append(parsed, *event)
parsed = append(parsed, event)
}

parsed = tools.SetNodeMetadataOnEvents(parsed, eventsData.Metadata, Version)
parsed = tools.SetNodeMetadata(parsed, eventsData.Metadata, Version)

return &types.EventsParsedResult{EVMEvents: evmEventsTotal, NativeEvents: nativeEventsTotal, ParsedEvents: parsed}, nil
}

func (p *Parser) ParseEthLogs(_ context.Context, eventsData types.EventsData) (*types.EventsParsedResult, error) {
var parsed []types.Event
var parsed []*types.Event
// sort the events by the TransactionIndex ASC and the logIndex ASC
slices.SortFunc(eventsData.EthLogs, func(a, b types.EthLog) int {
return cmp.Or(
Expand All @@ -174,10 +174,10 @@ func (p *Parser) ParseEthLogs(_ context.Context, eventsData types.EventsData) (*
zap.S().Errorf("error retrieving selector_sig for hash: %s err: %s", event.SelectorID, err)
}

parsed = append(parsed, *event)
parsed = append(parsed, event)
}

parsed = tools.SetNodeMetadataOnEvents(parsed, eventsData.Metadata, Version)
parsed = tools.SetNodeMetadata(parsed, eventsData.Metadata, Version)

return &types.EventsParsedResult{EVMEvents: len(parsed), ParsedEvents: parsed}, nil
}
Expand Down
36 changes: 4 additions & 32 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,7 @@ func BuildCidFromMessageTrace(msg filTypes.MessageTrace, parentMsgCid string) (s
return b.Cid().String(), nil
}

func SetNodeMetadataOnTxs(txs []*types.Transaction, metadata types.BlockMetadata, parserVer string) []*types.Transaction {
// TODO refactor this fn to make it generic for events and txs alike

nodeMajorMinorVersion := metadata.NodeMajorMinorVersion
if nodeMajorMinorVersion == "" {
nodeMajorMinorVersion = UnknownParserVersion
}

nodeFullVersion := metadata.NodeFullVersion
if nodeFullVersion == "" {
nodeFullVersion = UnknownParserVersion
}

for _, tx := range txs {
tx.NodeMajorMinorVersion = nodeMajorMinorVersion
tx.NodeFullVersion = nodeFullVersion
tx.ParserVersion = parserVer
}

return txs
}

func SetNodeMetadataOnEvents(events []types.Event, metadata types.BlockMetadata, parserVer string) []types.Event {
// TODO refactor this fn to make it generic for events and txs alike

func SetNodeMetadata[T types.HasNodeInfo](data []T, metadata types.BlockMetadata, parserVer string) []T {
nodeMajorMinorVersion := metadata.NodeMajorMinorVersion
if nodeMajorMinorVersion == "" {
nodeMajorMinorVersion = UnknownParserVersion
Expand All @@ -161,15 +137,11 @@ func SetNodeMetadataOnEvents(events []types.Event, metadata types.BlockMetadata,
nodeFullVersion = UnknownParserVersion
}

var newEvents []types.Event
for _, event := range events {
event.NodeMajorMinorVersion = nodeMajorMinorVersion
event.NodeFullVersion = nodeFullVersion
event.ParserVersion = parserVer
newEvents = append(newEvents, event)
for _, item := range data {
item.SetNodeMetadata(nodeMajorMinorVersion, nodeFullVersion, parserVer)
}
return data

return newEvents
}

func ParseTxMetadata(txMetadata string) (map[string]interface{}, error) {
Expand Down
6 changes: 6 additions & 0 deletions types/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ type Event struct {
ParserVersion string `json:"parser_version"`
NodeInfo
}

func (evt *Event) SetNodeMetadata(nodeMajorMinorVersion, nodeFullVersion, parserVer string) {
evt.NodeMajorMinorVersion = nodeMajorMinorVersion
evt.NodeFullVersion = nodeFullVersion
evt.ParserVersion = parserVer
}
4 changes: 4 additions & 0 deletions types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ type NodeInfo struct {
// NodeMajorMinorVersion contains the node major.minor version from which this metadata was extracted
NodeMajorMinorVersion string `json:"node_major_minor_version,omitempty"`
}

type HasNodeInfo interface {
SetNodeMetadata(nodeMajorMinorVersion, nodeFullVersion, parserVer string)
}
2 changes: 1 addition & 1 deletion types/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ type EventsData struct {
type EventsParsedResult struct {
EVMEvents int
NativeEvents int
ParsedEvents []Event
ParsedEvents []*Event
}
6 changes: 6 additions & 0 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (t Transaction) Equal(b Transaction) bool {
return reflect.DeepEqual(t, b)
}

func (tx *Transaction) SetNodeMetadata(nodeMajorMinorVersion, nodeFullVersion, parserVer string) {
tx.NodeMajorMinorVersion = nodeMajorMinorVersion
tx.NodeFullVersion = nodeFullVersion
tx.ParserVersion = parserVer
}

type EthLog struct {
ethtypes.EthLog
TransactionCid string `json:"transactionCid"`
Expand Down
Loading