Skip to content

Commit

Permalink
adding isBoostraping method
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Voiculescu committed Aug 4, 2024
1 parent c455a4e commit daef798
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rpc/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,19 @@ func (f *Fetcher) fetchBlockData(_ context.Context, requestedBlockNum uint64) (*
block: block,
}

if f.metadata == nil { // bootstraping
runtimeSpecVersion := f.lastBlockInfo.specVersion
if isBoostraping(f.metadata, f.lastBlockInfo.specVersion) { // bootstraping
fmt.Println("doudou: bootstraping")
_, err := f.setMetadata(blockHash, client)
if err != nil {
return nil, fmt.Errorf("failed to update metadata: %w", err)
}

runtimeVersion, err := client.state.GetRuntimeVersion(blockHash)
if err != nil {
return nil, fmt.Errorf("failed to get runtime version at block hash %s: %w", blockHash.Hex(), err)
}
runtimeSpecVersion = uint32(runtimeVersion.SpecVersion)
}

if requestedBlockNum > 0 {
Expand Down Expand Up @@ -178,7 +186,6 @@ func (f *Fetcher) fetchBlockData(_ context.Context, requestedBlockNum uint64) (*
previousSpecVersionHash = blobHash
}

runtimeSpecVersion := f.lastBlockInfo.specVersion
if shouldUpdateMetadata(currentSpecVersionHash, previousSpecVersionHash, isForward(f.lastBlockInfo.blockNum, requestedBlockNum)) {
runtimeVersion, err := client.state.GetRuntimeVersion(blockHash)
if err != nil {
Expand Down Expand Up @@ -263,6 +270,10 @@ func shouldUpdateMetadata(specVersionHash string, parentSpecVersionHash string,
return specVersionHash != parentSpecVersionHash
}

func isBoostraping(metadata *types.Metadata, specVersion uint32) bool {
return metadata == nil || specVersion == 0
}

func (f *Fetcher) fetchLatestBlockNum(_ context.Context) (uint64, error) {
return firecoreRPC.WithClients(f.gearClients, func(client *Client) (uint64, error) {
header, err := client.client.RPC.Chain.GetHeaderLatest()
Expand Down

0 comments on commit daef798

Please sign in to comment.