kaspanet / kaspad

Kaspad is the reference full node Kaspa implementation written in Go (golang).
ISC License
440 stars 227 forks source link

GetBlock grpc method response error block data #2272

Open HankPavel opened 3 months ago

HankPavel commented 3 months ago

Issue

wantBlockHash := "cd5beae67b3b469ff1633a4431ef9774d3d476ccc02ee4cce0b010ac62c718c5"
block, err := grpcSrv.GetBlock(wantBlockHash, true)
if err != nil {
   panic(err) // err == nil
}
fmt.Println(block.VerboseData.Hash == wantBlockHash) 
// output: false

fmt.Println(block.VerboseData.Hash)                                  
// output: 8713cde9f70c39c76c2bd133dd2576947d1c659e0b0b7111745e4e639c590f7c

The block returned by the grpcMethod is not specified by the HASH parameter

Env

kaspad version: v0.12.15 system version: Ubuntu 20.04.3 LTS

How to solve it?

now, restart node program or my program, this problem can fixed temporary.

How to solve this problem once and for all?

HankPavel commented 3 months ago

Maybe the bug is here:

// DequeueWithTimeout attempts to dequeue a message from the Route
// and returns an error if the given timeout expires first.
func (r *Route) DequeueWithTimeout(timeout time.Duration) (appmessage.Message, error) {
    select {
    case <-time.After(timeout): // timeout=5s
        return nil, errors.Wrapf(ErrTimeout, "route '%s' got timeout after %s", r.name, timeout)
    case message, isOpen := <-r.channel:
        if !isOpen {
            return nil, errors.WithStack(ErrRouteClosed)
        }
        return message, nil
    }
}

If GetBlock by blockHash escaped 5.1s, current grpc request return with timeout err, and the server response(BlockInfo) would stay in the r.channel util next Dequeue().

so, we can see a situation:

this is the same as what we see in the log: call GetBlock(hash2) method, but got Block(the hash eq hash1) response.