Skip to content

Commit

Permalink
consensus: fetch roothash last round results
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Feb 2, 2024
1 parent 630bde0 commit 91539b8
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions analyzer/consensus/data_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

beacon "github.com/oasisprotocol/nexus/coreapi/v22.2.11/beacon/api"
consensus "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api"
roothash "github.com/oasisprotocol/nexus/coreapi/v22.2.11/roothash/api"
"github.com/oasisprotocol/nexus/storage/oasis/nodeapi"
)

Expand Down Expand Up @@ -50,7 +51,7 @@ func fetchAllData(ctx context.Context, cc nodeapi.ConsensusApiLite, network sdkC
return nil, err
}

rootHashData, err := fetchRootHashData(ctx, cc, height)
rootHashData, err := fetchRootHashData(ctx, cc, network, height)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -277,15 +278,31 @@ func fetchGovernanceData(ctx context.Context, cc nodeapi.ConsensusApiLite, heigh
}

// fetchRootHashData retrieves roothash events at the provided block height.
func fetchRootHashData(ctx context.Context, cc nodeapi.ConsensusApiLite, height int64) (*rootHashData, error) {
func fetchRootHashData(ctx context.Context, cc nodeapi.ConsensusApiLite, network sdkConfig.Network, height int64) (*rootHashData, error) {
events, err := cc.RoothashEvents(ctx, height)
if err != nil {
return nil, err
}

lastRoundResults := make(map[coreCommon.Namespace]*roothash.RoundResults, len(network.ParaTimes.All))

for name := range network.ParaTimes.All {
var runtimeID coreCommon.Namespace
if err1 := runtimeID.UnmarshalHex(network.ParaTimes.All[name].ID); err1 != nil {
return nil, err1
}

res, err1 := cc.RoothashLastRoundResults(ctx, height, runtimeID)
if err1 != nil {
return nil, err1
}
lastRoundResults[runtimeID] = res
}

return &rootHashData{
Height: height,
Events: events,
Height: height,
Events: events,
LastRoundResults: lastRoundResults,
}, nil
}

Expand Down Expand Up @@ -352,6 +369,8 @@ type rootHashData struct {
Height int64

Events []nodeapi.Event

LastRoundResults map[coreCommon.Namespace]*roothash.RoundResults
}

// schedulerData represents data for elected committees and validators at a given height.
Expand Down

0 comments on commit 91539b8

Please sign in to comment.