From 4c4b53b804634bc994669d5f52606bd42c6a4086 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Mon, 20 May 2024 11:01:06 +0300 Subject: [PATCH] Added config for cross chain interval. --- go/config/host_config.go | 7 ++++ go/host/container/cli.go | 13 ++++++- go/host/container/cli_flags.go | 2 ++ go/host/enclave/guardian.go | 38 +++++++++++---------- integration/simulation/devnetwork/config.go | 30 ++++++++-------- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/go/config/host_config.go b/go/config/host_config.go index 2faa21b638..428d4371da 100644 --- a/go/config/host_config.go +++ b/go/config/host_config.go @@ -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 @@ -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, } @@ -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 @@ -273,5 +279,6 @@ func DefaultHostParsedConfig() *HostInputConfig { L1BlockTime: 15 * time.Second, IsInboundP2PDisabled: false, MaxRollupSize: 1024 * 64, + CrossChainInterval: 6 * time.Second, } } diff --git a/go/host/container/cli.go b/go/host/container/cli.go index 819a3f831e..ce2337a4ab 100644 --- a/go/host/container/cli.go +++ b/go/host/container/cli.go @@ -50,6 +50,7 @@ type HostConfigToml struct { BatchInterval string MaxBatchInterval string RollupInterval string + CrossChainInterval string IsInboundP2PDisabled bool L1BlockTime int MaxRollupSize int @@ -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]) @@ -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 @@ -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 } @@ -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, @@ -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 } diff --git a/go/host/container/cli_flags.go b/go/host/container/cli_flags.go index 8fe73f711a..cc01c4b7c6 100644 --- a/go/host/container/cli_flags.go +++ b/go/host/container/cli_flags.go @@ -34,6 +34,7 @@ const ( batchIntervalName = "batchInterval" maxBatchIntervalName = "maxBatchInterval" rollupIntervalName = "rollupInterval" + crossChainIntervalName = "crossChainInterval" isInboundP2PDisabledName = "isInboundP2PDisabled" maxRollupSizeFlagName = "maxRollupSize" ) @@ -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", } } diff --git a/go/host/enclave/guardian.go b/go/host/enclave/guardian.go index ed7851c9e5..4c5840bbc9 100644 --- a/go/host/enclave/guardian.go +++ b/go/host/enclave/guardian.go @@ -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 @@ -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, } } diff --git a/integration/simulation/devnetwork/config.go b/integration/simulation/devnetwork/config.go index ded2b59190..9ff45f3cb1 100644 --- a/integration/simulation/devnetwork/config.go +++ b/integration/simulation/devnetwork/config.go @@ -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 } }