Skip to content

Commit

Permalink
Fixed hive test on invalid transition payload (#4618)
Browse files Browse the repository at this point in the history
* experiment #1

* experiment #2

* experiment #3

* experiment 4
  • Loading branch information
Giulio2002 committed Jul 3, 2022
1 parent c422b8c commit b980280
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
32 changes: 24 additions & 8 deletions cmd/rpcdaemon/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,25 @@ func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *F
return nil, err
}

payloadStatus := convertPayloadStatus(reply.PayloadStatus)
if reply.PayloadStatus.Status == remote.EngineStatus_INVALID && payloadStatus["latestValidHash"] != nil {
tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()
latestValidHash := payloadStatus["latestValidHash"].(common.Hash)
isValidHashPos, err := rawdb.IsPosBlock(tx, latestValidHash)
if err != nil {
return nil, err
}
if !isValidHashPos {
payloadStatus["latestValidHash"] = common.Hash{}
}
}
json := map[string]interface{}{
"payloadStatus": convertPayloadStatus(reply.PayloadStatus),
"payloadStatus": payloadStatus,
}
if reply.PayloadId != 0 {
encodedPayloadId := make([]byte, 8)
Expand All @@ -128,13 +145,6 @@ func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *F
func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload) (map[string]interface{}, error) {
log.Trace("Received NewPayload", "height", uint64(payload.BlockNumber), "hash", payload.BlockHash)

tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()

var baseFee *uint256.Int
if payload.BaseFeePerGas != nil {
var overflow bool
Expand Down Expand Up @@ -172,6 +182,12 @@ func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload
}
payloadStatus := convertPayloadStatus(res)
if payloadStatus["latestValidHash"] != nil {
tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()
latestValidHash := payloadStatus["latestValidHash"].(common.Hash)
isValidHashPos, err := rawdb.IsPosBlock(tx, latestValidHash)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,9 @@ func (hi *HeaderInserter) FeedHeaderPoS(db kv.GetPut, header *types.Header, hash
return fmt.Errorf("[%s] failed to WriteTd: %w", hi.logPrefix, err)
}
rawdb.WriteHeader(db, header)
if err = rawdb.WriteHeaderNumber(db, hash, blockHeight); err != nil {
return err
}

hi.highest = blockHeight
hi.highestHash = hash
Expand Down

0 comments on commit b980280

Please sign in to comment.