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(disputes/coordinator): implements the coordinator module for the disputes-coordinator #3647

Closed

Conversation

kanishkatn
Copy link
Contributor

@kanishkatn kanishkatn commented Dec 14, 2023

Changes

Implements the coordinator module for the disputes coordinator.

Please skip reviewing BTree since it's waiting on an upstream update. Refer: #3536

Issues

#3593

Primary Reviewer

@EclesioMeloJunior

@kanishkatn kanishkatn force-pushed the feat/k/disputes/coordinator branch 3 times, most recently from 6185550 to ade4382 Compare December 14, 2023 21:57
@kanishkatn kanishkatn force-pushed the feat/k/disputes/coordinator branch from ade4382 to e888108 Compare December 16, 2023 15:33
Copy link
Contributor

@kishansagathiya kishansagathiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing this.

Since this is a big PR, I am not reviewing this entirely at a time but part by part.

I will also point out the obvious problem in base branch of this PR. into feat/k/disputes-coordinator from feat/k/disputes/coordinator doesn't make sense, please change the base branch to feat/parachain

Comment on lines 165 to 170
b.recentDisputes.RLock()
recentDisputes := b.recentDisputes.Copy()
recentDisputes, err := b.GetRecentDisputes()
if err != nil {
return scale.BTree{}, fmt.Errorf("get recent disputes: %w", err)
}
b.recentDisputes.RUnlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deadlock.
At line 165 b.recentDisputes is readlocked and then it gets readlocked again GetRecentDisputes.
Lock-Unlock are not needed here. Let's do them only inside GetRecentDisputes

Comment on lines +181 to +182
if err != nil {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting an error does not mean that dispute is still active or inactive.

}

if concludedAt != nil && *concludedAt+uint64(ActiveDuration.Seconds()) > uint64(now) {
if !isDisputeInactive(dispute.DisputeStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of using a variable named isDisputeInactive and then checking !isDisputeInactive, I would prefer IsDisputeActive, That is more readable and easy to understand.

if err != nil {
logger.Errorf("failed to get concluded at: %s", err)
return true
isDisputeInactive := func(status types.DisputeStatusVDT) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to create this extra function. Plus, instead of ConcludedAt, use dispute.DisputeStatus.IsActive directly.

@@ -97,10 +101,10 @@ func (b *overlayBackend) GetEarliestSession() (*parachainTypes.SessionIndex, err
return b.inner.GetEarliestSession()
}

func (b *overlayBackend) GetRecentDisputes() (*btree.BTree, error) {
func (b *overlayBackend) GetRecentDisputes() (scale.BTree, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github doesn't let me comment on line number 86, so doing it here.

The comment on overlayBackend struct is // overlayBackend implements OverlayBackend.. If I go to OverlayBackend interface line 32, that says // OverlayBackend is the overlay backend for the disputes coordinator module.

We should put better comments on these things to give sufficient explanation to whoever reads this code.

// update db
if recentDisputes.Len() > 0 {
if err = b.SetRecentDisputes(newRecentDisputes); err != nil {
return fmt.Errorf("set recent disputes: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets stick to the common pattern we have used across our code base of using -ing while wrapping errors.

Suggested change
return fmt.Errorf("set recent disputes: %w", err)
return fmt.Errorf("setting recent disputes: %w", err)

// clear recent disputes metadata
recentDisputes, err := b.GetRecentDisputes()
if err != nil {
return fmt.Errorf("get recent disputes: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("get recent disputes: %w", err)
return fmt.Errorf("getting recent disputes: %w", err)

@@ -0,0 +1,77 @@
package dispute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run make license

"github.com/ChainSafe/gossamer/pkg/scale"
)

type runtimeInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment about what this struct is for.

@@ -0,0 +1,153 @@
package comm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is comm short for something? Change this to full name? We could also add a comment about what this package is for.

Copy link
Contributor

@kishansagathiya kishansagathiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make lint flags a decent number of issue. Apart from ornamental issues, it show a bunch of serious issues such as import cycle, ineffective break, ineffectual memory assignment, redundant break, etc.


const timeout = 10 * time.Second

var logger = log.NewFromGlobal(log.AddContext("parachain", "disputes"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep parachain-disputes for package dot/parachain/disputes. Let's use parachain-disputes-comm here

respCh := make(chan any, 1)
relayParent, err := receipt.Hash()
if err != nil {
return 0, fmt.Errorf("get hash: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0, fmt.Errorf("get hash: %w", err)
return 0, fmt.Errorf("getting hash: %w", err)

Comment on lines +10 to +23
t.Run("successful send", func(t *testing.T) {
ch := make(chan any, 1)
defer close(ch)

err := SendMessage(ch, "test")
require.NoError(t, err)
})
t.Run("timeout", func(t *testing.T) {
ch := make(chan any)
defer close(ch)

err := SendMessage(ch, "test")
require.Error(t, err)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run this as a loop with two test cases. A test case struct in this case, would contain two things description and channel size

return n - getByzantineThreshold(n)
}

// Coordinator is the disputes coordinator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some more information.

Comment on lines +6 to +9
type Signal[data any] struct {
Data data
ResponseChannel chan<- any
}
Copy link
Contributor

@kishansagathiya kishansagathiya Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a signal does not require a response. It is a signal from overseer to subsystems and then subsystems would react/process based on that. Some subsystems, don't react at all.

@q9f q9f added A-stale issue or PR is deprecated and needs to be closed. S-subsystems-disputes issues related to polkadot host disputes subsystem functionality. labels Jan 16, 2024
@q9f q9f closed this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stale issue or PR is deprecated and needs to be closed. S-subsystems-disputes issues related to polkadot host disputes subsystem functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants