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

rename dns registry to service alias #223

Merged
merged 2 commits into from
Apr 3, 2024
Merged
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
26 changes: 13 additions & 13 deletions cmd/geth/forgecmd.go
Original file line number Diff line number Diff line change
@@ -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",
@@ -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) {
@@ -92,18 +92,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
@@ -127,7 +127,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,
}
@@ -146,7 +146,7 @@ var (
Flags: []cli.Flag{
isLocalForgeFlag,
whiteListForgeFlag,
dnsRegistryForgeFlag,
serviceAliasForgeFlag,
ethBackendForgeFlag,
tomlConfigForgeFlag,
},
14 changes: 7 additions & 7 deletions cmd/geth/forgecmd_test.go
Original file line number Diff line number Diff line change
@@ -32,20 +32,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)
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ var (

suaveFlags = []cli.Flag{
utils.SuaveEthRemoteBackendEndpointFlag,
utils.SuaveDnsFlag,
utils.SuaveServiceAlias,
utils.SuaveConfidentialTransportRedisEndpointFlag,
utils.SuaveConfidentialStoreRedisEndpointFlag,
utils.SuaveConfidentialStorePebbleDbPathFlag,
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
14 changes: 7 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
@@ -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,
}
@@ -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) {
2 changes: 1 addition & 1 deletion core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
@@ -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},
},
},
}
2 changes: 1 addition & 1 deletion core/vm/suave.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 11 additions & 11 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
},
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion suave/core/config.go
Original file line number Diff line number Diff line change
@@ -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
@@ -1471,7 +1471,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
}
}

Loading