Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #85 from primevprotocol/contract_fixes
Browse files Browse the repository at this point in the history
fix: user registry and cleanups
  • Loading branch information
kant777 authored Nov 16, 2023
2 parents 7decd9d + 7080bc5 commit 697f573
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 33 deletions.
52 changes: 27 additions & 25 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config/bootnode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions config/provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/<localhost>/tcp/13522/p2p/<p2p_ID>
3 changes: 3 additions & 0 deletions config/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/<localhost>/tcp/13522/p2p/<p2p_ID>
3 changes: 2 additions & 1 deletion pkg/contracts/preconf/preconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package preconfcontract

import (
"context"
"errors"
"log/slog"
"math/big"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions pkg/evmclient/evmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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)

providerRegistry := registrycontract.New(
registryContractAddr,
evmClient,
opts.Logger.With("component", "registrycontract"),
opts.Logger.With("component", "providerregistry"),
)

p2pSvc, err := libp2p.New(&libp2p.Options{
Expand Down
3 changes: 3 additions & 0 deletions pkg/preconfirmation/preconfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (p *Preconfirmation) SendBid(
return
}

logger.Info("received preconfirmation", "preConfirmation", preConfirmation)

select {
case preConfirmations <- preConfirmation:
case <-ctx.Done():
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 697f573

Please sign in to comment.