From c6908485beb0156abf6e657a93ba601991d06c39 Mon Sep 17 00:00:00 2001 From: Will Hester Date: Mon, 11 Nov 2024 14:49:28 +0000 Subject: [PATCH 1/4] remove hostID and set logging ID to hostAddress --- go/config/node.go | 3 +-- go/enclave/config/config.go | 3 --- go/enclave/container/enclave_container.go | 2 +- go/enclave/txpool/txpool.go | 2 -- go/host/config/config.go | 1 - go/host/host.go | 4 +--- go/host/storage/db_init.go | 8 +++++++- go/node/cmd/cli.go | 3 --- integration/common/constants.go | 1 - integration/noderunner/in_memory_node.go | 4 ++-- integration/simulation/devnetwork/node.go | 1 - integration/simulation/network/network_utils.go | 1 - integration/simulation/network/socket.go | 4 ---- 13 files changed, 12 insertions(+), 25 deletions(-) diff --git a/go/config/node.go b/go/config/node.go index ca72bd4b50..aad4372d4a 100644 --- a/go/config/node.go +++ b/go/config/node.go @@ -1,7 +1,6 @@ package config import ( - gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ten-protocol/go-ten/go/common" ) @@ -14,7 +13,7 @@ type NodeConfig struct { Name string `mapstructure:"name"` // The host's identity derived from the L1 Private Key // todo: does node ID still need to exist? Look to remove in favour of enclave IDs - ID gethcommon.Address `mapstructure:"id"` + // ID gethcommon.Address `mapstructure:"id"` // The public peer-to-peer IP address of the host // todo: does host address still need to exist for the enclave to sign over or does the enclave ID cover the usages? HostAddress string `mapstructure:"hostAddress"` diff --git a/go/enclave/config/config.go b/go/enclave/config/config.go index 6ddce15b8e..8b052c57b8 100644 --- a/go/enclave/config/config.go +++ b/go/enclave/config/config.go @@ -13,8 +13,6 @@ import ( // EnclaveConfig contains the full configuration for an Obscuro enclave service. type EnclaveConfig struct { - // The identity of the host the enclave service is tied to - HostID gethcommon.Address // The public peer-to-peer IP address of the host the enclave service is tied to HostAddress string // The address on which to serve requests @@ -76,7 +74,6 @@ type EnclaveConfig struct { func EnclaveConfigFromTenConfig(tenCfg *config.TenConfig) *EnclaveConfig { return &EnclaveConfig{ - HostID: tenCfg.Node.ID, HostAddress: tenCfg.Node.HostAddress, NodeType: tenCfg.Node.NodeType, WillAttest: tenCfg.Enclave.EnableAttestation, diff --git a/go/enclave/container/enclave_container.go b/go/enclave/container/enclave_container.go index 0e36971b0b..1022d06d3f 100644 --- a/go/enclave/container/enclave_container.go +++ b/go/enclave/container/enclave_container.go @@ -46,7 +46,7 @@ func (e *EnclaveContainer) Stop() error { func NewEnclaveContainerFromConfig(config *enclaveconfig.EnclaveConfig) *EnclaveContainer { // todo - improve this wiring, perhaps setup DB etc. at this level and inject into enclave // (at that point the WithLogger constructor could be a full DI constructor like the HostContainer tries, for testability) - logger := log.New(log.EnclaveCmp, config.LogLevel, config.LogPath, log.NodeIDKey, config.HostID) + logger := log.New(log.EnclaveCmp, config.LogLevel, config.LogPath, log.NodeIDKey, config.HostAddress) // todo - this is for debugging purposes only, should be remove in the future fmt.Printf("Building enclave container with config: %+v\n", config) diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 764d1d2cb7..0ed221ec3b 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -57,12 +57,10 @@ func (t *TxPool) Start() error { return fmt.Errorf("tx pool already started") } - fmt.Println("Starting tx pool") memp, err := gethtxpool.New(t.gasTip.Uint64(), t.Chain, []gethtxpool.SubPool{t.legacyPool}) if err != nil { return fmt.Errorf("unable to init geth tx pool - %w", err) } - fmt.Println("Tx pool started") t.pool = memp t.running = true diff --git a/go/host/config/config.go b/go/host/config/config.go index 7fcedc2b96..7cbd210147 100644 --- a/go/host/config/config.go +++ b/go/host/config/config.go @@ -112,7 +112,6 @@ type HostConfig struct { func HostConfigFromTenConfig(tenCfg *config.TenConfig) *HostConfig { return &HostConfig{ - ID: tenCfg.Node.ID, PrivateKeyString: tenCfg.Node.PrivateKeyString, IsGenesis: tenCfg.Node.IsGenesis, NodeType: tenCfg.Node.NodeType, diff --git a/go/host/host.go b/go/host/host.go index 3ac79a583c..ed1e31c451 100644 --- a/go/host/host.go +++ b/go/host/host.go @@ -33,7 +33,6 @@ import ( // Implementation of host.Host. type host struct { config *hostconfig.HostConfig - shortID uint64 services *ServicesRegistry // registry of services that the host manages and makes available // ignore incoming requests @@ -63,8 +62,7 @@ func NewHost(config *hostconfig.HostConfig, hostServices *ServicesRegistry, p2p hostIdentity := hostcommon.NewIdentity(config) host := &host{ // config - config: config, - shortID: common.ShortAddress(config.ID), + config: config, // services services: hostServices, diff --git a/go/host/storage/db_init.go b/go/host/storage/db_init.go index b2ed319b8b..88f6ae506a 100644 --- a/go/host/storage/db_init.go +++ b/go/host/storage/db_init.go @@ -2,6 +2,7 @@ package storage import ( "fmt" + "strings" hostconfig "github.com/ten-protocol/go-ten/go/host/config" "github.com/ten-protocol/go-ten/go/host/storage/hostdb" @@ -15,7 +16,7 @@ const HOST = "HOST_" // CreateDBFromConfig creates an appropriate ethdb.Database instance based on your config func CreateDBFromConfig(cfg *hostconfig.HostConfig, logger gethlog.Logger) (hostdb.HostDB, error) { - dbName := HOST + cfg.ID.String() + dbName := createHostName(cfg) if err := validateDBConf(cfg); err != nil { return nil, err } @@ -45,3 +46,8 @@ func validateDBConf(cfg *hostconfig.HostConfig) error { } return nil } + +func createHostName(cfg *hostconfig.HostConfig) string { + sanitizedAddress := strings.Replace(cfg.P2PPublicAddress, ":", "_", -1) + return fmt.Sprintf("%s_%s_%s", HOST, cfg.NodeType, sanitizedAddress) +} diff --git a/go/node/cmd/cli.go b/go/node/cmd/cli.go index 11a34dedad..a9cda62e3a 100644 --- a/go/node/cmd/cli.go +++ b/go/node/cmd/cli.go @@ -75,7 +75,6 @@ func ParseConfigCLI() *NodeConfigCLI { enclaveHTTPPort := flag.Int(enclaveHTTPPortFlag, 11000, flagUsageMap[enclaveHTTPPortFlag]) enclaveWSPort := flag.Int(enclaveWSPortFlag, 11001, flagUsageMap[enclaveWSPortFlag]) privateKey := flag.String(privateKeyFlag, "", flagUsageMap[privateKeyFlag]) - hostID := flag.String(hostIDFlag, "", flagUsageMap[hostIDFlag]) sequencerP2PAddr := flag.String(sequencerP2PAddrFlag, "", flagUsageMap[sequencerP2PAddrFlag]) managementContractAddr := flag.String(managementContractAddrFlag, "", flagUsageMap[managementContractAddrFlag]) messageBusContractAddr := flag.String(messageBusContractAddrFlag, "", flagUsageMap[messageBusContractAddrFlag]) @@ -107,7 +106,6 @@ func ParseConfigCLI() *NodeConfigCLI { cfg.enclaveHTTPPort = *enclaveHTTPPort cfg.enclaveWSPort = *enclaveWSPort cfg.privateKey = *privateKey - cfg.hostID = *hostID cfg.sequencerP2PAddr = *sequencerP2PAddr cfg.managementContractAddr = *managementContractAddr cfg.messageBusContractAddr = *messageBusContractAddr @@ -186,7 +184,6 @@ func NodeCLIConfigToTenConfig(cliCfg *NodeConfigCLI) *config.TenConfig { } tenCfg.Network.Sequencer.P2PAddress = cliCfg.sequencerP2PAddr - tenCfg.Node.ID = gethcommon.HexToAddress(cliCfg.hostID) tenCfg.Node.Name = cliCfg.nodeName tenCfg.Node.NodeType = nodeType tenCfg.Node.IsGenesis = cliCfg.isGenesis diff --git a/integration/common/constants.go b/integration/common/constants.go index 9073643301..aa10d29757 100644 --- a/integration/common/constants.go +++ b/integration/common/constants.go @@ -61,7 +61,6 @@ type ERC20Mapping struct { // DefaultEnclaveConfig returns an EnclaveConfig with default values. func DefaultEnclaveConfig() *enclaveconfig.EnclaveConfig { return &enclaveconfig.EnclaveConfig{ - HostID: gethcommon.BytesToAddress([]byte("")), HostAddress: "127.0.0.1:10000", Address: "127.0.0.1:11000", NodeType: common.Sequencer, diff --git a/integration/noderunner/in_memory_node.go b/integration/noderunner/in_memory_node.go index fb1381ea83..71ed4887be 100644 --- a/integration/noderunner/in_memory_node.go +++ b/integration/noderunner/in_memory_node.go @@ -84,14 +84,14 @@ func (d *InMemNode) Upgrade(networkCfg *node.NetworkConfig) error { func (d *InMemNode) startHost() error { hostConfig := hostconfig.HostConfigFromTenConfig(d.tenCfg) - logger := testlog.Logger().New(log.CmpKey, log.HostCmp, log.NodeIDKey, d.tenCfg.Node.ID) + logger := testlog.Logger().New(log.CmpKey, log.HostCmp, log.NodeIDKey, d.tenCfg.Node.HostAddress) d.host = hostcontainer.NewHostContainerFromConfig(hostConfig, logger) return d.host.Start() } func (d *InMemNode) startEnclave() error { enclaveCfg := enclaveconfig.EnclaveConfigFromTenConfig(d.tenCfg) - logger := testlog.Logger().New(log.CmpKey, log.EnclaveCmp, log.NodeIDKey, d.tenCfg.Node.ID) + logger := testlog.Logger().New(log.CmpKey, log.EnclaveCmp, log.NodeIDKey, d.tenCfg.Node.HostAddress) enclaveCfg.LogPath = testlog.LogFile() // if not nil, the node will use the testlog.Logger - NewEnclaveContainerWithLogger will create one otherwise diff --git a/integration/simulation/devnetwork/node.go b/integration/simulation/devnetwork/node.go index 4790a0a17e..383d59a90b 100644 --- a/integration/simulation/devnetwork/node.go +++ b/integration/simulation/devnetwork/node.go @@ -200,7 +200,6 @@ func (n *InMemNodeOperator) createEnclaveContainer(idx int) *enclavecontainer.En enclaveType = common.Validator } enclaveConfig := &config.EnclaveConfig{ - HostID: n.l1Wallet.Address(), HostAddress: hostAddr, Address: enclaveAddr, NodeType: enclaveType, diff --git a/integration/simulation/network/network_utils.go b/integration/simulation/network/network_utils.go index 83142c2291..6f04d3fb72 100644 --- a/integration/simulation/network/network_utils.go +++ b/integration/simulation/network/network_utils.go @@ -85,7 +85,6 @@ func createInMemTenNode( } enclaveConfig := &enclaveconfig.EnclaveConfig{ - HostID: hostConfig.ID, NodeType: nodeType, L1ChainID: integration.EthereumChainID, ObscuroChainID: integration.TenChainID, diff --git a/integration/simulation/network/socket.go b/integration/simulation/network/socket.go index 56732c08d6..c5f9098b84 100644 --- a/integration/simulation/network/socket.go +++ b/integration/simulation/network/socket.go @@ -68,14 +68,12 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat // get the sequencer Address seqPrivateKey := n.wallets.NodeWallets[0].PrivateKey() seqPrivKey := fmt.Sprintf("%x", crypto.FromECDSA(seqPrivateKey)) - seqHostAddress := crypto.PubkeyToAddress(seqPrivateKey.PublicKey) // create the nodes nodes := make([]node.Node, simParams.NumberOfNodes) var err error for i := 0; i < simParams.NumberOfNodes; i++ { privateKey := seqPrivKey - hostAddress := seqHostAddress nodeTypeStr := "sequencer" isInboundP2PDisabled := false @@ -83,7 +81,6 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat if i != 0 { nodeTypeStr = "validator" privateKey = fmt.Sprintf("%x", crypto.FromECDSA(n.wallets.NodeWallets[i].PrivateKey())) - hostAddress = crypto.PubkeyToAddress(n.wallets.NodeWallets[i].PrivateKey().PublicKey) // only the validators can have the incoming p2p disabled isInboundP2PDisabled = i == simParams.NodeWithInboundP2PDisabled } @@ -113,7 +110,6 @@ func (n *networkOfSocketNodes) Create(simParams *params.SimParams, _ *stats.Stat tenCfg.Node.HostAddress = hostP2PAddress tenCfg.Node.NodeType = nodeType tenCfg.Node.IsGenesis = i == 0 - tenCfg.Node.ID = hostAddress tenCfg.Host.P2P.IsDisabled = isInboundP2PDisabled tenCfg.Host.P2P.BindAddress = hostP2PAddress tenCfg.Host.RPC.HTTPPort = uint64(simParams.StartPort + integration.DefaultHostRPCHTTPOffset + i) From 6a50b7ff52587d95e80e0b0a61c407a0b51ff056 Mon Sep 17 00:00:00 2001 From: Will Hester Date: Mon, 11 Nov 2024 16:15:56 +0000 Subject: [PATCH 2/4] lint --- go/node/cmd/cli.go | 1 - integration/noderunner/noderunner_test.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/go/node/cmd/cli.go b/go/node/cmd/cli.go index a9cda62e3a..d8681b9be9 100644 --- a/go/node/cmd/cli.go +++ b/go/node/cmd/cli.go @@ -33,7 +33,6 @@ type NodeConfigCLI struct { enclaveHTTPPort int enclaveWSPort int privateKey string - hostID string sequencerP2PAddr string managementContractAddr string messageBusContractAddr string diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index 575889a612..3870ab695d 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ten-protocol/go-ten/go/common/profiler" "github.com/ten-protocol/go-ten/go/config" @@ -117,7 +116,6 @@ func createInMemoryNode(startPort int) node.Node { } tenCfg.Node.PrivateKeyString = integration.GethNodePK - tenCfg.Node.ID = common.HexToAddress(integration.GethNodeAddress) tenCfg.Node.IsGenesis = true tenCfg.Host.Debug.EnableProfiler = true From 5a9dd8120cdfe125dee914df41b71023a36d6abb Mon Sep 17 00:00:00 2001 From: Will Hester Date: Mon, 11 Nov 2024 16:56:05 +0000 Subject: [PATCH 3/4] remove ID from identity --- go/common/host/identity.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/go/common/host/identity.go b/go/common/host/identity.go index 663f695bdc..3612b83853 100644 --- a/go/common/host/identity.go +++ b/go/common/host/identity.go @@ -1,13 +1,11 @@ package host import ( - gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ten-protocol/go-ten/go/common" hostconfig "github.com/ten-protocol/go-ten/go/host/config" ) type Identity struct { - ID gethcommon.Address P2PPublicAddress string IsGenesis bool IsSequencer bool @@ -15,7 +13,6 @@ type Identity struct { func NewIdentity(cfg *hostconfig.HostConfig) Identity { return Identity{ - ID: cfg.ID, P2PPublicAddress: cfg.P2PPublicAddress, IsGenesis: cfg.IsGenesis, IsSequencer: cfg.NodeType == common.Sequencer, From ffd06c70e4e7b2132d3b655baa406f44119b43da Mon Sep 17 00:00:00 2001 From: Will Hester Date: Tue, 12 Nov 2024 10:16:32 +0000 Subject: [PATCH 4/4] turn off sys logging for sim tests --- go/config/defaults/sim/1-env-sim.yaml | 9 ++++++++- go/config/loader.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go/config/defaults/sim/1-env-sim.yaml b/go/config/defaults/sim/1-env-sim.yaml index cc4254019d..a38ebfbd85 100644 --- a/go/config/defaults/sim/1-env-sim.yaml +++ b/go/config/defaults/sim/1-env-sim.yaml @@ -1,6 +1,13 @@ host: debug: enableDebugNamespace: true + log: + level: 4 + path: "" + enclave: debug: - enableDebugNamespace: true \ No newline at end of file + enableDebugNamespace: true + log: + level: 4 + path: "" \ No newline at end of file diff --git a/go/config/loader.go b/go/config/loader.go index 33d141b6c1..7844f0a72d 100644 --- a/go/config/loader.go +++ b/go/config/loader.go @@ -88,6 +88,6 @@ func load(filePaths []string) (*TenConfig, error) { } fmt.Println("Successfully loaded Ten config.") - tenCfg.PrettyPrint() + //tenCfg.PrettyPrint() return &tenCfg, nil }