Fix cross shard bad block issue

pull/1368/head
Rongjian Lan 5 years ago committed by Chao Ma
parent d293e406cc
commit f335e0bb78
  1. 2
      consensus/consensus_service.go
  2. 1
      core/block_validator.go
  3. 1
      core/state_transition.go
  4. 4
      core/types/block.go
  5. 16
      node/node_newblock.go

@ -290,7 +290,7 @@ func (consensus *Consensus) Finalize(chain consensus_engine.ChainReader, header
if err := accumulateRewards(chain, state, header); err != nil {
return nil, ctxerror.New("cannot pay block reward").WithCause(err)
}
header.Root = state.IntermediateRoot(false)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
return types.NewBlock(header, txs, receipts, outcxs, incxs), nil
}

@ -95,6 +95,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
if cxsSha != header.OutgoingReceiptHash {
return fmt.Errorf("invalid cross shard receipt root hash (remote: %x local: %x)", header.OutgoingReceiptHash, cxsSha)
}
// Validate the state root against the received state root and throw
// an error if they don't match.
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {

@ -147,6 +147,7 @@ func ApplyIncomingReceipt(db *state.DB, cxp *types.CXReceiptsProof) {
utils.Logger().Warn().Msg("ApplyIncomingReceipts: Invalid incoming receipt!!")
continue
}
utils.Logger().Info().Msgf("ApplyIncomingReceipts: ADDING BALANCE %d", cx.Amount)
db.AddBalance(*cx.To, cx.Amount)
}
}

@ -210,6 +210,7 @@ type extblock struct {
Header *Header
Txs []*Transaction
Uncles []*Header
IncomingReceipts CXReceiptsProofs
}
// [deprecated by eth/63]
@ -314,7 +315,7 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error {
if err := s.Decode(&eb); err != nil {
return err
}
b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, eb.Txs
b.header, b.uncles, b.transactions, b.incomingReceipts = eb.Header, eb.Uncles, eb.Txs, eb.IncomingReceipts
b.size.Store(common.StorageSize(rlp.ListSize(size)))
return nil
}
@ -325,6 +326,7 @@ func (b *Block) EncodeRLP(w io.Writer) error {
Header: b.header,
Txs: b.transactions,
Uncles: b.uncles,
IncomingReceipts: b.incomingReceipts,
})
}

@ -90,14 +90,6 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
viewID := node.Consensus.GetViewID()
// add aggregated commit signatures from last block, except for the first two blocks
if node.NodeConfig.GetNetworkType() == nodeconfig.Mainnet {
if err = node.Worker.UpdateCurrent(coinbase); err != nil {
utils.Logger().Debug().
Err(err).
Msg("Failed updating worker's state")
continue
}
}
if node.NodeConfig.ShardID == 0 {
crossLinksToPropose, err := node.ProposeCrossLinkDataForBeaconchain()
@ -212,7 +204,8 @@ func (node *Node) proposeLocalShardState(block *types.Block) {
}
func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof {
receiptsList := []*types.CXReceiptsProof{}
validReceiptsList := []*types.CXReceiptsProof{}
pendingReceiptsList := []*types.CXReceiptsProof{}
node.pendingCXMutex.Lock()
sort.Slice(node.pendingCXReceipts, func(i, j int) bool {
@ -232,8 +225,9 @@ func (node *Node) proposeReceiptsProof() []*types.CXReceiptsProof {
// }
// }
// TODO: remove it after beacon chain sync is ready, for pass the test only
receiptsList = append(receiptsList, cxp)
validReceiptsList = append(validReceiptsList, cxp)
}
node.pendingCXReceipts = pendingReceiptsList
node.pendingCXMutex.Unlock()
return receiptsList
return validReceiptsList
}

Loading…
Cancel
Save