Skip to content

Commit

Permalink
Add Chain ID onto the Dymint block and use it instead of the namespac… (
Browse files Browse the repository at this point in the history
#167)

* Add Chain ID onto the Dymint block and use it instead of the namespace-id

* add chain-id to toProto method

* update dymension version
  • Loading branch information
ItzhakBokris authored Dec 22, 2022
1 parent ee6ae99 commit 8ec3b08
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 58 deletions.
14 changes: 6 additions & 8 deletions conv/abci/block.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package abci

import (
"encoding/hex"
"strings"
"time"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand All @@ -20,9 +18,8 @@ func ToABCIHeaderPB(header *types.Header) tmproto.Header {
Block: header.Version.Block,
App: header.Version.App,
},
ChainID: strings.ToUpper(hex.EncodeToString(header.NamespaceID[:])),
Height: int64(header.Height),
Time: time.Unix(0, int64(header.Time)),
Height: int64(header.Height),
Time: time.Unix(0, int64(header.Time)),
LastBlockId: tmproto.BlockID{
Hash: header.LastHeaderHash[:],
PartSetHeader: tmproto.PartSetHeader{
Expand All @@ -39,6 +36,7 @@ func ToABCIHeaderPB(header *types.Header) tmproto.Header {
LastResultsHash: header.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: header.ProposerAddress,
ChainID: header.ChainID,
}
}

Expand All @@ -50,9 +48,8 @@ func ToABCIHeader(header *types.Header) tmtypes.Header {
Block: header.Version.Block,
App: header.Version.App,
},
Height: int64(header.Height),
Time: time.Unix(0, int64(header.Time)),
ChainID: strings.ToUpper(hex.EncodeToString(header.NamespaceID[:])),
Height: int64(header.Height),
Time: time.Unix(0, int64(header.Time)),
LastBlockID: tmtypes.BlockID{
Hash: header.LastHeaderHash[:],
PartSetHeader: tmtypes.PartSetHeader{
Expand All @@ -69,6 +66,7 @@ func ToABCIHeader(header *types.Header) tmtypes.Header {
LastResultsHash: header.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: header.ProposerAddress,
ChainID: header.ChainID,
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221219141547-b43279e94b18
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221222094743-771d37d941db
github.com/elastic/gosigar v0.14.2 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/cosmosclient v0.2.0-alpha h1:x8UCXtWyZc7TXw99VH83ld2YD21d5m4fJx5k8zbdFj4=
github.com/dymensionxyz/cosmosclient v0.2.0-alpha/go.mod h1:Fxwqa+T2fG+Q1cK5niy+WE9L1ul1nf1fF6gi3nwCqVE=
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221219141547-b43279e94b18 h1:y7H8mQuHziM67cX0hvo+s6AGpnzL4Q6QgClY7XwIxvo=
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221219141547-b43279e94b18/go.mod h1:hYBEfiA8fOOkQ5H1cmJYfBIH3cVoFmGFqshayV8OQ54=
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221222094743-771d37d941db h1:xuLQHpXwBI0sZKmYiZM1ZBWHKOsDHSJd2SvEgNJHOuU=
github.com/dymensionxyz/dymension v0.1.0-alpha.0.20221222094743-771d37d941db/go.mod h1:3ufLzwMgEhOeQN8O/lSXOjHft/06FofFAEVJoRW9QIE=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
4 changes: 3 additions & 1 deletion proto/types/dymint/dymint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ message Header {
// pubkey can't be recovered by the signature (e.g. ed25519).
bytes proposer_address = 11;


// Hash of block aggregator set, at a time of block creation
bytes aggregators_hash = 12;

// Chain ID the block belongs to
string chain_id = 13;
}

message Commit {
Expand Down
1 change: 1 addition & 0 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las
Block: state.Version.Consensus.Block,
App: state.Version.Consensus.App,
},
ChainID: e.chainID,
NamespaceID: e.namespaceID,
Height: height,
Time: uint64(time.Now().UTC().UnixNano()),
Expand Down
3 changes: 3 additions & 0 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Header struct {

// Hash of block aggregator set, at a time of block creation
AggregatorsHash [32]byte

// The Chain ID
ChainID string
}

var _ encoding.BinaryMarshaler = &Header{}
Expand Down
8 changes: 3 additions & 5 deletions types/hashing.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"encoding/hex"
"strings"
"time"

tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
Expand All @@ -16,9 +14,8 @@ func (h *Header) Hash() [32]byte {
Block: h.Version.Block,
App: h.Version.App,
},
Height: int64(h.Height),
Time: time.Unix(0, int64(h.Time)),
ChainID: strings.ToUpper(hex.EncodeToString(h.NamespaceID[:])),
Height: int64(h.Height),
Time: time.Unix(0, int64(h.Time)),
LastBlockID: tmtypes.BlockID{
Hash: h.LastHeaderHash[:],
PartSetHeader: tmtypes.PartSetHeader{
Expand All @@ -35,6 +32,7 @@ func (h *Header) Hash() [32]byte {
LastResultsHash: h.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: h.ProposerAddress,
ChainID: h.ChainID,
}
var hash [32]byte
copy(hash[:], abciHeader.Hash())
Expand Down
135 changes: 94 additions & 41 deletions types/pb/dymint/dymint.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (h *Header) ToProto() *pb.Header {
NamespaceId: h.NamespaceID[:],
Height: h.Height,
Time: h.Time,
ChainId: h.ChainID,
LastHeaderHash: h.LastHeaderHash[:],
LastCommitHash: h.LastCommitHash[:],
DataHash: h.DataHash[:],
Expand All @@ -103,6 +104,7 @@ func (h *Header) ToProto() *pb.Header {
func (h *Header) FromProto(other *pb.Header) error {
h.Version.Block = other.Version.Block
h.Version.App = other.Version.App
h.ChainID = other.ChainId
if !safeCopy(h.NamespaceID[:], other.NamespaceId) {
return errors.New("invalid length of 'NamespaceId'")
}
Expand Down

0 comments on commit 8ec3b08

Please sign in to comment.