From 42652de24ee1451d2543d05bd5ca8b8b97622999 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Tue, 13 Jun 2023 07:06:34 +0800 Subject: [PATCH 1/6] feat: add `DataLayer` config --- pkg/config/config.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 899cc47..a0b7c9f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -19,6 +19,7 @@ type ChiaConfig struct { Harvester HarvesterConfig `yaml:"harvester"` Wallet WalletConfig `yaml:"wallet"` Seeder SeederConfig `yaml:"seeder"` + DataLayer DataLayerConfig `yaml:"data_layer"` SelectedNetwork string `yaml:"selected_network"` } @@ -60,6 +61,12 @@ type CrawlerConfig struct { SSL SSLConfig `yaml:"ssl"` } +// DataLayerConfig datalayer configuration section +type DataLayerConfig struct { + PortConfig `yaml:",inline"` + SSL SSLConfig `yaml:"ssl"` +} + // PortConfig common port settings found in many sections of the config type PortConfig struct { Port uint16 `yaml:"port"` From 64a87acd3779036d5929cb7f9c9987e158452bb9 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Tue, 13 Jun 2023 07:16:09 +0800 Subject: [PATCH 2/6] feat: update service type --- pkg/rpcinterface/servicetype.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/rpcinterface/servicetype.go b/pkg/rpcinterface/servicetype.go index 38ddf2e..a644f1a 100644 --- a/pkg/rpcinterface/servicetype.go +++ b/pkg/rpcinterface/servicetype.go @@ -27,4 +27,7 @@ const ( // ServiceCrawler crawler service ServiceCrawler + + // ServiceDataLayer datalayer service + ServiceDataLayer ) From eed43f9d589351527e9a9b3012d20a49e3aaec85 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Tue, 13 Jun 2023 07:32:38 +0800 Subject: [PATCH 3/6] feat: add datalayer in httpclient --- pkg/httpclient/httpclient.go | 15 +++++++++++++++ pkg/rpc/client_test.go | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/httpclient/httpclient.go b/pkg/httpclient/httpclient.go index b8107e4..8aedf63 100644 --- a/pkg/httpclient/httpclient.go +++ b/pkg/httpclient/httpclient.go @@ -46,6 +46,10 @@ type HTTPClient struct { crawlerPort uint16 crawlerKeyPair *tls.Certificate crawlerClient *http.Client + + datalayerPort uint16 + datalayerKeyPair *tls.Certificate + datalayerClient *http.Client } // NewHTTPClient returns a new HTTP client that satisfies the rpcinterface.Client interface @@ -60,6 +64,7 @@ func NewHTTPClient(cfg *config.ChiaConfig, options ...rpcinterface.ClientOptionF harvesterPort: cfg.Harvester.RPCPort, walletPort: cfg.Wallet.RPCPort, crawlerPort: cfg.Seeder.CrawlerConfig.RPCPort, + datalayerPort: cfg.DataLayer.RPCPort, } // Sets the default host. Can be overridden by client options @@ -226,6 +231,14 @@ func (c *HTTPClient) generateHTTPClientForService(service rpcinterface.ServiceTy } } keyPair = c.crawlerKeyPair + case rpcinterface.ServiceDataLayer: + if c.datalayerKeyPair == nil { + c.datalayerKeyPair, err = c.config.DataLayer.SSL.LoadPrivateKeyPair(c.config.ChiaRoot) + if err != nil { + return nil, err + } + } + keyPair = c.datalayerKeyPair default: return nil, fmt.Errorf("unknown service") } @@ -266,6 +279,8 @@ func (c *HTTPClient) portForService(service rpcinterface.ServiceType) uint16 { port = c.walletPort case rpcinterface.ServiceCrawler: port = c.crawlerPort + case rpcinterface.ServiceDataLayer: + port = c.datalayerPort } return port diff --git a/pkg/rpc/client_test.go b/pkg/rpc/client_test.go index 2406185..c828c1a 100644 --- a/pkg/rpc/client_test.go +++ b/pkg/rpc/client_test.go @@ -64,11 +64,11 @@ func setup(t *testing.T) (*http.ServeMux, *httptest.Server, *Client) { ChiaRoot: tmpDir, DaemonPort: portConf.RPCPort, DaemonSSL: sslConf, - FullNode: config.FullNodeConfig{ + Farmer: config.FarmerConfig{ PortConfig: portConf, SSL: sslConf, }, - Farmer: config.FarmerConfig{ + FullNode: config.FullNodeConfig{ PortConfig: portConf, SSL: sslConf, }, @@ -86,6 +86,10 @@ func setup(t *testing.T) (*http.ServeMux, *httptest.Server, *Client) { SSL: sslConf, }, }, + DataLayer: config.DataLayerConfig{ + PortConfig: portConf, + SSL: sslConf, + }, })) if err != nil { t.Fatal(err) From 6b4cfb60b3286625e58cf5b3263ae643bd779edb Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Tue, 13 Jun 2023 07:41:08 +0800 Subject: [PATCH 4/6] feat: add datalayer client --- pkg/httpclient/httpclient.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/httpclient/httpclient.go b/pkg/httpclient/httpclient.go index 8aedf63..964fae6 100644 --- a/pkg/httpclient/httpclient.go +++ b/pkg/httpclient/httpclient.go @@ -334,6 +334,14 @@ func (c *HTTPClient) httpClientForService(service rpcinterface.ServiceType) (*ht } } client = c.crawlerClient + case rpcinterface.ServiceDataLayer: + if c.datalayerClient == nil { + c.datalayerClient, err = c.generateHTTPClientForService(rpcinterface.ServiceDataLayer) + if err != nil { + return nil, err + } + } + client = c.datalayerClient } if client == nil { From b59c299cf04a0be4ddf630aab884418a05e83ac1 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Wed, 14 Jun 2023 09:43:49 +0800 Subject: [PATCH 5/6] feat: add datalayer service in client --- pkg/rpc/client.go | 2 ++ pkg/rpc/datalayer.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkg/rpc/datalayer.go diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index c23ea77..52af01b 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -23,6 +23,7 @@ type Client struct { FarmerService *FarmerService HarvesterService *HarvesterService CrawlerService *CrawlerService + DataLayerService *DataLayerService websocketHandlers []rpcinterface.WebsocketResponseHandler } @@ -67,6 +68,7 @@ func NewClient(connectionMode ConnectionMode, configOption rpcinterface.ConfigOp c.FarmerService = &FarmerService{client: c} c.HarvesterService = &HarvesterService{client: c} c.CrawlerService = &CrawlerService{client: c} + c.DataLayerService = &DataLayerService{client: c} return c, nil } diff --git a/pkg/rpc/datalayer.go b/pkg/rpc/datalayer.go new file mode 100644 index 0000000..fbc9dcf --- /dev/null +++ b/pkg/rpc/datalayer.go @@ -0,0 +1,22 @@ +package rpc + +import ( + "net/http" + + "github.com/chia-network/go-chia-libs/pkg/rpcinterface" +) + +// DataLayerService encapsulates data layer RPC methods +type DataLayerService struct { + client *Client +} + +// NewRequest returns a new request specific to the wallet service +func (s *DataLayerService) NewRequest(rpcEndpoint rpcinterface.Endpoint, opt interface{}) (*rpcinterface.Request, error) { + return s.client.NewRequest(rpcinterface.ServiceFullNode, rpcEndpoint, opt) +} + +// Do is just a shortcut to the client's Do method +func (s *DataLayerService) Do(req *rpcinterface.Request, v interface{}) (*http.Response, error) { + return s.client.Do(req, v) +} From ba778a32647c19a46bc1534bb003bb72fa3c9ae3 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Wed, 14 Jun 2023 10:14:46 +0800 Subject: [PATCH 6/6] fix: Update pkg/rpc/datalayer.go Co-authored-by: Chris Marslender --- pkg/rpc/datalayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/rpc/datalayer.go b/pkg/rpc/datalayer.go index fbc9dcf..f4dc6ee 100644 --- a/pkg/rpc/datalayer.go +++ b/pkg/rpc/datalayer.go @@ -13,7 +13,7 @@ type DataLayerService struct { // NewRequest returns a new request specific to the wallet service func (s *DataLayerService) NewRequest(rpcEndpoint rpcinterface.Endpoint, opt interface{}) (*rpcinterface.Request, error) { - return s.client.NewRequest(rpcinterface.ServiceFullNode, rpcEndpoint, opt) + return s.client.NewRequest(rpcinterface.ServiceDataLayer, rpcEndpoint, opt) } // Do is just a shortcut to the client's Do method