-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
relayer/relays/parachain/config.go
Outdated
// ID of current relayer, starting from 0 | ||
ID uint64 `mapstructure:"id"` | ||
// Number of total count of all relayers | ||
Num uint64 `mapstructure:"num"` |
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.
Num uint64 `mapstructure:"num"` | |
TotalRelayerCount uint64 `mapstructure:"totalRelayerCount"` |
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.
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 | ||
} |
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.
Please double check but the math below will produce the waiting period correctly for all input.
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.
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.
Nice catch! Fixed in e787143
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. |
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.