Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 4, 2023
1 parent 5087ef5 commit 190302d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 77 deletions.
59 changes: 30 additions & 29 deletions go/config/enclave_cli_flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "github.com/ten-protocol/go-ten/go/common/flag"
import (
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/flag"
)

// Flag names.
const (
Expand Down Expand Up @@ -32,34 +35,32 @@ const (
)

// EnclaveFlags are the flags that the enclave can receive
func EnclaveFlags() map[string]*flag.TenFlag {
return map[string]*flag.TenFlag{
HostIDFlag: flag.NewStringFlag(HostIDFlag, "", "The 20 bytes of the address of the Obscuro host this enclave serves"),
HostAddressFlag: flag.NewStringFlag(HostAddressFlag, "", "The peer-to-peer IP address of the Obscuro host this enclave serves"),
AddressFlag: flag.NewStringFlag(AddressFlag, "", "The address on which to serve the Obscuro enclave service"),
NodeTypeFlag: flag.NewStringFlag(NodeTypeFlag, "", "The node's type (e.g. sequencer, validator)"),
WillAttestFlag: flag.NewBoolFlag(WillAttestFlag, false, "Whether the enclave will produce a verified attestation report"),
ValidateL1BlocksFlag: flag.NewBoolFlag(ValidateL1BlocksFlag, false, "Whether to validate incoming blocks using the hardcoded L1 genesis.json config"),
ManagementContractAddressFlag: flag.NewStringFlag(ManagementContractAddressFlag, "", "The management contract address on the L1"),
LogLevelFlag: flag.NewIntFlag(LogLevelFlag, 0, "The verbosity level of logs. (Defaults to Info)"),
LogPathFlag: flag.NewStringFlag(LogPathFlag, "", "The path to use for the enclave service's log file"),
EdgelessDBHostFlag: flag.NewStringFlag(EdgelessDBHostFlag, "", "Host address for the edgeless DB instance (can be empty if useInMemoryDB is true or if not using attestation"),
SQLiteDBPathFlag: flag.NewStringFlag(SQLiteDBPathFlag, "", "Filepath for the sqlite DB persistence file (can be empty if a throwaway file in /tmp/ is acceptable or if using InMemory DB or if using attestation/EdgelessDB)"),
MinGasPriceFlag: flag.NewInt64Flag(MinGasPriceFlag, 0, "The minimum gas price for mining a transaction"),
MessageBusAddressFlag: flag.NewStringFlag(MessageBusAddressFlag, "", "The address of the L1 message bus contract owned by the management contract."),
SequencerIDFlag: flag.NewStringFlag(SequencerIDFlag, "", "The 20 bytes of the address of the sequencer for this network"),
MaxBatchSizeFlag: flag.NewUint64Flag(MaxBatchSizeFlag, 0, "The maximum size a batch is allowed to reach uncompressed"),
MaxRollupSizeFlag: flag.NewUint64Flag(MaxRollupSizeFlag, 0, "The maximum size a rollup is allowed to reach"),
L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, 0, ""),
L2CoinbaseFlag: flag.NewStringFlag(L2CoinbaseFlag, "", ""),
L2GasLimitFlag: flag.NewUint64Flag(L2GasLimitFlag, 0, ""),
ObscuroGenesisFlag: flag.NewStringFlag(ObscuroGenesisFlag, "", "The json string with the obscuro genesis"),
L1ChainIDFlag: flag.NewInt64Flag(L1ChainIDFlag, 0, "An integer representing the unique chain id of the Ethereum chain used as an L1 (default 1337)"),
ObscuroChainIDFlag: flag.NewInt64Flag(ObscuroChainIDFlag, 0, "An integer representing the unique chain id of the Obscuro chain (default 443)"),
UseInMemoryDBFlag: flag.NewBoolFlag(UseInMemoryDBFlag, false, "Whether the enclave will use an in-memory DB rather than persist data"),
ProfilerEnabledFlag: flag.NewBoolFlag(ProfilerEnabledFlag, false, "Runs a profiler instance (Defaults to false)"),
DebugNamespaceEnabledFlag: flag.NewBoolFlag(DebugNamespaceEnabledFlag, false, "Whether the debug namespace is enabled"),
}
var EnclaveFlags = map[string]*flag.TenFlag{
HostIDFlag: flag.NewStringFlag(HostIDFlag, "", "The 20 bytes of the address of the Obscuro host this enclave serves"),
HostAddressFlag: flag.NewStringFlag(HostAddressFlag, "127.0.0.1:10000", "The peer-to-peer IP address of the Obscuro host this enclave serves"),
AddressFlag: flag.NewStringFlag(AddressFlag, "127.0.0.1:11000", "The address on which to serve the Obscuro enclave service"),
NodeTypeFlag: flag.NewStringFlag(NodeTypeFlag, common.Sequencer.String(), "The node's type (e.g. sequencer, validator)"),
WillAttestFlag: flag.NewBoolFlag(WillAttestFlag, false, "Whether the enclave will produce a verified attestation report"),
ValidateL1BlocksFlag: flag.NewBoolFlag(ValidateL1BlocksFlag, false, "Whether to validate incoming blocks using the hardcoded L1 genesis.json config"),
ManagementContractAddressFlag: flag.NewStringFlag(ManagementContractAddressFlag, "", "The management contract address on the L1"),
LogLevelFlag: flag.NewIntFlag(LogLevelFlag, 3, "The verbosity level of logs. (Defaults to Info)"),
LogPathFlag: flag.NewStringFlag(LogPathFlag, "stdout", "The path to use for the enclave service's log file"),
EdgelessDBHostFlag: flag.NewStringFlag(EdgelessDBHostFlag, "", "Host address for the edgeless DB instance (can be empty if useInMemoryDB is true or if not using attestation"),
SQLiteDBPathFlag: flag.NewStringFlag(SQLiteDBPathFlag, "", "Filepath for the sqlite DB persistence file (can be empty if a throwaway file in /tmp/ is acceptable or if using InMemory DB or if using attestation/EdgelessDB)"),
MinGasPriceFlag: flag.NewInt64Flag(MinGasPriceFlag, 1, "The minimum gas price for mining a transaction"),
MessageBusAddressFlag: flag.NewStringFlag(MessageBusAddressFlag, "", "The address of the L1 message bus contract owned by the management contract."),
SequencerIDFlag: flag.NewStringFlag(SequencerIDFlag, "", "The 20 bytes of the address of the sequencer for this network"),
MaxBatchSizeFlag: flag.NewUint64Flag(MaxBatchSizeFlag, 1024*25, "The maximum size a batch is allowed to reach uncompressed"),
MaxRollupSizeFlag: flag.NewUint64Flag(MaxRollupSizeFlag, 1024*64, "The maximum size a rollup is allowed to reach"),
L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, 1, ""),
L2CoinbaseFlag: flag.NewStringFlag(L2CoinbaseFlag, "0xd6C9230053f45F873Cb66D8A02439380a37A4fbF", ""),
L2GasLimitFlag: flag.NewUint64Flag(L2GasLimitFlag, 9e18, ""),
ObscuroGenesisFlag: flag.NewStringFlag(ObscuroGenesisFlag, "", "The json string with the obscuro genesis"),
L1ChainIDFlag: flag.NewInt64Flag(L1ChainIDFlag, 1337, "An integer representing the unique chain id of the Ethereum chain used as an L1 (default 1337)"),
ObscuroChainIDFlag: flag.NewInt64Flag(ObscuroChainIDFlag, 443, "An integer representing the unique chain id of the Obscuro chain (default 443)"),
UseInMemoryDBFlag: flag.NewBoolFlag(UseInMemoryDBFlag, true, "Whether the enclave will use an in-memory DB rather than persist data"),
ProfilerEnabledFlag: flag.NewBoolFlag(ProfilerEnabledFlag, false, "Runs a profiler instance (Defaults to false)"),
DebugNamespaceEnabledFlag: flag.NewBoolFlag(DebugNamespaceEnabledFlag, false, "Whether the debug namespace is enabled"),
}

// enclaveRestrictedFlags are the flags that the enclave can receive ONLY over the Ego signed enclave.json
Expand Down
43 changes: 4 additions & 39 deletions go/config/enclave_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import (
"strconv"
"strings"

"github.com/ethereum/go-ethereum/params"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/flag"
"github.com/ten-protocol/go-ten/go/common/log"

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
)

// EnclaveConfig contains the full configuration for an Obscuro enclave service.
Expand Down Expand Up @@ -74,37 +70,6 @@ type EnclaveConfig struct {
GasLimit *big.Int
}

// DefaultEnclaveConfig returns an EnclaveConfig with default values.
func DefaultEnclaveConfig() *EnclaveConfig {
return &EnclaveConfig{
HostID: gethcommon.BytesToAddress([]byte("")),
HostAddress: "127.0.0.1:10000",
Address: "127.0.0.1:11000",
NodeType: common.Sequencer,
L1ChainID: 1337,
ObscuroChainID: 443,
WillAttest: false, // todo (config) - attestation should be on by default before production release
ValidateL1Blocks: false,
GenesisJSON: nil,
ManagementContractAddress: gethcommon.BytesToAddress([]byte("")),
LogLevel: int(gethlog.LvlInfo),
LogPath: log.SysOut,
UseInMemoryDB: true, // todo (config) - persistence should be on by default before production release
EdgelessDBHost: "",
SqliteDBPath: "",
ProfilerEnabled: false,
MinGasPrice: big.NewInt(1),
SequencerID: gethcommon.BytesToAddress([]byte("")),
ObscuroGenesis: "",
DebugNamespaceEnabled: false,
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
GasPaymentAddress: gethcommon.HexToAddress("0xd6C9230053f45F873Cb66D8A02439380a37A4fbF"),
BaseFee: new(big.Int).SetUint64(1),
GasLimit: new(big.Int).SetUint64(params.MaxGasLimit / 6),
}
}

func NewConfigFromFlags(cliFlags map[string]*flag.TenFlag) (*EnclaveConfig, error) {
productionMode := true

Expand Down Expand Up @@ -156,7 +121,7 @@ func retrieveEnvFlags() (map[string]*flag.TenFlag, error) {
return nil, fmt.Errorf("env var not set: %s", eflag)
}

switch EnclaveFlags()[eflag].FlagType {
switch EnclaveFlags[eflag].FlagType {
case "string":
parsedFlag := flag.NewStringFlag(eflag, "", "")
parsedFlag.Value = val
Expand All @@ -181,14 +146,14 @@ func retrieveEnvFlags() (map[string]*flag.TenFlag, error) {
parsedFlag.Value = b
parsedFlags[eflag] = parsedFlag
default:
return nil, fmt.Errorf("unexpected type: %s", EnclaveFlags()[eflag].FlagType)
return nil, fmt.Errorf("unexpected type: %s", EnclaveFlags[eflag].FlagType)
}
}
return parsedFlags, nil
}

func newConfig(flags map[string]*flag.TenFlag) (*EnclaveConfig, error) {
cfg := DefaultEnclaveConfig()
cfg := &EnclaveConfig{}

nodeType, err := common.ToNodeType(flags[NodeTypeFlag].String())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/config/enclave_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestCLIFlagTypes(t *testing.T) {
flag.CommandLine = originalFlagSet
}()

flags := EnclaveFlags()
flags := EnclaveFlags
err := tenflag.CreateCLIFlags(flags)
require.NoError(t, err)

Expand Down Expand Up @@ -81,7 +81,7 @@ func TestRestrictedMode(t *testing.T) {
t.Setenv("EDG_"+strings.ToUpper(ProfilerEnabledFlag), "true")
t.Setenv("EDG_"+strings.ToUpper(DebugNamespaceEnabledFlag), "true")

flags := EnclaveFlags()
flags := EnclaveFlags
err := tenflag.CreateCLIFlags(flags)
require.NoError(t, err)

Expand Down Expand Up @@ -120,7 +120,7 @@ func TestRestrictedModeNoCLIDuplication(t *testing.T) {
t.Setenv("EDG_"+strings.ToUpper(ProfilerEnabledFlag), "true")
t.Setenv("EDG_"+strings.ToUpper(DebugNamespaceEnabledFlag), "true")

flags := EnclaveFlags()
flags := EnclaveFlags
err := tenflag.CreateCLIFlags(flags)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions go/enclave/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
// Runs an Obscuro enclave as a standalone process.
func main() {
// fetch and parse flags
flags := config.EnclaveFlags()
err := tenflag.CreateCLIFlags(flags)
flags := config.EnclaveFlags // fetch the flags that enclave requires
err := tenflag.CreateCLIFlags(config.EnclaveFlags) // using tenflag convert those flags into the golang flags package ( go flags is a singlen )
if err != nil {
panic(fmt.Errorf("could not create CLI flags. Cause: %w", err))
}

tenflag.Parse()
tenflag.Parse() // parse the golang flags package defined flags from CLI

enclaveConfig, err := config.NewConfigFromFlags(flags)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ten-protocol/go-ten/integration/common/testlog"

gethcommon "github.com/ethereum/go-ethereum/common"
integrationCommon "github.com/ten-protocol/go-ten/integration/common"
)

const (
Expand Down Expand Up @@ -73,7 +74,7 @@ func NewNodeConfig(opts ...Option) *Config {
}

func (c *Config) ToEnclaveConfig() *config.EnclaveConfig {
cfg := config.DefaultEnclaveConfig()
cfg := integrationCommon.DefaultEnclaveConfig()

if c.nodeType == "validator" {
cfg.NodeType = common.Validator
Expand Down
41 changes: 40 additions & 1 deletion integration/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package common

import (
gethcommon "github.com/ethereum/go-ethereum/common"
"math/big"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/config"
"github.com/ten-protocol/go-ten/go/wallet"

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
)

// The Contract addresses are the result of the deploying a smart contract from hardcoded owners.
Expand Down Expand Up @@ -48,3 +56,34 @@ type ERC20Mapping struct {
Owner wallet.Wallet // for now the wrapped L2 version is owned by a wallet, but this will change
L2Address *gethcommon.Address
}

// DefaultEnclaveConfig returns an EnclaveConfig with default values.
func DefaultEnclaveConfig() *config.EnclaveConfig {
return &config.EnclaveConfig{
HostID: gethcommon.BytesToAddress([]byte("")),
HostAddress: "127.0.0.1:10000",
Address: "127.0.0.1:11000",
NodeType: common.Sequencer,
L1ChainID: 1337,
ObscuroChainID: 443,
WillAttest: false, // todo (config) - attestation should be on by default before production release
ValidateL1Blocks: false,
GenesisJSON: nil,
ManagementContractAddress: gethcommon.BytesToAddress([]byte("")),
LogLevel: int(gethlog.LvlInfo),
LogPath: log.SysOut,
UseInMemoryDB: true, // todo (config) - persistence should be on by default before production release
EdgelessDBHost: "",
SqliteDBPath: "",
ProfilerEnabled: false,
MinGasPrice: big.NewInt(1),
SequencerID: gethcommon.BytesToAddress([]byte("")),
ObscuroGenesis: "",
DebugNamespaceEnabled: false,
MaxBatchSize: 1024 * 25,
MaxRollupSize: 1024 * 64,
GasPaymentAddress: gethcommon.HexToAddress("0xd6C9230053f45F873Cb66D8A02439380a37A4fbF"),
BaseFee: new(big.Int).SetUint64(1),
GasLimit: new(big.Int).SetUint64(params.MaxGasLimit / 6),
}
}
4 changes: 3 additions & 1 deletion integration/simulation/devnetwork/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/ten-protocol/go-ten/integration/common/testlog"
"github.com/ten-protocol/go-ten/integration/simulation/network"
"github.com/ten-protocol/go-ten/integration/simulation/params"

integrationCommon "github.com/ten-protocol/go-ten/integration/common"
)

// InMemNodeOperator represents an Obscuro node playing a role in a DevSimulation
Expand Down Expand Up @@ -158,7 +160,7 @@ func (n *InMemNodeOperator) createEnclaveContainer() *enclavecontainer.EnclaveCo
hostPort := n.config.PortStart + integration.DefaultHostP2pOffset + n.operatorIdx
hostAddr := fmt.Sprintf("%s:%d", network.Localhost, hostPort)

defaultCfg := config.DefaultEnclaveConfig()
defaultCfg := integrationCommon.DefaultEnclaveConfig()

enclaveConfig := &config.EnclaveConfig{
HostID: n.l1Wallet.Address(),
Expand Down

0 comments on commit 190302d

Please sign in to comment.