From c956b9822f271298493312bb827e6bc777e2458a Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 11 Sep 2024 19:15:14 +0200 Subject: [PATCH] fix elad 2 --- protocol/chaintracker/chain_tracker.go | 21 ++++++++++++++++----- protocol/rpcprovider/rpcprovider.go | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/protocol/chaintracker/chain_tracker.go b/protocol/chaintracker/chain_tracker.go index 9b70ba07c9..29d6d390d6 100644 --- a/protocol/chaintracker/chain_tracker.go +++ b/protocol/chaintracker/chain_tracker.go @@ -68,6 +68,10 @@ type ChainTracker struct { blockEventsGap []time.Duration blockTimeUpdatables map[blockTimeUpdatable]struct{} pmetrics *metrics.ProviderMetricsManager + + // initial config + averageBlockTime time.Duration + serverAddress string } // this function returns block hashes of the blocks: [from block - to block] inclusive. an additional specific block hash can be provided. order is sorted ascending @@ -570,6 +574,16 @@ func (ct *ChainTracker) serve(ctx context.Context, listenAddr string) error { return nil } +func (ct *ChainTracker) StartAndServe(ctx context.Context) error { + err := ct.start(ctx, ct.averageBlockTime) + if err != nil { + return err + } + + err = ct.serve(ctx, ct.serverAddress) + return err +} + func NewChainTracker(ctx context.Context, chainFetcher ChainFetcher, config ChainTrackerConfig) (chainTracker *ChainTracker, err error) { if !rand.Initialized() { utils.LavaFormatFatal("can't start chainTracker with nil rand source", nil) @@ -598,16 +612,13 @@ func NewChainTracker(ctx context.Context, chainFetcher ChainFetcher, config Chai startupTime: time.Now(), pmetrics: config.Pmetrics, pollingTimeMultiplier: time.Duration(pollingTime), + averageBlockTime: config.AverageBlockTime, + serverAddress: config.ServerAddress, } if chainFetcher == nil { return nil, utils.LavaFormatError("can't start chainTracker with nil chainFetcher argument", nil) } chainTracker.endpoint = chainFetcher.FetchEndpoint() - err = chainTracker.start(ctx, config.AverageBlockTime) - if err != nil { - return nil, err - } - err = chainTracker.serve(ctx, config.ServerAddress) return chainTracker, err } diff --git a/protocol/rpcprovider/rpcprovider.go b/protocol/rpcprovider/rpcprovider.go index 5fa8ecc64f..9b860b433b 100644 --- a/protocol/rpcprovider/rpcprovider.go +++ b/protocol/rpcprovider/rpcprovider.go @@ -439,6 +439,7 @@ func (rpcp *RPCProvider) SetupEndpoint(ctx context.Context, rpcProviderEndpoint } if !loaded { // this is the first time we are setting up the chain tracker, we need to register for spec verifications + chainTracker.StartAndServe(ctx) utils.LavaFormatDebug("Registering for spec verifications for endpoint", utils.LogAttr("rpcEndpoint", rpcEndpoint)) // we register for spec verifications only once, and this triggers all chainFetchers of that specId when it triggers err = rpcp.providerStateTracker.RegisterForSpecVerifications(ctx, specValidator, rpcEndpoint.ChainID)