Skip to content

Commit

Permalink
Reduce API surface of l1 package (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshklop authored Jun 27, 2023
1 parent a63da45 commit e38ad45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 0 additions & 18 deletions l1/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/NethermindEth/juno/l1/contract"
"github.com/NethermindEth/juno/service"
"github.com/NethermindEth/juno/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
Expand All @@ -35,23 +34,6 @@ type Client struct {

var _ service.Service = (*Client)(nil)

func MakeClient(ethNode string, chain *blockchain.Blockchain, confirmationPeriod uint64, log utils.SimpleLogger) (*Client, error) {
var coreContractAddress common.Address
coreContractAddress, err := chain.Network().CoreContractAddress()
if err != nil {
log.Errorw("Error finding core contract address for network", "err", err, "network", chain.Network())
return nil, err
}

var ethSubscriber *EthSubscriber
ethSubscriber, err = NewEthSubscriber(ethNode, coreContractAddress)
if err != nil {
log.Errorw("Error creating ethSubscriber", "err", err)
return nil, err
}
return NewClient(ethSubscriber, chain, confirmationPeriod, log), nil
}

func NewClient(l1 Subscriber, chain *blockchain.Blockchain, confirmationPeriod uint64, log utils.SimpleLogger) *Client {
return &Client{
l1: l1,
Expand Down
20 changes: 19 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
"github.com/NethermindEth/juno/sync"
"github.com/NethermindEth/juno/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/sourcegraph/conc"
)

Expand Down Expand Up @@ -106,7 +107,7 @@ func New(cfg *Config, version string) (*Node, error) {
if n.cfg.EthNode == "" {
n.log.Warnw("Ethereum node address not found; will not verify against L1")
} else {
l1Client, err := l1.MakeClient(n.cfg.EthNode, n.blockchain, l1BlockConfirmationPeriod, n.log)
l1Client, err := makeClient(n.cfg.EthNode, n.blockchain, l1BlockConfirmationPeriod, n.log)
if err != nil {
n.log.Errorw("Error creating L1 client", "err", err)
return nil, err
Expand Down Expand Up @@ -235,6 +236,23 @@ func makeHTTP(listener net.Listener, rpcHandler *rpc.Handler, log utils.SimpleLo
}, log)
}

func makeClient(ethNode string, chain *blockchain.Blockchain, confirmationPeriod uint64, log utils.SimpleLogger) (*l1.Client, error) {
var coreContractAddress common.Address
coreContractAddress, err := chain.Network().CoreContractAddress()
if err != nil {
log.Errorw("Error finding core contract address for network", "err", err, "network", chain.Network())
return nil, err
}

var ethSubscriber *l1.EthSubscriber
ethSubscriber, err = l1.NewEthSubscriber(ethNode, coreContractAddress)
if err != nil {
log.Errorw("Error creating ethSubscriber", "err", err)
return nil, err
}
return l1.NewClient(ethSubscriber, chain, confirmationPeriod, log), nil
}

// Run starts Juno node by opening the DB, initialising services.
// All the services blocking and any errors returned by service run function is logged.
// Run will wait for all services to return before exiting.
Expand Down

0 comments on commit e38ad45

Please sign in to comment.