Skip to content

Commit 9df643f

Browse files
authored
Add Chain ID onto the Rollmint block (#649)
* Add Chain ID onto the Rollmint block since it is necessary for a correct hash
1 parent d5e63f9 commit 9df643f

7 files changed

Lines changed: 110 additions & 45 deletions

File tree

conv/abci/block.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func ToABCIHeaderPB(header *types.Header) (tmproto.Header, error) {
3636
LastResultsHash: header.LastResultsHash[:],
3737
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
3838
ProposerAddress: header.ProposerAddress,
39+
ChainID: header.ChainID,
3940
}, nil
4041
}
4142

@@ -65,6 +66,7 @@ func ToABCIHeader(header *types.Header) (tmtypes.Header, error) {
6566
LastResultsHash: header.LastResultsHash[:],
6667
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
6768
ProposerAddress: header.ProposerAddress,
69+
ChainID: header.ChainID,
6870
}, nil
6971
}
7072

proto/rollmint/rollmint.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ message Header {
5454

5555
// Hash of block aggregator set, at a time of block creation
5656
bytes aggregators_hash = 12;
57+
58+
// Chain ID the block belongs to
59+
string chain_id = 13;
5760
}
5861

5962
message Commit {

state/executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las
9898
Block: state.Version.Consensus.Block,
9999
App: state.Version.Consensus.App,
100100
},
101+
ChainID: e.chainID,
101102
NamespaceID: e.namespaceID,
102103
Height: height,
103104
Time: uint64(time.Now().Unix()), // TODO(tzdybal): how to get TAI64?

types/block.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type Header struct {
4040

4141
// Hash of block aggregator set, at a time of block creation
4242
AggregatorsHash [32]byte
43+
44+
// The Chain ID
45+
ChainID string
4346
}
4447

4548
var _ encoding.BinaryMarshaler = &Header{}

types/hashing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (h *Header) Hash() [32]byte {
3232
LastResultsHash: h.LastResultsHash[:],
3333
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
3434
ProposerAddress: h.ProposerAddress,
35+
ChainID: h.ChainID,
3536
}
3637
var hash [32]byte
3738
copy(hash[:], abciHeader.Hash())

types/pb/rollmint/rollmint.pb.go

Lines changed: 98 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/serialization.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,15 @@ func (h *Header) ToProto() *pb.Header {
199199
LastResultsHash: h.LastResultsHash[:],
200200
ProposerAddress: h.ProposerAddress[:],
201201
AggregatorsHash: h.AggregatorsHash[:],
202+
ChainId: h.ChainID,
202203
}
203204
}
204205

205206
// FromProto fills Header with data from its protobuf representation.
206207
func (h *Header) FromProto(other *pb.Header) error {
207208
h.Version.Block = other.Version.Block
208209
h.Version.App = other.Version.App
210+
h.ChainID = other.ChainId
209211
if !safeCopy(h.NamespaceID[:], other.NamespaceId) {
210212
return errors.New("invalid length of 'NamespaceId'")
211213
}

0 commit comments

Comments
 (0)