Skip to content

Commit

Permalink
feat(prospective-parachains) handle GetMinimumRelayParents signal
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielDDHM committed Dec 3, 2024
1 parent 36e20f7 commit 4e34f46
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions dot/parachain/prospective-parachains/prospective-parachains.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"

fragmentchain "github.com/ChainSafe/gossamer/dot/parachain/prospective-parachains/fragment-chain"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
Expand All @@ -22,19 +23,7 @@ type View struct {
}

type RelayParentData struct {
FragmentChains map[parachaintypes.ParaID]*FragmentChain
}

type FragmentChain struct {
Scope func() *Scope
}

type Scope struct {
EarliestRelayParent func() *RelayParent
}

type RelayParent struct {
Number parachaintypes.BlockNumber
FragmentChains map[parachaintypes.ParaID]*fragmentchain.FragmentChain
}

// Name returns the name of the subsystem
Expand Down Expand Up @@ -85,7 +74,7 @@ func (pp *ProspectiveParachains) processMessage(msg any) {
panic("not implemented yet: see issue #4311")
case GetMinimumRelayParents:
// Directly use the msg since it's already of type GetMinimumRelayParents
pp.AnswerMinimumRelayParentsRequest(pp.View, msg.RelayChainBlockHash, msg.Sender)
pp.AnswerMinimumRelayParentsRequest(msg.RelayChainBlockHash, msg.Sender)
case GetProspectiveValidationData:
panic("not implemented yet: see issue #4313")
default:
Expand All @@ -106,22 +95,21 @@ func (*ProspectiveParachains) ProcessBlockFinalizedSignal(parachaintypes.BlockFi
}

func (pp *ProspectiveParachains) AnswerMinimumRelayParentsRequest(
view *View,
relayChainBlockHash common.Hash,
sender chan []ParaIDBlockNumber,
) {
// Slice to store the results
var result []ParaIDBlockNumber

// Check if the relayChainBlockHash exists in active_leaves
if exists := view.ActiveLeaves[relayChainBlockHash]; exists {
if exists := pp.View.ActiveLeaves[relayChainBlockHash]; exists {
// Retrieve data associated with the relayChainBlockHash
if leafData, found := view.PerRelayParent[relayChainBlockHash]; found {
if leafData, found := pp.View.PerRelayParent[relayChainBlockHash]; found {
// Iterate over fragment_chains and collect the data
for paraID, fragmentChain := range leafData.FragmentChains {
result = append(result, ParaIDBlockNumber{
ParaId: paraID,
BlockNumber: fragmentChain.Scope().EarliestRelayParent().Number,
BlockNumber: parachaintypes.BlockNumber(fragmentChain.Scope().EarliestRelayParent().Number),
})
}
}
Expand Down

0 comments on commit 4e34f46

Please sign in to comment.