Skip to content

Commit

Permalink
go/consensus/api: delay Block.Meta decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Dec 23, 2019
1 parent 329e023 commit fbed77b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"

beacon "github.com/oasislabs/oasis-core/go/beacon/api"
"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/errors"
"github.com/oasislabs/oasis-core/go/common/node"
Expand Down Expand Up @@ -73,7 +74,7 @@ type Block struct {
// Height contains the block height.
Height int64 `json:"height"`
// Meta contains the consensus backend specific block metadata.
Meta interface{} `json:"meta"`
Meta cbor.RawMessage `json:"meta"`
}

// Backend is an interface that a consensus backend must provide.
Expand Down
12 changes: 8 additions & 4 deletions go/consensus/tendermint/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
tmp2p "github.com/tendermint/tendermint/p2p"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/node"
consensus "github.com/oasislabs/oasis-core/go/consensus/api"
Expand Down Expand Up @@ -140,11 +141,14 @@ type BlockMeta struct {

// NewBlock creates a new consensus.Block from a Tendermint block.
func NewBlock(blk *tmtypes.Block) *consensus.Block {
meta := BlockMeta{
Header: &blk.Header,
LastCommit: blk.LastCommit,
}
rawMeta := cbor.Marshal(meta)

return &consensus.Block{
Height: blk.Header.Height,
Meta: BlockMeta{
Header: &blk.Header,
LastCommit: blk.LastCommit,
},
Meta: rawMeta,
}
}

0 comments on commit fbed77b

Please sign in to comment.