Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prospective-parachains): implements GetBackableCandidates #4374

Open
wants to merge 56 commits into
base: feat/parachain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
afa3e68
feat: starting the fragment chain implementation
EclesioMeloJunior Nov 11, 2024
404f5fe
feat: implemented `CandidateStorage`
EclesioMeloJunior Nov 12, 2024
6648464
feat: create `Scope`, working on inclusionemulator.Fragment
EclesioMeloJunior Nov 13, 2024
5119649
wip: implementing `validateAgainstConstraints`
EclesioMeloJunior Nov 14, 2024
e072160
feat: implement `BackedChain`
EclesioMeloJunior Nov 14, 2024
0de059a
wip: `FragmentChain` struct implementation
EclesioMeloJunior Nov 15, 2024
0388b02
feat: full `FragmentChain` implementation done
EclesioMeloJunior Nov 16, 2024
1b796b8
chore: wip fragment chain tests
EclesioMeloJunior Nov 19, 2024
f11ee4f
chore: `TestPopulateAndCheckPotential` done
EclesioMeloJunior Nov 21, 2024
6a001c8
feat: bring polkadot-sdk test coverage to fragment chain
EclesioMeloJunior Nov 21, 2024
6b30bc6
chore: remove dsstore
EclesioMeloJunior Nov 26, 2024
5f01ccb
chore: change loopt
EclesioMeloJunior Nov 28, 2024
987c880
Merge branch 'feat/parachain' into eclesio/fragment-chain-impl
EclesioMeloJunior Nov 28, 2024
5abd1e3
chore: fix loop conditional
EclesioMeloJunior Dec 3, 2024
6555735
feat(prospective-parachains) add get backable candidates
DanielDDHM Dec 4, 2024
138c004
Merge branch 'eclesio/fragment-chain-impl' into feature/add_get_backa…
DanielDDHM Dec 4, 2024
2be6501
feat(prospective-parachains) add get backable candidates
DanielDDHM Dec 5, 2024
61f8ee6
Merge branch 'feature/add_get_backable_candidates' of github.com:Dani…
DanielDDHM Dec 5, 2024
54e0adb
chore: address comment
EclesioMeloJunior Dec 5, 2024
78dfef1
chore: address comments
EclesioMeloJunior Dec 6, 2024
e55b6ce
chore: test snakecase
EclesioMeloJunior Dec 6, 2024
2f60868
wip: fixing failing tests
EclesioMeloJunior Dec 6, 2024
041f161
chore: fix `TestScopeOnlyTakesAncestorsUpToMin` test
EclesioMeloJunior Dec 9, 2024
082bb9c
chore: loop until maxDepth + 1
EclesioMeloJunior Dec 9, 2024
153b7d6
Merge branch 'feat/parachain' into eclesio/fragment-chain-impl
EclesioMeloJunior Dec 9, 2024
7d716c7
chore: gofmt
EclesioMeloJunior Dec 9, 2024
1dfeb76
chore: address lint warns
EclesioMeloJunior Dec 9, 2024
ba8ede8
chore: removed `Unconnected` method
EclesioMeloJunior Dec 10, 2024
ef35ba9
chore: remove `candidates` method
EclesioMeloJunior Dec 10, 2024
6e28164
chore: added logs
EclesioMeloJunior Dec 10, 2024
b65841c
Merge branch 'feat/parachain' into eclesio/fragment-chain-impl
EclesioMeloJunior Dec 10, 2024
30062cf
chore: address comments
EclesioMeloJunior Dec 12, 2024
8d80d2d
Merge branch 'eclesio/fragment-chain-impl' of github.com:ChainSafe/go…
EclesioMeloJunior Dec 12, 2024
e484624
Merge branch 'feat/parachain' into eclesio/fragment-chain-impl
EclesioMeloJunior Dec 12, 2024
42a7345
chore: fix misspelling
EclesioMeloJunior Dec 12, 2024
87e096c
Merge branch 'eclesio/fragment-chain-impl' of github.com:ChainSafe/go…
EclesioMeloJunior Dec 12, 2024
dfca73c
Merge branch 'eclesio/fragment-chain-impl' into feature/add_get_backa…
DanielDDHM Dec 12, 2024
71085e7
chore: make types unexported
EclesioMeloJunior Dec 12, 2024
06c3f4d
Merge branch 'eclesio/fragment-chain-impl' into feature/add_get_backa…
DanielDDHM Dec 13, 2024
3d6f093
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 13, 2024
31bdd9d
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 13, 2024
3e65830
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 13, 2024
da18a0b
Trigger Build
EclesioMeloJunior Dec 13, 2024
b0a69e0
Merge branch 'eclesio/fragment-chain-impl' into feature/add_get_backa…
DanielDDHM Dec 13, 2024
d16b056
chore: addressing comments
EclesioMeloJunior Dec 14, 2024
e5d8019
chore: small comments
EclesioMeloJunior Dec 14, 2024
f85bff0
Merge branch 'eclesio/fragment-chain-impl' into feature/add_get_backa…
DanielDDHM Dec 16, 2024
83f38a2
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 16, 2024
111ba1c
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 16, 2024
ae2e7f4
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 24, 2024
5e0f3ef
feat(prospective-parachains) implement getBackableCandidates
DanielDDHM Dec 28, 2024
2465748
Merge branch 'feat/parachain' into feature/add_get_backable_candidates
DanielDDHM Jan 8, 2025
3d4bfa3
feat(prospective-parachains) fix lint
DanielDDHM Jan 8, 2025
4b2fef6
feat(prospective-parachains) fix test getBackableCandidates
DanielDDHM Jan 8, 2025
1de6164
feat(prospective-parachains) fix ancestors test
DanielDDHM Jan 10, 2025
4e9ff50
feat(prospective-parachains) fix ancestors test
DanielDDHM Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion dot/parachain/prospective-parachains/prospective-parachains.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import (

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
)

var logger = log.NewFromGlobal(log.AddContext("pkg", "prospective_parachains"), log.SetLevel(log.Debug))

type ProspectiveParachains struct {
SubsystemToOverseer chan<- any
View *view
}

type view struct {
activeLeaves map[common.Hash]bool
perRelayParent map[common.Hash]*relayParentData
}

type relayParentData struct {
fragmentChains map[parachaintypes.ParaID]*fragmentChain
}

// Name returns the name of the subsystem
Expand Down Expand Up @@ -57,7 +68,7 @@ func (pp *ProspectiveParachains) processMessage(msg any) {
case CandidateBacked:
panic("not implemented yet: see issue #4309")
case GetBackableCandidates:
panic("not implemented yet: see issue #4310")
pp.getBackableCandidates(msg)
case GetHypotheticalMembership:
panic("not implemented yet: see issue #4311")
case GetMinimumRelayParents:
Expand All @@ -80,3 +91,77 @@ func (*ProspectiveParachains) ProcessBlockFinalizedSignal(parachaintypes.BlockFi
// NOTE: this subsystem does not process block finalized signal
return nil
}

func (pp *ProspectiveParachains) getBackableCandidates(
msg GetBackableCandidates,
) {
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
// Extract details from the message
relayParentHash := msg.RelayParentHash
paraId := msg.ParaId
requestedQty := msg.RequestedQty
ancestors := msg.Ancestors
responseChan := msg.Response

// Check if the relay parent is active
if _, exists := pp.View.activeLeaves[relayParentHash]; !exists {
logger.Debugf(
"Requested backable candidates for inactive relay-parent. "+
"RelayParentHash: %v, ParaId: %v",
relayParentHash, paraId,
)
responseChan <- []parachaintypes.CandidateHashAndRelayParent{}
return
}

// Retrieve data for the relay parent
data, ok := pp.View.perRelayParent[relayParentHash]
if !ok {
logger.Debugf(
"Requested backable candidates for nonexistent relay-parent. "+
"RelayParentHash: %v, ParaId: %v",
relayParentHash, paraId,
)
responseChan <- []parachaintypes.CandidateHashAndRelayParent{}
return
}

// Retrieve the fragment chain for the ParaID
chain, ok := data.fragmentChains[paraId]
if !ok {
logger.Debugf(
"Requested backable candidates for inactive ParaID. "+
"RelayParentHash: %v, ParaId: %v",
relayParentHash, paraId,
)
responseChan <- []parachaintypes.CandidateHashAndRelayParent{}
return
}

// Retrieve backable candidates from the fragment chain
backableCandidates := chain.findBackableChain(ancestors, requestedQty)
if len(backableCandidates) == 0 {
logger.Debugf(
"No backable candidates found. RelayParentHash: %v, ParaId: %v, Ancestors: %v",
relayParentHash, paraId, ancestors,
)
responseChan <- []parachaintypes.CandidateHashAndRelayParent{}
return
}

logger.Debugf(
"Found backable candidates: %v. RelayParentHash: %v, ParaId: %v, Ancestors: %v",
backableCandidates, relayParentHash, paraId, ancestors,
)

// Convert backable candidates to the expected response format
candidateHashes := make([]parachaintypes.CandidateHashAndRelayParent, len(backableCandidates))
for i, candidate := range backableCandidates {
candidateHashes[i] = parachaintypes.CandidateHashAndRelayParent{
CandidateHash: candidate.candidateHash,
CandidateRelayParent: candidate.realyParentHash,
}
}

// Send the result through the response channel
responseChan <- candidateHashes
}
Loading
Loading