Skip to content

Commit 9a2a898

Browse files
committed
Extend manifest with chain exchange configuration
Add chain exchange configuration to the manifest along with validation. Part of #792
1 parent fbd674a commit 9a2a898

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

f3_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ var base = manifest.Manifest{
312312
CertificateExchange: manifest.DefaultCxConfig,
313313
CatchUpAlignment: manifest.DefaultCatchUpAlignment,
314314
PubSub: manifest.DefaultPubSubConfig,
315+
ChainExchange: manifest.DefaultChainExchangeConfig,
315316
}
316317

317318
type testNode struct {

manifest/manifest.go

+50-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ var (
5757
CompressionEnabled: false,
5858
}
5959

60+
DefaultChainExchangeConfig = ChainExchangeConfig{
61+
SubscriptionBufferSize: 32,
62+
MaxChainLength: gpbft.ChainDefaultLen,
63+
MaxInstanceLookahead: DefaultCommitteeLookback,
64+
MaxDiscoveredChainsPerInstance: 1_000,
65+
MaxWantedChainsPerInstance: 1_000,
66+
}
67+
6068
// Default instance alignment when catching up.
6169
DefaultCatchUpAlignment = DefaultEcConfig.Period / 2
6270
)
@@ -171,7 +179,7 @@ type EcConfig struct {
171179
BaseDecisionBackoffTable []float64
172180
// HeadLookback number of unfinalized tipsets to remove from the head
173181
HeadLookback int
174-
// Finalize indicates whether or not F3 should finalize tipsets as F3 agrees on them.
182+
// Finalize indicates whether F3 should finalize tipsets as F3 agrees on them.
175183
Finalize bool
176184
}
177185

@@ -211,6 +219,31 @@ type PubSubConfig struct {
211219

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

222+
type ChainExchangeConfig struct {
223+
SubscriptionBufferSize int
224+
MaxChainLength int
225+
MaxInstanceLookahead uint64
226+
MaxDiscoveredChainsPerInstance int
227+
MaxWantedChainsPerInstance int
228+
}
229+
230+
func (cx *ChainExchangeConfig) Validate() error {
231+
// Note that MaxInstanceLookahead may be zero, which indicates that the chain
232+
// exchange will only accept discovery of chains from current instance.
233+
switch {
234+
case cx.SubscriptionBufferSize < 1:
235+
return fmt.Errorf("chain exchange subscription buffer size must be at least 1, got: %d", cx.SubscriptionBufferSize)
236+
case cx.MaxChainLength < 1:
237+
return fmt.Errorf("chain exchange max chain length must be at least 1, got: %d", cx.MaxChainLength)
238+
case cx.MaxDiscoveredChainsPerInstance < 1:
239+
return fmt.Errorf("chain exchange max discovered chains per instance must be at least 1, got: %d", cx.MaxDiscoveredChainsPerInstance)
240+
case cx.MaxWantedChainsPerInstance < 1:
241+
return fmt.Errorf("chain exchange max wanted chains per instance must be at least 1, got: %d", cx.MaxWantedChainsPerInstance)
242+
default:
243+
return nil
244+
}
245+
}
246+
214247
// Manifest identifies the specific configuration for the F3 instance currently running.
215248
type Manifest struct {
216249
// Pause stops the participation in F3.
@@ -246,6 +279,8 @@ type Manifest struct {
246279
CertificateExchange CxConfig
247280
// PubSubConfig specifies the pubsub related configuration.
248281
PubSub PubSubConfig
282+
// ChainExchange specifies the chain exchange configuration parameters.
283+
ChainExchange ChainExchangeConfig
249284
}
250285

251286
func (m *Manifest) Equal(o *Manifest) bool {
@@ -311,6 +346,15 @@ func (m *Manifest) Validate() error {
311346
if err := m.PubSub.Validate(); err != nil {
312347
return fmt.Errorf("invalid manifest: invalid pubsub config: %w", err)
313348
}
349+
if err := m.ChainExchange.Validate(); err != nil {
350+
return fmt.Errorf("invalid manifest: invalid chain exchange config: %w", err)
351+
}
352+
if m.ChainExchange.MaxChainLength > m.Gpbft.ChainProposedLength {
353+
return fmt.Errorf("invalid manifest: chain exchange max chain length %d exceeds gpbft proposed chain length %d", m.ChainExchange.MaxChainLength, m.Gpbft.ChainProposedLength)
354+
}
355+
if m.ChainExchange.MaxInstanceLookahead > m.CommitteeLookback {
356+
return fmt.Errorf("invalid manifest: chain exchange max instance lookahead %d exceeds committee lookback %d", m.ChainExchange.MaxInstanceLookahead, m.CommitteeLookback)
357+
}
314358

315359
return nil
316360
}
@@ -328,6 +372,7 @@ func LocalDevnetManifest() *Manifest {
328372
CertificateExchange: DefaultCxConfig,
329373
CatchUpAlignment: DefaultCatchUpAlignment,
330374
PubSub: DefaultPubSubConfig,
375+
ChainExchange: DefaultChainExchangeConfig,
331376
}
332377
return m
333378
}
@@ -363,6 +408,10 @@ func PubSubTopicFromNetworkName(nn gpbft.NetworkName) string {
363408
return "/f3/granite/0.0.2/" + string(nn)
364409
}
365410

411+
func ChainExchangeTopicFromNetworkName(nn gpbft.NetworkName) string {
412+
return "/f3/chainexchange/0.0.1/" + string(nn)
413+
}
414+
366415
func (m *Manifest) GpbftOptions() []gpbft.Option {
367416
return m.Gpbft.ToOptions()
368417
}

manifest/manifest_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ var base = manifest.Manifest{
5050
MinimumPollInterval: 30 * time.Second,
5151
MaximumPollInterval: 2 * time.Minute,
5252
},
53+
PubSub: manifest.DefaultPubSubConfig,
54+
ChainExchange: manifest.DefaultChainExchangeConfig,
5355
CatchUpAlignment: 0,
5456
}
5557

0 commit comments

Comments
 (0)