Skip to content

Commit

Permalink
rename dns registry to service alias (#223)
Browse files Browse the repository at this point in the history
* rename dns registry to service alias

* fix failing test
  • Loading branch information
jinmel authored Apr 3, 2024
1 parent cc42af4 commit 277c65b
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 47 deletions.
26 changes: 13 additions & 13 deletions cmd/geth/forgecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var (
Name: "whitelist",
Usage: `The whitelist external endpoints to call`,
}
dnsRegistryForgeFlag = &cli.StringSliceFlag{
Name: "dns-registry",
Usage: `The DNS registry to resolve aliases to endpoints`,
serviceAliasForgeFlag = &cli.StringSliceFlag{
Name: "service-alias",
Usage: `The list of alias to endpoint mappings.`,
}
ethBackendForgeFlag = &cli.StringFlag{
Name: "eth-backend",
Expand All @@ -51,9 +51,9 @@ var (
)

type suaveForgeConfig struct {
Whitelist []string `toml:"whitelist"`
DnsRegistry map[string]string `toml:"dns_registry"`
EthBackend string `toml:"eth_backend"`
Whitelist []string `toml:"whitelist"`
ServiceAlias map[string]string `toml:"service_alias"`
EthBackend string `toml:"eth_backend"`
}

func readContext(ctx *cli.Context) (*vm.SuaveContext, error) {
Expand Down Expand Up @@ -95,18 +95,18 @@ func readContext(ctx *cli.Context) (*vm.SuaveContext, error) {
if ctx.IsSet(whiteListForgeFlag.Name) {
cfg.Whitelist = ctx.StringSlice(whiteListForgeFlag.Name)
}
if ctx.IsSet(dnsRegistryForgeFlag.Name) {
dnsRegistry := make(map[string]string)
for _, endpoint := range ctx.StringSlice(dnsRegistryForgeFlag.Name) {
if ctx.IsSet(serviceAliasForgeFlag.Name) {
registry := make(map[string]string)
for _, endpoint := range ctx.StringSlice(serviceAliasForgeFlag.Name) {
parts := strings.Split(endpoint, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid value for remote backend endpoint: %s", endpoint)
}
name := parts[0]
domain := parts[1]
dnsRegistry[name] = domain
registry[name] = domain
}
cfg.DnsRegistry = dnsRegistry
cfg.ServiceAlias = registry
}

// create the suave context
Expand All @@ -130,7 +130,7 @@ func readContext(ctx *cli.Context) (*vm.SuaveContext, error) {
backend := &vm.SuaveExecutionBackend{
ExternalWhitelist: cfg.Whitelist,
ConfidentialEthBackend: suaveEthBackend,
DnsRegistry: cfg.DnsRegistry,
ServiceAliasRegistry: cfg.ServiceAlias,
EthBlockSigningKey: blsKey,
EthBundleSigningKey: ecdsaKey,
}
Expand All @@ -149,7 +149,7 @@ var (
Flags: []cli.Flag{
isLocalForgeFlag,
whiteListForgeFlag,
dnsRegistryForgeFlag,
serviceAliasForgeFlag,
ethBackendForgeFlag,
tomlConfigForgeFlag,
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/geth/forgecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ func TestForgeReadConfig(t *testing.T) {

sCtx, err = readContext(ctx)
require.NoError(t, err)
require.Equal(t, sCtx.Backend.ExternalWhitelist, []string{"a", "b"})
require.Equal(t, sCtx.Backend.DnsRegistry, map[string]string{"a": "b", "c": "d"})
require.Equal(t, sCtx.Backend.ConfidentialEthBackend.(*suave_backends.RemoteEthBackend).Endpoint(), "suave")
require.Equal(t, []string{"a", "b"}, sCtx.Backend.ExternalWhitelist)
require.Equal(t, map[string]string{"a": "b", "c": "d"}, sCtx.Backend.ServiceAliasRegistry)
require.Equal(t, "suave", sCtx.Backend.ConfidentialEthBackend.(*suave_backends.RemoteEthBackend).Endpoint())

// override the config if the flags are set
ctx.Set("eth-backend", "http://localhost:8545")
ctx.Set("whitelist", "c,d")
ctx.Set("dns-registry", "e=f,g=h")
ctx.Set("service-alias", "e=f,g=h")

sCtx, err = readContext(ctx)
require.NoError(t, err)
require.Equal(t, sCtx.Backend.ExternalWhitelist, []string{"c", "d"})
require.Equal(t, sCtx.Backend.DnsRegistry, map[string]string{"e": "f", "g": "h"})
require.Equal(t, sCtx.Backend.ConfidentialEthBackend.(*suave_backends.RemoteEthBackend).Endpoint(), "http://localhost:8545")
require.Equal(t, []string{"c", "d"}, sCtx.Backend.ExternalWhitelist)
require.Equal(t, map[string]string{"e": "f", "g": "h"}, sCtx.Backend.ServiceAliasRegistry)
require.Equal(t, "http://localhost:8545", sCtx.Backend.ConfidentialEthBackend.(*suave_backends.RemoteEthBackend).Endpoint())

// set flags to null and use default values
ctx = cli.NewContext(nil, flagSet(t, forgeCommand.Flags), nil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ var (

suaveFlags = []cli.Flag{
utils.SuaveEthRemoteBackendEndpointFlag,
utils.SuaveDnsFlag,
utils.SuaveServiceAlias,
utils.SuaveConfidentialTransportRedisEndpointFlag,
utils.SuaveConfidentialStoreRedisEndpointFlag,
utils.SuaveConfidentialStorePebbleDbPathFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/testdata/forge.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[profile.suave]
whitelist = ["a", "b"]
dns_registry = { a = "b", c = "d" }
service_alias = { a = "b", c = "d" }
eth_backend = "suave"
[profile.ci.fuzz]
runs = 10_000
Expand Down
14 changes: 7 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ var (
Category: flags.SuaveCategory,
}

SuaveDnsFlag = &cli.StringSliceFlag{
Name: "suave.dns",
SuaveServiceAlias = &cli.StringSliceFlag{
Name: "suave.service-alias",
Usage: "Suave domain name resolver settings. (format: alias=url)",
Category: flags.SuaveCategory,
}
Expand Down Expand Up @@ -1730,18 +1730,18 @@ func SetSuaveConfig(ctx *cli.Context, stack *node.Node, cfg *suave.Config) {
cfg.SuaveEthRemoteBackendEndpoint = ctx.String(SuaveEthRemoteBackendEndpointFlag.Name)
}

if ctx.IsSet(SuaveDnsFlag.Name) {
dnsRegistry := make(map[string]string)
for _, endpoint := range ctx.StringSlice(SuaveDnsFlag.Name) {
if ctx.IsSet(SuaveServiceAlias.Name) {
registry := make(map[string]string)
for _, endpoint := range ctx.StringSlice(SuaveServiceAlias.Name) {
parts := strings.Split(endpoint, "=")
if len(parts) != 2 {
Fatalf("invalid value for remote backend endpoint: %s", endpoint)
}
name := parts[0]
domain := parts[1]
dnsRegistry[name] = domain
registry[name] = domain
}
cfg.DnsRegistry = dnsRegistry
cfg.AliasRegistry = registry
}

if ctx.IsSet(SuaveConfidentialTransportRedisEndpointFlag.Name) {
Expand Down
2 changes: 1 addition & 1 deletion core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (s *suaveRuntime) doHTTPRequest(request types.HttpRequest) ([]byte, error)

var allowed bool
// resolve dns if possible
if endpoint, ok := s.suaveContext.Backend.DnsRegistry[request.Url]; ok {
if endpoint, ok := s.suaveContext.Backend.ServiceAliasRegistry[request.Url]; ok {
request.Url = endpoint
} else {
// decode the url and check if the domain is allowed
Expand Down
4 changes: 2 additions & 2 deletions core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func TestSuave_HttpRequest_Basic(t *testing.T) {
s := &suaveRuntime{
suaveContext: &SuaveContext{
Backend: &SuaveExecutionBackend{
ExternalWhitelist: []string{"127.0.0.1"},
DnsRegistry: map[string]string{"goerli": srv.URL},
ExternalWhitelist: []string{"127.0.0.1"},
ServiceAliasRegistry: map[string]string{"goerli": srv.URL},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SuaveExecutionBackend struct {
EthBundleSigningKey *ecdsa.PrivateKey
EthBlockSigningKey *bls.SecretKey
ExternalWhitelist []string
DnsRegistry map[string]string
ServiceAliasRegistry map[string]string
ConfidentialStore ConfidentialStore
ConfidentialEthBackend suave.ConfidentialEthBackend
}
Expand Down
22 changes: 11 additions & 11 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ import (

// EthAPIBackend implements ethapi.Backend for full nodes
type EthAPIBackend struct {
extRPCEnabled bool
allowUnprotectedTxs bool
eth *Ethereum
gpo *gasprice.Oracle
suaveEthBundleSigningKey *ecdsa.PrivateKey
suaveEthBlockSigningKey *bls.SecretKey
suaveEngine *cstore.CStoreEngine
suaveEthBackend suave.ConfidentialEthBackend
suaveExternalWhitelist []string
suaveDnsRegistry map[string]string
extRPCEnabled bool
allowUnprotectedTxs bool
eth *Ethereum
gpo *gasprice.Oracle
suaveEthBundleSigningKey *ecdsa.PrivateKey
suaveEthBlockSigningKey *bls.SecretKey
suaveEngine *cstore.CStoreEngine
suaveEthBackend suave.ConfidentialEthBackend
suaveExternalWhitelist []string
suaveServiceAliasRegistry map[string]string
}

// For testing purposes
Expand Down Expand Up @@ -446,7 +446,7 @@ func (b *EthAPIBackend) SuaveContext(requestTx *types.Transaction, ccr *types.Co
EthBundleSigningKey: b.suaveEthBundleSigningKey,
EthBlockSigningKey: b.suaveEthBlockSigningKey,
ExternalWhitelist: b.suaveExternalWhitelist,
DnsRegistry: b.suaveDnsRegistry,
ServiceAliasRegistry: b.suaveServiceAliasRegistry,
ConfidentialStore: storeTransaction,
ConfidentialEthBackend: b.suaveEthBackend,
},
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
confidentialStoreEngine := cstore.NewEngine(confidentialStoreBackend, confidentialStoreTransport, suaveDaSigner, types.LatestSigner(chainConfig))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil,
suaveEthBundleSigningKey, suaveEthBlockSigningKey, confidentialStoreEngine, suaveEthBackend, config.Suave.ExternalWhitelist, config.Suave.DnsRegistry}
suaveEthBundleSigningKey, suaveEthBlockSigningKey, confidentialStoreEngine, suaveEthBackend, config.Suave.ExternalWhitelist, config.Suave.AliasRegistry}
if eth.APIBackend.allowUnprotectedTxs {
log.Info("Unprotected transactions allowed")
}
Expand Down
2 changes: 1 addition & 1 deletion suave/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Config struct {
EthBundleSigningKeyHex string
EthBlockSigningKeyHex string
ExternalWhitelist []string
DnsRegistry map[string]string
AliasRegistry map[string]string
}

var DefaultConfig = Config{}
2 changes: 1 addition & 1 deletion suave/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ func WithWhitelist(whitelist []string) frameworkOpt {

func WithDnsRegistry(registry map[string]string) frameworkOpt {
return func(c *frameworkConfig) {
c.suaveConfig.DnsRegistry = registry
c.suaveConfig.AliasRegistry = registry
}
}

Expand Down

0 comments on commit 277c65b

Please sign in to comment.