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

feat: PRT - Add capability to parse block fetch errors #1849

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
240f5f9
consumer is now supporting chainRouter interface
omerlavanet Dec 11, 2024
849ea03
allow parsing block errors and do archive on the 4th retry
omerlavanet Dec 11, 2024
840426f
use only the error message when extracting node data
omerlavanet Dec 11, 2024
5459134
added earliest update if a block error was detected
omerlavanet Dec 12, 2024
6945503
allow updating latest requested block if a block error was detected
omerlavanet Dec 12, 2024
ae2633f
fix unitests and fetcher init with endpoint
omerlavanet Dec 12, 2024
9dd95d8
add max int calls to mock maps
omerlavanet Dec 12, 2024
3dd29aa
add a retry mechanism to ExtractNodeData
omerlavanet Dec 12, 2024
7f93a1d
added locks in chainParser
omerlavanet Dec 12, 2024
0ce8ac3
wip
omerlavanet Dec 15, 2024
b911556
added the ability to parse latest block errors
omerlavanet Dec 17, 2024
58da257
add sanity to boost performance
omerlavanet Dec 17, 2024
573e60c
lint
omerlavanet Dec 18, 2024
26746a4
lint
omerlavanet Dec 18, 2024
f37b95a
Merge remote-tracking branch 'origin/main' into PRT-add-capability-to…
omerlavanet Dec 18, 2024
ba44b27
added tests
omerlavanet Dec 19, 2024
ff32875
fix state transition to update latest block
omerlavanet Dec 19, 2024
a409038
add interceptor capability to provider listener in tests
omerlavanet Dec 22, 2024
8d0f17d
Merge remote-tracking branch 'origin/main' into PRT-add-capability-to…
omerlavanet Dec 22, 2024
aac33dd
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
omerlavanet Dec 24, 2024
ce371dd
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
omerlavanet Dec 25, 2024
59d4a4f
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
omerlavanet Dec 25, 2024
55682e7
Ran go mod tidy
shleikes Dec 25, 2024
820aa86
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
nimrod-teich Dec 25, 2024
4a48eff
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
shleikes Dec 29, 2024
78206c8
Merge branch 'main' into PRT-add-capability-to-parse-block-fetch-errors
shleikes Jan 2, 2025
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
github.com/dgraph-io/badger/v4 v4.1.0
github.com/dgraph-io/ristretto/v2 v2.0.1
github.com/fullstorydev/grpcurl v1.8.5
github.com/goccy/go-json v0.10.2
github.com/gogo/status v1.1.0
Expand All @@ -44,6 +46,7 @@ require (
github.com/joho/godotenv v1.3.0
github.com/newrelic/go-agent/v3 v3.20.4
github.com/praserx/ipconv v1.2.1
github.com/sergi/go-diff v1.3.1
github.com/spf13/pflag v1.0.5
github.com/tidwall/gjson v1.16.0
github.com/tidwall/sjson v1.2.5
Expand Down Expand Up @@ -80,13 +83,10 @@ require (
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgraph-io/ristretto/v2 v2.0.1 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
Expand Down Expand Up @@ -155,7 +155,7 @@ require (
github.com/deckarep/golang-set v1.8.0
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.2.0
github.com/dgraph-io/ristretto v0.2.0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
Expand Down Expand Up @@ -461,8 +459,6 @@ github.com/dgraph-io/badger/v4 v4.1.0 h1:E38jc0f+RATYrycSUf9LMv/t47XAy+3CApyYSq4
github.com/dgraph-io/badger/v4 v4.1.0/go.mod h1:P50u28d39ibBRmIJuQC/NSdBOg46HnHw7al2SW5QRHg=
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
github.com/dgraph-io/ristretto/v2 v2.0.1 h1:7W0LfEP+USCmtrUjJsk+Jv2jbhJmb72N4yRI7GrLdMI=
Expand Down Expand Up @@ -621,8 +617,6 @@ github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -1176,6 +1170,8 @@ github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KR
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand Down Expand Up @@ -1234,8 +1230,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand Down Expand Up @@ -1622,12 +1616,9 @@ golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
72 changes: 61 additions & 11 deletions protocol/chainlib/base_chain_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/lavanet/lava/v4/protocol/chainlib/extensionslib"
"github.com/lavanet/lava/v4/protocol/common"
"github.com/lavanet/lava/v4/protocol/parser"
"github.com/lavanet/lava/v4/utils"
"github.com/lavanet/lava/v4/utils/lavaslices"
"github.com/lavanet/lava/v4/utils/maps"
Expand All @@ -35,25 +36,74 @@ type InternalPath struct {
Addon string
}

type ErrorPattern struct {
TooNewPattern string
TooOldPattern string
}

func (bep *ErrorPattern) IsEmpty() bool {
return bep.TooNewPattern == "" && bep.TooOldPattern == ""
}

type BaseChainParser struct {
internalPaths map[string]InternalPath
taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer
spec spectypes.Spec
rwLock sync.RWMutex
serverApis map[ApiKey]ApiContainer
apiCollections map[CollectionKey]*spectypes.ApiCollection
headers map[ApiKey]*spectypes.Header
verifications map[VerificationKey]map[string][]VerificationContainer // map[VerificationKey]map[InternalPath][]VerificationContainer
allowedAddons map[string]bool
extensionParser extensionslib.ExtensionParser
active bool
internalPaths map[string]InternalPath
taggedApis map[spectypes.FUNCTION_TAG]TaggedContainer
spec spectypes.Spec
rwLock sync.RWMutex
serverApis map[ApiKey]ApiContainer
apiCollections map[CollectionKey]*spectypes.ApiCollection
headers map[ApiKey]*spectypes.Header
verifications map[VerificationKey]map[string][]VerificationContainer // map[VerificationKey]map[InternalPath][]VerificationContainer
allowedAddons map[string]bool
extensionParser extensionslib.ExtensionParser
active bool
blockErrorPattern ErrorPattern
}

// allows an optional kind to specify the type of error to identify
// LATEST is identifying too new error
// EARLIEST is identifying too old error
func (bcp *BaseChainParser) IdentifyNodeError(message string, kind ...DataKind) (isBlockError bool, blockHeight int64) {
bcp.rwLock.RLock()
defer bcp.rwLock.RUnlock()
if bcp.blockErrorPattern.IsEmpty() {
return false, 0
}
if len(kind) == 0 || kind[0] == LATEST {
var success bool
success, blockHeight := parser.ParseNumberFromPattern(bcp.blockErrorPattern.TooNewPattern, message)
if success {
return true, blockHeight
}
}
if len(kind) == 0 || kind[0] == EARLIEST {
success, blockHeight := parser.ParseNumberFromPattern(bcp.blockErrorPattern.TooOldPattern, message)
if success {
return true, blockHeight
}
}
return false, 0
}

func (bcp *BaseChainParser) SetBlockErrorPattern(pattern string, kind DataKind) {
bcp.rwLock.Lock()
defer bcp.rwLock.Unlock()
if kind == EARLIEST {
bcp.blockErrorPattern.TooOldPattern = pattern
} else if kind == LATEST {
bcp.blockErrorPattern.TooNewPattern = pattern
}
}

func (bcp *BaseChainParser) Activate() {
bcp.rwLock.Lock()
defer bcp.rwLock.Unlock()
bcp.active = true
}

func (bcp *BaseChainParser) Active() bool {
bcp.rwLock.RLock()
defer bcp.rwLock.RUnlock()
return bcp.active
}

Expand Down
44 changes: 38 additions & 6 deletions protocol/chainlib/chain_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ type ChainFetcher struct {
}

func (cf *ChainFetcher) FetchEndpoint() lavasession.RPCProviderEndpoint {
return *cf.endpoint
endpoint := cf.endpoint
if endpoint == nil {
return lavasession.RPCProviderEndpoint{}
}
return *endpoint
}

func (cf *ChainFetcher) Validate(ctx context.Context) error {
Expand Down Expand Up @@ -369,28 +373,56 @@ func (cf *ChainFetcher) constructRelayData(conectionType string, path string, da
return relayData
}

func (cf *ChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error) {
func findFormatDirective(template, data string) string {
for i := 0; i < len(template); i++ {
if template[i] != data[i] {
return template[i : i+2] // Assuming the directive is two characters long, like %x or %d
}
}
return ""
}

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
}
template := parsing.FunctionTemplate
format = findFormatDirective(template, string(data))
_, 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) {
parsing, apiCollection, ok := cf.chainParser.GetParsingByTag(spectypes.FUNCTION_TAG_GET_BLOCK_BY_NUM)
tagName := spectypes.FUNCTION_TAG_GET_BLOCK_BY_NUM.String()
if !ok {
return "", utils.LavaFormatError(tagName+" tag function not found", nil, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
return nil, "", spectypes.CollectionData{}, "", nil, nil, nil, common.NodeUrl{}, "", utils.LavaFormatError(tagName+" tag function not found", nil, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
}
collectionData := apiCollection.CollectionData

if parsing.FunctionTemplate == "" {
return "", utils.LavaFormatError(tagName+" missing function template", nil, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
return nil, "", spectypes.CollectionData{}, "", nil, nil, nil, common.NodeUrl{}, "", utils.LavaFormatError(tagName+" missing function template", nil, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
}
path := parsing.ApiName
data := []byte(fmt.Sprintf(parsing.FunctionTemplate, blockNum))
chainMessage, err := CraftChainMessage(parsing, collectionData.Type, cf.chainParser, &CraftData{Path: path, Data: data, ConnectionType: collectionData.Type}, cf.ChainFetcherMetadata())
if err != nil {
return "", utils.LavaFormatError(tagName+" failed CraftChainMessage on function template", err, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
return nil, "", spectypes.CollectionData{}, "", nil, nil, nil, common.NodeUrl{}, "", utils.LavaFormatError(tagName+" failed CraftChainMessage on function template", err, []utils.Attribute{{Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
}
start := time.Now()
reply, _, _, proxyUrl, chainId, err := cf.chainRouter.SendNodeMsg(ctx, nil, chainMessage, nil)
if err != nil {
timeTaken := time.Since(start)
return "", utils.LavaFormatDebug(tagName+" failed sending chainMessage", []utils.Attribute{{Key: "sendTime", Value: timeTaken}, {Key: "error", Value: err}, {Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
return nil, "", spectypes.CollectionData{}, "", nil, nil, nil, common.NodeUrl{}, "", utils.LavaFormatDebug(tagName+" failed sending chainMessage", []utils.Attribute{{Key: "sendTime", Value: timeTaken}, {Key: "error", Value: err}, {Key: "chainID", Value: cf.endpoint.ChainID}, {Key: "APIInterface", Value: cf.endpoint.ApiInterface}}...)
}
return parsing, tagName, collectionData, path, data, chainMessage, reply, proxyUrl, chainId, nil
}

func (cf *ChainFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error) {
parsing, tagName, collectionData, path, data, chainMessage, reply, proxyUrl, chainId, err := cf.fetchSpecificBlock(ctx, blockNum)
if err != nil {
return "", err
}
parserInput, err := FormatResponseForParsing(reply.RelayReply, chainMessage)
if err != nil {
Expand Down
28 changes: 17 additions & 11 deletions protocol/chainlib/chain_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import (
spectypes "github.com/lavanet/lava/v4/x/spec/types"
)

type OriginalRaw struct {
Path string
Data []byte
}

type updatableRPCInput interface {
rpcInterfaceMessages.GenericMessage
UpdateLatestBlockInMessage(latestBlock uint64, modifyContent bool) (success bool)
UpdateLatestBlockInMessage(latestBlock uint64) (success bool)
AppendHeader(metadata []pairingtypes.Metadata)
SubscriptionIdExtractor(reply *rpcclient.JsonrpcMessage) string
GetRawRequestHash() ([]byte, error)
Expand All @@ -32,13 +37,17 @@ type baseChainMessageContainer struct {
forceCacheRefresh bool
parseDirective *spectypes.ParseDirective // setting the parse directive related to the api, can be nil
usedDefaultValue bool

inputHashCache []byte
originalRaw OriginalRaw
inputHashCache []byte
// resultErrorParsingMethod passed by each api interface message to parse the result of the message
// and validate it doesn't contain a node error
resultErrorParsingMethod func(data []byte, httpStatusCode int) (hasError bool, errorMessage string)
}

func (bcmc *baseChainMessageContainer) GetOriginal() (path string, data []byte) {
return bcmc.originalRaw.Path, bcmc.originalRaw.Data
}

func (bcmc *baseChainMessageContainer) UpdateEarliestInMessage(incomingEarliest int64) bool {
updatedSuccessfully := false
if bcmc.earliestRequestedBlock != spectypes.EARLIEST_BLOCK {
Expand Down Expand Up @@ -130,17 +139,14 @@ func (bcnc baseChainMessageContainer) GetRPCMessage() rpcInterfaceMessages.Gener
return bcnc.msg
}

func (bcnc *baseChainMessageContainer) UpdateLatestBlockInMessage(latestBlock int64, modifyContent bool) (modifiedOnLatestReq bool) {
func (bcnc *baseChainMessageContainer) UpdateLatestBlockInMessage(latestBlock int64) (modifiedOnLatestReq bool) {
requestedBlock, _ := bcnc.RequestedBlock()
if latestBlock <= spectypes.NOT_APPLICABLE || requestedBlock != spectypes.LATEST_BLOCK {
// we disallow setting latest block to 0 or one of the wildcards as an override
if requestedBlock > latestBlock || latestBlock <= 0 {
return false
}
success := bcnc.msg.UpdateLatestBlockInMessage(uint64(latestBlock), modifyContent)
if success {
bcnc.latestRequestedBlock = latestBlock
return true
}
return false
bcnc.latestRequestedBlock = latestBlock
return true
}

func (bcnc *baseChainMessageContainer) GetExtensions() []*spectypes.Extension {
Expand Down
5 changes: 4 additions & 1 deletion protocol/chainlib/chainlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ type ChainParser interface {
ExtensionsParser() *extensionslib.ExtensionParser
ExtractDataFromRequest(*http.Request) (url string, data string, connectionType string, metadata []pairingtypes.Metadata, err error)
SetResponseFromRelayResult(*common.RelayResult) (*http.Response, error)
SetBlockErrorPattern(string, DataKind)
IdentifyNodeError(message string, kind ...DataKind) (isBlockError bool, blockHeight int64)
}

type ChainMessage interface {
SubscriptionIdExtractor(reply *rpcclient.JsonrpcMessage) string
RequestedBlock() (latest int64, earliest int64)
UpdateLatestBlockInMessage(latestBlock int64, modifyContent bool) (modified bool)
UpdateLatestBlockInMessage(latestBlock int64) (modified bool)
AppendHeader(metadata []pairingtypes.Metadata)
GetExtensions() []*spectypes.Extension
OverrideExtensions(extensionNames []string, extensionParser *extensionslib.ExtensionParser)
Expand All @@ -113,6 +115,7 @@ type ChainMessageForSend interface {
GetApiCollection() *spectypes.ApiCollection
GetParseDirective() *spectypes.ParseDirective
CheckResponseError(data []byte, httpStatusCode int) (hasError bool, errorMessage string)
GetOriginal() (path string, data []byte)
}

type HealthReporter interface {
Expand Down
Loading
Loading