Skip to content

Commit

Permalink
Add l1 block time config for host
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel committed Sep 14, 2023
1 parent 1e6ba68 commit 7420fef
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 19 deletions.
7 changes: 7 additions & 0 deletions go/config/host_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -126,6 +129,7 @@ func (p HostInputConfig) ToHostConfig() *HostConfig {
DebugNamespaceEnabled: p.DebugNamespaceEnabled,
BatchInterval: p.BatchInterval,
RollupInterval: p.RollupInterval,
L1BlockTime: p.L1BlockTime,
IsInboundP2PDisabled: p.IsInboundP2PDisabled,
}
}
Expand All @@ -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
Expand Down Expand Up @@ -247,6 +253,7 @@ func DefaultHostParsedConfig() *HostInputConfig {
DebugNamespaceEnabled: false,
BatchInterval: 1 * time.Second,
RollupInterval: 5 * time.Second,
L1BlockTime: 15 * time.Second,
IsInboundP2PDisabled: false,
}
}
5 changes: 4 additions & 1 deletion go/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 28 additions & 18 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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}
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions go/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package node

import (
"fmt"
"time"

"github.com/obscuronet/go-obscuro/go/common"
"github.com/obscuronet/go-obscuro/go/config"
Expand Down Expand Up @@ -46,6 +47,7 @@ type Config struct {
profilerEnabled bool
logLevel int
isInboundP2PDisabled bool
l1BlockTime time.Duration
}

func NewNodeConfig(opts ...Option) *Config {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions integration/simulation/network/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func createInMemObscuroNode(
l1StartBlk gethcommon.Hash,
batchInterval time.Duration,
incomingP2PDisabled bool,
l1BlockTime time.Duration,
) *container.HostContainer {
mgtContractAddress := mgmtContractLib.GetContractAddr()

Expand All @@ -74,6 +75,7 @@ func createInMemObscuroNode(
MessageBusAddress: l1BusAddress,
BatchInterval: batchInterval,
IsInboundP2PDisabled: incomingP2PDisabled,
L1BlockTime: l1BlockTime,
}

enclaveConfig := &config.EnclaveConfig{
Expand Down
1 change: 1 addition & 0 deletions integration/simulation/network/obscuro_node_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions integration/simulation/network/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
)

Expand Down

0 comments on commit 7420fef

Please sign in to comment.