Skip to content

Commit

Permalink
Update for cosmos-sdk v0.46.1 compatibility (cosmos#536)
Browse files Browse the repository at this point in the history
* deps: update to cosmos-sdk v0.46.1
* refactor: replace AppCons, ClientCreator with Client
* ci: use go 1.19 in CI
* fix: address review comments
  • Loading branch information
tzdybal authored Sep 27, 2022
1 parent 2eb987e commit 722b44e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 1,059 deletions.
4 changes: 2 additions & 2 deletions docker/mockserv.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS build-env
FROM --platform=$BUILDPLATFORM golang:1.19-alpine AS build-env

# Set working directory for the build
WORKDIR /src

COPY . .

RUN go mod tidy -compat=1.17 && \
RUN go mod tidy -compat=1.19 && \
go build /src/da/grpc/mockserv/cmd/main.go

# Final image
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/celestiaorg/optimint

go 1.17
go 1.18

require (
github.com/celestiaorg/go-cnc v0.1.0
Expand All @@ -21,7 +21,7 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.20
github.com/tendermint/tendermint v0.34.21
go.uber.org/multierr v1.8.0
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b
google.golang.org/grpc v1.48.0
Expand Down Expand Up @@ -82,6 +82,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
github.com/koron/go-ssdp v0.0.3 // indirect
Expand All @@ -107,7 +108,7 @@ require (
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
Expand Down Expand Up @@ -164,7 +165,7 @@ require (
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
1,004 changes: 9 additions & 995 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
"testing"
"time"

mockda "github.com/celestiaorg/optimint/da/mock"
"github.com/celestiaorg/optimint/p2p"
"github.com/celestiaorg/optimint/store"
"github.com/stretchr/testify/assert"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
abcicli "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/optimint/config"
"github.com/celestiaorg/optimint/da"
mockda "github.com/celestiaorg/optimint/da/mock"
"github.com/celestiaorg/optimint/mocks"
"github.com/celestiaorg/optimint/p2p"
"github.com/celestiaorg/optimint/store"
)

func TestAggregatorMode(t *testing.T) {
Expand All @@ -49,7 +49,7 @@ func TestAggregatorMode(t *testing.T) {
BlockTime: 1 * time.Second,
NamespaceID: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
}
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, signingKey, abcicli.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -244,7 +244,7 @@ func createNode(ctx context.Context, n int, aggregator bool, dalc da.DataAvailab
},
keys[n],
signingKey,
proxy.NewLocalClientCreator(app),
abcicli.NewLocalClient(nil, app),
&types.GenesisDoc{ChainID: "test"},
log.TestingLogger().With("node", n))
require.NoError(err)
Expand Down
34 changes: 18 additions & 16 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"
"go.uber.org/multierr"

abciclient "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
llcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
corep2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/optimint/block"
Expand Down Expand Up @@ -50,8 +50,8 @@ const (
// It connects all the components and orchestrates their work.
type Node struct {
service.BaseService
eventBus *tmtypes.EventBus
proxyApp proxy.AppConns
eventBus *tmtypes.EventBus
appClient abciclient.Client

genesis *tmtypes.GenesisDoc
// cache of chunked genesis data.
Expand Down Expand Up @@ -79,13 +79,15 @@ type Node struct {
}

// NewNode creates new Optimint node.
func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger) (*Node, error) {
proxyApp := proxy.NewAppConns(clientCreator)
proxyApp.SetLogger(logger.With("module", "proxy"))
if err := proxyApp.Start(); err != nil {
return nil, fmt.Errorf("error starting proxy app connections: %w", err)
}

func NewNode(
ctx context.Context,
conf config.NodeConfig,
p2pKey crypto.PrivKey,
signingKey crypto.PrivKey,
appClient abciclient.Client,
genesis *tmtypes.GenesisDoc,
logger log.Logger,
) (*Node, error) {
eventBus := tmtypes.NewEventBus()
eventBus.SetLogger(logger.With("module", "events"))
if err := eventBus.Start(); err != nil {
Expand Down Expand Up @@ -124,16 +126,16 @@ func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey,
return nil, err
}

mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), proxyApp.Mempool(), 0)
mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), appClient, 0)
mpIDs := newMempoolIDs()

blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, proxyApp.Consensus(), dalc, eventBus, logger.With("module", "BlockManager"))
blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, appClient, dalc, eventBus, logger.With("module", "BlockManager"))
if err != nil {
return nil, fmt.Errorf("BlockManager initialization error: %w", err)
}

node := &Node{
proxyApp: proxyApp,
appClient: appClient,
eventBus: eventBus,
genesis: genesis,
conf: conf,
Expand Down Expand Up @@ -269,9 +271,9 @@ func (n *Node) EventBus() *tmtypes.EventBus {
return n.eventBus
}

// ProxyApp returns ABCI proxy connections to communicate with application.
func (n *Node) ProxyApp() proxy.AppConns {
return n.proxyApp
// AppClient returns ABCI proxy connections to communicate with application.
func (n *Node) AppClient() abciclient.Client {
return n.appClient
}

// newTxValidator creates a pubsub validator that uses the node's mempool to check the
Expand Down
8 changes: 4 additions & 4 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"testing"
"time"

"github.com/celestiaorg/optimint/mempool"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
abcicli "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/optimint/config"
"github.com/celestiaorg/optimint/mempool"
"github.com/celestiaorg/optimint/mocks"
)

Expand All @@ -31,7 +31,7 @@ func TestStartup(t *testing.T) {
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand All @@ -57,7 +57,7 @@ func TestMempoolDirectly(t *testing.T) {
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)

node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down
23 changes: 6 additions & 17 deletions rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"time"

abcicli "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/config"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
Expand Down Expand Up @@ -60,7 +61,7 @@ func NewClient(node *node.Node) *Client {

// ABCIInfo returns basic information about application state.
func (c *Client) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
resInfo, err := c.query().InfoSync(proxy.RequestInfo)
resInfo, err := c.appClient().InfoSync(proxy.RequestInfo)
if err != nil {
return nil, err
}
Expand All @@ -74,7 +75,7 @@ func (c *Client) ABCIQuery(ctx context.Context, path string, data tmbytes.HexByt

// ABCIQueryWithOptions queries for data from application.
func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
resQuery, err := c.query().QuerySync(abci.RequestQuery{
resQuery, err := c.appClient().QuerySync(abci.RequestQuery{
Path: path,
Data: data,
Height: opts.Height,
Expand Down Expand Up @@ -755,7 +756,7 @@ func (c *Client) UnconfirmedTxs(ctx context.Context, limitPtr *int) (*ctypes.Res
//
// If valid, the tx is automatically added to the mempool.
func (c *Client) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
res, err := c.mempool().CheckTxSync(abci.RequestCheckTx{Tx: tx})
res, err := c.appClient().CheckTxSync(abci.RequestCheckTx{Tx: tx})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -810,20 +811,8 @@ func (c *Client) resubscribe(subscriber string, q tmpubsub.Query) types.Subscrip
}
}

func (c *Client) consensus() proxy.AppConnConsensus {
return c.node.ProxyApp().Consensus()
}

func (c *Client) mempool() proxy.AppConnMempool {
return c.node.ProxyApp().Mempool()
}

func (c *Client) query() proxy.AppConnQuery {
return c.node.ProxyApp().Query()
}

func (c *Client) snapshot() proxy.AppConnSnapshot {
return c.node.ProxyApp().Snapshot()
func (c *Client) appClient() abcicli.Client {
return c.node.AppClient()
}

func (c *Client) normalizeHeight(height *int64) uint64 {
Expand Down
21 changes: 9 additions & 12 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
abcicli "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proxy"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/optimint/config"
Expand All @@ -40,14 +40,11 @@ var expectedInfo = abci.ResponseInfo{

var mockTxProcessingTime = 10 * time.Millisecond

func TestConnectionGetters(t *testing.T) {
func TestConnectionGetter(t *testing.T) {
assert := assert.New(t)

_, rpc := getRPC(t)
assert.NotNil(rpc.consensus())
assert.NotNil(rpc.mempool())
assert.NotNil(rpc.snapshot())
assert.NotNil(rpc.query())
assert.NotNil(rpc.appClient())
}

func TestInfo(t *testing.T) {
Expand Down Expand Up @@ -91,7 +88,7 @@ func TestGenesisChunked(t *testing.T) {
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
privKey, _, _ := crypto.GenerateEd25519Key(cryptorand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(cryptorand.Reader)
n, _ := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger())
n, _ := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, signingKey, abcicli.NewLocalClient(nil, mockApp), genDoc, log.TestingLogger())

rpc := NewClient(n)

Expand Down Expand Up @@ -410,7 +407,7 @@ func TestTx(t *testing.T) {
BlockManagerConfig: config.BlockManagerConfig{
BlockTime: 200 * time.Millisecond,
}},
key, signingKey, proxy.NewLocalClientCreator(mockApp),
key, signingKey, abcicli.NewLocalClient(nil, mockApp),
&tmtypes.GenesisDoc{ChainID: "test"},
log.TestingLogger())
require.NoError(err)
Expand Down Expand Up @@ -657,7 +654,7 @@ func TestValidatorSetHandling(t *testing.T) {
waitCh <- nil
})

node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond}}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond}}, key, signingKey, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -777,7 +774,7 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -847,7 +844,7 @@ func TestMempool2Nodes(t *testing.T) {
P2P: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
},
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key1, signingKey1, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node1)

Expand All @@ -857,7 +854,7 @@ func TestMempool2Nodes(t *testing.T) {
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.Pretty(),
},
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key2, signingKey2, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node1)

Expand Down
4 changes: 2 additions & 2 deletions rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (

"github.com/gorilla/rpc/v2/json2"
"github.com/libp2p/go-libp2p/core/crypto"
abciclient "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/optimint/config"
Expand Down Expand Up @@ -290,7 +290,7 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
node, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}}, key, signingKey, abciclient.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
require.NoError(err)
require.NotNil(node)

Expand Down
2 changes: 1 addition & 1 deletion state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (e *BlockExecutor) ApplyBlock(ctx context.Context, state types.State, block
return types.State{}, nil, err
}

// This makes calls to the ProxyApp
// This makes calls to the AppClient
resp, err := e.execute(ctx, state, block)
if err != nil {
return types.State{}, nil, err
Expand Down

0 comments on commit 722b44e

Please sign in to comment.