Skip to content

Decentralize parachain relayer with linear timeout#1266

Merged
yrong merged 5 commits into
mainfrom
ron/decentralize-relay-with-linear-timeout
Aug 19, 2024
Merged

Decentralize parachain relayer with linear timeout#1266
yrong merged 5 commits into
mainfrom
ron/decentralize-relay-with-linear-timeout

Conversation

@yrong
Copy link
Copy Markdown
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
Comment thread 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"`
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread relayer/relays/parachain/beefy-listener.go Outdated
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
Copy Markdown
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
Copy Markdown
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
@yrong yrong deleted the ron/decentralize-relay-with-linear-timeout branch August 19, 2024 12:49
@acatangiu
Copy link
Copy Markdown

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