From 7420fef922257c46a91b12acaf5b6909179f37d0 Mon Sep 17 00:00:00 2001 From: Matt Curtis Date: Thu, 14 Sep 2023 15:47:16 +0100 Subject: [PATCH] Add l1 block time config for host --- go/config/host_config.go | 7 +++ go/host/host.go | 5 +- go/host/l1/publisher.go | 46 +++++++++++-------- go/node/config.go | 9 ++++ integration/simulation/network/inmemory.go | 1 + .../simulation/network/network_utils.go | 2 + .../simulation/network/obscuro_node_utils.go | 1 + integration/simulation/network/socket.go | 1 + 8 files changed, 53 insertions(+), 19 deletions(-) diff --git a/go/config/host_config.go b/go/config/host_config.go index c8f0ae47e2..fcafd2127d 100644 --- a/go/config/host_config.go +++ b/go/config/host_config.go @@ -87,6 +87,9 @@ type HostInputConfig struct { // Min interval before creating the next rollup (only used by Sequencer nodes) RollupInterval time.Duration + // The expected time between blocks on the L1 network + L1BlockTime time.Duration + // Whether inbound p2p is enabled or not IsInboundP2PDisabled bool } @@ -126,6 +129,7 @@ func (p HostInputConfig) ToHostConfig() *HostConfig { DebugNamespaceEnabled: p.DebugNamespaceEnabled, BatchInterval: p.BatchInterval, RollupInterval: p.RollupInterval, + L1BlockTime: p.L1BlockTime, IsInboundP2PDisabled: p.IsInboundP2PDisabled, } } @@ -152,6 +156,8 @@ type HostConfig struct { BatchInterval time.Duration // Min interval before creating the next rollup (only used by Sequencer nodes) RollupInterval time.Duration + // The expected time between blocks on the L1 network + L1BlockTime time.Duration ///// // NODE CONFIG @@ -247,6 +253,7 @@ func DefaultHostParsedConfig() *HostInputConfig { DebugNamespaceEnabled: false, BatchInterval: 1 * time.Second, RollupInterval: 5 * time.Second, + L1BlockTime: 15 * time.Second, IsInboundP2PDisabled: false, } } diff --git a/go/host/host.go b/go/host/host.go index 6d0336cf74..3edf44a28c 100644 --- a/go/host/host.go +++ b/go/host/host.go @@ -74,7 +74,10 @@ func NewHost(config *config.HostConfig, hostServices *ServicesRegistry, p2p host hostServices.RegisterService(hostcommon.P2PName, p2p) hostServices.RegisterService(hostcommon.L1BlockRepositoryName, l1Repo) - hostServices.RegisterService(hostcommon.L1PublisherName, l1.NewL1Publisher(hostIdentity, ethWallet, ethClient, mgmtContractLib, l1Repo, logger)) + maxWaitForL1Receipt := 4 * config.L1BlockTime // wait ~4 blocks to see if tx gets published before retrying + retryIntervalForL1Receipt := config.L1BlockTime // retry ~every block + l1Publisher := l1.NewL1Publisher(hostIdentity, ethWallet, ethClient, mgmtContractLib, l1Repo, host.stopControl, logger, maxWaitForL1Receipt, retryIntervalForL1Receipt) + hostServices.RegisterService(hostcommon.L1PublisherName, l1Publisher) hostServices.RegisterService(hostcommon.L2BatchRepositoryName, l2Repo) hostServices.RegisterService(hostcommon.EnclaveServiceName, enclService) hostServices.RegisterService(hostcommon.LogSubscriptionServiceName, subsService) diff --git a/go/host/l1/publisher.go b/go/host/l1/publisher.go index f213ac59e8..0827e119a0 100644 --- a/go/host/l1/publisher.go +++ b/go/host/l1/publisher.go @@ -4,9 +4,10 @@ import ( "encoding/json" "fmt" "math/big" - "sync/atomic" "time" + "github.com/obscuronet/go-obscuro/go/common/stopcontrol" + gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" gethlog "github.com/ethereum/go-ethereum/log" @@ -25,11 +26,6 @@ const ( l1TxTriesRollup = 3 // Attempts to send secret initialisation, request or response transactions to the L1. Worst-case, equates to 63 seconds, plus time per request. l1TxTriesSecret = 7 - - // todo - these values have to be configurable - maxWaitForL1Receipt = 100 * time.Second - retryIntervalForL1Receipt = 10 * time.Second - maxWaitForSecretResponse = 120 * time.Second ) type Publisher struct { @@ -41,34 +37,48 @@ type Publisher struct { repository host.L1BlockRepository logger gethlog.Logger - running atomic.Bool + hostStopper *stopcontrol.StopControl + + maxWaitForL1Receipt time.Duration + retryIntervalForL1Receipt time.Duration } -func NewL1Publisher(hostData host.Identity, hostWallet wallet.Wallet, client ethadapter.EthClient, mgmtContract mgmtcontractlib.MgmtContractLib, repository host.L1BlockRepository, logger gethlog.Logger) *Publisher { +func NewL1Publisher( + hostData host.Identity, + hostWallet wallet.Wallet, + client ethadapter.EthClient, + mgmtContract mgmtcontractlib.MgmtContractLib, + repository host.L1BlockRepository, + hostStopper *stopcontrol.StopControl, + logger gethlog.Logger, + maxWaitForL1Receipt time.Duration, + retryIntervalForL1Receipt time.Duration, +) *Publisher { return &Publisher{ - hostData: hostData, - hostWallet: hostWallet, - ethClient: client, - mgmtContractLib: mgmtContract, - repository: repository, - logger: logger, + hostData: hostData, + hostWallet: hostWallet, + ethClient: client, + mgmtContractLib: mgmtContract, + repository: repository, + hostStopper: hostStopper, + logger: logger, + maxWaitForL1Receipt: maxWaitForL1Receipt, + retryIntervalForL1Receipt: retryIntervalForL1Receipt, } } func (p *Publisher) Start() error { - p.running.Store(true) return nil } func (p *Publisher) Stop() error { - p.running.Store(false) return nil } func (p *Publisher) HealthStatus() host.HealthStatus { // todo (@matt) do proper health status based on failed transactions or something errMsg := "" - if !p.running.Load() { + if p.hostStopper.IsStopping() { errMsg = "not running" } return &host.BasicErrHealthStatus{ErrMsg: errMsg} @@ -312,7 +322,7 @@ func (p *Publisher) waitForReceipt(txHash common.TxHash) error { } return err }, - retry.NewTimeoutStrategy(maxWaitForL1Receipt, retryIntervalForL1Receipt), + retry.NewTimeoutStrategy(p.maxWaitForL1Receipt, p.retryIntervalForL1Receipt), ) if err != nil { return errors.Wrap(err, "receipt for L1 tx not found despite successful broadcast") diff --git a/go/node/config.go b/go/node/config.go index 862ab226dd..4412275518 100644 --- a/go/node/config.go +++ b/go/node/config.go @@ -2,6 +2,7 @@ package node import ( "fmt" + "time" "github.com/obscuronet/go-obscuro/go/common" "github.com/obscuronet/go-obscuro/go/config" @@ -46,6 +47,7 @@ type Config struct { profilerEnabled bool logLevel int isInboundP2PDisabled bool + l1BlockTime time.Duration } func NewNodeConfig(opts ...Option) *Config { @@ -104,6 +106,7 @@ func (c *Config) ToHostConfig() *config.HostInputConfig { cfg.LogLevel = c.logLevel cfg.SequencerID = gethcommon.HexToAddress(c.sequencerID) cfg.IsInboundP2PDisabled = c.isInboundP2PDisabled + cfg.L1BlockTime = c.l1BlockTime return cfg } @@ -277,3 +280,9 @@ func WithInboundP2PDisabled(b bool) Option { c.isInboundP2PDisabled = b } } + +func WithL1BlockTime(d time.Duration) Option { + return func(c *Config) { + c.l1BlockTime = d + } +} diff --git a/integration/simulation/network/inmemory.go b/integration/simulation/network/inmemory.go index 39e935c924..d5a15cf22f 100644 --- a/integration/simulation/network/inmemory.go +++ b/integration/simulation/network/inmemory.go @@ -67,6 +67,7 @@ func (n *basicNetworkOfInMemoryNodes) Create(params *params.SimParams, stats *st common.Hash{}, params.AvgBlockDuration/2, incomingP2PDisabled, + params.AvgBlockDuration, ) obscuroClient := p2p.NewInMemObscuroClient(agg) diff --git a/integration/simulation/network/network_utils.go b/integration/simulation/network/network_utils.go index 7e07a82250..f7e52ae780 100644 --- a/integration/simulation/network/network_utils.go +++ b/integration/simulation/network/network_utils.go @@ -59,6 +59,7 @@ func createInMemObscuroNode( l1StartBlk gethcommon.Hash, batchInterval time.Duration, incomingP2PDisabled bool, + l1BlockTime time.Duration, ) *container.HostContainer { mgtContractAddress := mgmtContractLib.GetContractAddr() @@ -74,6 +75,7 @@ func createInMemObscuroNode( MessageBusAddress: l1BusAddress, BatchInterval: batchInterval, IsInboundP2PDisabled: incomingP2PDisabled, + L1BlockTime: l1BlockTime, } enclaveConfig := &config.EnclaveConfig{ diff --git a/integration/simulation/network/obscuro_node_utils.go b/integration/simulation/network/obscuro_node_utils.go index ad8771fe56..322a1d6413 100644 --- a/integration/simulation/network/obscuro_node_utils.go +++ b/integration/simulation/network/obscuro_node_utils.go @@ -52,6 +52,7 @@ func startInMemoryObscuroNodes(params *params.SimParams, genesisJSON []byte, l1C params.L1SetupData.ObscuroStartBlock, params.AvgBlockDuration/3, true, + params.AvgBlockDuration, ) obscuroHosts[i] = obscuroNodes[i].Host() } diff --git a/integration/simulation/network/socket.go b/integration/simulation/network/socket.go index 74c9b36d37..dda022033e 100644 --- a/integration/simulation/network/socket.go +++ b/integration/simulation/network/socket.go @@ -98,6 +98,7 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat node.WithInboundP2PDisabled(isInboundP2PDisabled), node.WithLogLevel(4), node.WithDebugNamespaceEnabled(true), + node.WithL1BlockTime(simParams.AvgBlockDuration), ), )