Skip to content

Commit

Permalink
Added config for cross chain interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed May 20, 2024
1 parent 49b64df commit 4c4b53b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
7 changes: 7 additions & 0 deletions go/config/host_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type HostInputConfig struct {
// The expected time between blocks on the L1 network
L1BlockTime time.Duration

// CrossChainInterval - The interval at which the host will check for new cross chain data to submit
CrossChainInterval time.Duration

// Whether inbound p2p is enabled or not
IsInboundP2PDisabled bool

Expand Down Expand Up @@ -138,6 +141,7 @@ func (p HostInputConfig) ToHostConfig() *HostConfig {
MaxBatchInterval: p.MaxBatchInterval,
RollupInterval: p.RollupInterval,
L1BlockTime: p.L1BlockTime,
CrossChainInterval: p.CrossChainInterval,
IsInboundP2PDisabled: p.IsInboundP2PDisabled,
MaxRollupSize: p.MaxRollupSize,
}
Expand Down Expand Up @@ -172,6 +176,8 @@ type HostConfig struct {
MaxRollupSize uint64
// The expected time between blocks on the L1 network
L1BlockTime time.Duration
// CrossChainInterval - The interval at which the host will check for new cross chain data to submit
CrossChainInterval time.Duration

/////
// NODE CONFIG
Expand Down Expand Up @@ -273,5 +279,6 @@ func DefaultHostParsedConfig() *HostInputConfig {
L1BlockTime: 15 * time.Second,
IsInboundP2PDisabled: false,
MaxRollupSize: 1024 * 64,
CrossChainInterval: 6 * time.Second,
}
}
13 changes: 12 additions & 1 deletion go/host/container/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type HostConfigToml struct {
BatchInterval string
MaxBatchInterval string
RollupInterval string
CrossChainInterval string
IsInboundP2PDisabled bool
L1BlockTime int
MaxRollupSize int
Expand Down Expand Up @@ -92,6 +93,7 @@ func ParseConfig() (*config.HostInputConfig, error) {
batchInterval := flag.String(batchIntervalName, cfg.BatchInterval.String(), flagUsageMap[batchIntervalName])
maxBatchInterval := flag.String(maxBatchIntervalName, cfg.MaxBatchInterval.String(), flagUsageMap[maxBatchIntervalName])
rollupInterval := flag.String(rollupIntervalName, cfg.RollupInterval.String(), flagUsageMap[rollupIntervalName])
crossChainInterval := flag.String(crossChainIntervalName, cfg.CrossChainInterval.String(), flagUsageMap[crossChainIntervalName])
isInboundP2PDisabled := flag.Bool(isInboundP2PDisabledName, cfg.IsInboundP2PDisabled, flagUsageMap[isInboundP2PDisabledName])
maxRollupSize := flag.Uint64(maxRollupSizeFlagName, cfg.MaxRollupSize, flagUsageMap[maxRollupSizeFlagName])

Expand Down Expand Up @@ -147,6 +149,10 @@ func ParseConfig() (*config.HostInputConfig, error) {
if err != nil {
return nil, err
}
cfg.CrossChainInterval, err = time.ParseDuration(*crossChainInterval)
if err != nil {
return nil, err
}
cfg.IsInboundP2PDisabled = *isInboundP2PDisabled
cfg.MaxRollupSize = *maxRollupSize

Expand All @@ -171,7 +177,7 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) {
return &config.HostInputConfig{}, fmt.Errorf("unrecognised node type '%s'", tomlConfig.NodeType)
}

batchInterval, maxBatchInterval, rollupInterval := 1*time.Second, 1*time.Second, 5*time.Second
batchInterval, maxBatchInterval, rollupInterval, crossChainInterval := 1*time.Second, 1*time.Second, 5*time.Second, 6*time.Second
if interval, err := time.ParseDuration(tomlConfig.BatchInterval); err == nil {
batchInterval = interval
}
Expand All @@ -182,6 +188,10 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) {
maxBatchInterval = interval
}

if interval, err := time.ParseDuration(tomlConfig.CrossChainInterval); err == nil {
crossChainInterval = interval
}

return &config.HostInputConfig{
IsGenesis: tomlConfig.IsGenesis,
NodeType: nodeType,
Expand Down Expand Up @@ -216,5 +226,6 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) {
RollupInterval: rollupInterval,
IsInboundP2PDisabled: tomlConfig.IsInboundP2PDisabled,
L1BlockTime: time.Duration(tomlConfig.L1BlockTime) * time.Second,
CrossChainInterval: crossChainInterval,
}, nil
}
2 changes: 2 additions & 0 deletions go/host/container/cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
batchIntervalName = "batchInterval"
maxBatchIntervalName = "maxBatchInterval"
rollupIntervalName = "rollupInterval"
crossChainIntervalName = "crossChainInterval"
isInboundP2PDisabledName = "isInboundP2PDisabled"
maxRollupSizeFlagName = "maxRollupSize"
)
Expand Down Expand Up @@ -76,5 +77,6 @@ func getFlagUsageMap() map[string]string {
rollupIntervalName: "Duration between each rollup. Can be put down as 1.0s",
isInboundP2PDisabledName: "Whether inbound p2p is enabled",
maxRollupSizeFlagName: "Max size of a rollup",
crossChainIntervalName: "Duration between each cross chain bundle. Can be put down as 1.0s",
}
}
38 changes: 20 additions & 18 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ type Guardian struct {

submitDataLock sync.Mutex // we only submit one block, batch or transaction to enclave at a time

batchInterval time.Duration
rollupInterval time.Duration
blockTime time.Duration
l1StartHash gethcommon.Hash
maxRollupSize uint64
batchInterval time.Duration
rollupInterval time.Duration
blockTime time.Duration
crossChainInterval time.Duration
l1StartHash gethcommon.Hash
maxRollupSize uint64

hostInterrupter *stopcontrol.StopControl // host hostInterrupter so we can stop quickly

Expand All @@ -78,19 +79,20 @@ type Guardian struct {

func NewGuardian(cfg *config.HostConfig, hostData host.Identity, serviceLocator guardianServiceLocator, enclaveClient common.Enclave, storage storage.Storage, interrupter *stopcontrol.StopControl, logger gethlog.Logger) *Guardian {
return &Guardian{
hostData: hostData,
state: NewStateTracker(logger),
enclaveClient: enclaveClient,
sl: serviceLocator,
batchInterval: cfg.BatchInterval,
maxBatchInterval: cfg.MaxBatchInterval,
rollupInterval: cfg.RollupInterval,
l1StartHash: cfg.L1StartHash,
maxRollupSize: cfg.MaxRollupSize,
blockTime: cfg.L1BlockTime,
storage: storage,
hostInterrupter: interrupter,
logger: logger,
hostData: hostData,
state: NewStateTracker(logger),
enclaveClient: enclaveClient,
sl: serviceLocator,
batchInterval: cfg.BatchInterval,
maxBatchInterval: cfg.MaxBatchInterval,
rollupInterval: cfg.RollupInterval,
l1StartHash: cfg.L1StartHash,
maxRollupSize: cfg.MaxRollupSize,
blockTime: cfg.L1BlockTime,
crossChainInterval: cfg.CrossChainInterval,
storage: storage,
hostInterrupter: interrupter,
logger: logger,
}
}

Expand Down
30 changes: 16 additions & 14 deletions integration/simulation/devnetwork/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,28 @@ type TenConfigOption func(*TenConfig) // option pattern - typically used as over

// TenConfig describes the L2 network configuration we want to spin up
type TenConfig struct {
PortStart int
InitNumValidators int
BatchInterval time.Duration
RollupInterval time.Duration
NumNodes int
TenGatewayEnabled bool
NumSeqEnclaves int
PortStart int
InitNumValidators int
BatchInterval time.Duration
RollupInterval time.Duration
CrossChainInterval time.Duration
NumNodes int
TenGatewayEnabled bool
NumSeqEnclaves int

L1BlockTime time.Duration
}

func DefaultTenConfig() *TenConfig {
return &TenConfig{
PortStart: integration.StartPortNetworkTests,
NumNodes: 4,
InitNumValidators: 3,
BatchInterval: 1 * time.Second,
RollupInterval: 10 * time.Second,
TenGatewayEnabled: false,
NumSeqEnclaves: 1, // increase for HA simulation
PortStart: integration.StartPortNetworkTests,
NumNodes: 4,
InitNumValidators: 3,
BatchInterval: 1 * time.Second,
RollupInterval: 10 * time.Second,
CrossChainInterval: 11 * time.Second,
TenGatewayEnabled: false,
NumSeqEnclaves: 1, // increase for HA simulation
}
}

Expand Down

0 comments on commit 4c4b53b

Please sign in to comment.