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

Sync beefy commitment on demand #1342

Merged
merged 12 commits into from
Dec 5, 2024
Merged

Sync beefy commitment on demand #1342

merged 12 commits into from
Dec 5, 2024

Conversation

vgeddes
Copy link
Collaborator

@vgeddes vgeddes commented Nov 29, 2024

Syncs beefy commitment immediately if paraNonce > ethNonce, as long as the configured rate-limit is not exceeded.

The rate-limiting algorithm is implemented using a token bucket approach. For example, every hour, 1 token is added to the bucket. Every time a new commitment needs to be a synced, a token is consumed from the bucket as long as there are tokens available.

Algorithm:

while True
    Sleep(1min)
    ParaNonce, EthNonce := GetNonces()
    if ParaNonce > EthNonce:
        if !TokenBucket.TryConsume(1):
            Continue
        SyncLatestBeefyCommitment()
        WaitUntil {
            _, EthNonce := GetNonces() 
            EthNonce >= ParaNonce
        }

Can run this on-demand relayer using:

snowbridge-relay run beefy --on-demand ...

Added new configuration fields, mostly for rate-limiting configuration:

type OnDemandSyncConfig struct {
	// ID of the AssetHub channel
	AssetHubChannelID string `mapstructure:"asset-hub-channel-id"`
	// Maximum number of tokens available to consume
	MaxTokens uint64 `mapstructure:"max-tokens"`
	// Number of tokens added each `RefillPeriod`
	RefillAmount uint64 `mapstructure:"refill-amount"`
	// Period between token refills
	RefillPeriod uint64 `mapstructure:"refill-period"`
}

Infra companion: https://github.com/Snowfork/snowbridge-infra-suite/pull/28

@vgeddes vgeddes self-assigned this Dec 5, 2024
@vgeddes vgeddes merged commit a1b5a1c into main Dec 5, 2024
2 checks passed
@vgeddes vgeddes deleted the vincent/token-bucket branch December 5, 2024 14:57
@vgeddes vgeddes restored the vincent/token-bucket branch December 5, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant