Skip to content

Commit

Permalink
Merge pull request #460 from tablelandnetwork/joe/rm-relay
Browse files Browse the repository at this point in the history
remove the legacy API and stop relaying smart contract calls
  • Loading branch information
brunocalza authored Mar 28, 2023
2 parents 2f4d211 + ced2e5f commit a21d495
Show file tree
Hide file tree
Showing 59 changed files with 1,089 additions and 5,247 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ system-sql-assets:
.PHONY: system-sql-assets

mocks: clean-mocks
go run github.com/vektra/mockery/[email protected] --name='\b(?:SQLRunner|Tableland)\b' --recursive --with-expecter
go run github.com/vektra/mockery/[email protected] --name='\b(?:Gateway)\b' --recursive --with-expecter
.PHONY: mocks

clean-mocks:
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ They have the following responsibilities:

- Listen to on-chain events to materialize Tableland-compliant SQL queries in a database engine (currently, SQLite by default).
- Serve read-queries (e.g: `SELECT * FROM foo_69_1`) to the external world.
- Relay write-queries to the `Registry` SC on behalf of users.

> 💡 The responsibilities of the validator will continue to change as the Tableland protocol evolves. In the future, validators will have more responsibilities in the network.
Expand All @@ -36,7 +35,7 @@ To understand better the usual work mechanics of the validator, let’s go throu

6- The validators will detect the new event and execute the mutating query in the corresponding table.

7- The user can query the RPC endpoint of the validator to execute read-queries (e.g: `SELECT * FROM ...`), to see the materialized result of its interaction with the SC.
7- The user can query the `/query?statement=...` REST endpoint of the validator to execute read-queries (e.g: `SELECT * FROM ...`), to see the materialized result of its interaction with the SC.

> 💡 The description above is optimized to understand the general mechanics of the validator. Minting tables, and executing mutating statements also imply more work both at the SC and validator levels (e.g: ACL enforcing); we’re skipping them here.
Expand All @@ -63,7 +62,6 @@ The `cmd/toolkit` is a CLI which contain useful commands:

- `gaspricebump`: Bumps gas price for a stuck transaction
- `sc`: Offers smart sontract calls
- `siwe`: SIWE utilities
- `wallet`: Offers wallet utilites

# Contributing
Expand Down
7 changes: 3 additions & 4 deletions cmd/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ type QueryConstraints struct {

// ChainConfig contains all the chain execution stack configuration for a particular EVM chain.
type ChainConfig struct {
Name string `default:""`
ChainID tableland.ChainID `default:"0"`
AllowTransactionRelay bool `default:"false"`
Registry struct {
Name string `default:""`
ChainID tableland.ChainID `default:"0"`
Registry struct {
EthEndpoint string `default:"eth_endpoint"`
ContractAddress string `default:"contract_address"`
}
Expand Down
65 changes: 16 additions & 49 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/textileio/cli"
"github.com/textileio/go-tableland/buildinfo"
"github.com/textileio/go-tableland/internal/chains"
"github.com/textileio/go-tableland/internal/gateway"
"github.com/textileio/go-tableland/internal/router"
systemimpl "github.com/textileio/go-tableland/internal/system/impl"
"github.com/textileio/go-tableland/internal/tableland"
"github.com/textileio/go-tableland/internal/tableland/impl"
"github.com/textileio/go-tableland/pkg/backup"
Expand All @@ -37,10 +37,8 @@ import (
parserimpl "github.com/textileio/go-tableland/pkg/parsing/impl"
"github.com/textileio/go-tableland/pkg/readstatementresolver"
"github.com/textileio/go-tableland/pkg/sqlstore"
sqlstoreimpl "github.com/textileio/go-tableland/pkg/sqlstore/impl"
"github.com/textileio/go-tableland/pkg/sqlstore/impl/system"
"github.com/textileio/go-tableland/pkg/sqlstore/impl/user"
"github.com/textileio/go-tableland/pkg/tables/impl/ethereum"

"github.com/textileio/go-tableland/pkg/telemetry"
"github.com/textileio/go-tableland/pkg/telemetry/chainscollector"
"github.com/textileio/go-tableland/pkg/telemetry/publisher"
Expand Down Expand Up @@ -94,18 +92,17 @@ func main() {
log.Fatal().Err(err).Msg("creating chains stack")
}

// User store.
eps := make(map[tableland.ChainID]eventprocessor.EventProcessor, len(chainStacks))
for chainID, stack := range chainStacks {
eps[chainID] = stack.EventProcessor
}
userStore, err := user.New(databaseURL, readstatementresolver.New(eps))
if err != nil {
log.Fatal().Err(err).Msg("creating user store")

for _, stack := range chainStacks {
stack.Store.SetReadResolver(readstatementresolver.New(eps))
}

// HTTP API server.
closeHTTPServer, err := createAPIServer(config.HTTP, config.Gateway, parser, userStore, chainStacks)
closeHTTPServer, err := createAPIServer(config.HTTP, config.Gateway, parser, chainStacks)
if err != nil {
log.Fatal().Err(err).Msg("creating HTTP server")
}
Expand Down Expand Up @@ -147,11 +144,6 @@ func main() {
log.Error().Err(err).Msg("closing backuper")
}

// Close user store.
if err := userStore.Close(); err != nil {
log.Error().Err(err).Msg("closing user store")
}

// Close telemetry.
if err := closeTelemetryModule(ctx); err != nil {
log.Error().Err(err).Msg("closing telemetry module")
Expand All @@ -172,7 +164,7 @@ func createChainIDStack(
return chains.ChainStack{}, fmt.Errorf("failed initialize sqlstore: %s", err)
}

systemStore, err := sqlstoreimpl.NewInstrumentedSystemStore(config.ChainID, store)
systemStore, err := system.NewInstrumentedSystemStore(config.ChainID, store)
if err != nil {
return chains.ChainStack{}, fmt.Errorf("instrumenting system store: %s", err)
}
Expand Down Expand Up @@ -216,18 +208,8 @@ func createChainIDStack(
}

scAddress := common.HexToAddress(config.Registry.ContractAddress)
registry, err := ethereum.NewClient(
conn,
config.ChainID,
scAddress,
wallet,
tracker,
)
if err != nil {
return chains.ChainStack{}, fmt.Errorf("failed to create ethereum client: %s", err)
}

acl := impl.NewACL(systemStore, registry)
acl := impl.NewACL(systemStore)

ex, err := executor.NewExecutor(config.ChainID, executorsDB, parser, tableConstraints.MaxRowCount, acl)
if err != nil {
Expand Down Expand Up @@ -270,10 +252,7 @@ func createChainIDStack(
}
return chains.ChainStack{
Store: systemStore,
Registry: registry,
EventProcessor: ep,
// TODO: we can remove the AllowTransactionRelay config property entirely in a future PR
AllowTransactionRelay: false,
Close: func(ctx context.Context) error {
log.Info().Int64("chain_id", int64(config.ChainID)).Msg("closing stack...")
defer log.Info().Int64("chain_id", int64(config.ChainID)).Msg("stack closed")
Expand Down Expand Up @@ -396,8 +375,8 @@ func createParser(queryConstraints QueryConstraints) (parsing.SQLValidator, erro

parser, err := parserimpl.New([]string{
"sqlite_",
systemimpl.SystemTablesPrefix,
systemimpl.RegistryTableName,
parsing.SystemTablesPrefix,
parsing.RegistryTableName,
}, parserOpts...)
if err != nil {
return nil, fmt.Errorf("new parser: %s", err)
Expand Down Expand Up @@ -479,46 +458,34 @@ func createAPIServer(
httpConfig HTTPConfig,
gatewayConfig GatewayConfig,
parser parsing.SQLValidator,
userStore *user.UserStore,
chainStacks map[tableland.ChainID]chains.ChainStack,
) (moduleCloser, error) {
instrUserStore, err := sqlstoreimpl.NewInstrumentedUserStore(userStore)
if err != nil {
return nil, fmt.Errorf("creating instrumented user store: %s", err)
}

mesaService := impl.NewTablelandMesa(parser, instrUserStore, chainStacks)
mesaService, err = impl.NewInstrumentedTablelandMesa(mesaService)
if err != nil {
return nil, fmt.Errorf("instrumenting mesa: %s", err)
}

supportedChainIDs := make([]tableland.ChainID, 0, len(chainStacks))
stores := make(map[tableland.ChainID]sqlstore.SystemStore, len(chainStacks))
for chainID, stack := range chainStacks {
stores[chainID] = stack.Store
supportedChainIDs = append(supportedChainIDs, chainID)
}
sysStore, err := systemimpl.NewSystemSQLStoreService(
g, err := gateway.NewGateway(
parser,
stores,
gatewayConfig.ExternalURIPrefix,
gatewayConfig.MetadataRendererURI,
gatewayConfig.AnimationRendererURI)
if err != nil {
return nil, fmt.Errorf("creating system store: %s", err)
return nil, fmt.Errorf("creating gateway: %s", err)
}
systemService, err := systemimpl.NewInstrumentedSystemSQLStoreService(sysStore)
g, err = gateway.NewInstrumentedGateway(g)
if err != nil {
return nil, fmt.Errorf("instrumenting system sql store: %s", err)
return nil, fmt.Errorf("instrumenting gateway: %s", err)
}
rateLimInterval, err := time.ParseDuration(httpConfig.RateLimInterval)
if err != nil {
return nil, fmt.Errorf("parsing http ratelimiter interval: %s", err)
}

router, err := router.ConfiguredRouter(
mesaService,
systemService,
g,
httpConfig.MaxRequestPerInterval,
rateLimInterval,
supportedChainIDs,
Expand Down
7 changes: 0 additions & 7 deletions cmd/toolkit/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"time"

"github.com/spf13/cobra"
)

Expand All @@ -20,16 +18,11 @@ func main() {
}

func init() {
rootCmd.AddCommand(siweCmd)
rootCmd.AddCommand(scCmd)
rootCmd.AddCommand(walletCmd)
rootCmd.AddCommand(gasPriceBumperCmd)
rootCmd.AddCommand(replaceNonceRangeCmd)

siweCreateCmd.Flags().Duration("duration", time.Hour*24*365*100, "validity duration")
siweCreateCmd.Flags().Int("chain-id", 69, "chain id")
siweCmd.AddCommand(siweCreateCmd)

scCmd.PersistentFlags().String("contract-address", "", "the smart contract address")
scCmd.PersistentFlags().Int("chain-id", 69, "chain id")
scCmd.PersistentFlags().String("privatekey", "", "the private key used to make the contract calls")
Expand Down
51 changes: 0 additions & 51 deletions cmd/toolkit/siwe.go

This file was deleted.

10 changes: 5 additions & 5 deletions cmd/toolkit/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/spf13/cobra"
systemimpl "github.com/textileio/go-tableland/internal/system/impl"
"github.com/textileio/go-tableland/internal/tableland"
"github.com/textileio/go-tableland/pkg/nonce/impl"
"github.com/textileio/go-tableland/pkg/parsing"
parserimpl "github.com/textileio/go-tableland/pkg/parsing/impl"
"github.com/textileio/go-tableland/pkg/tables"
"github.com/textileio/go-tableland/pkg/tables/impl/ethereum"
Expand Down Expand Up @@ -63,8 +63,8 @@ var runSQLCmd = &cobra.Command{

parser, err := parserimpl.New([]string{
"sqlite_",
systemimpl.SystemTablesPrefix,
systemimpl.RegistryTableName,
parsing.SystemTablesPrefix,
parsing.RegistryTableName,
})
if err != nil {
return fmt.Errorf("new parser: %s", err)
Expand Down Expand Up @@ -138,8 +138,8 @@ var createTableCmd = &cobra.Command{

parser, err := parserimpl.New([]string{
"sqlite_",
systemimpl.SystemTablesPrefix,
systemimpl.RegistryTableName,
parsing.SystemTablesPrefix,
parsing.RegistryTableName,
})
if err != nil {
return fmt.Errorf("new parser: %s", err)
Expand Down
4 changes: 0 additions & 4 deletions docker/deployed/mainnet/api/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
{
"Name": "Ethereum Mainnet",
"ChainID": 1,
"AllowTransactionRelay": false,
"Registry": {
"EthEndpoint": "wss://eth-mainnet.g.alchemy.com/v2/${VALIDATOR_ALCHEMY_ETHEREUM_MAINNET_API_KEY}",
"ContractAddress": "0x012969f7e3439a9B04025b5a049EB9BAD82A8C12"
Expand Down Expand Up @@ -82,7 +81,6 @@
{
"Name": "Arbitrum Mainnet",
"ChainID": 42161,
"AllowTransactionRelay": false,
"Registry": {
"EthEndpoint": "https://arb-mainnet.g.alchemy.com/v2/${VALIDATOR_ALCHEMY_ARBITRUM_MAINNET_API_KEY}",
"ContractAddress": "0x9aBd75E8640871A5a20d3B4eE6330a04c962aFfd"
Expand Down Expand Up @@ -137,7 +135,6 @@
{
"Name": "Polygon Mainnet",
"ChainID": 137,
"AllowTransactionRelay": false,
"Registry": {
"EthEndpoint": "wss://polygon-mainnet.g.alchemy.com/v2/${VALIDATOR_ALCHEMY_POLYGON_MAINNET_API_KEY}",
"ContractAddress": "0x5c4e6A9e5C1e1BF445A062006faF19EA6c49aFeA"
Expand Down Expand Up @@ -165,7 +162,6 @@
{
"Name": "Optimism Mainnet",
"ChainID": 10,
"AllowTransactionRelay": false,
"Registry": {
"EthEndpoint": "wss://opt-mainnet.g.alchemy.com/v2/${VALIDATOR_ALCHEMY_OPTIMISM_MAINNET_API_KEY}",
"ContractAddress": "0xfad44BF5B843dE943a09D4f3E84949A11d3aa3e6"
Expand Down
2 changes: 1 addition & 1 deletion docker/deployed/mainnet/healthbot/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"Human": false,
"Debug": true
},
"Target": "https://tableland.network/rpc",
"Target": "https://tableland.network/",
"Chains": []
}
1 change: 0 additions & 1 deletion docker/deployed/staging/api/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"Chains": [
{
"Name": "Optimism Goerli",
"AllowTransactionRelay": false,
"ChainID": 420,
"Registry": {
"EthEndpoint": "wss://opt-goerli.g.alchemy.com/v2/${VALIDATOR_ALCHEMY_OPTIMISM_GOERLI_API_KEY}",
Expand Down
Loading

0 comments on commit a21d495

Please sign in to comment.