Fixed get-payload and Hanging ForkChoice (#3575)

* done

* removed sleep

* f

* errors.Is(err, io.EOF) instead of err == io.EOF

Co-authored-by: yperbasis <andrey.ashikhmin@gmail.com>
This commit is contained in:
Giulio rebuffo 2022-02-22 14:47:23 +01:00 committed by GitHub
parent 266625f56a
commit b49381821f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"errors"
"fmt"
"io"
"reflect"
@ -160,7 +161,7 @@ func (ff *Filters) subscribeToPendingTransactions(ctx context.Context, txPool tx
}
for {
event, err := subscription.Recv()
if err == io.EOF {
if errors.Is(err, io.EOF) {
log.Info("rpcdaemon: the subscription channel was closed")
break
}
@ -186,7 +187,7 @@ func (ff *Filters) subscribeToPendingBlocks(ctx context.Context, mining txpool.M
}
event, err := subscription.Recv()
if err == io.EOF {
if errors.Is(err, io.EOF) {
log.Info("rpcdaemon: the subscription channel was closed")
break
}
@ -230,7 +231,7 @@ func (ff *Filters) subscribeToPendingLogs(ctx context.Context, mining txpool.Min
}
event, err := subscription.Recv()
if err == io.EOF {
if errors.Is(err, io.EOF) {
log.Info("rpcdaemon: the subscription channel was closed")
break
}

View File

@ -144,7 +144,7 @@ func (back *RemoteBackend) Subscribe(ctx context.Context, onNewEvent func(*remot
}
for {
event, err := subscription.Recv()
if err == io.EOF {
if errors.Is(err, io.EOF) {
log.Info("rpcdaemon: the subscription channel was closed")
break
}

View File

@ -229,7 +229,7 @@ func readASCII(buf []byte, r *bufio.Reader) (n int, err error) {
for ; n < len(buf); n++ {
buf[n], err = r.ReadByte()
switch {
case err == io.EOF || buf[n] < '!':
case errors.Is(err, io.EOF) || buf[n] < '!':
return n, nil
case err != nil:
return n, err
@ -243,7 +243,7 @@ func checkKeyFileEnd(r *bufio.Reader) error {
for i := 0; ; i++ {
b, err := r.ReadByte()
switch {
case err == io.EOF:
case errors.Is(err, io.EOF):
return nil
case err != nil:
return err

View File

@ -193,8 +193,14 @@ func HeadersPOS(
select {
case <-ctx.Done():
cfg.hd.PayloadStatusCh <- privateapi.PayloadStatus{CriticalError: errors.New("server is stopping")}
if !useExternalTx {
return tx.Commit()
}
return nil
case <-cfg.hd.SkipCycleHack:
if !useExternalTx {
return tx.Commit()
}
return nil
case forkChoiceMessage = <-cfg.forkChoiceCh:
forkChoiceInsteadOfNewPayload = true

View File

@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"io"
"math/big"
"time"
@ -129,6 +130,10 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
}
txs, err = types.DecodeTransactions(txSlots.Txs)
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
return fmt.Errorf("decode rlp of pending txs: %w", err)
}

View File

@ -20,6 +20,7 @@ import (
"archive/tar"
"archive/zip"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
@ -215,7 +216,7 @@ func extractTarball(ar io.Reader, dest string) error {
// Move to the next file header.
header, err := tr.Next()
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
return nil
}
return err

View File

@ -1057,7 +1057,7 @@ func (s *Stream) readFull(buf []byte) (err error) {
nn, err = s.r.Read(buf[n:])
n += nn
}
if err == io.EOF {
if errors.Is(err, io.EOF) {
if n < len(buf) {
err = io.ErrUnexpectedEOF
} else {
@ -1074,7 +1074,7 @@ func (s *Stream) readByte() (byte, error) {
return 0, err
}
b, err := s.r.ReadByte()
if err == io.EOF {
if errors.Is(err, io.EOF) {
err = io.ErrUnexpectedEOF
}
return b, err

View File

@ -422,7 +422,7 @@ func TestEncodeToReaderPiecewise(t *testing.T) {
}
n, err := r.Read(output[start:end])
end = start + n
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
} else if err != nil {
return nil, err

View File

@ -284,7 +284,7 @@ func parsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]
var args []reflect.Value
tok, err := dec.Token()
switch {
case err == io.EOF || tok == nil && err == nil:
case errors.Is(err, io.EOF) || tok == nil && err == nil:
// "params" is optional and may be empty. Also allow "params":null even though it's
// not in the spec because our own client used to send it.
case err != nil:

View File

@ -3,6 +3,7 @@ package app
import (
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"os"
@ -122,7 +123,7 @@ func ImportChain(ethereum *eth.Ethereum, chainDB kv.RwDB, fn string) error {
i := 0
for ; i < importBatchSize; i++ {
var b types.Block
if err := stream.Decode(&b); err == io.EOF {
if err := stream.Decode(&b); errors.Is(err, io.EOF) {
break
} else if err != nil {
return fmt.Errorf("at block %d: %v", n, err)

View File

@ -2,6 +2,7 @@ package trie
import (
"bytes"
"errors"
"fmt"
"io"
)
@ -84,7 +85,7 @@ func NewWitnessFromReader(input io.Reader, trace bool) (*Witness, error) {
var err error
operands := make([]WitnessOperator, 0)
for _, err = input.Read(opcode); ; _, err = input.Read(opcode) {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {