Skip to content

Commit

Permalink
CR Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shleikes committed Nov 5, 2024
1 parent 60edfc0 commit 444c69e
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions protocol/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,10 @@ func ParseRawBlock(rpcInput RPCInput, parsedInput *ParsedInput, defaultValue str
parsedInput.SetBlock(parsedBlock)
}

func parseInputWithLegacyBlockParser(rpcInput RPCInput, blockParser spectypes.BlockParser, source int, disableWarningLevelLog bool) (string, error) {
parseErrorLogLevel := utils.LAVA_LOG_WARN
if disableWarningLevelLog {
// found a hash, no need to log warning later
parseErrorLogLevel = utils.LAVA_LOG_DEBUG
}

func parseInputWithLegacyBlockParser(rpcInput RPCInput, blockParser spectypes.BlockParser, source int) (string, error) {
result, err := legacyParse(rpcInput, blockParser, source)
if err != nil || result == nil {
return "", utils.LavaFormatLog("blockParsing - parse failed", nil,
lavaslices.Slice(
utils.LogAttr("error", err),
utils.LogAttr("result", result),
utils.LogAttr("blockParser", blockParser),
utils.LogAttr("rpcInput", rpcInput),
),
uint(parseErrorLogLevel),
)
return "", fmt.Errorf("blockParsing - parse failed. result=%v error=%w", result, err)
}

resString, ok := result[spectypes.DEFAULT_PARSED_RESULT_INDEX].(string)
Expand All @@ -198,7 +184,7 @@ func parseInputWithLegacyBlockParser(rpcInput RPCInput, blockParser spectypes.Bl
// Returns:
// - A pointer to a ParsedInput struct containing the parsed data.
func parseBlock(rpcInput RPCInput, blockParser spectypes.BlockParser, genericParsers []spectypes.GenericParser, source int) *ParsedInput {
parsedBlockInfo, parsedSuccessfully := parseInputWithGenericParsers(rpcInput, genericParsers)
parsedBlockInfo, _ := parseInputWithGenericParsers(rpcInput, genericParsers)
if parsedBlockInfo == nil {
parsedBlockInfo = NewParsedInput()
} else {
Expand All @@ -209,7 +195,7 @@ func parseBlock(rpcInput RPCInput, blockParser spectypes.BlockParser, genericPar
}
}

parsedRawBlock, _ := parseInputWithLegacyBlockParser(rpcInput, blockParser, source, parsedSuccessfully)
parsedRawBlock, _ := parseInputWithLegacyBlockParser(rpcInput, blockParser, source)
parsedBlockInfo.parsedDataRaw = unquoteString(parsedRawBlock)
return parsedBlockInfo
}
Expand Down Expand Up @@ -242,9 +228,21 @@ func unquoteString(str string) string {
func ParseBlockHashFromReplyAndDecode(rpcInput RPCInput, resultParser spectypes.BlockParser, genericParsers []spectypes.GenericParser) (string, error) {
parsedInput, parsedSuccessfully := parseInputWithGenericParsers(rpcInput, genericParsers)
if parsedInput == nil {
parsedBlockHashFromBlockParser, err := parseInputWithLegacyBlockParser(rpcInput, resultParser, PARSE_RESULT, parsedSuccessfully)
parsedBlockHashFromBlockParser, err := parseInputWithLegacyBlockParser(rpcInput, resultParser, PARSE_RESULT)
if err != nil {
return "", err
parseErrorLogLevel := utils.LAVA_LOG_WARN
if parsedSuccessfully {
// found a hash, no need to log warning later
parseErrorLogLevel = utils.LAVA_LOG_DEBUG
}

return "", utils.LavaFormatLog("failed to parse with legacy block parser", err,
lavaslices.Slice(
utils.LogAttr("rpcInput", rpcInput),
utils.LogAttr("resultParser", resultParser),
),
uint(parseErrorLogLevel),
)
}
return parseResponseByEncoding([]byte(parsedBlockHashFromBlockParser), resultParser.Encoding)
}
Expand Down

0 comments on commit 444c69e

Please sign in to comment.