From c48f95495a87548b23249242ee648e7dd11c7ca5 Mon Sep 17 00:00:00 2001 From: alok Date: Thu, 16 Nov 2023 01:38:55 +0530 Subject: [PATCH 1/2] fix: user registry and cleanups --- cmd/main.go | 52 ++++++++++++++++++++------------------ config/provider.yml | 1 + config/user.yml | 3 +++ pkg/evmclient/evmclient.go | 11 ++++---- pkg/node/node.go | 4 +-- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 86e287cc..2f1150c4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -90,19 +90,20 @@ func createKey(c *cli.Context) error { } type config struct { - PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` - Secret string `yaml:"secret" json:"secret"` - PeerType string `yaml:"peer_type" json:"peer_type"` - P2PPort int `yaml:"p2p_port" json:"p2p_port"` - HTTPPort int `yaml:"http_port" json:"http_port"` - RPCPort int `yaml:"rpc_port" json:"rpc_port"` - LogFmt string `yaml:"log_fmt" json:"log_fmt"` - LogLevel string `yaml:"log_level" json:"log_level"` - Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` - ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` - PreconfContract string `yaml:"preconf_contract" json:"preconf_contract"` - RegistryContract string `yaml:"registry_contract" json:"registry_contract"` - RPCEndpoint string `yaml:"rpc_endpoint" json:"rpc_endpoint"` + PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` + Secret string `yaml:"secret" json:"secret"` + PeerType string `yaml:"peer_type" json:"peer_type"` + P2PPort int `yaml:"p2p_port" json:"p2p_port"` + HTTPPort int `yaml:"http_port" json:"http_port"` + RPCPort int `yaml:"rpc_port" json:"rpc_port"` + LogFmt string `yaml:"log_fmt" json:"log_fmt"` + LogLevel string `yaml:"log_level" json:"log_level"` + Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` + ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` + PreconfContract string `yaml:"preconf_contract" json:"preconf_contract"` + RegistryContract string `yaml:"registry_contract" json:"registry_contract"` + UserRegistryContract string `yaml:"user_registry_contract" json:"user_registry_contract"` + RPCEndpoint string `yaml:"rpc_endpoint" json:"rpc_endpoint"` } func checkConfig(cfg *config) error { @@ -180,18 +181,19 @@ func start(c *cli.Context) error { } nd, err := node.NewNode(&node.Options{ - PrivKey: privKey, - Secret: cfg.Secret, - PeerType: cfg.PeerType, - P2PPort: cfg.P2PPort, - HTTPPort: cfg.HTTPPort, - RPCPort: cfg.RPCPort, - Logger: logger, - Bootnodes: cfg.Bootnodes, - ExposeProviderAPI: cfg.ExposeProviderAPI, - PreconfContract: cfg.PreconfContract, - RegistryContract: cfg.RegistryContract, - RPCEndpoint: cfg.RPCEndpoint, + PrivKey: privKey, + Secret: cfg.Secret, + PeerType: cfg.PeerType, + P2PPort: cfg.P2PPort, + HTTPPort: cfg.HTTPPort, + RPCPort: cfg.RPCPort, + Logger: logger, + Bootnodes: cfg.Bootnodes, + ExposeProviderAPI: cfg.ExposeProviderAPI, + PreconfContract: cfg.PreconfContract, + RegistryContract: cfg.RegistryContract, + UserRegistryContract: cfg.UserRegistryContract, + RPCEndpoint: cfg.RPCEndpoint, }) if err != nil { return fmt.Errorf("failed starting node: %w", err) diff --git a/config/provider.yml b/config/provider.yml index b65c448e..8abbd894 100644 --- a/config/provider.yml +++ b/config/provider.yml @@ -9,6 +9,7 @@ log_level: debug expose_provider_api: true preconf_contract: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 registry_contract: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +user_registry_contract: 0x5FbDB2315678afecb367f032d93F642f64180aa3 rpc_endpoint: http://34.215.163.180:8545 bootnodes: - /ip4//tcp/13522/p2p/ diff --git a/config/user.yml b/config/user.yml index db7a8863..1c3f18f4 100644 --- a/config/user.yml +++ b/config/user.yml @@ -6,5 +6,8 @@ rpc_port: 13524 secret: hello log_fmt: text log_level: debug +registry_contract: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +user_registry_contract: 0x5FbDB2315678afecb367f032d93F642f64180aa3 +rpc_endpoint: http://34.215.163.180:8545 bootnodes: - /ip4//tcp/13522/p2p/ diff --git a/pkg/evmclient/evmclient.go b/pkg/evmclient/evmclient.go index 1f7491de..ada2541f 100644 --- a/pkg/evmclient/evmclient.go +++ b/pkg/evmclient/evmclient.go @@ -81,9 +81,10 @@ func (c *evmClient) newTx(ctx context.Context, req *TxRequest) (*types.Transacti if req.GasLimit == 0 { // if gas limit is not provided, estimate it req.GasLimit, err = c.ethClient.EstimateGas(ctx, ethereum.CallMsg{ - From: c.owner, - To: req.To, - Data: req.CallData, + From: c.owner, + To: req.To, + Data: req.CallData, + Value: req.Value, }) if err != nil { return nil, fmt.Errorf("failed to estimate gas: %w", err) @@ -184,11 +185,11 @@ func (c *evmClient) Call( Value: tx.Value, } - receipt, err := c.ethClient.CallContract(ctx, msg, nil) + result, err := c.ethClient.CallContract(ctx, msg, nil) if err != nil { c.logger.Error("failed to call contract", "err", err) return nil, fmt.Errorf("failed to call contract: %w", err) } - return receipt, nil + return result, nil } diff --git a/pkg/node/node.go b/pkg/node/node.go index 19805d76..b6cbba13 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -92,7 +92,7 @@ func NewNode(opts *Options) (*Node, error) { userRegistry := userregistrycontract.New( userRegistryContractAddr, evmClient, - opts.Logger.With("component", "registrycontract"), + opts.Logger.With("component", "userregistry"), ) registryContractAddr := common.HexToAddress(opts.RegistryContract) @@ -100,7 +100,7 @@ func NewNode(opts *Options) (*Node, error) { providerRegistry := registrycontract.New( registryContractAddr, evmClient, - opts.Logger.With("component", "registrycontract"), + opts.Logger.With("component", "providerregistry"), ) p2pSvc, err := libp2p.New(&libp2p.Options{ From 7080bc57e5c50d7df99730d7cb41824b9e2c9728 Mon Sep 17 00:00:00 2001 From: alok Date: Thu, 16 Nov 2023 02:40:12 +0530 Subject: [PATCH 2/2] fix: user registry and cleanups --- config/bootnode.yml | 3 +++ pkg/contracts/preconf/preconf.go | 3 ++- pkg/preconfirmation/preconfirmation.go | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/bootnode.yml b/config/bootnode.yml index 2fcc8a51..c0900523 100644 --- a/config/bootnode.yml +++ b/config/bootnode.yml @@ -6,3 +6,6 @@ rpc_port: 13524 secret: hello log_fmt: text log_level: debug +registry_contract: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +user_registry_contract: 0x5FbDB2315678afecb367f032d93F642f64180aa3 +rpc_endpoint: http://34.215.163.180:8545 diff --git a/pkg/contracts/preconf/preconf.go b/pkg/contracts/preconf/preconf.go index cb3cd9f6..e6e51900 100644 --- a/pkg/contracts/preconf/preconf.go +++ b/pkg/contracts/preconf/preconf.go @@ -2,6 +2,7 @@ package preconfcontract import ( "context" + "errors" "log/slog" "math/big" "strings" @@ -93,7 +94,7 @@ func (p *preconfContract) StoreCommitment( "txnHash", txnHash, "receipt", receipt, ) - return err + return errors.New("preconf contract storeCommitment receipt error") } p.logger.Info("preconf contract storeCommitment successful", "txnHash", txnHash) diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 8f01c47c..7103f80c 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -142,6 +142,8 @@ func (p *Preconfirmation) SendBid( return } + logger.Info("received preconfirmation", "preConfirmation", preConfirmation) + select { case preConfirmations <- preConfirmation: case <-ctx.Done(): @@ -214,6 +216,7 @@ func (p *Preconfirmation) handleBid( preConfirmation.Signature, ) if err != nil { + p.logger.Error("storing commitment", "err", err) return err } return w.WriteMsg(ctx, preConfirmation)