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

Add l1 block time config for host #1523

Merged
merged 2 commits into from
Sep 14, 2023
Merged
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
7 changes: 7 additions & 0 deletions go/config/host_config.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 2 additions & 0 deletions go/host/container/cli.go
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ type HostConfigToml struct {
BatchInterval string
RollupInterval string
IsInboundP2PDisabled bool
L1BlockTime int
}

// ParseConfig returns a config.HostInputConfig based on either the file identified by the `config` flag, or the flags with
@@ -200,5 +201,6 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) {
BatchInterval: batchInterval,
RollupInterval: rollupInterval,
IsInboundP2PDisabled: tomlConfig.IsInboundP2PDisabled,
L1BlockTime: time.Duration(tomlConfig.L1BlockTime) * time.Second,
}, nil
}
5 changes: 4 additions & 1 deletion go/host/host.go
Original file line number Diff line number Diff line change
@@ -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)
46 changes: 28 additions & 18 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions go/node/config.go
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions integration/simulation/network/inmemory.go
Original file line number Diff line number Diff line change
@@ -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)

2 changes: 2 additions & 0 deletions integration/simulation/network/network_utils.go
Original file line number Diff line number Diff line change
@@ -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{
1 change: 1 addition & 0 deletions integration/simulation/network/obscuro_node_utils.go
Original file line number Diff line number Diff line change
@@ -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()
}
1 change: 1 addition & 0 deletions integration/simulation/network/socket.go
Original file line number Diff line number Diff line change
@@ -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),
),
)

Loading