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

Remove HostID #2137

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions go/common/host/identity.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
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
}

func NewIdentity(cfg *hostconfig.HostConfig) Identity {
return Identity{
ID: cfg.ID,
P2PPublicAddress: cfg.P2PPublicAddress,
IsGenesis: cfg.IsGenesis,
IsSequencer: cfg.NodeType == common.Sequencer,
Expand Down
9 changes: 8 additions & 1 deletion go/config/defaults/sim/1-env-sim.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
host:
debug:
enableDebugNamespace: true
log:
level: 4
path: ""

enclave:
debug:
enableDebugNamespace: true
enableDebugNamespace: true
log:
level: 4
path: ""
2 changes: 1 addition & 1 deletion go/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ func load(filePaths []string) (*TenConfig, error) {
}

fmt.Println("Successfully loaded Ten config.")
tenCfg.PrettyPrint()
//tenCfg.PrettyPrint()
return &tenCfg, nil
}
3 changes: 1 addition & 2 deletions go/config/node.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

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

Expand All @@ -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"`
Expand Down
3 changes: 0 additions & 3 deletions go/enclave/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/container/enclave_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions go/enclave/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go/host/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions go/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion go/host/storage/db_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
4 changes: 0 additions & 4 deletions go/node/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type NodeConfigCLI struct {
enclaveHTTPPort int
enclaveWSPort int
privateKey string
hostID string
sequencerP2PAddr string
managementContractAddr string
messageBusContractAddr string
Expand Down Expand Up @@ -75,7 +74,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])
Expand Down Expand Up @@ -107,7 +105,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
Expand Down Expand Up @@ -186,7 +183,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
Expand Down
1 change: 0 additions & 1 deletion integration/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions integration/noderunner/in_memory_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions integration/noderunner/noderunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion integration/simulation/devnetwork/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion integration/simulation/network/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func createInMemTenNode(
}

enclaveConfig := &enclaveconfig.EnclaveConfig{
HostID: hostConfig.ID,
NodeType: nodeType,
L1ChainID: integration.EthereumChainID,
ObscuroChainID: integration.TenChainID,
Expand Down
4 changes: 0 additions & 4 deletions integration/simulation/network/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,19 @@ 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

// if it's not the sequencer
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
}
Expand Down Expand Up @@ -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)
Expand Down
Loading