mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 13:26:23 +00:00
state: proto migration (#4951)
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmversion "github.com/tendermint/tendermint/proto/version"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -333,10 +332,10 @@ func MaxDataBytesUnknownEvidence(maxBytes int64, valsCount int, maxNumEvidence u
|
||||
// - https://github.com/tendermint/spec/blob/master/spec/blockchain/blockchain.md
|
||||
type Header struct {
|
||||
// basic block info
|
||||
Version version.Consensus `json:"version"`
|
||||
ChainID string `json:"chain_id"`
|
||||
Height int64 `json:"height"`
|
||||
Time time.Time `json:"time"`
|
||||
Version tmversion.Consensus `json:"version"`
|
||||
ChainID string `json:"chain_id"`
|
||||
Height int64 `json:"height"`
|
||||
Time time.Time `json:"time"`
|
||||
|
||||
// prev block info
|
||||
LastBlockID BlockID `json:"last_block_id"`
|
||||
@@ -361,7 +360,7 @@ type Header struct {
|
||||
// Populate the Header with state-derived data.
|
||||
// Call this after MakeBlock to complete the Header.
|
||||
func (h *Header) Populate(
|
||||
version version.Consensus, chainID string,
|
||||
version tmversion.Consensus, chainID string,
|
||||
timestamp time.Time, lastBlockID BlockID,
|
||||
valHash, nextValHash []byte,
|
||||
consensusHash, appHash, lastResultsHash []byte,
|
||||
@@ -507,12 +506,13 @@ func (h *Header) ToProto() *tmproto.Header {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &tmproto.Header{
|
||||
Version: tmversion.Consensus{Block: h.Version.App.Uint64(), App: h.Version.App.Uint64()},
|
||||
Version: h.Version,
|
||||
ChainID: h.ChainID,
|
||||
Height: h.Height,
|
||||
Time: h.Time,
|
||||
LastBlockID: h.LastBlockID.ToProto(),
|
||||
LastBlockId: h.LastBlockID.ToProto(),
|
||||
ValidatorsHash: h.ValidatorsHash,
|
||||
NextValidatorsHash: h.NextValidatorsHash,
|
||||
ConsensusHash: h.ConsensusHash,
|
||||
@@ -534,12 +534,12 @@ func HeaderFromProto(ph *tmproto.Header) (Header, error) {
|
||||
|
||||
h := new(Header)
|
||||
|
||||
bi, err := BlockIDFromProto(&ph.LastBlockID)
|
||||
bi, err := BlockIDFromProto(&ph.LastBlockId)
|
||||
if err != nil {
|
||||
return Header{}, err
|
||||
}
|
||||
|
||||
h.Version = version.Consensus{Block: version.Protocol(ph.Version.Block), App: version.Protocol(ph.Version.App)}
|
||||
h.Version = ph.Version
|
||||
h.ChainID = ph.ChainID
|
||||
h.Height = ph.Height
|
||||
h.Time = ph.Time
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/proto/version"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
@@ -175,7 +175,7 @@ func (b *EventBus) PublishEventTx(data EventDataTx) error {
|
||||
|
||||
// add predefined compositeKeys
|
||||
events[EventTypeKey] = append(events[EventTypeKey], EventTx)
|
||||
events[TxHashKey] = append(events[TxHashKey], fmt.Sprintf("%X", data.Tx.Hash()))
|
||||
events[TxHashKey] = append(events[TxHashKey], fmt.Sprintf("%X", Tx(data.Tx).Hash()))
|
||||
events[TxHeightKey] = append(events[TxHeightKey], fmt.Sprintf("%d", data.Height))
|
||||
|
||||
return b.pubsub.PublishWithEvents(ctx, data, events)
|
||||
|
||||
@@ -41,12 +41,12 @@ func TestEventBusPublishEventTx(t *testing.T) {
|
||||
edt := msg.Data().(EventDataTx)
|
||||
assert.Equal(t, int64(1), edt.Height)
|
||||
assert.Equal(t, uint32(0), edt.Index)
|
||||
assert.Equal(t, tx, edt.Tx)
|
||||
assert.EqualValues(t, tx, edt.Tx)
|
||||
assert.Equal(t, result, edt.Result)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
err = eventBus.PublishEventTx(EventDataTx{TxResult{
|
||||
err = eventBus.PublishEventTx(EventDataTx{abci.TxResult{
|
||||
Height: 1,
|
||||
Index: 0,
|
||||
Tx: tx,
|
||||
@@ -183,7 +183,7 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
|
||||
data := msg.Data().(EventDataTx)
|
||||
assert.Equal(t, int64(1), data.Height)
|
||||
assert.Equal(t, uint32(0), data.Index)
|
||||
assert.Equal(t, tx, data.Tx)
|
||||
assert.EqualValues(t, tx, data.Tx)
|
||||
assert.Equal(t, result, data.Result)
|
||||
close(done)
|
||||
case <-time.After(1 * time.Second):
|
||||
@@ -191,7 +191,7 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
err = eventBus.PublishEventTx(EventDataTx{TxResult{
|
||||
err = eventBus.PublishEventTx(EventDataTx{abci.TxResult{
|
||||
Height: 1,
|
||||
Index: 0,
|
||||
Tx: tx,
|
||||
|
||||
@@ -80,7 +80,7 @@ type EventDataNewBlockHeader struct {
|
||||
|
||||
// All txs fire EventDataTx
|
||||
type EventDataTx struct {
|
||||
TxResult
|
||||
abci.TxResult
|
||||
}
|
||||
|
||||
// NOTE: This goes into the replay WAL
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
//-------------------------------------------------------
|
||||
@@ -42,17 +43,14 @@ var TM2PB = tm2pb{}
|
||||
|
||||
type tm2pb struct{}
|
||||
|
||||
func (tm2pb) Header(header *Header) abci.Header {
|
||||
return abci.Header{
|
||||
Version: abci.Version{
|
||||
Block: header.Version.Block.Uint64(),
|
||||
App: header.Version.App.Uint64(),
|
||||
},
|
||||
func (tm2pb) Header(header *Header) tmproto.Header {
|
||||
return tmproto.Header{
|
||||
Version: header.Version,
|
||||
ChainID: header.ChainID,
|
||||
Height: header.Height,
|
||||
Time: header.Time,
|
||||
|
||||
LastBlockId: TM2PB.BlockID(header.LastBlockID),
|
||||
LastBlockId: header.LastBlockID.ToProto(),
|
||||
|
||||
LastCommitHash: header.LastCommitHash,
|
||||
DataHash: header.DataHash,
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
"github.com/tendermint/tendermint/proto/version"
|
||||
)
|
||||
|
||||
func TestABCIPubKey(t *testing.T) {
|
||||
@@ -105,8 +105,8 @@ func TestABCIHeader(t *testing.T) {
|
||||
cdc := amino.NewCodec()
|
||||
headerBz := cdc.MustMarshalBinaryBare(header)
|
||||
|
||||
pbHeader := TM2PB.Header(header)
|
||||
pbHeaderBz, err := proto.Marshal(&pbHeader)
|
||||
pbHeader := header.ToProto()
|
||||
pbHeaderBz, err := proto.Marshal(pbHeader)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// assert some fields match
|
||||
|
||||
11
types/tx.go
11
types/tx.go
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
@@ -109,13 +108,3 @@ func (tp TxProof) Validate(dataHash []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TxResult contains results of executing the transaction.
|
||||
//
|
||||
// One usage is indexing transaction results.
|
||||
type TxResult struct {
|
||||
Height int64 `json:"height"`
|
||||
Index uint32 `json:"index"`
|
||||
Tx Tx `json:"tx"`
|
||||
Result abci.ResponseDeliverTx `json:"result"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user