Skip to content

Commit

Permalink
go: Bump CometBFT to v0.37.1
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Jun 13, 2023
1 parent 6759903 commit 5523600
Show file tree
Hide file tree
Showing 66 changed files with 508 additions and 507 deletions.
1 change: 1 addition & 0 deletions .changelog/5280.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go: Bump CometBFT to v0.37.1
4 changes: 2 additions & 2 deletions go/common/crypto/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"
"hash"

tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmtbytes "github.com/cometbft/cometbft/libs/bytes"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
)
Expand Down Expand Up @@ -151,7 +151,7 @@ func NewFromBytes(data ...[]byte) (h Hash) {

// LoadFromHexBytes creates a new hash by loading it from the given Tendermint
// HexBytes byte array.
func LoadFromHexBytes(data tmbytes.HexBytes) (h Hash) {
func LoadFromHexBytes(data cmtbytes.HexBytes) (h Hash) {
_ = h.UnmarshalBinary(data[:])
return
}
Expand Down
11 changes: 5 additions & 6 deletions go/consensus/api/events/events.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package events

import (
"bytes"
"encoding/base64"
"fmt"

Expand All @@ -28,8 +27,8 @@ type CustomTypedAttribute interface {
}

// IsAttributeKind checks whether the given attribute key corresponds to the passed typed attribute.
func IsAttributeKind(key []byte, kind TypedAttribute) bool {
return bytes.Equal(key, []byte(kind.EventKind()))
func IsAttributeKind(key string, kind TypedAttribute) bool {
return key == kind.EventKind()
}

// DecodeValue decodes the attribute event value.
Expand All @@ -47,11 +46,11 @@ func DecodeValue(value string, ev TypedAttribute) error {
}

// EncodeValue encodes the attribute event value.
func EncodeValue(ev TypedAttribute) []byte {
func EncodeValue(ev TypedAttribute) string {
// Use custom decode if this is a custom typed attribute.
if cta, ok := ev.(CustomTypedAttribute); ok {
return []byte(cta.EventValue())
return cta.EventValue()
}
// Otherwise default to base64 encoded CBOR marshalled value.
return []byte(base64.StdEncoding.EncodeToString(cbor.Marshal(ev)))
return base64.StdEncoding.EncodeToString(cbor.Marshal(ev))
}
22 changes: 14 additions & 8 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"sync/atomic"
"time"

"github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand Down Expand Up @@ -349,11 +349,12 @@ func (mux *abciMux) InitChain(req types.RequestInitChain) types.ResponseInitChai
}
}

mux.logger.Debug("InitChain: initializing of applications complete", "num_collected_events", len(ctx.GetEvents()))
events := ctx.GetEvents()
mux.logger.Debug("InitChain: initializing of applications complete", "num_collected_events", len(events))

// Since returning emitted events doesn't work for InitChain() response yet,
// we store those and return them in BeginBlock().
evBinary := cbor.Marshal(ctx.GetEvents())
evBinary := cbor.Marshal(events)
err = ctx.State().Insert(ctx, []byte(stateKeyInitChainEvents), evBinary)
if err != nil {
panic(err)
Expand Down Expand Up @@ -506,11 +507,16 @@ func (mux *abciMux) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginB

func (mux *abciMux) decodeTx(ctx *api.Context, rawTx []byte) (*transaction.Transaction, *transaction.SignedTransaction, error) {
if mux.state.haltMode {
ctx.Logger().Debug("executeTx: in halt, rejecting all transactions")
ctx.Logger().Debug("decodeTx: in halt, rejecting all transactions")
return nil, nil, fmt.Errorf("halt mode, rejecting all transactions")
}

params := mux.state.ConsensusParameters()
if params == nil {
ctx.Logger().Debug("decodeTx: state not yet initialized")
return nil, nil, consensus.ErrNoCommittedBlocks
}

if params.MaxTxSize > 0 && uint64(len(rawTx)) > params.MaxTxSize {
// This deliberately avoids logging the rawTx since spamming the
// logs is also bad.
Expand Down Expand Up @@ -799,9 +805,9 @@ func (mux *abciMux) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
resp.Events = ctx.GetEvents()

// Update version to what we are actually running.
resp.ConsensusParamUpdates = &types.ConsensusParams{
Version: &tmproto.VersionParams{
AppVersion: version.TendermintAppVersion,
resp.ConsensusParamUpdates = &cmtproto.ConsensusParams{
Version: &cmtproto.VersionParams{
App: version.TendermintAppVersion,
},
}

Expand Down
2 changes: 1 addition & 1 deletion go/consensus/tendermint/abci/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sync"
"time"

"github.com/cometbft/cometbft/abci/types"
"github.com/eapache/channels"
"github.com/tendermint/tendermint/abci/types"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common"
Expand Down
66 changes: 33 additions & 33 deletions go/consensus/tendermint/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"fmt"
"strings"

"github.com/tendermint/tendermint/abci/types"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
tmp2p "github.com/tendermint/tendermint/p2p"
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cometbft/cometbft/abci/types"
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
cmtquery "github.com/cometbft/cometbft/libs/pubsub/query"
cmtp2p "github.com/cometbft/cometbft/p2p"
cmtcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
Expand Down Expand Up @@ -41,8 +41,8 @@ func PublicKeyToValidatorUpdate(id signature.PublicKey, power int64) types.Valid
pk, _ := id.MarshalBinary()

return types.ValidatorUpdate{
PubKey: tmcrypto.PublicKey{
Sum: &tmcrypto.PublicKey_Ed25519{
PubKey: cmtcrypto.PublicKey{
Sum: &cmtcrypto.PublicKey_Ed25519{
Ed25519: pk,
},
},
Expand All @@ -52,7 +52,7 @@ func PublicKeyToValidatorUpdate(id signature.PublicKey, power int64) types.Valid

// NodeToP2PAddr converts an Oasis node descriptor to a tendermint p2p
// address book entry.
func NodeToP2PAddr(n *node.Node) (*tmp2p.NetAddress, error) {
func NodeToP2PAddr(n *node.Node) (*cmtp2p.NetAddress, error) {
// WARNING: p2p/transport.go:MultiplexTransport.upgrade() uses
// a case sensitive string comparison to validate public keys,
// because tendermint.
Expand All @@ -76,7 +76,7 @@ func NodeToP2PAddr(n *node.Node) (*tmp2p.NetAddress, error) {

addr := pubKeyAddrHex + "@" + string(coreAddress)

tmAddr, err := tmp2p.NewNetAddressString(addr)
tmAddr, err := cmtp2p.NewNetAddressString(addr)
if err != nil {
return nil, fmt.Errorf("tendermint/api: failed to reformat validator: %w", err)
}
Expand All @@ -91,7 +91,7 @@ type EventBuilder struct {
}

// attribute appends a key/value pair to the event.
func (bld *EventBuilder) attribute(key, value []byte) *EventBuilder {
func (bld *EventBuilder) attribute(key, value string) *EventBuilder {
bld.ev.Attributes = append(bld.ev.Attributes, types.EventAttribute{
Key: key,
Value: value,
Expand All @@ -102,7 +102,7 @@ func (bld *EventBuilder) attribute(key, value []byte) *EventBuilder {

// TypedAttribute appends a typed attribute to the event.
func (bld *EventBuilder) TypedAttribute(value events.TypedAttribute) *EventBuilder {
return bld.attribute([]byte(value.EventKind()), events.EncodeValue(value))
return bld.attribute(value.EventKind(), events.EncodeValue(value))
}

// Dirty returns true iff the EventBuilder has attributes.
Expand Down Expand Up @@ -137,23 +137,23 @@ func EventTypeForApp(eventApp string) string {
return "oasis_event_" + eventApp
}

// QueryForApp generates a tmquery.Query for events belonging to the
// QueryForApp generates a cmtquery.Query for events belonging to the
// specified App.
func QueryForApp(eventApp string) tmpubsub.Query {
return tmquery.MustParse(fmt.Sprintf("%s EXISTS", EventTypeForApp(eventApp)))
func QueryForApp(eventApp string) cmtpubsub.Query {
return cmtquery.MustParse(fmt.Sprintf("%s EXISTS", EventTypeForApp(eventApp)))
}

// BlockMeta is the Tendermint-specific per-block metadata that is
// exposed via the consensus API.
type BlockMeta struct {
// Header is the Tendermint block header.
Header *tmtypes.Header `json:"header"`
Header *cmttypes.Header `json:"header"`
// LastCommit is the Tendermint last commit info.
LastCommit *tmtypes.Commit `json:"last_commit"`
LastCommit *cmttypes.Commit `json:"last_commit"`
}

// NewBlock creates a new consensus.Block from a Tendermint block.
func NewBlock(blk *tmtypes.Block) *consensus.Block {
func NewBlock(blk *cmttypes.Block) *consensus.Block {
meta := BlockMeta{
Header: &blk.Header,
LastCommit: blk.LastCommit,
Expand Down Expand Up @@ -198,15 +198,15 @@ type Backend interface {
SetTransactionAuthHandler(TransactionAuthHandler) error

// GetBlock returns the Tendermint block at the specified height.
GetTendermintBlock(ctx context.Context, height int64) (*tmtypes.Block, error)
GetTendermintBlock(ctx context.Context, height int64) (*cmttypes.Block, error)

// GetBlockResults returns the ABCI results from processing a block
// at a specific height.
GetBlockResults(ctx context.Context, height int64) (*tmrpctypes.ResultBlockResults, error)
GetBlockResults(ctx context.Context, height int64) (*cmtrpctypes.ResultBlockResults, error)

// WatchTendermintBlocks returns a stream of Tendermint blocks as they are
// returned via the `EventDataNewBlock` query.
WatchTendermintBlocks() (<-chan *tmtypes.Block, *pubsub.Subscription, error)
WatchTendermintBlocks() (<-chan *cmttypes.Block, *pubsub.Subscription, error)

// GetLastRetainedVersion returns the earliest retained version the ABCI
// state.
Expand Down Expand Up @@ -258,8 +258,8 @@ type TransactionAuthHandler interface {

// ServiceEvent is a Tendermint-specific consensus.ServiceEvent.
type ServiceEvent struct {
Block *tmtypes.EventDataNewBlockHeader `json:"block,omitempty"`
Tx *tmtypes.EventDataTx `json:"tx,omitempty"`
Block *cmttypes.EventDataNewBlockHeader `json:"block,omitempty"`
Tx *cmttypes.EventDataTx `json:"tx,omitempty"`
}

// ServiceDescriptor is a Tendermint consensus service descriptor.
Expand All @@ -271,7 +271,7 @@ type ServiceDescriptor interface {
EventType() string

// Queries returns a channel that emits queries that need to be subscribed to.
Queries() <-chan tmpubsub.Query
Queries() <-chan cmtpubsub.Query

// Commands returns a channel that emits commands for the service client.
Commands() <-chan interface{}
Expand All @@ -280,7 +280,7 @@ type ServiceDescriptor interface {
type serviceDescriptor struct {
name string
eventType string
queryCh <-chan tmpubsub.Query
queryCh <-chan cmtpubsub.Query
cmdCh <-chan interface{}
}

Expand All @@ -292,7 +292,7 @@ func (sd *serviceDescriptor) EventType() string {
return sd.eventType
}

func (sd *serviceDescriptor) Queries() <-chan tmpubsub.Query {
func (sd *serviceDescriptor) Queries() <-chan cmtpubsub.Query {
return sd.queryCh
}

Expand All @@ -301,7 +301,7 @@ func (sd *serviceDescriptor) Commands() <-chan interface{} {
}

// NewServiceDescriptor creates a new consensus service descriptor.
func NewServiceDescriptor(name, eventType string, queryCh <-chan tmpubsub.Query, cmdCh <-chan interface{}) ServiceDescriptor {
func NewServiceDescriptor(name, eventType string, queryCh <-chan cmtpubsub.Query, cmdCh <-chan interface{}) ServiceDescriptor {
return &serviceDescriptor{
name: name,
eventType: eventType,
Expand All @@ -311,8 +311,8 @@ func NewServiceDescriptor(name, eventType string, queryCh <-chan tmpubsub.Query,
}

// NewStaticServiceDescriptor creates a new static consensus service descriptor.
func NewStaticServiceDescriptor(name, eventType string, queries []tmpubsub.Query) ServiceDescriptor {
ch := make(chan tmpubsub.Query)
func NewStaticServiceDescriptor(name, eventType string, queries []cmtpubsub.Query) ServiceDescriptor {
ch := make(chan cmtpubsub.Query)
go func() {
defer close(ch)

Expand All @@ -334,7 +334,7 @@ type ServiceClient interface {
DeliverBlock(ctx context.Context, height int64) error

// DeliverEvent delivers an event emitted by the consensus service.
DeliverEvent(ctx context.Context, height int64, tx tmtypes.Tx, ev *types.Event) error
DeliverEvent(ctx context.Context, height int64, tx cmttypes.Tx, ev *types.Event) error

// DeliverCommand delivers a command emitted via the command channel.
DeliverCommand(ctx context.Context, height int64, cmd interface{}) error
Expand All @@ -350,7 +350,7 @@ func (bsc *BaseServiceClient) DeliverBlock(ctx context.Context, height int64) er
}

// DeliverEvent implements ServiceClient.
func (bsc *BaseServiceClient) DeliverEvent(ctx context.Context, height int64, tx tmtypes.Tx, ev *types.Event) error {
func (bsc *BaseServiceClient) DeliverEvent(ctx context.Context, height int64, tx cmttypes.Tx, ev *types.Event) error {
return nil
}

Expand All @@ -377,5 +377,5 @@ var MessageStateSyncCompleted = messageKind(0)

// TendermintChainID returns the Tendermint chain ID computed from chain context.
func TendermintChainID(chainContext string) string {
return chainContext[:tmtypes.MaxChainIDLen]
return chainContext[:cmttypes.MaxChainIDLen]
}
8 changes: 4 additions & 4 deletions go/consensus/tendermint/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (

"github.com/stretchr/testify/require"

tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
cmtquery "github.com/cometbft/cometbft/libs/pubsub/query"
)

func TestServiceDescriptor(t *testing.T) {
require := require.New(t)

q1 := tmquery.MustParse("a='b'")
q1 := cmtquery.MustParse("a='b'")

sd := NewStaticServiceDescriptor("test", "test_type", []tmpubsub.Query{q1})
sd := NewStaticServiceDescriptor("test", "test_type", []cmtpubsub.Query{q1})
require.Equal("test", sd.Name())
require.Equal("test_type", sd.EventType())
recvQ1 := <-sd.Queries()
Expand Down
8 changes: 4 additions & 4 deletions go/consensus/tendermint/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"errors"

tmabcitypes "github.com/tendermint/tendermint/abci/types"
cmtabcitypes "github.com/cometbft/cometbft/abci/types"

"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
genesis "github.com/oasisprotocol/oasis-core/go/genesis/api"
Expand Down Expand Up @@ -89,20 +89,20 @@ type Application interface {
// info from TendermintCore.
//
// Note: Errors are irrecoverable and will result in a panic.
InitChain(*Context, tmabcitypes.RequestInitChain, *genesis.Document) error
InitChain(*Context, cmtabcitypes.RequestInitChain, *genesis.Document) error

// BeginBlock signals the beginning of a block.
//
// Returned tags will be added to the current block.
//
// Note: Errors are irrecoverable and will result in a panic.
BeginBlock(*Context, tmabcitypes.RequestBeginBlock) error
BeginBlock(*Context, cmtabcitypes.RequestBeginBlock) error

// EndBlock signals the end of a block, returning changes to the
// validator set.
//
// Note: Errors are irrecoverable and will result in a panic.
EndBlock(*Context, tmabcitypes.RequestEndBlock) (tmabcitypes.ResponseEndBlock, error)
EndBlock(*Context, cmtabcitypes.RequestEndBlock) (cmtabcitypes.ResponseEndBlock, error)

// Commit is omitted because Applications will work on a cache of
// the state bound to the multiplexer.
Expand Down

0 comments on commit 5523600

Please sign in to comment.