-
Notifications
You must be signed in to change notification settings - Fork 19
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
Validate peers on startup #231
Changes from 12 commits
7a4c847
0fbcb79
0c0cdfd
55b6b24
c02cf8b
25e2472
6bb878f
b4e681c
5db104b
67e2410
5e0b9f1
253e247
3976dbc
f4bc236
5ee36e3
f3d64ad
0cb6139
9311703
a2c0e86
46e8fb8
9fa3f75
f504c2f
d48e359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,10 @@ type SourceBlockchain struct { | |
SupportedDestinations []string `mapstructure:"supported-destinations" json:"supported-destinations"` | ||
ProcessHistoricalBlocksFromHeight uint64 `mapstructure:"process-historical-blocks-from-height" json:"process-historical-blocks-from-height"` | ||
|
||
// convenience field to access the supported destinations after initialization | ||
// convenience fields to access parsed data after initialization | ||
supportedDestinations set.Set[ids.ID] | ||
subnetID ids.ID | ||
blockchainID ids.ID | ||
} | ||
|
||
type DestinationBlockchain struct { | ||
|
@@ -81,6 +83,10 @@ type DestinationBlockchain struct { | |
|
||
// Fetched from the chain after startup | ||
warpQuorum WarpQuorum | ||
|
||
// convenience fields to access parsed data after initialization | ||
subnetID ids.ID | ||
blockchainID ids.ID | ||
} | ||
|
||
type WarpQuorum struct { | ||
|
@@ -97,10 +103,6 @@ type Config struct { | |
DestinationBlockchains []*DestinationBlockchain `mapstructure:"destination-blockchains" json:"destination-blockchains"` | ||
ProcessMissedBlocks bool `mapstructure:"process-missed-blocks" json:"process-missed-blocks"` | ||
ManualWarpMessages []*ManualWarpMessage `mapstructure:"manual-warp-messages" json:"manual-warp-messages"` | ||
|
||
// convenience fields to access the source subnet and chain IDs after initialization | ||
sourceSubnetIDs []ids.ID | ||
sourceBlockchainIDs []ids.ID | ||
} | ||
|
||
func SetDefaultConfigValues(v *viper.Viper) { | ||
|
@@ -208,8 +210,6 @@ func (c *Config) Validate() error { | |
|
||
// Validate the source chains and store the source subnet and chain IDs for future use | ||
sourceBlockchains := set.NewSet[string](len(c.SourceBlockchains)) | ||
var sourceSubnetIDs []ids.ID | ||
var sourceBlockchainIDs []ids.ID | ||
for _, s := range c.SourceBlockchains { | ||
// Validate configuration | ||
if err := s.Validate(&destinationChains); err != nil { | ||
|
@@ -220,24 +220,8 @@ func (c *Config) Validate() error { | |
return errors.New("configured source subnets must have unique chain IDs") | ||
} | ||
sourceBlockchains.Add(s.BlockchainID) | ||
|
||
// Save IDs for future use | ||
subnetID, err := ids.FromString(s.SubnetID) | ||
if err != nil { | ||
return fmt.Errorf("invalid subnetID in configuration. error: %w", err) | ||
} | ||
sourceSubnetIDs = append(sourceSubnetIDs, subnetID) | ||
|
||
blockchainID, err := ids.FromString(s.BlockchainID) | ||
if err != nil { | ||
return fmt.Errorf("invalid subnetID in configuration. error: %w", err) | ||
} | ||
sourceBlockchainIDs = append(sourceBlockchainIDs, blockchainID) | ||
} | ||
|
||
c.sourceSubnetIDs = sourceSubnetIDs | ||
c.sourceBlockchainIDs = sourceBlockchainIDs | ||
|
||
// Validate the manual warp messages | ||
for i, msg := range c.ManualWarpMessages { | ||
if err := msg.Validate(); err != nil { | ||
|
@@ -417,6 +401,18 @@ func (s *SourceBlockchain) Validate(destinationBlockchainIDs *set.Set[string]) e | |
} | ||
} | ||
|
||
// Validate and store the subnet and blockchain IDs for future use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but we should consider splitting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed and some of the similarities between the source/destination can be abstracted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Viper doesn't play nicely with this unfortunately. There may be a workaround, but I haven't looked to deeply into it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look too bad, but we can definitely defer to a separate ticket https://stackoverflow.com/questions/47185318/multiple-config-files-with-go-viper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, I think we should keep a single user-facing configuration file, but split it into multiple Go files for easier code readability. I experimented with Matt's suggestion of composing |
||
blockchainID, err := ids.FromString(s.BlockchainID) | ||
if err != nil { | ||
return fmt.Errorf("invalid blockchainID in configuration. error: %w", err) | ||
} | ||
s.blockchainID = blockchainID | ||
subnetID, err := ids.FromString(s.SubnetID) | ||
if err != nil { | ||
return fmt.Errorf("invalid subnetID in configuration. error: %w", err) | ||
} | ||
s.subnetID = subnetID | ||
|
||
// Validate and store the allowed destinations for future use | ||
s.supportedDestinations = set.Set[ids.ID]{} | ||
|
||
|
@@ -447,6 +443,14 @@ func (s *SourceBlockchain) Validate(destinationBlockchainIDs *set.Set[string]) e | |
return nil | ||
} | ||
|
||
func (s *SourceBlockchain) GetSubnetID() ids.ID { | ||
return s.subnetID | ||
} | ||
|
||
func (s *SourceBlockchain) GetBlockchainID() ids.ID { | ||
return s.blockchainID | ||
} | ||
|
||
// Validatees the destination subnet configuration | ||
func (s *DestinationBlockchain) Validate() error { | ||
if _, err := ids.FromString(s.SubnetID); err != nil { | ||
|
@@ -473,9 +477,29 @@ func (s *DestinationBlockchain) Validate() error { | |
return fmt.Errorf("unsupported VM type for source subnet: %s", s.VM) | ||
} | ||
|
||
// Validate and store the subnet and blockchain IDs for future use | ||
blockchainID, err := ids.FromString(s.BlockchainID) | ||
if err != nil { | ||
return fmt.Errorf("invalid blockchainID in configuration. error: %w", err) | ||
} | ||
s.blockchainID = blockchainID | ||
subnetID, err := ids.FromString(s.SubnetID) | ||
if err != nil { | ||
return fmt.Errorf("invalid subnetID in configuration. error: %w", err) | ||
} | ||
s.subnetID = subnetID | ||
|
||
return nil | ||
} | ||
|
||
func (s *DestinationBlockchain) GetSubnetID() ids.ID { | ||
return s.subnetID | ||
} | ||
|
||
func (s *DestinationBlockchain) GetBlockchainID() ids.ID { | ||
return s.blockchainID | ||
} | ||
|
||
func (s *DestinationBlockchain) initializeWarpQuorum() error { | ||
blockchainID, err := ids.FromString(s.BlockchainID) | ||
if err != nil { | ||
|
@@ -514,11 +538,6 @@ func (s *DestinationBlockchain) GetRelayerAccountInfo() (*ecdsa.PrivateKey, comm | |
// Top-level config getters | ||
// | ||
|
||
// GetSourceIDs returns the Subnet and Chain IDs of all subnets configured as a source | ||
func (c *Config) GetSourceIDs() ([]ids.ID, []ids.ID) { | ||
return c.sourceSubnetIDs, c.sourceBlockchainIDs | ||
} | ||
|
||
func (c *Config) GetWarpQuorum(blockchainID ids.ID) (WarpQuorum, error) { | ||
for _, s := range c.DestinationBlockchains { | ||
if blockchainID.String() == s.BlockchainID { | ||
|
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.
These were only used to pass to the app request network constructor. With this change, it makes more sense to pass the configuration and iterate over the
SourceBlockchain
andDestinationBlockchain
slices directly, so the parsed IDs were moved there.