-
Notifications
You must be signed in to change notification settings - Fork 127
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): Implement HandleIntroduceSecondedCandidate
#4350
base: feat/parachain
Are you sure you want to change the base?
Changes from all commits
afa3e68
404f5fe
6648464
5119649
e072160
0de059a
0388b02
1b796b8
f11ee4f
6a001c8
6b30bc6
5f01ccb
987c880
e9b4852
15feb1b
fe27ee3
a8960d8
a53f150
038dfce
0465a41
5abd1e3
a4e8f34
d344eb5
2ac2d82
44b74ea
cdf03de
44a1ad1
75f979b
cecbc74
fdfb811
4ccca75
16d94c1
3809bec
ea78d43
54e0adb
78dfef1
e55b6ce
2f60868
d2b6df7
5999e88
041f161
082bb9c
153b7d6
7d716c7
1dfeb76
ba8ede8
ef35ba9
6e28164
b65841c
30062cf
8d80d2d
e484624
42a7345
87e096c
71085e7
da18a0b
d16b056
e5d8019
1835388
ee66827
3ba5603
38aefbd
df24773
1e2a74b
2db086d
3985deb
f8e5e9e
bc7d201
f6f4a27
c4917eb
35a714d
3a83846
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,13 +4,24 @@ import ( | |||
"context" | ||||
"errors" | ||||
|
||||
"github.com/ChainSafe/gossamer/dot/parachain/backing" | ||||
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)) | ||||
|
||||
// Initialize with empty values. | ||||
func NewView() *view { | ||||
return &view{ | ||||
perRelayParent: make(map[common.Hash]*relayParentData), | ||||
activeLeaves: make(map[common.Hash]bool), | ||||
implicitView: nil, // TODO: currently there's no implementation for ImplicitView, reference is: | ||||
// https://github.com/ChainSafe/gossamer/blob/main/lib/prospective_parachains/view.go#L10 | ||||
} | ||||
} | ||||
|
||||
type ProspectiveParachains struct { | ||||
SubsystemToOverseer chan<- any | ||||
View *view | ||||
|
@@ -19,6 +30,7 @@ type ProspectiveParachains struct { | |||
type view struct { | ||||
activeLeaves map[common.Hash]bool | ||||
perRelayParent map[common.Hash]*relayParentData | ||||
implicitView backing.ImplicitView | ||||
} | ||||
|
||||
type relayParentData struct { | ||||
|
@@ -34,6 +46,7 @@ func (*ProspectiveParachains) Name() parachaintypes.SubSystemName { | |||
func NewProspectiveParachains(overseerChan chan<- any) *ProspectiveParachains { | ||||
prospectiveParachain := ProspectiveParachains{ | ||||
SubsystemToOverseer: overseerChan, | ||||
View: NewView(), | ||||
} | ||||
return &prospectiveParachain | ||||
} | ||||
|
@@ -64,7 +77,11 @@ func (pp *ProspectiveParachains) processMessage(msg any) { | |||
case parachaintypes.BlockFinalizedSignal: | ||||
_ = pp.ProcessBlockFinalizedSignal(msg) | ||||
case IntroduceSecondedCandidate: | ||||
panic("not implemented yet: see issue #4308") | ||||
pp.introduceSecondedCandidate( | ||||
pp.View, | ||||
msg.IntroduceSecondedCandidateRequest, | ||||
msg.Response, | ||||
) | ||||
case CandidateBacked: | ||||
panic("not implemented yet: see issue #4309") | ||||
case GetBackableCandidates: | ||||
|
@@ -82,6 +99,96 @@ func (pp *ProspectiveParachains) processMessage(msg any) { | |||
|
||||
} | ||||
|
||||
func (pp *ProspectiveParachains) introduceSecondedCandidate( | ||||
rebonat0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
view *view, | ||||
request IntroduceSecondedCandidateRequest, | ||||
response chan bool, | ||||
) { | ||||
para := request.CandidateParaID | ||||
candidate := request.CandidateReceipt | ||||
pvd := request.PersistedValidationData | ||||
|
||||
hash, err := candidate.Hash() | ||||
|
||||
if err != nil { | ||||
logger.Tracef("hashing candidate: %s", err.Error()) | ||||
response <- false | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually the writer closes the channel when it is done. Will this channel be used somewhere else as well or should it be closed here? If it should be closed here, I suggest adding If you are unsure we can leave it as is and figure it out later. In that case please add a TODO comment somewhere. |
||||
return | ||||
} | ||||
|
||||
candidateHash := parachaintypes.CandidateHash{Value: hash} | ||||
|
||||
entry, err := newCandidateEntry( | ||||
candidateHash, | ||||
candidate, | ||||
pvd, | ||||
seconded, | ||||
) | ||||
|
||||
if err != nil { | ||||
logger.Tracef("adding seconded candidate error: %s para: %v", err.Error(), para) | ||||
response <- false | ||||
return | ||||
} | ||||
|
||||
added := make([]common.Hash, 0, len(view.perRelayParent)) | ||||
paraScheduled := false | ||||
|
||||
for relayParent, rpData := range view.perRelayParent { | ||||
chain, exists := rpData.fragmentChains[para] | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||
if !exists { | ||||
continue | ||||
} | ||||
|
||||
_, isActiveLeaf := view.activeLeaves[relayParent] | ||||
|
||||
paraScheduled = true | ||||
|
||||
err = chain.tryAddingSecondedCandidate(entry) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||
if err != nil { | ||||
if errors.Is(err, errCandidateAlreadyKnown) { | ||||
logger.Tracef( | ||||
"attempting to introduce an already known candidate with hash: %s, para: %v relayParent: %v isActiveLeaf: %v", | ||||
candidateHash, | ||||
para, | ||||
relayParent, | ||||
isActiveLeaf, | ||||
) | ||||
added = append(added, relayParent) | ||||
} else { | ||||
logger.Tracef( | ||||
"adding seconded candidate with hash: %s error: %s para: %v relayParent: %v isActiveLeaf: %v", | ||||
candidateHash, | ||||
err.Error(), | ||||
para, | ||||
relayParent, | ||||
isActiveLeaf, | ||||
) | ||||
} | ||||
} else { | ||||
added = append(added, relayParent) | ||||
} | ||||
} | ||||
|
||||
if !paraScheduled { | ||||
logger.Warnf( | ||||
"received seconded candidate with hash: %s for inactive para: %v", | ||||
candidateHash, | ||||
para, | ||||
) | ||||
} | ||||
|
||||
if len(added) == 0 { | ||||
logger.Debugf("newly-seconded candidate cannot be kept under any relay parent: %s", candidateHash) | ||||
} else { | ||||
logger.Tracef("added seconded candidate to %d relay parents: %s", len(added), candidateHash) | ||||
} | ||||
|
||||
response <- len(added) > 0 | ||||
} | ||||
|
||||
// ProcessActiveLeavesUpdateSignal processes active leaves update signal | ||||
func (pp *ProspectiveParachains) ProcessActiveLeavesUpdateSignal(parachaintypes.ActiveLeavesUpdateSignal) error { | ||||
panic("not implemented yet: see issue #4305") | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL returns 404. Was this meant to be https://github.com/paritytech/polkadot-sdk/blob/028e61be43f05f6f6c88c5cca94160f8db075585/polkadot/node/subsystem-util/src/backing_implicit_view.rs#L40?