Skip to content

Sync finalized headers on demand #1206

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

Merged
merged 24 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
178590d
sync finalized headers on demand
claravanstaden May 24, 2024
bd56320
fix tests
claravanstaden May 24, 2024
b897bc3
refactor
claravanstaden May 27, 2024
47a073e
missing change
claravanstaden May 27, 2024
8505af3
fixes
claravanstaden May 27, 2024
f327b8a
Remove lodestar from git modules & Use geth from nix package
yrong May 28, 2024
586fd58
Cleanup build script
yrong May 28, 2024
e94ff89
Merge branch 'main' into finalized-headers-on-demand
claravanstaden May 28, 2024
74aa302
fixes
claravanstaden May 28, 2024
60c9d21
apply long range sync changes
claravanstaden May 24, 2024
1a3c8da
add sync committee majority check
claravanstaden May 28, 2024
772a68d
Build source from official repo without fork
yrong May 31, 2024
11aadb8
update finalized header every 4 hours
claravanstaden May 31, 2024
a7e290d
Merge remote-tracking branch 'origin/ron/remove-lodestar-from-submodu…
claravanstaden May 31, 2024
ecbf6c5
update js deps
claravanstaden May 31, 2024
60d029c
adds instant verification flag
claravanstaden Jun 3, 2024
3b2cd88
Merge branch 'main' into finalized-headers-on-demand
claravanstaden Jun 3, 2024
0c22608
fallback methods log error reason
claravanstaden Jun 3, 2024
4a76149
validate config files
claravanstaden Jun 3, 2024
0132221
Merge branch 'main' into finalized-headers-on-demand
claravanstaden Jun 18, 2024
6b5abcf
merge damage
claravanstaden Jun 18, 2024
e17f159
validate config
claravanstaden Jun 19, 2024
7b59367
config cleanup
claravanstaden Jun 19, 2024
2953674
rollback forge version
claravanstaden Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions relayer/chain/parachain/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

type ChainWriter interface {
BatchCall(ctx context.Context, extrinsic string, calls []interface{}) error
BatchCall(ctx context.Context, extrinsic []string, calls []interface{}) error
WriteToParachainAndRateLimit(ctx context.Context, extrinsicName string, payload ...interface{}) error
WriteToParachainAndWatch(ctx context.Context, extrinsicName string, payload ...interface{}) error
GetLastFinalizedHeaderState() (state.FinalizedHeader, error)
Expand All @@ -34,19 +34,16 @@ type ParachainWriter struct {
pool *ExtrinsicPool
genesisHash types.Hash
maxWatchedExtrinsics int64
maxBatchCallSize int64
mu sync.Mutex
}

func NewParachainWriter(
conn *Connection,
maxWatchedExtrinsics int64,
maxBatchCallSize int64,
) *ParachainWriter {
return &ParachainWriter{
conn: conn,
maxWatchedExtrinsics: maxWatchedExtrinsics,
maxBatchCallSize: maxBatchCallSize,
}
}

Expand All @@ -69,8 +66,8 @@ func (wr *ParachainWriter) Start(ctx context.Context, eg *errgroup.Group) error
return nil
}

func (wr *ParachainWriter) BatchCall(ctx context.Context, extrinsic string, calls []interface{}) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change function to allow calling different extrinsics.

batchSize := int(wr.maxBatchCallSize)
func (wr *ParachainWriter) BatchCall(ctx context.Context, extrinsic []string, calls []interface{}) error {
batchSize := int(wr.maxWatchedExtrinsics)
var j int
for i := 0; i < len(calls); i += batchSize {
j += batchSize
Expand All @@ -80,13 +77,13 @@ func (wr *ParachainWriter) BatchCall(ctx context.Context, extrinsic string, call
slicedCalls := append([]interface{}{}, calls[i:j]...)
encodedCalls := make([]types.Call, len(slicedCalls))
for k := range slicedCalls {
call, err := wr.prepCall(extrinsic, slicedCalls[k])
call, err := wr.prepCall(extrinsic[k], slicedCalls[k])
if err != nil {
return err
}
encodedCalls[k] = *call
}
err := wr.WriteToParachainAndRateLimit(ctx, "Utility.batch_all", encodedCalls)
err := wr.WriteToParachainAndWatch(ctx, "Utility.batch_all", encodedCalls)
if err != nil {
return fmt.Errorf("batch call failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/cmd/import_execution_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func importExecutionHeaderFn(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("connect to parachain: %w", err)
}

writer := parachain.NewParachainWriter(paraconn, 8, 8)
writer := parachain.NewParachainWriter(paraconn, 8)
err = writer.Start(ctx, eg)
if err != nil {
return fmt.Errorf("start parachain conn: %w", err)
Expand Down
8 changes: 7 additions & 1 deletion relayer/cmd/run/beacon/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package beacon

import (
"context"
"fmt"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -54,11 +55,16 @@ func run(_ *cobra.Command, _ []string) error {
}

var config config.Config
err := viper.Unmarshal(&config)
err := viper.UnmarshalExact(&config)
if err != nil {
return err
}

err = config.Validate()
if err != nil {
return fmt.Errorf("config file validation failed: %w", err)
}

keypair, err := parachain.ResolvePrivateKey(privateKey, privateKeyFile, privateKeyID)
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion relayer/cmd/run/beefy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package beefy

import (
"context"
"fmt"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -50,11 +51,16 @@ func run(_ *cobra.Command, _ []string) error {
}

var config beefy.Config
err := viper.Unmarshal(&config)
err := viper.UnmarshalExact(&config)
if err != nil {
return err
}

err = config.Validate()
if err != nil {
return fmt.Errorf("config file validation failed: %w", err)
}

keypair, err := ethereum.ResolvePrivateKey(privateKey, privateKeyFile, privateKeyID)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions relayer/cmd/run/execution/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package execution
import (
"context"
"encoding/hex"
"fmt"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -41,7 +42,6 @@ func Command() *cobra.Command {
cmd.Flags().StringVar(&privateKeyFile, "substrate.private-key-file", "", "The file from which to read the private key URI")
cmd.Flags().StringVar(&privateKeyID, "substrate.private-key-id", "", "The secret id to lookup the private key in AWS Secrets Manager")


return cmd
}

Expand All @@ -57,11 +57,16 @@ func run(_ *cobra.Command, _ []string) error {
}

var config execution.Config
err := viper.Unmarshal(&config, viper.DecodeHook(HexHookFunc()))
err := viper.UnmarshalExact(&config, viper.DecodeHook(HexHookFunc()))
if err != nil {
return err
}

err = config.Validate()
if err != nil {
return fmt.Errorf("config file validation failed: %w", err)
}

keypair, err := parachain.ResolvePrivateKey(privateKey, privateKeyFile, privateKeyID)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions relayer/cmd/run/parachain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parachain
import (
"context"
"encoding/hex"
"fmt"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -41,7 +42,6 @@ func Command() *cobra.Command {
cmd.Flags().StringVar(&privateKeyFile, "ethereum.private-key-file", "", "The file from which to read the private key")
cmd.Flags().StringVar(&privateKeyID, "ethereum.private-key-id", "", "The secret id to lookup the private key in AWS Secrets Manager")


return cmd
}

Expand All @@ -55,11 +55,16 @@ func run(_ *cobra.Command, _ []string) error {
}

var config parachain.Config
err := viper.Unmarshal(&config, viper.DecodeHook(HexHookFunc()))
err := viper.UnmarshalExact(&config, viper.DecodeHook(HexHookFunc()))
if err != nil {
return err
}

err = config.Validate()
if err != nil {
return fmt.Errorf("config file validation failed: %w", err)
}

keypair, err := ethereum.ResolvePrivateKey(privateKey, privateKeyFile, privateKeyID)
if err != nil {
return err
Expand Down
27 changes: 26 additions & 1 deletion relayer/config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package config

import "errors"

type PolkadotConfig struct {
Endpoint string `mapstructure:"endpoint"`
}

type ParachainConfig struct {
Endpoint string `mapstructure:"endpoint"`
MaxWatchedExtrinsics int64 `mapstructure:"maxWatchedExtrinsics"`
MaxBatchCallSize int64 `mapstructure:"maxBatchCallSize"`
}

type EthereumConfig struct {
Expand All @@ -16,3 +17,27 @@ type EthereumConfig struct {
GasTipCap uint64 `mapstructure:"gas-tip-cap"`
GasLimit uint64 `mapstructure:"gas-limit"`
}

func (p ParachainConfig) Validate() error {
if p.Endpoint == "" {
return errors.New("[endpoint] is not set")
}
if p.MaxWatchedExtrinsics == 0 {
return errors.New("[maxWatchedExtrinsics] is not set")
}
return nil
}

func (e EthereumConfig) Validate() error {
if e.Endpoint == "" {
return errors.New("[endpoint] config is not set")
}
return nil
}

func (p PolkadotConfig) Validate() error {
if p.Endpoint == "" {
return errors.New("[endpoint] config is not set")
}
return nil
}
48 changes: 47 additions & 1 deletion relayer/relays/beacon/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"errors"
"fmt"
"github.com/snowfork/snowbridge/relayer/config"
)

Expand Down Expand Up @@ -33,5 +35,49 @@ type BeaconConfig struct {
}

type SinkConfig struct {
Parachain config.ParachainConfig `mapstructure:"parachain"`
Parachain config.ParachainConfig `mapstructure:"parachain"`
UpdateSlotInterval uint64 `mapstructure:"updateSlotInterval"`
}

func (c Config) Validate() error {
err := c.Source.Beacon.Validate()
if err != nil {
return fmt.Errorf("source beacon config: %w", err)
}
err = c.Sink.Parachain.Validate()
if err != nil {
return fmt.Errorf("sink parachain config: %w", err)
}
if c.Sink.UpdateSlotInterval == 0 {
return errors.New("parachain [updateSlotInterval] config is not set")
}
return nil
}

func (b BeaconConfig) Validate() error {
// spec settings
if b.Spec.EpochsPerSyncCommitteePeriod == 0 {
return errors.New("source beacon setting [epochsPerSyncCommitteePeriod] is not set")
}
if b.Spec.SlotsInEpoch == 0 {
return errors.New("source beacon setting [slotsInEpoch] is not set")
}
if b.Spec.SyncCommitteeSize == 0 {
return errors.New("source beacon setting [syncCommitteeSize] is not set")
}
// data store
if b.DataStore.Location == "" {
return errors.New("source beacon datastore [location] is not set")
}
if b.DataStore.MaxEntries == 0 {
return errors.New("source beacon datastore [maxEntries] is not set")
}
// api endpoints
if b.Endpoint == "" {
return errors.New("source beacon setting [endpoint] is not set")
}
if b.StateEndpoint == "" {
return errors.New("source beacon setting [stateEndpoint] is not set")
}
return nil
}
Loading
Loading