Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): added getL1Addresses(chainId) rpc support #254

Merged
merged 10 commits into from
Nov 13, 2024

Conversation

s4rv4d
Copy link
Contributor

@s4rv4d s4rv4d commented Nov 8, 2024

Description

added getL1Addresses(chainId) support with /getL1Addresses/:chainID, essentially letting devs check L1 address for a particular L2 chain via chain ID

Additional context
Just prints L1 address for particular L2 chain via chain ID

Metadata

@s4rv4d s4rv4d requested a review from a team as a code owner November 8, 2024 18:11
@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 8, 2024

sharing some ss for examples

Screenshot 2024-11-08 at 11 26 35 pm
Screenshot 2024-11-08 at 11 26 43 pm

@jakim929
Copy link
Contributor

jakim929 commented Nov 9, 2024

@s4rv4d thank you for the contribution!

However, this PR currently feels a bit far off, partly my fault because the issue was underspecified.

  • It's not using JSON RPC - since this will be the basis for all the other admin read endpoints, it should be built in a reusable way.
  • It's not looking up the correct config for the chainId - it's currently looking it up by port
  • the chain config it returns should be based on the network config not the default config

Please let me know if you have any questions about the implementation.

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 9, 2024

Got it working on this

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 12, 2024

  • the chain config it returns should be based on the network config not the default config

the network config is getting init by GetDefaultNetworkConfig, if this isnt the right implementation, can you tell me which other way to init networkConfig?

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 13, 2024

@jakim929 can you pls review this, just wanted to see if im approaching this the right way

admin/admin.go Outdated
defer s.wg.Done()

http.Handle("/", rpcServer)
err := http.ListenAndServe(fmt.Sprintf(":%d", s.port+1), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rpc server should just be on the same port as the specified

there should be very limited direct http endpoints here so

/: defaults to rpc
/ready: probably the only http endpoint we need

these can all be on the same port since they are separated by the route

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome got it, making these revisions

@jakim929
Copy link
Contributor

the network config is getting init by GetDefaultNetworkConfig, if this isnt the right implementation, can you tell me which other way to init networkConfig?

the network config gets initialized by GetDefaultNetworkConfig, but then some fields are updated subsequently (if you take a look at NewSupersim). would suggest you just pass networkConfig to the NewAdminServer function

func NewAdminServer(log log.Logger, port uint64, networkConfig *config.NetworkConfig) *AdminServer {

admin/admin.go Outdated
NetworkConfig: s.networkConfig, // Ensure this is correctly set
}

if err := rpcServer.RegisterName("Admin", rpcMethods); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention is to lower case the namespace "admin"

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 13, 2024

the network config is getting init by GetDefaultNetworkConfig, if this isnt the right implementation, can you tell me which other way to init networkConfig?

the network config gets initialized by GetDefaultNetworkConfig, but then some fields are updated subsequently (if you take a look at NewSupersim). would suggest you just pass networkConfig to the NewAdminServer function

func NewAdminServer(log log.Logger, port uint64, networkConfig *config.NetworkConfig) *AdminServer {

cool thanks for the reference making these changes

@jakim929
Copy link
Contributor

overall approach looks correct! sry for the delay in responding and lmk if u have other qs

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 13, 2024

@jakim929 made the changes and updated admin_test as well

@s4rv4d s4rv4d changed the title feat(admin): added getL1Addresses(chainId) support with /getL1Addresses/:chainID feat(admin): added getL1Addresses(chainId) rpc support Nov 13, 2024
Copy link
Contributor

@jakim929 jakim929 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments, once those are fixed up it looks good to go!

admin/admin.go Outdated
@@ -38,7 +63,7 @@ func (s *AdminServer) Start(ctx context.Context) error {
addr := listener.Addr().(*net.TCPAddr)

s.port = uint64(addr.Port)
s.log.Debug("admin server listening", "port", s.port)
s.log.Debug("Admin server and RPC server listening on the same port", "port", s.port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: admin server listening is probably fine. The admin server is just the RPC server except for a single endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
"L2CrossDomainMessenger": chain.L2Config.L1Addresses.L1CrossDomainMessengerProxy.String(),
"L2StandardBridge": chain.L2Config.L1Addresses.L1StandardBridgeProxy.String(),
}
m.Log.Info("GetL2Addresses called", "chainId", *args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prob should just be a debug log

m.Log.Debug("admin_getL2Addresses)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
Comment on lines 141 to 142
"L2CrossDomainMessenger": chain.L2Config.L1Addresses.L1CrossDomainMessengerProxy.String(),
"L2StandardBridge": chain.L2Config.L1Addresses.L1StandardBridgeProxy.String(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are named wrong - they should be named identically to the ones they refer to
L1CrossDomainMessengerProxy
L1StandardBridgeProxy

we should also add all of these?

	AddressManager                    Address `json:"AddressManager" toml:"AddressManager"`
	L1CrossDomainMessengerProxy       Address `json:"L1CrossDomainMessengerProxy" toml:"L1CrossDomainMessengerProxy"`
	L1ERC721BridgeProxy               Address `json:"L1ERC721BridgeProxy" toml:"L1ERC721BridgeProxy"`
	L1StandardBridgeProxy             Address `json:"L1StandardBridgeProxy" toml:"L1StandardBridgeProxy"`
	L2OutputOracleProxy               Address `json:"L2OutputOracleProxy" toml:"L2OutputOracleProxy,omitempty"`
	OptimismMintableERC20FactoryProxy Address `json:"OptimismMintableERC20FactoryProxy" toml:"OptimismMintableERC20FactoryProxy"`
	OptimismPortalProxy               Address `json:"OptimismPortalProxy,omitempty" toml:"OptimismPortalProxy,omitempty"`
	SystemConfigProxy                 Address `json:"SystemConfigProxy" toml:"SystemConfigProxy"`
	ProxyAdmin                        Address `json:"ProxyAdmin" toml:"ProxyAdmin"`
	SuperchainConfig                  Address `json:"SuperchainConfig,omitempty" toml:"SuperchainConfig,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
rpcServer := rpc.NewServer()
rpcMethods := &RPCMethods{
Log: s.log,
NetworkConfig: s.networkConfig, // Ensure this is correctly set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
Comment on lines 42 to 54
// Set up RPC server
rpcServer := rpc.NewServer()
rpcMethods := &RPCMethods{
Log: s.log,
NetworkConfig: s.networkConfig, // Ensure this is correctly set
}

if err := rpcServer.RegisterName("admin", rpcMethods); err != nil {
return fmt.Errorf("failed to register RPC methods: %w", err)
}

// Mount the RPC server on the root path `/` to handle all RPC requests
router.Any("/", gin.WrapH(rpcServer))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should move this logic to setupRouter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup makes sense

done✅

admin/admin.go Outdated
Comment on lines 42 to 54
// Set up RPC server
rpcServer := rpc.NewServer()
rpcMethods := &RPCMethods{
Log: s.log,
NetworkConfig: s.networkConfig, // Ensure this is correctly set
}

if err := rpcServer.RegisterName("admin", rpcMethods); err != nil {
return fmt.Errorf("failed to register RPC methods: %w", err)
}

// Mount the RPC server on the root path `/` to handle all RPC requests
router.Any("/", gin.WrapH(rpcServer))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should stick to just POST requests here

router.POST

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
func (m *RPCMethods) GetL1Addresses(args *uint64) *map[string]string {
chain := filterByChainID(m.NetworkConfig.L2Configs, *args)
if chain == nil {
m.Log.Info("chain not found")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be m.Log.Debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated

func (m *RPCMethods) GetConfig(args *struct{}) *config.NetworkConfig {

m.Log.Info("GetConfig called")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be m.Log.Debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
Comment on lines 102 to 104
var b strings.Builder
fmt.Fprintf(&b, "Admin Server: %s\n\n", s.Endpoint())
return b.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: doesn't need to be a string builder because it's a single interpolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

admin/admin.go Outdated
@@ -19,15 +21,38 @@ type AdminServer struct {
cancel context.CancelFunc
wg sync.WaitGroup

rpcServer *rpc.Server // New field for the RPC server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done✅

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 13, 2024

@jakim929 made the necessary review changes

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go server.Start(ctx)
time.Sleep(1 * time.Second) // Allow time for the server to start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we replace this with WaitForWithTimeout? time.Sleep makes tests more flaky and adds to time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sir we can, making this change

Copy link
Contributor

@jakim929 jakim929 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few last changes! will keep an eye so once those are done I can approve - no need to re-ping

admin/admin.go Outdated Show resolved Hide resolved
supersim.go Outdated Show resolved Hide resolved
@jakim929 jakim929 merged commit 9890af2 into ethereum-optimism:main Nov 13, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants