Skip to content

Commit

Permalink
use only the error message when extracting node data
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Dec 11, 2024
1 parent 849ea03 commit 840426f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions protocol/chainlib/chain_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,15 @@ func findFormatDirective(template, data string) string {
return ""
}

func (cf *ChainFetcher) FetchBlock(ctx context.Context, blockNum int64) (response string, format string, err error) {
parsing, _, _, _, data, _, reply, _, _, err := cf.fetchSpecificBlock(ctx, blockNum)
func (cf *ChainFetcher) FetchBlock(ctx context.Context, blockNum int64) (response string, errorMessage string, format string, err error) {
parsing, _, _, _, data, chainMessage, reply, _, _, err := cf.fetchSpecificBlock(ctx, blockNum)
if err != nil {
return "", "", err
return "", "", "", err
}
template := parsing.FunctionTemplate
format = findFormatDirective(template, string(data))
return string(reply.RelayReply.Data), format, nil
_, errorMessage = chainMessage.CheckResponseError(reply.RelayReply.Data, reply.StatusCode)
return string(reply.RelayReply.Data), errorMessage, format, nil
}

func (cf *ChainFetcher) fetchSpecificBlock(ctx context.Context, blockNum int64) (*spectypes.ParseDirective, string, spectypes.CollectionData, string, []byte, ChainMessageForSend, *RelayReplyWrapper, common.NodeUrl, string, error) {
Expand Down
12 changes: 6 additions & 6 deletions protocol/rpcconsumer/rpcconsumer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1656,26 +1656,26 @@ func (rpccs *RPCConsumerServer) ExtractNodeData(ctx context.Context) {
Cache: nil,
})
// we want a block that will surely fail
response, format, err := chainFetcher.FetchBlock(ctx, math.MaxInt64)
_, responseErrorMessage, format, err := chainFetcher.FetchBlock(ctx, math.MaxInt64)
if err != nil {
utils.LavaFormatError("failed sending a fault block fetch to parse errors", err)
return
}
if response != "" {
if responseErrorMessage != "" {
blockError := ""
formatted := fmt.Sprintf(format, math.MaxInt64)
re := regexp.MustCompile(formatted)
blockError = re.ReplaceAllString(response, format)
if blockError == response {
blockError = re.ReplaceAllString(responseErrorMessage, format)
if blockError == responseErrorMessage {
// this shouldnt happen if the block exists in the response
return
}
response2, _, err := chainFetcher.FetchBlock(ctx, math.MaxInt64-1)
_, responseErrorMessage, _, err = chainFetcher.FetchBlock(ctx, math.MaxInt64-1)
if err != nil {
utils.LavaFormatError("failed fetching block for Node Data", err)
}
formatted = fmt.Sprintf(blockError, math.MaxInt64-1)
if formatted == response2 {
if formatted == responseErrorMessage {
utils.LavaFormatInfo("[+] identified pattern for node errors, setting in chain parser", utils.LogAttr("pattern", blockError))
rpccs.chainParser.SetBlockErrorPattern(blockError)
return
Expand Down

0 comments on commit 840426f

Please sign in to comment.