Skip to content

Commit

Permalink
go: bump tendermint to 0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Jun 16, 2022
1 parent fb171c4 commit 2fac3d8
Show file tree
Hide file tree
Showing 47 changed files with 1,007 additions and 765 deletions.
14 changes: 14 additions & 0 deletions .changelog/4427.cfg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Bump Tendermint Core to 0.35.x

Configuration changes required due to Tendermint changes:

Flags `consensus.tendermint.p2p.max_num_{inbound,outbound}_peers` have
been replaced with a single `consensus.tendermint.p2p.max_connections`.
Flag `consensus.tendermint.state_sync.consensus_node` has been removed,
as it is no longer required.

Previously, when running a sentry node, the node behind the sentry had to
use `consensus.tendermint.p2p.disable_peer_exchange`, but now it must not
use that flag. You must instead set `consensus.tendermint.p2p.max_peers`
and `consensus.tendermint.p2p.max_connections` to 1, and add the sentry
node's Tendermint ID to `consensus.tendermint.p2p.whitelisted_peers`.
1 change: 1 addition & 0 deletions .changelog/4427.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump Tendermint Core to 0.35.x
5 changes: 2 additions & 3 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 Down
14 changes: 10 additions & 4 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,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.GetEventsAsByte()
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 @@ -503,11 +504,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 @@ -795,7 +801,7 @@ 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{
resp.ConsensusParamUpdates = &tmproto.ConsensusParams{
Version: &tmproto.VersionParams{
AppVersion: version.TendermintAppVersion,
},
Expand Down
13 changes: 6 additions & 7 deletions go/consensus/tendermint/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"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"
tmrpctypes "github.com/tendermint/tendermint/rpc/coretypes"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand Down Expand Up @@ -52,7 +51,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) (*tmtypes.NetAddress, error) {
// WARNING: p2p/transport.go:MultiplexTransport.upgrade() uses
// a case sensitive string comparison to validate public keys,
// because tendermint.
Expand All @@ -76,7 +75,7 @@ func NodeToP2PAddr(n *node.Node) (*tmp2p.NetAddress, error) {

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

tmAddr, err := tmp2p.NewNetAddressString(addr)
tmAddr, err := tmtypes.NewNetAddressString(addr)
if err != nil {
return nil, fmt.Errorf("tendermint/api: failed to reformat validator: %w", err)
}
Expand All @@ -91,7 +90,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 +101,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(), string(events.EncodeValue(value)))
}

// Dirty returns true iff the EventBuilder has attributes.
Expand Down Expand Up @@ -140,7 +139,7 @@ func EventTypeForApp(eventApp string) string {
// QueryForApp generates a tmquery.Query for events belonging to the
// specified App.
func QueryForApp(eventApp string) tmpubsub.Query {
return tmquery.MustParse(fmt.Sprintf("%s EXISTS", EventTypeForApp(eventApp)))
return tmquery.MustCompile(fmt.Sprintf("%s EXISTS", EventTypeForApp(eventApp)))
}

// BlockMeta is the Tendermint-specific per-block metadata that is
Expand Down
2 changes: 1 addition & 1 deletion go/consensus/tendermint/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestServiceDescriptor(t *testing.T) {
require := require.New(t)

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

sd := NewStaticServiceDescriptor("test", "test_type", []tmpubsub.Query{q1})
require.Equal("test", sd.Name())
Expand Down
43 changes: 41 additions & 2 deletions go/consensus/tendermint/api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,45 @@ func (c *Context) GetEvents() []types.Event {
return c.events
}

// LegacyEventAttribute is the pre-0.35 tendermint format for event attributes.
// The pre-0.35 versions used []byte for the keys and values, while 0.35 and
// later use strings.
type LegacyEventAttribute struct {
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
Index bool `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"`
}

// LegacyEvent is the pre-0.35 tendermint format for events.
type LegacyEvent struct {
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
Attributes []LegacyEventAttribute `protobuf:"bytes,2,rep,name=attributes,proto3" json:"attributes,omitempty"`
}

// GetEventsAsByte returns the ABCI event vector corresponding to the tags
// using the legacy Tendermint representation (this is only used in abci/mux.go).
func (c *Context) GetEventsAsByte() []LegacyEvent {
// Convert the new representation into the old one.
evs := c.GetEvents()
out := make([]LegacyEvent, 0, len(evs))
for _, ev := range evs {
nev := LegacyEvent{
Type: ev.Type,
Attributes: make([]LegacyEventAttribute, 0, len(ev.Attributes)),
}
for _, attr := range ev.Attributes {
nattr := LegacyEventAttribute{
Key: []byte(attr.Key),
Value: []byte(attr.Value),
Index: attr.Index,
}
nev.Attributes = append(nev.Attributes, nattr)
}
out = append(out, nev)
}
return out
}

// hasEvent checks if a specific event has been emitted.
func (c *Context) hasEvent(app string, key []byte) bool {
evType := EventTypeForApp(app)
Expand All @@ -339,7 +378,7 @@ func (c *Context) hasEvent(app string, key []byte) bool {
}

for _, pair := range ev.Attributes {
if bytes.Equal(pair.GetKey(), key) {
if bytes.Equal([]byte(pair.GetKey()), key) {
return true
}
}
Expand All @@ -357,7 +396,7 @@ func (c *Context) DecodeEvent(index int, ev events.TypedAttribute) error {
raw := c.events[index]
for _, pair := range raw.Attributes {
if events.IsAttributeKind(pair.GetKey(), ev) {
return events.DecodeValue(string(pair.GetValue()), ev)
return events.DecodeValue(pair.GetValue(), ev)
}
}
return fmt.Errorf("incompatible event")
Expand Down
21 changes: 7 additions & 14 deletions go/consensus/tendermint/api/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sort"
"time"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
Expand Down Expand Up @@ -47,11 +46,6 @@ func GetTendermintGenesisDocument(provider genesis.Provider) (*tmtypes.GenesisDo
return nil, fmt.Errorf("tendermint: failed to create genesis document: %w", err)
}

// HACK: Certain test cases use TimeoutCommit < 1 sec, and care about the
// BFT view of time pulling ahead.
timeoutCommit := doc.Consensus.Parameters.TimeoutCommit
tmGenDoc.ConsensusParams.Block.TimeIotaMs = int64(timeoutCommit / time.Millisecond)

return tmGenDoc, nil
}

Expand Down Expand Up @@ -113,7 +107,7 @@ func genesisToTendermint(d *genesis.Document) (*tmtypes.GenesisDoc, error) {
return nil, fmt.Errorf("tendermint: unable to determine epoch interval")
}

var evCfg tmproto.EvidenceParams
var evCfg tmtypes.EvidenceParams
evCfg.MaxBytes = int64(d.Consensus.Parameters.MaxEvidenceSize)
evCfg.MaxAgeNumBlocks = debondingInterval * epochInterval
evCfg.MaxAgeDuration = time.Duration(evCfg.MaxAgeNumBlocks) * (d.Consensus.Parameters.TimeoutCommit + 1*time.Second)
Expand All @@ -122,17 +116,16 @@ func genesisToTendermint(d *genesis.Document) (*tmtypes.GenesisDoc, error) {
ChainID: d.ChainContext()[:tmtypes.MaxChainIDLen],
GenesisTime: d.Time,
InitialHeight: d.Height,
ConsensusParams: &tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: int64(d.Consensus.Parameters.MaxBlockSize),
MaxGas: maxBlockGas,
TimeIotaMs: 1000,
ConsensusParams: &tmtypes.ConsensusParams{
Block: tmtypes.BlockParams{
MaxBytes: int64(d.Consensus.Parameters.MaxBlockSize),
MaxGas: maxBlockGas,
},
Evidence: evCfg,
Validator: tmproto.ValidatorParams{
Validator: tmtypes.ValidatorParams{
PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeEd25519},
},
Version: tmproto.VersionParams{
Version: tmtypes.VersionParams{
AppVersion: version.TendermintAppVersion,
},
},
Expand Down
2 changes: 1 addition & 1 deletion go/consensus/tendermint/apps/roothash/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ var (
// limited to a specific runtime.
func QueryForRuntime(runtimeID common.Namespace) tmpubsub.Query {
ev := roothash.RuntimeIDAttribute{ID: runtimeID}
return tmquery.MustParse(fmt.Sprintf("%s AND %s.%s='%s'", QueryApp, EventType, ev.EventKind(), ev.EventValue()))
return tmquery.MustCompile(fmt.Sprintf("%s AND %s.%s='%s'", QueryApp, EventType, ev.EventKind(), ev.EventValue()))
}
24 changes: 12 additions & 12 deletions go/consensus/tendermint/apps/staking/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,22 @@ func TestRewardAndSlash(t *testing.T) {
require.Equal(abciAPI.EventTypeForApp(AppName), ev.Type, "all emitted events should be staking events")
require.Len(ev.Attributes, 1, "each event should have a single attribute")

switch string(ev.Attributes[0].Key) {
switch ev.Attributes[0].Key {
case "add_escrow":
var v staking.AddEscrowEvent
err = events.DecodeValue(string(ev.Attributes[0].Value), &v)
err = events.DecodeValue(ev.Attributes[0].Value, &v)
require.NoError(err, "malformed add escrow event")
case "transfer":
var v staking.TransferEvent
err = events.DecodeValue(string(ev.Attributes[0].Value), &v)
err = events.DecodeValue(ev.Attributes[0].Value, &v)
require.NoError(err, "malformed transfer event")
default:
t.Fatalf("unexpected event key: %+v", ev.Attributes[0].Key)
}
}
require.Equal("add_escrow", string(evs[0].Attributes[0].Key), "first event should be an add escrow event")
require.Equal("transfer", string(evs[1].Attributes[0].Key), "second event should be a transfer event")
require.Equal("add_escrow", string(evs[2].Attributes[0].Key), "second event should be an add escrow event")
require.Equal("add_escrow", evs[0].Attributes[0].Key, "first event should be an add escrow event")
require.Equal("transfer", evs[1].Attributes[0].Key, "second event should be a transfer event")
require.Equal("add_escrow", evs[2].Attributes[0].Key, "second event should be an add escrow event")

// 100% gain.
delegatorAccount, err = s.Account(ctx, delegatorAddr)
Expand Down Expand Up @@ -371,22 +371,22 @@ func TestRewardAndSlash(t *testing.T) {
require.Equal(abciAPI.EventTypeForApp(AppName), ev.Type, "all emitted events should be staking events")
require.Len(ev.Attributes, 1, "each event should have a single attribute")

switch string(ev.Attributes[0].Key) {
switch ev.Attributes[0].Key {
case "add_escrow":
var v staking.AddEscrowEvent
err = events.DecodeValue(string(ev.Attributes[0].Value), &v)
err = events.DecodeValue(ev.Attributes[0].Value, &v)
require.NoError(err, "malformed add escrow event")
case "transfer":
var v staking.TransferEvent
err = events.DecodeValue(string(ev.Attributes[0].Value), &v)
err = events.DecodeValue(ev.Attributes[0].Value, &v)
require.NoError(err, "malformed transfer event")
default:
t.Fatalf("unexpected event key: %+v", ev.Attributes[0].Key)
}
}
require.Equal("add_escrow", string(evs[0].Attributes[0].Key), "first event should be an add escrow event")
require.Equal("transfer", string(evs[1].Attributes[0].Key), "second event should be a transfer event")
require.Equal("add_escrow", string(evs[2].Attributes[0].Key), "second event should be an add escrow event")
require.Equal("add_escrow", evs[0].Attributes[0].Key, "first event should be an add escrow event")
require.Equal("transfer", evs[1].Attributes[0].Key, "second event should be a transfer event")
require.Equal("add_escrow", evs[2].Attributes[0].Key, "second event should be an add escrow event")

// 5% gain.
escrowAccount, err = s.Account(ctx, escrowAddr)
Expand Down
11 changes: 7 additions & 4 deletions go/consensus/tendermint/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ func (sc *serviceClient) DeliverBlock(ctx context.Context, height int64) error {

func (sc *serviceClient) DeliverEvent(ctx context.Context, height int64, tx tmtypes.Tx, ev *tmabcitypes.Event) error {
for _, pair := range ev.GetAttributes() {
if events.IsAttributeKind(pair.GetKey(), &beaconAPI.EpochEvent{}) {
key := pair.GetKey()
val := pair.GetValue()

if events.IsAttributeKind(key, &beaconAPI.EpochEvent{}) {
var event beaconAPI.EpochEvent
if err := events.DecodeValue(string(pair.GetValue()), &event); err != nil {
if err := events.DecodeValue(val, &event); err != nil {
sc.logger.Error("epochtime: malformed epoch event value",
"err", err,
)
Expand All @@ -296,9 +299,9 @@ func (sc *serviceClient) DeliverEvent(ctx context.Context, height int64, tx tmty
sc.epochNotifier.Broadcast(event.Epoch)
}
}
if events.IsAttributeKind(pair.GetKey(), &beaconAPI.VRFEvent{}) {
if events.IsAttributeKind(key, &beaconAPI.VRFEvent{}) {
var event beaconAPI.VRFEvent
if err := events.DecodeValue(string(pair.GetValue()), &event); err != nil {
if err := events.DecodeValue(val, &event); err != nil {
sc.logger.Error("beacon: malformed VRF event",
"err", err,
)
Expand Down
Loading

0 comments on commit 2fac3d8

Please sign in to comment.