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

Decentralize parachain relayer with linear timeout #1266

Merged
merged 5 commits into from
Aug 19, 2024

Conversation

yrong
Copy link
Contributor

@yrong yrong commented Aug 14, 2024

Context

This is the implementation idea from Alistair, essentially linear waiting time for each relayer to avoid race condition, it's more deterministic/predictable.

So basically we've 2 options

The PR here for option 2.

@yrong yrong marked this pull request as ready for review August 14, 2024 01:46
// ID of current relayer, starting from 0
ID uint64 `mapstructure:"id"`
// Number of total count of all relayers
Num uint64 `mapstructure:"num"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Num uint64 `mapstructure:"num"`
TotalRelayerCount uint64 `mapstructure:"totalRelayerCount"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 162 to 169
paraNonce := (*task.MessageProofs)[0].Message.Nonce
modNonce := paraNonce % li.scheduleConfig.Num
var waitingPeriod uint64
if modNonce > li.scheduleConfig.ID {
waitingPeriod = modNonce - li.scheduleConfig.ID
} else {
waitingPeriod = li.scheduleConfig.ID - modNonce
}
Copy link
Contributor

@alistair-singh alistair-singh Aug 14, 2024

Choose a reason for hiding this comment

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

Please double check but the math below will produce the waiting period correctly for all input.

Suggested change
paraNonce := (*task.MessageProofs)[0].Message.Nonce
modNonce := paraNonce % li.scheduleConfig.Num
var waitingPeriod uint64
if modNonce > li.scheduleConfig.ID {
waitingPeriod = modNonce - li.scheduleConfig.ID
} else {
waitingPeriod = li.scheduleConfig.ID - modNonce
}
paraNonce := (*task.MessageProofs)[0].Message.Nonce
waitingPeriod := (paraNonce + li.scheduleConfig.Num - li.scheduleConfig.ID) % li.scheduleConfig.Num

The if/else version does not produce the correct waiting period for the scenario:
3 Relayers, relayer id 1, message nonce 5 and 6 both will produce a waiting period of 1.

Maybe we should add a unit test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Fixed in e787143

@yrong yrong changed the title Decentralize relayer with linear timeout Decentralize parachain relayer with linear timeout Aug 15, 2024
@yrong yrong merged commit 6cbf2a8 into main Aug 19, 2024
1 check passed
@yrong yrong deleted the ron/decentralize-relay-with-linear-timeout branch August 19, 2024 12:49
@acatangiu
Copy link

Just to make sure I'm on the same page:

These changes are a "best effort" decentralization that assumes all relayers willingly follow this protocol and wait for their turn, right?

IIUC this will help with deploying multiple instances of these "nice/behaving" relayers, but there is no mechanism that prevents a relayer looking to maximize gains to just step on the other's slots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants