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 rpc method for getL2ToL2 Message(msgHash) #265

Merged
merged 10 commits into from
Nov 25, 2024

Conversation

s4rv4d
Copy link
Contributor

@s4rv4d s4rv4d commented Nov 14, 2024

Description
added getL2ToL2 Message(msgHash), essentially letting devs fetch L2ToL2Message via msgHash

Metadata

@s4rv4d s4rv4d requested a review from a team as a code owner November 14, 2024 08:03
@s4rv4d s4rv4d marked this pull request as draft November 14, 2024 08:03
@s4rv4d s4rv4d changed the title featsetting up rpc method for getting l2tol2 message via message has feat(admin): added rpc method for getL2ToL2 Message(msgHash) Nov 14, 2024
@s4rv4d s4rv4d marked this pull request as ready for review November 15, 2024 12:11
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.

thanks for the PR - some changes requested

admin/admin.go Outdated
Comment on lines 187 to 190
} else {
m.log.Error("auto relay not enabled", "args", *args)
return 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 indexer runs regardless of the auto relayer. maybe some thing like "Interop is not enabled, please enable interop with --interop.enabled"

Copy link
Contributor

Choose a reason for hiding this comment

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

also this should not be a log it should return an RPC error with the correct code

admin/admin.go Outdated
Comment on lines 183 to 185
reply := storeEntry.Message()

return reply
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

return storeEntry.Message()

@@ -23,7 +23,7 @@ func TestAdminServerBasicFunctionality(t *testing.T) {
testlog := testlog.Logger(t, log.LevelInfo)

Copy link
Contributor

Choose a reason for hiding this comment

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

can u add a test to see that the result is returned correctly? or alternatively can be in supersim_test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to supersim_test

Comment on lines +39 to +43
adminServer := &AdminServer{log: log, port: port, networkConfig: networkConfig}

if networkConfig.InteropEnabled && indexer != nil {
adminServer.l2ToL2MsgIndexer = indexer
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit- if it's nil then it will be initialized correctly

	adminServer := &AdminServer{log: log, port: port, networkConfig: networkConfig, l2ToL2MsgIndexer: indexer}

admin/admin.go Outdated
Comment on lines 120 to 121
if s.networkConfig.InteropEnabled {
rpcMethods.l2ToL2MsgIndexer = s.l2ToL2MsgIndexer
Copy link
Contributor

Choose a reason for hiding this comment

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

rpcMethods.l2ToL2MsgIndexer = s.l2ToL2MsgIndexer

no need to check for interopEnabled. from the perspective of the admin server, if it gets passed a non-nil indexer it assumes it's usable

Comment on lines 214 to 217
func (o *Orchestrator) L2ToL2MessageIndexer() *interop.L2ToL2MessageIndexer {
return o.l2ToL2MsgIndexer
}

Copy link
Contributor

Choose a reason for hiding this comment

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

see comment on supersim.go

once the admin server start logic is moved into here, we can remove this fn

admin/admin.go Outdated

reply := storeEntry.Message()

return reply
Copy link
Contributor

Choose a reason for hiding this comment

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

can u verify that this returns correctly (serialized and formatted correctly) when u call the json rpc server? and add a test for it?

Copy link
Contributor Author

@s4rv4d s4rv4d Nov 15, 2024

Choose a reason for hiding this comment

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

did test it on local

Uploading Screenshot 2024-11-15 at 10.59.09 pm.png…

will add test cases too

admin/admin.go Outdated

if m.networkConfig.InteropEnabled && m.l2ToL2MsgIndexer != nil {

storeEntry, err := m.l2ToL2MsgIndexer.Get(*args)
Copy link
Contributor

Choose a reason for hiding this comment

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

also need to handle case if the storeEntry just doesn't exist - should end up returning nil

m.log.Error("valid msg hash not provided", "args", *args)
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: early return is better than the if/else statement below

if m.l2ToL2MsgIndexer == nil {
m.log.Error("auto relay not enabled", "args", *args)
return nil
}

^ we should return a better error

admin/admin.go Outdated
Comment on lines 169 to 172
if args == nil {
m.log.Error("valid msg hash not provided", "args", *args)
return nil
}
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 validate that it's a correct msgHash?

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 17, 2024

adding a screenshot of test results on local

Screenshot 2024-11-17 at 4 40 58 pm

@s4rv4d
Copy link
Contributor Author

s4rv4d commented Nov 19, 2024

Updated example rpc response

{ "jsonrpc": "2.0", "id": 1, "result": { "Destination": 902, "Source": 901, "Nonce": 0, "Sender": "0x4200000000000000000000000000000000000028", "Target": "0x4200000000000000000000000000000000000028", "Message": "0x7cfd6dbc000000000000000000000000420beef000000000000000000000000000000001000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e8" } }

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.

looks good just one nit, can u rebase? will run CI checks then

Comment on lines +68 to +75
type JSONL2ToL2Message struct {
Destination uint64 `json:"Destination"`
Source uint64 `json:"Source"`
Nonce *big.Int `json:"Nonce"`
Sender common.Address `json:"Sender"`
Target common.Address `json:"Target"`
Message hexutil.Bytes `json:"Message"`
}
Copy link
Contributor

@jakim929 jakim929 Nov 25, 2024

Choose a reason for hiding this comment

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

nit: you can prob just import this from admin.JSONL2ToL2Message

In a future PR might make sense to unify with the indexer's message type so we don't have two types. As discussed, out of scope for this PR! just noting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noted

@jakim929 jakim929 merged commit e577602 into ethereum-optimism:main Nov 25, 2024
3 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