Skip to content

Commit

Permalink
fix elad 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Sep 11, 2024
1 parent 1dc01d6 commit c956b98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions protocol/chaintracker/chain_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions protocol/rpcprovider/rpcprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c956b98

Please sign in to comment.