diff --git a/core/blockchain.go b/core/blockchain.go index 4371d257c..7e6a36ae6 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1137,6 +1137,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { return n, errors.New("proposed cross links are not sorted") } for _, crossLink := range *crossLinks { + utils.Logger().Info().Interface("crosslink", crossLink).Msg("hehehe") bc.WriteCrossLinks(types.CrossLinks{crossLink}, false) bc.WriteShardLastCrossLink(crossLink.ShardID(), crossLink) } diff --git a/core/types/block.go b/core/types/block.go index 633d09ebb..bc1adc942 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -301,10 +301,14 @@ func CopyHeader(h *Header) *Header { cpy.Vdf = make([]byte, len(h.Vdf)) copy(cpy.Vdf, h.Vdf) } - //if len(h.CrossLinks) > 0 { - // cpy.CrossLinks = make([]byte, len(h.CrossLinks)) - // copy(cpy.CrossLinks, h.CrossLinks) - //} + if len(h.CrossLinks) > 0 { + cpy.CrossLinks = make([]byte, len(h.CrossLinks)) + copy(cpy.CrossLinks, h.CrossLinks) + } + if len(h.LastCommitBitmap) > 0 { + cpy.LastCommitBitmap = make([]byte, len(h.LastCommitBitmap)) + copy(cpy.LastCommitBitmap, h.LastCommitBitmap) + } return &cpy } diff --git a/core/types/cx_receipt.go b/core/types/cx_receipt.go index 09bf0e6f5..23fb35e24 100644 --- a/core/types/cx_receipt.go +++ b/core/types/cx_receipt.go @@ -132,7 +132,6 @@ func (cxp *CXReceiptsProof) GetToShardID() (uint32, error) { } // IsValidCXReceiptsProof checks whether the given CXReceiptsProof is consistency with itself -// Remaining to check whether there is a corresonding block finalized func (cxp *CXReceiptsProof) IsValidCXReceiptsProof() error { toShardID, err := cxp.GetToShardID() if err != nil { diff --git a/node/node_cross_shard.go b/node/node_cross_shard.go index 9deb741fa..3b7ff2142 100644 --- a/node/node_cross_shard.go +++ b/node/node_cross_shard.go @@ -101,10 +101,26 @@ func (node *Node) verifyIncomingReceipts(block *types.Block) error { if _, ok := m[hash]; ok { return ctxerror.New("[verifyIncomingReceipts] Double Spent!") } - m[hash] = true + + sourceShardID := cxp.MerkleProof.ShardID + sourceBlockNum := cxp.MerkleProof.BlockNum + beaconChain := node.Beaconchain() // TODO: read from real beacon chain + crossLink, err := beaconChain.ReadCrossLink(sourceShardID, sourceBlockNum.Uint64(), false) + if err == nil { + // verify the source block hash is from a finalized block + if crossLink.ChainHeader.Hash() == cxp.MerkleProof.BlockHash && crossLink.ChainHeader.OutgoingReceiptHash == cxp.MerkleProof.CXReceiptHash { + utils.Logger().Debug().Msg("hehe00") + continue + } else { + utils.Logger().Debug().Msg("hehe11") + return ctxerror.New("[verifyIncomingReceipts] crosslink verification failed") + } + } else { + utils.Logger().Debug().Msg("hehe22") + return ctxerror.New("[verifyIncomingReceipts] crosslink not exists yet") + } } - // TODO: add crosslink blockHeaderHash checking return nil } diff --git a/node/node_newblock.go b/node/node_newblock.go index 1ba70612d..8ef2efcc1 100644 --- a/node/node_newblock.go +++ b/node/node_newblock.go @@ -216,18 +216,6 @@ func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof { m := make(map[common.Hash]bool) for _, cxp := range node.pendingCXReceipts { - //sourceShardID := cxp.MerkleProof.ShardID - //sourceBlockNum := cxp.MerkleProof.BlockNum - // - // beaconChain := node.Blockchain() // TODO: read from real beacon chain - // crossLink, err := beaconChain.ReadCrossLink(sourceShardID, sourceBlockNum.Uint64(), false) - // if err == nil { - // // verify the source block hash is from a finalized block - // if crossLink.ChainHeader.Hash() == cxp.MerkleProof.BlockHash && crossLink.ChainHeader.OutgoingReceiptHash == cxp.MerkleProof.CXReceiptHash { - // receiptsList = append(receiptsList, cxp.Receipts) - // } - // } - // check double spent if node.Blockchain().IsSpent(cxp) { continue @@ -240,8 +228,23 @@ func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof { m[hash] = true } - // TODO: remove it after beacon chain sync is ready, for pass the test only - validReceiptsList = append(validReceiptsList, cxp) + sourceShardID := cxp.MerkleProof.ShardID + sourceBlockNum := cxp.MerkleProof.BlockNum + + beaconChain := node.Beaconchain() // TODO: read from real beacon chain + crossLink, err := beaconChain.ReadCrossLink(sourceShardID, sourceBlockNum.Uint64(), false) + if err == nil { + // verify the source block hash is from a finalized block + if crossLink.ChainHeader.Hash() == cxp.MerkleProof.BlockHash && crossLink.ChainHeader.OutgoingReceiptHash == cxp.MerkleProof.CXReceiptHash { + utils.Logger().Debug().Msg("hehe0") + validReceiptsList = append(validReceiptsList, cxp) + } else { + utils.Logger().Debug().Msg("hehe1") + } + } else { + utils.Logger().Debug().Msg("hehe2") + pendingReceiptsList = append(pendingReceiptsList, cxp) + } } node.pendingCXReceipts = pendingReceiptsList node.pendingCXMutex.Unlock()