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

Refactor x/rollup module to adhere to Cosmos SDK suggested standards #124

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ lint:

.PHONY: gen-proto
gen-proto:
${GOBIN}/buf generate --template buf.gen.yaml
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved
${SCRIPTS_PATH}/gen-proto.sh

.PHONY: install-gofumpt
install-gofumpt:
Expand Down
8 changes: 4 additions & 4 deletions x/rollup/types/adapters.go → adapters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package types
package monomer

import (
"errors"
Expand All @@ -9,7 +9,7 @@ import (
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
rollupv1 "github.com/polymerdao/monomer/gen/rollup/v1"
rolluptypes "github.com/polymerdao/monomer/x/rollup/types"
)

var errL1AttributesNotFound = errors.New("L1 attributes tx not found")
Expand Down Expand Up @@ -44,7 +44,7 @@ func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes, signTx txSigner, from st
for _, depositTx := range ethTxs[:numDepositTxs] {
depositTxsBytes = append(depositTxsBytes, depositTx)
}
msgAny, err := codectypes.NewAnyWithValue(&rollupv1.ApplyL1TxsRequest{
msgAny, err := codectypes.NewAnyWithValue(&rolluptypes.ApplyL1TxsRequest{
TxBytes: depositTxsBytes,
FromAddress: from,
})
Expand Down Expand Up @@ -99,7 +99,7 @@ func AdaptCosmosTxsToEthTxs(cosmosTxs bfttypes.Txs) (ethtypes.Transactions, erro
if num := len(msgs); num != 1 {
return nil, fmt.Errorf("unexpected number of msgs in Eth Cosmos tx: want 1, got %d", num)
}
msg := new(rollupv1.ApplyL1TxsRequest)
msg := new(rolluptypes.ApplyL1TxsRequest)
if err := msg.Unmarshal(msgs[0].GetValue()); err != nil {
return nil, fmt.Errorf("unmarshal MsgL1Txs smsg: %v", err)
}
Expand Down
21 changes: 5 additions & 16 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
version: v2
managed:
enabled: true
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
- file_option: go_package
module: buf.build/cosmos/gogo-proto
- file_option: go_package
module: buf.build/cosmos/cosmos-proto
override:
- file_option: go_package_prefix
value: github.com/polymerdao/monomer/gen
- file_option: go_package_prefix
module: buf.build/cosmos/cosmos-sdk
value: cosmossdk.io/api
plugins:
- local: protoc-gen-gocosmos
out: gen
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,paths=source_relative
opt:
- plugins=grpc
- paths=source_relative
- Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
- Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
5 changes: 2 additions & 3 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/polymerdao/monomer/app/peptide/txstore"
"github.com/polymerdao/monomer/bindings"
"github.com/polymerdao/monomer/evm"
"github.com/polymerdao/monomer/gen/rollup/v1"
"github.com/polymerdao/monomer/mempool"
rolluptypes "github.com/polymerdao/monomer/x/rollup/types"
)
Expand Down Expand Up @@ -255,7 +254,7 @@ func (b *Builder) parseWithdrawalMessages(
return nil, fmt.Errorf("unmarshal cosmos tx: %v", err)
}
for _, msg := range cosmosTx.GetBody().GetMessages() {
withdrawalMsg := new(rollupv1.InitiateWithdrawalRequest)
withdrawalMsg := new(rolluptypes.InitiateWithdrawalRequest)
if msg.TypeUrl == cdctypes.MsgTypeURL(withdrawalMsg) {
if err := withdrawalMsg.Unmarshal(msg.GetValue()); err != nil {
return nil, fmt.Errorf("unmarshal InitiateWithdrawalRequest: %v", err)
Expand Down Expand Up @@ -285,7 +284,7 @@ func (b *Builder) parseWithdrawalMessages(
// storeWithdrawalMsgInEVM stores the withdrawal message hash in the monomer evm state db and returns the L2ToL1MessagePasser
// message nonce used for the withdrawal. This is used for proving withdrawals.
func (b *Builder) storeWithdrawalMsgInEVM(
withdrawalMsg *rollupv1.InitiateWithdrawalRequest,
withdrawalMsg *rolluptypes.InitiateWithdrawalRequest,
ethState *state.StateDB,
header *monomer.Header,
) (*big.Int, error) {
Expand Down
5 changes: 2 additions & 3 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/polymerdao/monomer/builder"
"github.com/polymerdao/monomer/engine/signer"
"github.com/polymerdao/monomer/monomerdb"
rolluptypes "github.com/polymerdao/monomer/x/rollup/types"
)

type DB interface {
Expand Down Expand Up @@ -182,7 +181,7 @@ func (e *EngineAPI) ForkchoiceUpdatedV3(
return nil, engine.InvalidPayloadAttributes.With(errors.New("gas limit not provided"))
}

cosmosTxs, err := rolluptypes.AdaptPayloadTxsToCosmosTxs(
cosmosTxs, err := monomer.AdaptPayloadTxsToCosmosTxs(
pa.Transactions,
e.signer.Sign,
e.signer.AccountAddress().String(),
Expand Down Expand Up @@ -276,7 +275,7 @@ func (e *EngineAPI) GetPayloadV3(ctx context.Context, payloadID engine.PayloadID
panic(fmt.Errorf("build block: %v", err))
}

txs, err := rolluptypes.AdaptCosmosTxsToEthTxs(block.Txs)
txs, err := monomer.AdaptCosmosTxsToEthTxs(block.Txs)
if err != nil {
return nil, engine.GenericServerError.With(fmt.Errorf("convert cosmos txs to eth txs: %v", err))
}
Expand Down
16 changes: 6 additions & 10 deletions gen/rollup/module/v1/module.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions gen/rollup/v1/helpers.go

This file was deleted.

16 changes: 6 additions & 10 deletions gen/testapp/module/v1/module.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions gen/testapp/v1/get.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions gen/testapp/v1/set.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions monomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
rolluptypes "github.com/polymerdao/monomer/x/rollup/types"
)

type Application interface {
Expand Down Expand Up @@ -123,7 +122,7 @@ func (b *Block) ToEth() (*ethtypes.Block, error) {
return nil, errors.New("converted a nil block")
}

txs, err := rolluptypes.AdaptCosmosTxsToEthTxs(b.Txs)
txs, err := AdaptCosmosTxsToEthTxs(b.Txs)
if err != nil {
return nil, fmt.Errorf("adapt txs: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions proto/rollup/module/v1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package rollup.module.v1;

import "cosmos/app/v1alpha1/module.proto";

option go_package = "github.com/polymerdao/monomer/gen/rollup/module/v1;modulev1";

message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/polymerdao/monomer/x/rollup"
Expand Down
3 changes: 2 additions & 1 deletion proto/rollup/v1/msg.proto → proto/rollup/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/polymerdao/monomer/x/rollup/types";

// MsgService defines all tx endpoints for the rollup module.
service MsgService {
rpc ApplyL1Txs(ApplyL1TxsRequest) returns (ApplyL1TxsResponse);
Expand All @@ -26,7 +28,6 @@ message ApplyL1TxsRequest {

message ApplyL1TxsResponse {}

// TODO: add validations in the x/rollup module to ensure that the target address and gas limit are valid before burning the users ETH
// InitiateWithdrawalRequest defines a message for all L2 withdrawal txs
message InitiateWithdrawalRequest {
option (cosmos.msg.v1.signer) = "sender";
Expand Down
17 changes: 17 additions & 0 deletions scripts/gen-proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

SCRIPTS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MONOMER_DIR=$(cd "$SCRIPTS_DIR/.." && pwd)
GEN_DIR=$(cd "$MONOMER_DIR/gen" && pwd)
ROLLUP_DIR=$(cd "$MONOMER_DIR/x/rollup" && pwd)

# generate cosmos proto code
buf generate

# move the generated rollup module message types to the x/rollup module
cp -r $GEN_DIR/rollup/v1/* $ROLLUP_DIR/types
rm -rf $GEN_DIR/rollup/v1

# TODO: move the testapp module message types to the testapp/x/testmodule module
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions testapp/proto/testapp/module/v1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package testapp.module.v1;

import "cosmos/app/v1alpha1/module.proto";

option go_package = "github.com/polymerdao/monomer/gen/testapp/module/v1;modulev1";

message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/polymerdao/monomer/testapp/x/testmodule"
Expand Down
2 changes: 2 additions & 0 deletions testapp/proto/testapp/v1/get.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package testapp.v1;

option go_package = "github.com/polymerdao/monomer/gen/testapp/v1;testappv1";
natebeauregard marked this conversation as resolved.
Show resolved Hide resolved

message GetRequest {
string key = 1;
}
Expand Down
2 changes: 2 additions & 0 deletions testapp/proto/testapp/v1/set.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package testapp.v1;

import "cosmos/msg/v1/msg.proto";

option go_package = "github.com/polymerdao/monomer/gen/testapp/v1;testappv1";

message SetRequest {
option (cosmos.msg.v1.signer) = "from_address";

Expand Down
Loading
Loading