Skip to content

Commit

Permalink
chore: cleanup (#19843)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Mar 26, 2024
1 parent bcb1931 commit d7f3a59
Show file tree
Hide file tree
Showing 52 changed files with 9,583 additions and 2,297 deletions.
6,522 changes: 6,522 additions & 0 deletions api/cosmos/consensus/v1/comet.pulsar.go

Large diffs are not rendered by default.

1,367 changes: 0 additions & 1,367 deletions api/cosmos/consensus/v1/consensus.pulsar.go

This file was deleted.

13 changes: 10 additions & 3 deletions server/v2/core/appmanager/app.go → core/app/app.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appmanager
package app

import (
"time"
Expand All @@ -23,6 +23,8 @@ type BlockRequest[T any] struct {
Height uint64
Time time.Time
Hash []byte
ChainId string
AppHash []byte
Txs []T
ConsensusMessages []transaction.Type
}
Expand Down Expand Up @@ -51,8 +53,13 @@ type ResponseInitChain struct {

type TxResult struct {
Events []event.Event
GasUsed uint64
GasWanted uint64
Resp []transaction.Type
Error error
Code uint32
Data []byte
Log string
Info string
GasWanted uint64
GasUsed uint64
Codespace string
}
2 changes: 1 addition & 1 deletion server/v2/core/appmanager/codec.go → core/app/codec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appmanager
package app

import (
"github.com/cosmos/gogoproto/jsonpb"
Expand Down
3 changes: 3 additions & 0 deletions core/app/identity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package app

var RuntimeIdentity = []byte("runtime")
1 change: 0 additions & 1 deletion go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use (
./x/accounts/defaults/lockup
./server/v2/appmanager
./server/v2/cometbft
./server/v2/core
./server/v2/stf
./server/v2
./runtime/v2
Expand Down
8 changes: 6 additions & 2 deletions runtime/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ func (gm SDKGasMeter) Limit() storetypes.Gas {
}

func (gm SDKGasMeter) ConsumeGas(amount storetypes.Gas, descriptor string) {
gm.gm.Consume(amount, descriptor)
if err := gm.gm.Consume(amount, descriptor); err != nil {
panic(err)
}
}

func (gm SDKGasMeter) RefundGas(amount storetypes.Gas, descriptor string) {
gm.gm.Refund(amount, descriptor)
if err := gm.gm.Refund(amount, descriptor); err != nil {
panic(err)
}
}

func (gm SDKGasMeter) IsPastLimit() bool {
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
coreappmanager "cosmossdk.io/core/app"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
"cosmossdk.io/server/v2/appmanager"
coreappmanager "cosmossdk.io/server/v2/core/appmanager"
"cosmossdk.io/server/v2/stf"
storetypes "cosmossdk.io/store/types"

Expand Down
2 changes: 0 additions & 2 deletions runtime/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ replace (
cosmossdk.io/depinject => ../../depinject
cosmossdk.io/server/v2 => ../../server/v2
cosmossdk.io/server/v2/appmanager => ../../server/v2/appmanager
cosmossdk.io/server/v2/core => ../../server/v2/core
cosmossdk.io/server/v2/stf => ../../server/v2/stf
cosmossdk.io/store/v2 => ../../store
cosmossdk.io/x/accounts => ../../x/accounts
Expand Down Expand Up @@ -39,7 +38,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.3.1
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/core v0.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/stf v0.0.0-00010101000000-000000000000
cosmossdk.io/store v1.1.0
cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000
Expand Down
2 changes: 1 addition & 1 deletion server/v2/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"google.golang.org/protobuf/proto"

_ "cosmossdk.io/api/amino" // Import amino.proto file for reflection
appmanager "cosmossdk.io/core/app"
"cosmossdk.io/log"
"cosmossdk.io/server/v2/api/grpc/gogoreflection"
"cosmossdk.io/server/v2/core/appmanager"
)

const serverName = "grpc-server"
Expand Down
5 changes: 3 additions & 2 deletions server/v2/api/telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
FormatDefault = ""
FormatPrometheus = "prometheus"
FormatText = "text"
ContentTypeText = `text/plain; version=` + expfmt.TextVersion + `; charset=utf-8`

MetricSinkInMem = "mem"
MetricSinkStatsd = "statsd"
Expand Down Expand Up @@ -155,15 +156,15 @@ func (m *Metrics) gatherPrometheus() (GatherResponse, error) {
buf := &bytes.Buffer{}
defer buf.Reset()

e := expfmt.NewEncoder(buf, expfmt.FmtText)
e := expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeTextPlain))

for _, mf := range metricsFamilies {
if err := e.Encode(mf); err != nil {
return GatherResponse{}, fmt.Errorf("failed to encode prometheus metrics: %w", err)
}
}

return GatherResponse{ContentType: string(expfmt.FmtText), Metrics: buf.Bytes()}, nil
return GatherResponse{ContentType: ContentTypeText, Metrics: buf.Bytes()}, nil
}

// gatherGeneric collects generic metrics and returns a GatherResponse.
Expand Down
4 changes: 2 additions & 2 deletions server/v2/appmanager/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"io"

appmanager "cosmossdk.io/core/app"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/server/v2/appmanager/store"
"cosmossdk.io/server/v2/core/appmanager"
"cosmossdk.io/server/v2/stf"
)

Expand Down Expand Up @@ -50,7 +50,7 @@ func (a AppManager[T]) ValidateTx(ctx context.Context, tx T) (appmanager.TxResul
if err != nil {
return appmanager.TxResult{}, err
}
return a.stf.ValidateTx(ctx, latestState, a.config.ValidateTxGasLimit, tx), nil
return a.stf.ValidateTx(ctx, latestState, a.config.ValidateTxGasLimit, tx, nil), nil
}

// Simulate runs validation and execution flow of a Tx.
Expand Down
1 change: 0 additions & 1 deletion server/v2/appmanager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ replace (

require (
cosmossdk.io/core v0.12.0
cosmossdk.io/server/v2/core v0.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/stf v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.9.0
Expand Down
34 changes: 23 additions & 11 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"sync/atomic"

abci "github.com/cometbft/cometbft/abci/types"
"google.golang.org/protobuf/proto"

corecomet "cosmossdk.io/core/comet"
consensusv1 "cosmossdk.io/api/cosmos/consensus/v1"
coreappmgr "cosmossdk.io/core/app"
"cosmossdk.io/core/event"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
Expand All @@ -20,7 +20,6 @@ import (
"cosmossdk.io/server/v2/cometbft/mempool"
"cosmossdk.io/server/v2/cometbft/types"
cometerrors "cosmossdk.io/server/v2/cometbft/types/errors"
coreappmgr "cosmossdk.io/server/v2/core/appmanager"
"cosmossdk.io/server/v2/streaming"
"cosmossdk.io/store/v2/snapshots"
)
Expand Down Expand Up @@ -52,6 +51,8 @@ type Consensus[T transaction.Tx] struct {
processProposalHandler handlers.ProcessHandler[T]
verifyVoteExt handlers.VerifyVoteExtensionhandler
extendVote handlers.ExtendVoteHandler

chainID string
}

func NewConsensus[T transaction.Tx](
Expand Down Expand Up @@ -120,7 +121,6 @@ type BlockData struct {
// CheckTx implements types.Application.
// It is called by cometbft to verify transaction validity
func (c *Consensus[T]) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
// TODO: evaluate here if to return error, or CheckTxResponse.error.
decodedTx, err := c.txCodec.Decode(req.Tx)
if err != nil {
return nil, err
Expand All @@ -132,10 +132,14 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*
}

cometResp := &abci.ResponseCheckTx{
// Code: resp.Code, //TODO: extract error code from resp.Error
Code: resp.Code,
GasWanted: uint64ToInt64(resp.GasWanted),
GasUsed: uint64ToInt64(resp.GasUsed),
Events: intoABCIEvents(resp.Events, c.cfg.IndexEvents),
Info: resp.Info,
Data: resp.Data,
Log: resp.Log,
Codespace: resp.Codespace,
}
if resp.Error != nil {
cometResp.Code = 1
Expand Down Expand Up @@ -219,7 +223,9 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abci.RequestQuery) (*abci
func (c *Consensus[T]) InitChain(ctx context.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
c.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId)

// TODO: won't work for now
c.chainID = req.ChainId

// TODO: populate
return &abci.ResponseInitChain{
ConsensusParams: req.ConsensusParams,
Validators: req.Validators,
Expand Down Expand Up @@ -250,7 +256,6 @@ func (c *Consensus[T]) PrepareProposal(ctx context.Context, req *abci.RequestPre
return nil, err
}

// TODO add bytes method in x/tx or cachetx
encodedTxs := make([][]byte, len(txs))
for i, tx := range txs {
encodedTxs[i] = tx.Bytes()
Expand Down Expand Up @@ -300,8 +305,8 @@ func (c *Consensus[T]) FinalizeBlock(ctx context.Context, req *abci.RequestFinal
}

// for passing consensus info as a consensus message
cometInfo := &types.ConsensusInfo{
Info: corecomet.Info{
cometInfo := &consensusv1.ConsensusMsgCometInfoRequest{
Info: &consensusv1.CometInfo{
Evidence: ToSDKEvidence(req.Misbehavior),
ValidatorsHash: req.NextValidatorsHash,
ProposerAddress: req.ProposerAddress,
Expand All @@ -317,12 +322,19 @@ func (c *Consensus[T]) FinalizeBlock(ctx context.Context, req *abci.RequestFinal
return nil, err
}

cid, err := c.store.LastCommitID()
if err != nil {
return nil, err
}

blockReq := &coreappmgr.BlockRequest[T]{
Height: uint64(req.Height),
Time: req.Time,
Hash: req.Hash,
AppHash: cid.Hash,
ChainId: c.chainID,
Txs: decodedTxs,
ConsensusMessages: []proto.Message{cometInfo},
ConsensusMessages: []transaction.Type{cometInfo},
}

resp, newState, err := c.app.DeliverBlock(ctx, blockReq)
Expand Down Expand Up @@ -358,7 +370,7 @@ func (c *Consensus[T]) FinalizeBlock(ctx context.Context, req *abci.RequestFinal
// remove txs from the mempool
err = c.mempool.Remove(decodedTxs)
if err != nil {
return nil, fmt.Errorf("unable to remove txs: %w", err) // TODO: evaluate what erroring means here, and if we should even error.
return nil, fmt.Errorf("unable to remove txs: %w", err)
}

c.lastCommittedBlock.Store(&BlockData{
Expand Down
3 changes: 2 additions & 1 deletion server/v2/cometbft/client/grpc/cmtservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ func (s queryServer) ABCIQuery(ctx context.Context, req *ABCIQueryRequest) (*ABC

if path := SplitABCIQueryPath(req.Path); len(path) > 0 {
switch path[0] {
case "app", "store", "p2p", "custom": // TODO: check if we can use the ones from abci.go without having circular deps.
case "app", "store", "p2p", "custom":
// valid path
// TODO complete this

default:
// Otherwise, error as to prevent either valid gRPC service requests or
Expand Down
2 changes: 1 addition & 1 deletion server/v2/cometbft/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Config struct {
HaltTime uint64 `mapstructure:"halt_time" toml:"halt_time"`
// end of app.toml config options

AddrPeerFilter types.PeerFilter // filter peers by address and port // TODO:
AddrPeerFilter types.PeerFilter // filter peers by address and port
IdPeerFilter types.PeerFilter // filter peers by node ID

Transport string `mapstructure:"transport" toml:"transport"`
Expand Down
4 changes: 1 addition & 3 deletions server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ replace (
cosmossdk.io/runtime/v2 => ../../../runtime/v2
cosmossdk.io/server/v2 => ../
cosmossdk.io/server/v2/appmanager => ../appmanager
cosmossdk.io/server/v2/core => ../core
cosmossdk.io/server/v2/stf => ../stf
cosmossdk.io/store/v2 => ../../../store
cosmossdk.io/x/accounts => ../../../x/accounts
Expand All @@ -29,15 +28,13 @@ require (
cosmossdk.io/log v1.3.1
cosmossdk.io/server/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/core v0.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/stf v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.38.6
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ics23/go v0.10.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.6.0
Expand Down Expand Up @@ -83,6 +80,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.1.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down
6 changes: 2 additions & 4 deletions server/v2/cometbft/handlers/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/gogoproto/proto" // TODO: use protov2
"github.com/cosmos/gogoproto/proto"

consensusv1 "cosmossdk.io/api/cosmos/consensus/v1"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"

appmanager "cosmossdk.io/core/app"
"cosmossdk.io/server/v2/cometbft/mempool"
"cosmossdk.io/server/v2/core/appmanager"
)

type AppManager[T transaction.Tx] interface {
Expand Down Expand Up @@ -58,7 +58,6 @@ func (h *DefaultProposalHandler[T]) PrepareHandler() PrepareHandler[T] {

defer h.txSelector.Clear()

// TODO: can we assume nil mempool is NoOp?
// If the mempool is nil or NoOp we simply return the transactions
// requested from CometBFT, which, by default, should be in FIFO order.
//
Expand Down Expand Up @@ -112,7 +111,6 @@ func (h *DefaultProposalHandler[T]) ProcessHandler() ProcessHandler[T] {
return nil
}

// TODO: not using this request for now
_, ok := req.(*abci.RequestProcessProposal)
if !ok {
return fmt.Errorf("invalid request type: %T", req)
Expand Down
2 changes: 1 addition & 1 deletion server/v2/cometbft/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/gogoproto/proto" // TODO: use protov2
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
Expand Down
5 changes: 0 additions & 5 deletions server/v2/cometbft/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/spf13/cast"

// "cosmossdk.io/store/v2/db"
"cosmossdk.io/store/v2/snapshots"
snapshottypes "cosmossdk.io/store/v2/snapshots/types"
)
Expand All @@ -29,10 +28,6 @@ func GetSnapshotStore(appOpts types.AppOptions) (*snapshots.Store, error) {
return nil, fmt.Errorf("failed to create snapshots directory: %w", err)
}

// snapshotDB, err := db.NewGoLevelDB("metadata", snapshotDir, nil) // TODO: goleveldb? talk with storage team on if this will change
// if err != nil {
// return nil, err
// }
snapshotStore, err := snapshots.NewStore(snapshotDir)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit d7f3a59

Please sign in to comment.