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

Extend manifest with chain exchange configuration #810

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions f3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ var base = manifest.Manifest{
CertificateExchange: manifest.DefaultCxConfig,
CatchUpAlignment: manifest.DefaultCatchUpAlignment,
PubSub: manifest.DefaultPubSubConfig,
ChainExchange: manifest.DefaultChainExchangeConfig,
}

type testNode struct {
Expand Down
51 changes: 50 additions & 1 deletion manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
CompressionEnabled: false,
}

DefaultChainExchangeConfig = ChainExchangeConfig{
SubscriptionBufferSize: 32,
MaxChainLength: gpbft.ChainDefaultLen,
MaxInstanceLookahead: DefaultCommitteeLookback,
MaxDiscoveredChainsPerInstance: 1_000,
MaxWantedChainsPerInstance: 1_000,
}

// Default instance alignment when catching up.
DefaultCatchUpAlignment = DefaultEcConfig.Period / 2
)
Expand Down Expand Up @@ -171,7 +179,7 @@
BaseDecisionBackoffTable []float64
// HeadLookback number of unfinalized tipsets to remove from the head
HeadLookback int
// Finalize indicates whether or not F3 should finalize tipsets as F3 agrees on them.
// Finalize indicates whether F3 should finalize tipsets as F3 agrees on them.
Finalize bool
}

Expand Down Expand Up @@ -211,6 +219,31 @@

func (p *PubSubConfig) Validate() error { return nil }

type ChainExchangeConfig struct {
SubscriptionBufferSize int
MaxChainLength int
MaxInstanceLookahead uint64
MaxDiscoveredChainsPerInstance int
MaxWantedChainsPerInstance int
}

func (cx *ChainExchangeConfig) Validate() error {
// Note that MaxInstanceLookahead may be zero, which indicates that the chain
// exchange will only accept discovery of chains from current instance.
switch {
case cx.SubscriptionBufferSize < 1:
return fmt.Errorf("chain exchange subscription buffer size must be at least 1, got: %d", cx.SubscriptionBufferSize)
case cx.MaxChainLength < 1:
return fmt.Errorf("chain exchange max chain length must be at least 1, got: %d", cx.MaxChainLength)
case cx.MaxDiscoveredChainsPerInstance < 1:
return fmt.Errorf("chain exchange max discovered chains per instance must be at least 1, got: %d", cx.MaxDiscoveredChainsPerInstance)
case cx.MaxWantedChainsPerInstance < 1:
return fmt.Errorf("chain exchange max wanted chains per instance must be at least 1, got: %d", cx.MaxWantedChainsPerInstance)

Check warning on line 241 in manifest/manifest.go

View check run for this annotation

Codecov / codecov/patch

manifest/manifest.go#L234-L241

Added lines #L234 - L241 were not covered by tests
default:
return nil
}
}

// Manifest identifies the specific configuration for the F3 instance currently running.
type Manifest struct {
// Pause stops the participation in F3.
Expand Down Expand Up @@ -246,6 +279,8 @@
CertificateExchange CxConfig
// PubSubConfig specifies the pubsub related configuration.
PubSub PubSubConfig
// ChainExchange specifies the chain exchange configuration parameters.
ChainExchange ChainExchangeConfig
}

func (m *Manifest) Equal(o *Manifest) bool {
Expand Down Expand Up @@ -311,6 +346,15 @@
if err := m.PubSub.Validate(); err != nil {
return fmt.Errorf("invalid manifest: invalid pubsub config: %w", err)
}
if err := m.ChainExchange.Validate(); err != nil {
return fmt.Errorf("invalid manifest: invalid chain exchange config: %w", err)
}

Check warning on line 351 in manifest/manifest.go

View check run for this annotation

Codecov / codecov/patch

manifest/manifest.go#L350-L351

Added lines #L350 - L351 were not covered by tests
if m.ChainExchange.MaxChainLength > m.Gpbft.ChainProposedLength {
return fmt.Errorf("invalid manifest: chain exchange max chain length %d exceeds gpbft proposed chain length %d", m.ChainExchange.MaxChainLength, m.Gpbft.ChainProposedLength)
}

Check warning on line 354 in manifest/manifest.go

View check run for this annotation

Codecov / codecov/patch

manifest/manifest.go#L353-L354

Added lines #L353 - L354 were not covered by tests
if m.ChainExchange.MaxInstanceLookahead > m.CommitteeLookback {
return fmt.Errorf("invalid manifest: chain exchange max instance lookahead %d exceeds committee lookback %d", m.ChainExchange.MaxInstanceLookahead, m.CommitteeLookback)
}

Check warning on line 357 in manifest/manifest.go

View check run for this annotation

Codecov / codecov/patch

manifest/manifest.go#L356-L357

Added lines #L356 - L357 were not covered by tests

return nil
}
Expand All @@ -328,6 +372,7 @@
CertificateExchange: DefaultCxConfig,
CatchUpAlignment: DefaultCatchUpAlignment,
PubSub: DefaultPubSubConfig,
ChainExchange: DefaultChainExchangeConfig,
}
return m
}
Expand Down Expand Up @@ -363,6 +408,10 @@
return "/f3/granite/0.0.2/" + string(nn)
}

func ChainExchangeTopicFromNetworkName(nn gpbft.NetworkName) string {
return "/f3/chainexchange/0.0.1/" + string(nn)

Check warning on line 412 in manifest/manifest.go

View check run for this annotation

Codecov / codecov/patch

manifest/manifest.go#L411-L412

Added lines #L411 - L412 were not covered by tests
}

func (m *Manifest) GpbftOptions() []gpbft.Option {
return m.Gpbft.ToOptions()
}
2 changes: 2 additions & 0 deletions manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var base = manifest.Manifest{
MinimumPollInterval: 30 * time.Second,
MaximumPollInterval: 2 * time.Minute,
},
PubSub: manifest.DefaultPubSubConfig,
ChainExchange: manifest.DefaultChainExchangeConfig,
CatchUpAlignment: 0,
}

Expand Down
Loading