Skip to content

Commit

Permalink
Treating the HeaderView separately for the slices
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers authored and Djadih committed May 20, 2024
1 parent 0d156e9 commit 4ae4b91
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
12 changes: 7 additions & 5 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion p2p/pb/proto_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions quai/p2p_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4ae4b91

Please sign in to comment.