Decentralize parachain relayer with linear timeout#1266
Conversation
| // 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.
| Num uint64 `mapstructure:"num"` | |
| TotalRelayerCount uint64 `mapstructure:"totalRelayerCount"` |
| 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.
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.
|
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.