diff --git a/block/executor.go b/block/executor.go index 6f6cfc71f..8ac0a7e0d 100644 --- a/block/executor.go +++ b/block/executor.go @@ -5,7 +5,6 @@ import ( "time" proto2 "github.com/gogo/protobuf/proto" - proto "github.com/gogo/protobuf/types" "go.uber.org/multierr" abci "github.com/tendermint/tendermint/abci/types" @@ -17,6 +16,7 @@ import ( "github.com/dymensionxyz/dymint/mempool" "github.com/dymensionxyz/dymint/types" + protoutils "github.com/dymensionxyz/dymint/utils/proto" ) // default minimum block max size allowed. not specific reason to set it to 10K, but we need to avoid no transactions can be included in a block. @@ -167,7 +167,7 @@ func (e *Executor) CreateBlock( Txs: toDymintTxs(mempoolTxs), IntermediateStateRoots: types.IntermediateStateRoots{RawRootsList: nil}, Evidence: types.EvidenceData{Evidence: nil}, - ConsensusMessages: fromProtoMsgSliceToAnySlice(e.consensusMsgQueue.Get()...), + ConsensusMessages: protoutils.FromProtoMsgSliceToAnySlice(e.consensusMsgQueue.Get()...), }, LastCommit: *lastCommit, } @@ -337,23 +337,3 @@ func fromDymintTxs(optiTxs types.Txs) tmtypes.Txs { } return txs } - -func fromProtoMsgToAny(msg proto2.Message) *proto.Any { - theType, err := proto2.Marshal(msg) - if err != nil { - return nil - } - - return &proto.Any{ - TypeUrl: proto2.MessageName(msg), - Value: theType, - } -} - -func fromProtoMsgSliceToAnySlice(msgs ...proto2.Message) []*proto.Any { - result := make([]*proto.Any, len(msgs)) - for i, msg := range msgs { - result[i] = fromProtoMsgToAny(msg) - } - return result -} diff --git a/types/serialization.go b/types/serialization.go index 43bca0d87..8c04fe512 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -175,6 +175,7 @@ func (d *Data) ToProto() *pb.Data { Txs: txsToByteSlices(d.Txs), IntermediateStateRoots: d.IntermediateStateRoots.RawRootsList, Evidence: evidenceToProto(d.Evidence), + ConsensusMessages: d.ConsensusMessages, } } @@ -187,6 +188,7 @@ func (b *Block) FromProto(other *pb.Block) error { b.Data.Txs = byteSlicesToTxs(other.Data.Txs) b.Data.IntermediateStateRoots.RawRootsList = other.Data.IntermediateStateRoots b.Data.Evidence = evidenceFromProto(other.Data.Evidence) + b.Data.ConsensusMessages = other.Data.ConsensusMessages if other.LastCommit != nil { err := b.LastCommit.FromProto(other.LastCommit) if err != nil { diff --git a/types/serialization_test.go b/types/serialization_test.go index 780235585..2ed884500 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -6,14 +6,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + "github.com/dymensionxyz/dymint/block" "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" pb "github.com/dymensionxyz/dymint/types/pb/dymint" + protoutils "github.com/dymensionxyz/dymint/utils/proto" ) func TestBlockSerializationRoundTrip(t *testing.T) { @@ -31,6 +32,10 @@ func TestBlockSerializationRoundTrip(t *testing.T) { h = append(h, h1) } + sequencers := []types.Sequencer{testutil.GenerateSequencer()} + consensusMsgs, err := block.ConsensusMsgsOnSequencerSetUpdate(sequencers) + require.NoError(err) + cases := []struct { name string input *types.Block @@ -57,7 +62,8 @@ func TestBlockSerializationRoundTrip(t *testing.T) { Txs: nil, IntermediateStateRoots: types.IntermediateStateRoots{RawRootsList: [][]byte{{0x1}}}, // TODO(tzdybal): update when we have actual evidence types - Evidence: types.EvidenceData{Evidence: nil}, + Evidence: types.EvidenceData{Evidence: nil}, + ConsensusMessages: protoutils.FromProtoMsgSliceToAnySlice(consensusMsgs...), }, LastCommit: types.Commit{ Height: 8, diff --git a/utils/proto/converters.go b/utils/proto/converters.go index 32c9902a5..1a2073dd0 100644 --- a/utils/proto/converters.go +++ b/utils/proto/converters.go @@ -2,6 +2,7 @@ package proto import ( cosmos "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/proto" gogo "github.com/gogo/protobuf/types" ) @@ -24,3 +25,23 @@ func CosmosToGogo(v *cosmos.Any) *gogo.Any { Value: v.Value, } } + +func FromProtoMsgToAny(msg proto.Message) *gogo.Any { + theType, err := proto.Marshal(msg) + if err != nil { + return nil + } + + return &gogo.Any{ + TypeUrl: proto.MessageName(msg), + Value: theType, + } +} + +func FromProtoMsgSliceToAnySlice(msgs ...proto.Message) []*gogo.Any { + result := make([]*gogo.Any, len(msgs)) + for i, msg := range msgs { + result[i] = FromProtoMsgToAny(msg) + } + return result +}