diff --git a/core/block_validator.go b/core/block_validator.go index 56cdf5001c..36afb899ea 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -93,11 +93,13 @@ func (v *BlockValidator) ValidateBody(block *types.WorkObject) error { if hash := types.CalcUncleHash(block.Uncles()); hash != header.UncleHash() { return fmt.Errorf("uncle root hash mismatch: have %x, want %x", hash, header.UncleHash()) } - if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash() { - return fmt.Errorf("transaction root hash mismatch: have %x, want %x", hash, header.TxHash()) - } - if hash := types.DeriveSha(block.ExtTransactions(), trie.NewStackTrie(nil)); hash != header.EtxHash() { - return fmt.Errorf("external transaction root hash mismatch: have %x, want %x", hash, header.EtxHash()) + if v.hc.ProcessingState() { + if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash() { + return fmt.Errorf("transaction root hash mismatch: have %x, want %x", hash, header.TxHash()) + } + if hash := types.DeriveSha(block.ExtTransactions(), trie.NewStackTrie(nil)); hash != header.EtxHash() { + return fmt.Errorf("external transaction root hash mismatch: have %x, want %x", hash, header.EtxHash()) + } } } return nil diff --git a/internal/quaiapi/quai_api.go b/internal/quaiapi/quai_api.go index ddf074d659..bbee7ae0e1 100644 --- a/internal/quaiapi/quai_api.go +++ b/internal/quaiapi/quai_api.go @@ -710,9 +710,11 @@ func (s *PublicBlockChainQuaiAPI) ReceiveMinedHeader(ctx context.Context, raw js if err != nil { s.b.Logger().WithField("err", err).Error("Error broadcasting block") } - err = s.b.BroadcastHeader(block, s.b.NodeLocation()) - if err != nil { - s.b.Logger().WithField("err", err).Error("Error broadcasting header") + if nodeCtx == common.ZONE_CTX { + err = s.b.BroadcastHeader(block, s.b.NodeLocation()) + if err != nil { + s.b.Logger().WithField("err", err).Error("Error broadcasting header") + } } } s.b.Logger().WithFields(log.Fields{ diff --git a/p2p/node/api.go b/p2p/node/api.go index ea30606aaf..450369328e 100644 --- a/p2p/node/api.go +++ b/p2p/node/api.go @@ -323,6 +323,7 @@ func (p *P2PNode) handleBroadcast(sourcePeer peer.ID, topic string, data interfa p.cacheAdd(v.Hash(), &v, nodeLocation) log.Global.WithField("context", v.Location().Context()).Print("") // TODO: send it to consensus + case types.WorkObjectHeaderView: case types.Transactions: case types.WorkObjectHeader: default: diff --git a/p2p/pb/proto_services.go b/p2p/pb/proto_services.go index f083966a56..ea9a9924d9 100644 --- a/p2p/pb/proto_services.go +++ b/p2p/pb/proto_services.go @@ -269,7 +269,7 @@ func ConvertAndMarshal(data interface{}) ([]byte, error) { // Unmarshals a protobuf message into a proto type and converts it to a custom go type func UnmarshalAndConvert(data []byte, sourceLocation common.Location, dataPtr *interface{}, datatype interface{}) error { switch datatype.(type) { - case *types.WorkObjectHeaderView, *types.WorkObjectBlockView: + case *types.WorkObjectBlockView: protoWorkObject := &types.ProtoWorkObject{} err := proto.Unmarshal(data, protoWorkObject) if err != nil { @@ -285,6 +285,23 @@ func UnmarshalAndConvert(data []byte, sourceLocation common.Location, dataPtr *i } *dataPtr = *workObject return nil + case *types.WorkObjectHeaderView: + protoWorkObject := &types.ProtoWorkObjectHeaderView{} + err := proto.Unmarshal(data, protoWorkObject) + if err != nil { + return err + } + workObjectHeaderView := &types.WorkObjectHeaderView{} + if protoWorkObject.WoHeader.Location == nil { + return errors.New("location is nil") + } + workObjectHeaderView.WorkObject = &types.WorkObject{} + err = workObjectHeaderView.ProtoDecode(protoWorkObject, sourceLocation) + if err != nil { + return err + } + *dataPtr = *workObjectHeaderView + return nil case *types.WorkObjectHeader: protoWorkObjectHeader := &types.ProtoWorkObjectHeader{} err := proto.Unmarshal(data, protoWorkObjectHeader) diff --git a/quai/p2p_backend.go b/quai/p2p_backend.go index ed28892deb..6bd46c2205 100644 --- a/quai/p2p_backend.go +++ b/quai/p2p_backend.go @@ -89,6 +89,16 @@ func (qbe *QuaiBackend) OnNewBroadcast(sourcePeer p2p.PeerID, topic string, data // TODO: Determine if the block information was lively or stale and rate // the peer accordingly backend.WriteBlock(&data) + case types.WorkObjectHeaderView: + backend := *qbe.GetBackend(nodeLocation) + if backend == nil { + log.Global.Error("no backend found") + return false + } + // Only append this in the case of the slice + if !backend.ProcessingState() && backend.NodeCtx() == common.ZONE_CTX { + backend.WriteBlock(data.ConvertToBlockView().WorkObject) + } case types.Header: case types.Transactions: backend := *qbe.GetBackend(nodeLocation)