Skip to content

Commit

Permalink
chore: repo refactoring (cosmos#1217)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

Implement low impact refactoring from
rollkit/rollkit#1216

See commit messages for description of each refactoring step. 

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->
  • Loading branch information
MSevey authored Oct 2, 2023
1 parent d9eb2da commit eb7bdc0
Show file tree
Hide file tree
Showing 81 changed files with 127 additions and 150 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_call:
inputs:
GO_VERSION:
description: 'Go version to use'
description: "Go version to use"
type: string
required: true

Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
hadolint:
uses: rollkit/.github/.github/workflows/reusable_dockerfile_lint.yml@v0.2.2 # yamllint disable-line rule:line-length
with:
dockerfile: docker/mockserv.Dockerfile
dockerfile: test/docker/mockserv.Dockerfile

yamllint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lint: vet
@echo "--> Running markdownlint"
@markdownlint --config .markdownlint.yaml '**/*.md'
@echo "--> Running hadolint"
@hadolint docker/mockserv.Dockerfile
@hadolint test/docker/mockserv.Dockerfile
@echo "--> Running yamllint"
@yamllint --no-warnings . -c .yamllint.yml

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Please join our [Community Discord](https://discord.com/invite/YsnTPcSfWQ) to as
## Dependency Graph

To see our progress and a possible future of Rollkit visit our [Dependency
Graph](./docs/specification/rollkit-dependency-graph.md).
Graph](./specs/src/specs/rollkit-dependency-graph.md).

## Code of Conduct

Expand Down
2 changes: 1 addition & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/da"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/mempool"
"github.com/rollkit/rollkit/state"
"github.com/rollkit/rollkit/store"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
2 changes: 1 addition & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/da"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/log/test"
"github.com/rollkit/rollkit/store"
test "github.com/rollkit/rollkit/test/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
9 changes: 6 additions & 3 deletions conv/addr.go → config/addr.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package conv
package config

import (
"errors"
"strings"

"github.com/multiformats/go-multiaddr"
)

"github.com/rollkit/rollkit/config"
var (
errInvalidAddress = errors.New("invalid address format, expected [protocol://][<NODE_ID>@]<IPv4>:<PORT>")
)

// TranslateAddresses updates conf by changing Cosmos-style addresses to Multiaddr format.
func TranslateAddresses(conf *config.NodeConfig) error {
func TranslateAddresses(conf *NodeConfig) error {
if conf.P2P.ListenAddress != "" {
addr, err := GetMultiAddr(conf.P2P.ListenAddress)
if err != nil {
Expand Down
26 changes: 12 additions & 14 deletions conv/addr_test.go → config/addr_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package conv
package config

import (
"strings"
"testing"

"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/assert"

"github.com/rollkit/rollkit/config"
)

func TestTranslateAddresses(t *testing.T) {
Expand All @@ -19,33 +17,33 @@ func TestTranslateAddresses(t *testing.T) {

cases := []struct {
name string
input config.NodeConfig
expected config.NodeConfig
input NodeConfig
expected NodeConfig
expectedErr string
}{
{"empty", config.NodeConfig{}, config.NodeConfig{}, ""},
{"empty", NodeConfig{}, NodeConfig{}, ""},
{
"valid listen address",
config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validCosmos}},
config.NodeConfig{P2P: config.P2PConfig{ListenAddress: validRollkit}},
NodeConfig{P2P: P2PConfig{ListenAddress: validCosmos}},
NodeConfig{P2P: P2PConfig{ListenAddress: validRollkit}},
"",
},
{
"valid seed address",
config.NodeConfig{P2P: config.P2PConfig{Seeds: validCosmos + "," + validCosmos}},
config.NodeConfig{P2P: config.P2PConfig{Seeds: validRollkit + "," + validRollkit}},
NodeConfig{P2P: P2PConfig{Seeds: validCosmos + "," + validCosmos}},
NodeConfig{P2P: P2PConfig{Seeds: validRollkit + "," + validRollkit}},
"",
},
{
"invalid listen address",
config.NodeConfig{P2P: config.P2PConfig{ListenAddress: invalidCosmos}},
config.NodeConfig{},
NodeConfig{P2P: P2PConfig{ListenAddress: invalidCosmos}},
NodeConfig{},
errInvalidAddress.Error(),
},
{
"invalid seed address",
config.NodeConfig{P2P: config.P2PConfig{Seeds: validCosmos + "," + invalidCosmos}},
config.NodeConfig{},
NodeConfig{P2P: P2PConfig{Seeds: validCosmos + "," + invalidCosmos}},
NodeConfig{},
errInvalidAddress.Error(),
},
}
Expand Down
26 changes: 26 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/hex"
"time"

cmcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -56,6 +58,30 @@ type BlockManagerConfig struct {
NamespaceID types.NamespaceID `mapstructure:"namespace_id"`
}

// GetNodeConfig translates Tendermint's configuration into Rollkit configuration.
//
// This method only translates configuration, and doesn't verify it. If some option is missing in Tendermint's
// config, it's skipped during translation.
func GetNodeConfig(nodeConf *NodeConfig, cmConf *cmcfg.Config) {
if cmConf != nil {
nodeConf.RootDir = cmConf.RootDir
nodeConf.DBPath = cmConf.DBPath
if cmConf.P2P != nil {
nodeConf.P2P.ListenAddress = cmConf.P2P.ListenAddress
nodeConf.P2P.Seeds = cmConf.P2P.Seeds
}
if cmConf.RPC != nil {
nodeConf.RPC.ListenAddress = cmConf.RPC.ListenAddress
nodeConf.RPC.CORSAllowedOrigins = cmConf.RPC.CORSAllowedOrigins
nodeConf.RPC.CORSAllowedMethods = cmConf.RPC.CORSAllowedMethods
nodeConf.RPC.CORSAllowedHeaders = cmConf.RPC.CORSAllowedHeaders
nodeConf.RPC.MaxOpenConnections = cmConf.RPC.MaxOpenConnections
nodeConf.RPC.TLSCertFile = cmConf.RPC.TLSCertFile
nodeConf.RPC.TLSKeyFile = cmConf.RPC.TLSKeyFile
}
}
}

// GetViperConfig reads configuration parameters from Viper instance.
//
// This method is called in cosmos-sdk.
Expand Down
25 changes: 25 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@ import (
"testing"
"time"

cmcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"github.com/rollkit/rollkit/types"
)

func TestGetNodeConfig(t *testing.T) {
t.Parallel()

cases := []struct {
name string
input *cmcfg.Config
expected NodeConfig
}{
{"empty", nil, NodeConfig{}},
{"Seeds", &cmcfg.Config{P2P: &cmcfg.P2PConfig{Seeds: "seeds"}}, NodeConfig{P2P: P2PConfig{Seeds: "seeds"}}},
{"ListenAddress", &cmcfg.Config{P2P: &cmcfg.P2PConfig{ListenAddress: "127.0.0.1:7676"}}, NodeConfig{P2P: P2PConfig{ListenAddress: "127.0.0.1:7676"}}},
{"RootDir", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{RootDir: "~/root"}}, NodeConfig{RootDir: "~/root"}},
{"DBPath", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{DBPath: "./database"}}, NodeConfig{DBPath: "./database"}},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
var actual NodeConfig
GetNodeConfig(&actual, c.input)
assert.Equal(t, c.expected, actual)
})
}
}
func TestViperAndCobra(t *testing.T) {
t.Parallel()
assert := assert.New(t)
Expand Down
31 changes: 0 additions & 31 deletions conv/config.go

This file was deleted.

35 changes: 0 additions & 35 deletions conv/config_test.go

This file was deleted.

7 changes: 0 additions & 7 deletions conv/errors.go

This file was deleted.

2 changes: 1 addition & 1 deletion da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

openrpcns "github.com/rollkit/celestia-openrpc/types/namespace"
"github.com/rollkit/rollkit/da"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
pb "github.com/rollkit/rollkit/types/pb/rollkit"
)
Expand Down
2 changes: 1 addition & 1 deletion da/celestia/mock/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/rollkit/celestia-openrpc/types/blob"
"github.com/rollkit/celestia-openrpc/types/header"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/store"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
2 changes: 1 addition & 1 deletion da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

ds "github.com/ipfs/go-datastore"

"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
2 changes: 1 addition & 1 deletion da/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
ds "github.com/ipfs/go-datastore"

"github.com/rollkit/rollkit/da"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
"github.com/rollkit/rollkit/types/pb/dalc"
"github.com/rollkit/rollkit/types/pb/rollkit"
Expand Down
2 changes: 1 addition & 1 deletion da/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/rollkit/celestia-openrpc/types/core"
"github.com/rollkit/rollkit/da"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/store"
"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
2 changes: 1 addition & 1 deletion da/test/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/rollkit/rollkit/da/grpc/mockserv"
"github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/da/registry"
"github.com/rollkit/rollkit/log/test"
"github.com/rollkit/rollkit/store"
test "github.com/rollkit/rollkit/test/log"
"github.com/rollkit/rollkit/types"
)

Expand Down
2 changes: 1 addition & 1 deletion conv/crypto.go → node/crypto.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package conv
package node

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion conv/crypto_test.go → node/crypto_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package conv
package node

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion node/full_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/cometbft/cometbft/version"

rconfig "github.com/rollkit/rollkit/config"
abciconv "github.com/rollkit/rollkit/conv/abci"
"github.com/rollkit/rollkit/mempool"
"github.com/rollkit/rollkit/types"
abciconv "github.com/rollkit/rollkit/types/abci"
)

const (
Expand Down
7 changes: 3 additions & 4 deletions node/full_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import (
"github.com/libp2p/go-libp2p/core/peer"

"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/conv"
abciconv "github.com/rollkit/rollkit/conv/abci"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/mocks"
"github.com/rollkit/rollkit/store"
"github.com/rollkit/rollkit/test/mocks"
"github.com/rollkit/rollkit/types"
abciconv "github.com/rollkit/rollkit/types/abci"
)

var expectedInfo = abci.ResponseInfo{
Expand Down Expand Up @@ -784,7 +783,7 @@ func createGenesisValidators(t *testing.T, numNodes int, appCreator func(require
nodeKey := &p2p.NodeKey{
PrivKey: vKeys[i],
}
signingKey, err := conv.GetNodeKey(nodeKey)
signingKey, err := GetNodeKey(nodeKey)
require.NoError(err)
nodes[i], err = newFullNode(
context.Background(),
Expand Down
Loading

0 comments on commit eb7bdc0

Please sign in to comment.