-
Notifications
You must be signed in to change notification settings - Fork 78
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
Conversation
@s4rv4d thank you for the contribution! However, this PR currently feels a bit far off, partly my fault because the issue was underspecified.
Please let me know if you have any questions about the implementation. |
Got it working on this |
the network config is getting init by GetDefaultNetworkConfig, if this isnt the right implementation, can you tell me which other way to init networkConfig? |
@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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
|
admin/admin.go
Outdated
NetworkConfig: s.networkConfig, // Ensure this is correctly set | ||
} | ||
|
||
if err := rpcServer.RegisterName("Admin", rpcMethods); err != nil { |
There was a problem hiding this comment.
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"
cool thanks for the reference making these changes |
overall approach looks correct! sry for the delay in responding and lmk if u have other qs |
@jakim929 made the changes and updated admin_test as well |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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"`
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove comment
There was a problem hiding this comment.
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
// 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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
// 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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
var b strings.Builder | ||
fmt.Fprintf(&b, "Admin Server: %s\n\n", s.Endpoint()) | ||
return b.String() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unnecessary comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done✅
@jakim929 made the necessary review changes |
admin/admin_test.go
Outdated
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
go server.Start(ctx) | ||
time.Sleep(1 * time.Second) // Allow time for the server to start |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
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