From cfac491edb4e926ea1d7eebff2ea466eb7133c0e Mon Sep 17 00:00:00 2001 From: Jaynti Kanani Date: Sat, 15 Feb 2020 15:36:53 +0530 Subject: [PATCH] check bor chain id for commit span and state --- consensus/bor/bor.go | 20 ++++++++++++++++++++ consensus/bor/clerk.go | 1 + 2 files changed, 21 insertions(+) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index e6d39fd7a3..0daf9353b0 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -1048,6 +1048,15 @@ func (c *Bor) commitSpan( return err } + // check if chain id matches with heimdall span + if heimdallSpan.ChainID != c.chainConfig.ChainID.String() { + return fmt.Errorf( + "Chain id proposed span, %s, and bor chain id, %s, doesn't match", + heimdallSpan.ChainID, + c.chainConfig.ChainID, + ) + } + // get validators bytes var validators []MinimalVal for _, val := range heimdallSpan.ValidatorSet.Validators { @@ -1167,11 +1176,22 @@ func (c *Bor) CommitStates( if err := json.Unmarshal(response.Result, &eventRecord); err != nil { return err } + + // check if chain id matches with event record + if eventRecord.ChainID != "" && eventRecord.ChainID != c.chainConfig.ChainID.String() { + return fmt.Errorf( + "Chain id proposed state in span, %s, and bor chain id, %s, doesn't match", + eventRecord.ChainID, + c.chainConfig.ChainID, + ) + } + log.Info("→ committing new state", "id", eventRecord.ID, "contract", eventRecord.Contract, "data", hex.EncodeToString(eventRecord.Data), "txHash", eventRecord.TxHash, + "chainID", eventRecord.ChainID, ) recordBytes, err := rlp.EncodeToBytes(eventRecord) diff --git a/consensus/bor/clerk.go b/consensus/bor/clerk.go index b97148e0ca..adcbfb78b4 100644 --- a/consensus/bor/clerk.go +++ b/consensus/bor/clerk.go @@ -12,4 +12,5 @@ type EventRecord struct { Data hexutil.Bytes `json:"data" yaml:"data"` TxHash common.Hash `json:"tx_hash" yaml:"tx_hash"` LogIndex uint64 `json:"log_index" yaml:"log_index"` + ChainID string `json:"bor_chain_id" yaml:"bor_chain_id"` }